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
78d3ccf2
Unverified
Commit
78d3ccf2
authored
Feb 10, 2021
by
randy
Committed by
GitHub
Feb 10, 2021
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #2 from ztelur/refactor
1 solve test may fail problem
parents
9031b2c6
2f58aadc
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 @
78d3ccf2
...
...
@@ -15,7 +15,7 @@
* limitations under the License.
*/
package
etcdv3
package
gxetcd
import
(
"context"
...
...
@@ -31,17 +31,6 @@ import (
"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
(
// ErrNilETCDV3Client raw client nil
ErrNilETCDV3Client
=
perrors
.
New
(
"etcd raw client is nil"
)
// full describe the ERR
...
...
@@ -49,46 +38,6 @@ var (
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
func
NewConfigClient
(
opts
...
Option
)
*
Client
{
options
:=
&
Options
{
...
...
@@ -134,6 +83,7 @@ func NewClient(name string, endpoints []string, timeout time.Duration, heartbeat
DialTimeout
:
timeout
,
DialOptions
:
[]
grpc
.
DialOption
{
grpc
.
WithBlock
()},
})
if
err
!=
nil
{
cancel
()
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 @
78d3ccf2
...
...
@@ -15,7 +15,7 @@
* limitations under the License.
*/
package
etcdv3
package
gxetcd
import
(
"net/url"
...
...
@@ -23,7 +23,6 @@ import (
"path"
"reflect"
"strings"
"sync"
"testing"
"time"
)
...
...
@@ -289,12 +288,24 @@ func (suite *ClientTestSuite) TestClientWatch() {
c
:=
suite
.
client
t
:=
suite
.
T
()
wg
:=
sync
.
WaitGroup
{}
wg
.
Add
(
1
)
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
)
if
err
!=
nil
{
...
...
@@ -321,25 +332,6 @@ func (suite *ClientTestSuite) TestClientWatch() {
assert
.
Equal
(
t
,
2
,
len
(
events
))
assert
.
Contains
(
t
,
events
,
eCreate
)
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() {
observeC
:=
suite
.
setUpClient
()
t
:=
suite
.
T
()
wg
:=
sync
.
WaitGroup
{}
wg
.
Add
(
1
)
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"
)
wc
,
err
:=
observeC
.
watch
(
completePath
)
...
...
@@ -382,17 +377,6 @@ func (suite *ClientTestSuite) TestClientRegisterTemp() {
assert
.
Equal
(
t
,
2
,
len
(
events
))
assert
.
Contains
(
t
,
events
,
eCreate
)
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
)
{
...
...
database/kv/etcd/v3/options.go
0 → 100644
View file @
78d3ccf2
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