Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gostnops
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
wei.xuan
gostnops
Commits
2f58aadc
Commit
2f58aadc
authored
Feb 10, 2021
by
ztelur
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
1 solve test may fail problem
2 refactor etcd package dir and name
parent
9031b2c6
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
114 additions
and
124 deletions
+114
-124
client.go
database/kv/etcd/v3/client.go
+2
-52
client_test.go
database/kv/etcd/v3/client_test.go
+56
-72
options.go
database/kv/etcd/v3/options.go
+56
-0
No files found.
remoting/etcd
3/client.go
→
database/kv/etcd/v
3/client.go
View file @
2f58aadc
...
@@ -15,7 +15,7 @@
...
@@ -15,7 +15,7 @@
* limitations under the License.
* limitations under the License.
*/
*/
package
etcdv3
package
gxetcd
import
(
import
(
"context"
"context"
...
@@ -31,17 +31,6 @@ import (
...
@@ -31,17 +31,6 @@ import (
"google.golang.org/grpc"
"google.golang.org/grpc"
)
)
const
(
// ConnDelay connection delay
ConnDelay
=
3
// MaxFailTimes max failure times
MaxFailTimes
=
15
// RegistryETCDV3Client client name
RegistryETCDV3Client
=
"etcd registry"
// MetadataETCDV3Client client name
MetadataETCDV3Client
=
"etcd metadata"
)
var
(
var
(
// ErrNilETCDV3Client raw client nil
// ErrNilETCDV3Client raw client nil
ErrNilETCDV3Client
=
perrors
.
New
(
"etcd raw client is nil"
)
// full describe the ERR
ErrNilETCDV3Client
=
perrors
.
New
(
"etcd raw client is nil"
)
// full describe the ERR
...
@@ -49,46 +38,6 @@ var (
...
@@ -49,46 +38,6 @@ var (
ErrKVPairNotFound
=
perrors
.
New
(
"k/v pair not found"
)
ErrKVPairNotFound
=
perrors
.
New
(
"k/v pair not found"
)
)
)
// Options client configuration
type
Options
struct
{
name
string
endpoints
[]
string
client
*
Client
timeout
time
.
Duration
heartbeat
int
// heartbeat second
}
// Option will define a function of handling Options
type
Option
func
(
*
Options
)
// WithEndpoints sets etcd client endpoints
func
WithEndpoints
(
endpoints
...
string
)
Option
{
return
func
(
opt
*
Options
)
{
opt
.
endpoints
=
endpoints
}
}
// WithName sets etcd client name
func
WithName
(
name
string
)
Option
{
return
func
(
opt
*
Options
)
{
opt
.
name
=
name
}
}
// WithTimeout sets etcd client timeout
func
WithTimeout
(
timeout
time
.
Duration
)
Option
{
return
func
(
opt
*
Options
)
{
opt
.
timeout
=
timeout
}
}
// WithHeartbeat sets etcd client heartbeat
func
WithHeartbeat
(
heartbeat
int
)
Option
{
return
func
(
opt
*
Options
)
{
opt
.
heartbeat
=
heartbeat
}
}
// NewConfigClient create new Client
// NewConfigClient create new Client
func
NewConfigClient
(
opts
...
Option
)
*
Client
{
func
NewConfigClient
(
opts
...
Option
)
*
Client
{
options
:=
&
Options
{
options
:=
&
Options
{
...
@@ -134,6 +83,7 @@ func NewClient(name string, endpoints []string, timeout time.Duration, heartbeat
...
@@ -134,6 +83,7 @@ func NewClient(name string, endpoints []string, timeout time.Duration, heartbeat
DialTimeout
:
timeout
,
DialTimeout
:
timeout
,
DialOptions
:
[]
grpc
.
DialOption
{
grpc
.
WithBlock
()},
DialOptions
:
[]
grpc
.
DialOption
{
grpc
.
WithBlock
()},
})
})
if
err
!=
nil
{
if
err
!=
nil
{
cancel
()
cancel
()
return
nil
,
perrors
.
WithMessage
(
err
,
"new raw client block connect to server"
)
return
nil
,
perrors
.
WithMessage
(
err
,
"new raw client block connect to server"
)
...
...
remoting/etcd
3/client_test.go
→
database/kv/etcd/v
3/client_test.go
View file @
2f58aadc
...
@@ -15,7 +15,7 @@
...
@@ -15,7 +15,7 @@
* limitations under the License.
* limitations under the License.
*/
*/
package
etcdv3
package
gxetcd
import
(
import
(
"net/url"
"net/url"
...
@@ -23,7 +23,6 @@ import (
...
@@ -23,7 +23,6 @@ import (
"path"
"path"
"reflect"
"reflect"
"strings"
"strings"
"sync"
"testing"
"testing"
"time"
"time"
)
)
...
@@ -289,12 +288,24 @@ func (suite *ClientTestSuite) TestClientWatch() {
...
@@ -289,12 +288,24 @@ func (suite *ClientTestSuite) TestClientWatch() {
c
:=
suite
.
client
c
:=
suite
.
client
t
:=
suite
.
T
()
t
:=
suite
.
T
()
wg
:=
sync
.
WaitGroup
{}
wg
.
Add
(
1
)
go
func
()
{
go
func
()
{
time
.
Sleep
(
time
.
Second
)
for
_
,
tc
:=
range
tests
{
k
:=
tc
.
input
.
k
v
:=
tc
.
input
.
v
if
err
:=
c
.
Create
(
k
,
v
);
err
!=
nil
{
t
.
Fatal
(
err
)
}
if
err
:=
c
.
delete
(
k
);
err
!=
nil
{
t
.
Fatal
(
err
)
}
}
defer
wg
.
Done
()
c
.
Close
()
}()
wc
,
err
:=
c
.
watch
(
prefix
)
wc
,
err
:=
c
.
watch
(
prefix
)
if
err
!=
nil
{
if
err
!=
nil
{
...
@@ -321,25 +332,6 @@ func (suite *ClientTestSuite) TestClientWatch() {
...
@@ -321,25 +332,6 @@ func (suite *ClientTestSuite) TestClientWatch() {
assert
.
Equal
(
t
,
2
,
len
(
events
))
assert
.
Equal
(
t
,
2
,
len
(
events
))
assert
.
Contains
(
t
,
events
,
eCreate
)
assert
.
Contains
(
t
,
events
,
eCreate
)
assert
.
Contains
(
t
,
events
,
eDelete
)
assert
.
Contains
(
t
,
events
,
eDelete
)
}()
for
_
,
tc
:=
range
tests
{
k
:=
tc
.
input
.
k
v
:=
tc
.
input
.
v
if
err
:=
c
.
Create
(
k
,
v
);
err
!=
nil
{
t
.
Fatal
(
err
)
}
if
err
:=
c
.
delete
(
k
);
err
!=
nil
{
t
.
Fatal
(
err
)
}
}
c
.
Close
()
wg
.
Wait
()
}
}
...
@@ -349,11 +341,14 @@ func (suite *ClientTestSuite) TestClientRegisterTemp() {
...
@@ -349,11 +341,14 @@ func (suite *ClientTestSuite) TestClientRegisterTemp() {
observeC
:=
suite
.
setUpClient
()
observeC
:=
suite
.
setUpClient
()
t
:=
suite
.
T
()
t
:=
suite
.
T
()
wg
:=
sync
.
WaitGroup
{}
wg
.
Add
(
1
)
go
func
()
{
go
func
()
{
defer
wg
.
Done
()
time
.
Sleep
(
2
*
time
.
Second
)
err
:=
c
.
RegisterTemp
(
"scott/wang"
,
"test"
)
if
err
!=
nil
{
t
.
Fatal
(
err
)
}
c
.
Close
()
}()
completePath
:=
path
.
Join
(
"scott"
,
"wang"
)
completePath
:=
path
.
Join
(
"scott"
,
"wang"
)
wc
,
err
:=
observeC
.
watch
(
completePath
)
wc
,
err
:=
observeC
.
watch
(
completePath
)
...
@@ -382,17 +377,6 @@ func (suite *ClientTestSuite) TestClientRegisterTemp() {
...
@@ -382,17 +377,6 @@ func (suite *ClientTestSuite) TestClientRegisterTemp() {
assert
.
Equal
(
t
,
2
,
len
(
events
))
assert
.
Equal
(
t
,
2
,
len
(
events
))
assert
.
Contains
(
t
,
events
,
eCreate
)
assert
.
Contains
(
t
,
events
,
eCreate
)
assert
.
Contains
(
t
,
events
,
eDelete
)
assert
.
Contains
(
t
,
events
,
eDelete
)
}()
err
:=
c
.
RegisterTemp
(
"scott/wang"
,
"test"
)
if
err
!=
nil
{
t
.
Fatal
(
err
)
}
time
.
Sleep
(
2
*
time
.
Second
)
c
.
Close
()
wg
.
Wait
()
}
}
func
TestClientSuite
(
t
*
testing
.
T
)
{
func
TestClientSuite
(
t
*
testing
.
T
)
{
...
...
database/kv/etcd/v3/options.go
0 → 100644
View file @
2f58aadc
package
gxetcd
import
(
"time"
)
const
(
// ConnDelay connection delay
ConnDelay
=
3
// MaxFailTimes max failure times
MaxFailTimes
=
15
// RegistryETCDV3Client client name
RegistryETCDV3Client
=
"etcd registry"
// MetadataETCDV3Client client name
MetadataETCDV3Client
=
"etcd metadata"
)
// Options client configuration
type
Options
struct
{
name
string
endpoints
[]
string
client
*
Client
timeout
time
.
Duration
heartbeat
int
// heartbeat second
}
// Option will define a function of handling Options
type
Option
func
(
*
Options
)
// WithEndpoints sets etcd client endpoints
func
WithEndpoints
(
endpoints
...
string
)
Option
{
return
func
(
opt
*
Options
)
{
opt
.
endpoints
=
endpoints
}
}
// WithName sets etcd client name
func
WithName
(
name
string
)
Option
{
return
func
(
opt
*
Options
)
{
opt
.
name
=
name
}
}
// WithTimeout sets etcd client timeout
func
WithTimeout
(
timeout
time
.
Duration
)
Option
{
return
func
(
opt
*
Options
)
{
opt
.
timeout
=
timeout
}
}
// WithHeartbeat sets etcd client heartbeat
func
WithHeartbeat
(
heartbeat
int
)
Option
{
return
func
(
opt
*
Options
)
{
opt
.
heartbeat
=
heartbeat
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment