-
Notifications
You must be signed in to change notification settings - Fork 930
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Imp: Zk client #601
Imp: Zk client #601
Changes from 6 commits
b815070
efd2305
2398d20
4f382b0
a7c2c8b
e6c92b9
df758dc
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,14 +18,17 @@ | |
package zookeeper | ||
|
||
import ( | ||
"fmt" | ||
"testing" | ||
"time" | ||
) | ||
|
||
import ( | ||
"github.com/dubbogo/go-zookeeper/zk" | ||
"github.com/stretchr/testify/assert" | ||
"github.com/stretchr/testify/require" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think u can rollback the testify/require to testify/assert package. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. an examplefunc TestSomething(t *testing.T) {
var err error
err = perrors.Errorf("something1")
assert.NoError(t, err)
err = perrors.Errorf("something2")
assert.NoError(t, err)
}
why I prefer
|
||
) | ||
|
||
import ( | ||
"github.com/apache/dubbo-go/common/logger" | ||
) | ||
|
||
func verifyEventStateOrder(t *testing.T, c <-chan zk.Event, expectedStates []zk.State, source string) { | ||
|
@@ -35,7 +38,7 @@ func verifyEventStateOrder(t *testing.T, c <-chan zk.Event, expectedStates []zk. | |
if !ok { | ||
t.Fatalf("unexpected channel close for %s", source) | ||
} | ||
fmt.Println(event) | ||
logger.Debug(event) | ||
if event.Type != zk.EventSession { | ||
continue | ||
} | ||
|
@@ -77,7 +80,7 @@ func verifyEventStateOrder(t *testing.T, c <-chan zk.Event, expectedStates []zk. | |
|
||
func Test_newMockZookeeperClient(t *testing.T) { | ||
ts, z, event, err := NewMockZookeeperClient("test", 15*time.Second) | ||
assert.NoError(t, err) | ||
require.NoError(t, err) | ||
defer ts.Stop() | ||
states := []zk.State{zk.StateConnecting, zk.StateConnected, zk.StateHasSession} | ||
verifyEventStateOrder(t, event, states, "event channel") | ||
|
@@ -87,49 +90,53 @@ func Test_newMockZookeeperClient(t *testing.T) { | |
} | ||
|
||
func TestCreate(t *testing.T) { | ||
ts, z, event, _ := NewMockZookeeperClient("test", 15*time.Second) | ||
ts, z, event, err := NewMockZookeeperClient("test", 15*time.Second) | ||
require.NoError(t, err) | ||
defer ts.Stop() | ||
err := z.Create("test1/test2/test3/test4") | ||
assert.NoError(t, err) | ||
err = z.Create("test1/test2/test3/test4") | ||
require.NoError(t, err) | ||
|
||
states := []zk.State{zk.StateConnecting, zk.StateConnected, zk.StateHasSession} | ||
verifyEventStateOrder(t, event, states, "event channel") | ||
} | ||
|
||
func TestCreateDelete(t *testing.T) { | ||
ts, z, event, _ := NewMockZookeeperClient("test", 15*time.Second) | ||
ts, z, event, err := NewMockZookeeperClient("test", 15*time.Second) | ||
require.NoError(t, err) | ||
defer ts.Stop() | ||
|
||
states := []zk.State{zk.StateConnecting, zk.StateConnected, zk.StateHasSession} | ||
verifyEventStateOrder(t, event, states, "event channel") | ||
err := z.Create("/test1/test2/test3/test4") | ||
assert.NoError(t, err) | ||
err2 := z.Delete("/test1/test2/test3/test4") | ||
assert.NoError(t, err2) | ||
//verifyEventOrder(t, event, []zk.EventType{zk.EventNodeCreated}, "event channel") | ||
err = z.Create("/test1/test2/test3/test4") | ||
require.NoError(t, err) | ||
err = z.Delete("/test1/test2/test3/test4") | ||
require.NoError(t, err) | ||
// verifyEventOrder(t, event, []zk.EventType{zk.EventNodeCreated}, "event channel") | ||
} | ||
|
||
func TestRegisterTemp(t *testing.T) { | ||
ts, z, event, _ := NewMockZookeeperClient("test", 15*time.Second) | ||
ts, z, event, err := NewMockZookeeperClient("test", 15*time.Second) | ||
require.NoError(t, err) | ||
defer ts.Stop() | ||
err := z.Create("/test1/test2/test3") | ||
assert.NoError(t, err) | ||
err = z.Create("/test1/test2/test3") | ||
require.NoError(t, err) | ||
|
||
tmpath, err := z.RegisterTemp("/test1/test2/test3", "test4") | ||
assert.NoError(t, err) | ||
assert.Equal(t, "/test1/test2/test3/test4", tmpath) | ||
require.NoError(t, err) | ||
require.Equal(t, "/test1/test2/test3/test4", tmpath) | ||
states := []zk.State{zk.StateConnecting, zk.StateConnected, zk.StateHasSession} | ||
verifyEventStateOrder(t, event, states, "event channel") | ||
} | ||
|
||
func TestRegisterTempSeq(t *testing.T) { | ||
ts, z, event, _ := NewMockZookeeperClient("test", 15*time.Second) | ||
ts, z, event, err := NewMockZookeeperClient("test", 15*time.Second) | ||
require.NoError(t, err) | ||
defer ts.Stop() | ||
err := z.Create("/test1/test2/test3") | ||
assert.NoError(t, err) | ||
err = z.Create("/test1/test2/test3") | ||
require.NoError(t, err) | ||
tmpath, err := z.RegisterTempSeq("/test1/test2/test3", []byte("test")) | ||
assert.NoError(t, err) | ||
assert.Equal(t, "/test1/test2/test3/0000000000", tmpath) | ||
require.NoError(t, err) | ||
require.Equal(t, "/test1/test2/test3/0000000000", tmpath) | ||
states := []zk.State{zk.StateConnecting, zk.StateConnected, zk.StateHasSession} | ||
verifyEventStateOrder(t, event, states, "event channel") | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maybe u can add some comments for this struct or just using "nolint" instead.