diff --git a/registry/etcdv3/listener_test.go b/registry/etcdv3/listener_test.go index 2c3da4b249160b2df2f81823a5cd8778ad757cca..4a805c31c3b229934b041a2588ea7e88c7126b94 100644 --- a/registry/etcdv3/listener_test.go +++ b/registry/etcdv3/listener_test.go @@ -12,7 +12,7 @@ import ( ) -func Test_StartEtcdServer(t *testing.T){ +func startETCDServer(t *testing.T){ cmd := exec.Command("./load.sh", "start") //cmd := exec.Command("pwd") @@ -26,7 +26,27 @@ func Test_StartEtcdServer(t *testing.T){ } +func stopETCDServer(t *testing.T){ + + cmd := exec.Command("./load.sh", "stop") + //cmd := exec.Command("pwd") + cmd.Stdout= os.Stdout + cmd.Stderr = os.Stdout + cmd.Dir = "../../remoting/etcdv3/single" + + if err := cmd.Run(); err != nil{ + t.Fatal(err) + } + +} + + func Test_DataChange(t *testing.T) { + + + startETCDServer(t) + defer stopETCDServer(t) + listener := NewRegistryDataListener(&MockDataListener{}) url, _ := common.NewURL(context.TODO(), "jsonrpc%3A%2F%2F127.0.0.1%3A20001%2Fcom.ikurento.user.UserProvider%3Fanyhost%3Dtrue%26app.version%3D0.0.1%26application%3DBDTService%26category%3Dproviders%26cluster%3Dfailover%26dubbo%3Ddubbo-provider-golang-2.6.0%26environment%3Ddev%26group%3D%26interface%3Dcom.ikurento.user.UserProvider%26ip%3D10.32.20.124%26loadbalance%3Drandom%26methods.GetUser.loadbalance%3Drandom%26methods.GetUser.retries%3D1%26methods.GetUser.weight%3D0%26module%3Ddubbogo%2Buser-info%2Bserver%26name%3DBDTService%26organization%3Dikurento.com%26owner%3DZX%26pid%3D74500%26retries%3D0%26service.filter%3Decho%26side%3Dprovider%26timestamp%3D1560155407%26version%3D%26warmup%3D100") listener.AddInterestedURL(&url) diff --git a/registry/etcdv3/registry_test.go b/registry/etcdv3/registry_test.go index 3912fc95c694853a855ebcb8c6eab8b26c6a5577..7c69f4d31e8ba68f11b2f7f16aa32590ec3c4aa8 100644 --- a/registry/etcdv3/registry_test.go +++ b/registry/etcdv3/registry_test.go @@ -2,8 +2,6 @@ package etcdv3 import ( "context" - "os" - "os/exec" "strconv" "testing" "time" @@ -36,6 +34,10 @@ func initRegistry(t *testing.T) *etcdV3Registry { } func Test_Register(t *testing.T) { + + startETCDServer(t) + defer stopETCDServer(t) + url, _ := common.NewURL(context.TODO(), "dubbo://127.0.0.1:20000/com.ikurento.user.UserProvider", common.WithParamsValue(constant.CLUSTER_KEY, "mock"), common.WithMethods([]string{"GetUser", "AddUser"})) reg := initRegistry(t) @@ -50,6 +52,9 @@ func Test_Register(t *testing.T) { func Test_Subscribe(t *testing.T) { + startETCDServer(t) + defer stopETCDServer(t) + regurl, _ := common.NewURL(context.TODO(), "registry://127.0.0.1:1111", common.WithParamsValue(constant.ROLE_KEY, strconv.Itoa(common.PROVIDER))) url, _ := common.NewURL(context.TODO(), "dubbo://127.0.0.1:20000/com.ikurento.user.UserProvider", common.WithParamsValue(constant.CLUSTER_KEY, "mock"), common.WithMethods([]string{"GetUser", "AddUser"})) @@ -78,6 +83,10 @@ func Test_Subscribe(t *testing.T) { } func Test_ConsumerDestory(t *testing.T) { + + startETCDServer(t) + defer stopETCDServer(t) + url, _ := common.NewURL(context.TODO(), "dubbo://127.0.0.1:20000/com.ikurento.user.UserProvider", common.WithParamsValue(constant.CLUSTER_KEY, "mock"), common.WithMethods([]string{"GetUser", "AddUser"})) reg := initRegistry(t) @@ -96,6 +105,10 @@ func Test_ConsumerDestory(t *testing.T) { func Test_ProviderDestory(t *testing.T) { + + startETCDServer(t) + defer stopETCDServer(t) + reg := initRegistry(t) url, _ := common.NewURL(context.TODO(), "dubbo://127.0.0.1:20000/com.ikurento.user.UserProvider", common.WithParamsValue(constant.CLUSTER_KEY, "mock"), common.WithMethods([]string{"GetUser", "AddUser"})) reg.Register(url) @@ -107,17 +120,3 @@ func Test_ProviderDestory(t *testing.T) { } -func Test_StopEtcdServer(t *testing.T){ - - cmd := exec.Command("./load.sh", "stop") - //cmd := exec.Command("pwd") - cmd.Stdout= os.Stdout - cmd.Stderr = os.Stdout - cmd.Dir = "../../remoting/etcdv3/single" - - if err := cmd.Run(); err != nil{ - t.Fatal(err) - } - -} - diff --git a/remoting/etcdv3/client_test.go b/remoting/etcdv3/client_test.go index d484bca8a4af9549671c13481a2a3ce162399509..f3b44797ed81d495e713f9900b87c021f9f60c4c 100644 --- a/remoting/etcdv3/client_test.go +++ b/remoting/etcdv3/client_test.go @@ -61,12 +61,24 @@ func initClient(t *testing.T) *Client { return c } -func Test_StartEtcdServer(t *testing.T){ +func startETCDServer(t *testing.T){ + cmd := exec.Command("./load.sh", "start") cmd.Stdout= os.Stdout cmd.Stderr = os.Stdout cmd.Dir = "./single" + if err := cmd.Run(); err != nil{ + t.Fatal(err) + } +} + +func stopETCDServer(t *testing.T){ + cmd := exec.Command("./load.sh", "stop") + cmd.Stdout= os.Stdout + cmd.Stderr = os.Stdout + cmd.Dir = "./single" + if err := cmd.Run(); err != nil{ t.Fatal(err) } @@ -75,6 +87,9 @@ func Test_StartEtcdServer(t *testing.T){ func Test_newClient(t *testing.T) { + startETCDServer(t) + defer stopETCDServer(t) + c := initClient(t) defer c.Close() @@ -85,12 +100,18 @@ func Test_newClient(t *testing.T) { func TestClient_Close(t *testing.T) { + startETCDServer(t) + defer stopETCDServer(t) + c := initClient(t) c.Close() } func TestClient_Create(t *testing.T) { + startETCDServer(t) + defer stopETCDServer(t) + tests := tests c := initClient(t) @@ -122,6 +143,9 @@ func TestClient_Create(t *testing.T) { func TestClient_Delete(t *testing.T) { + startETCDServer(t) + defer stopETCDServer(t) + tests := tests c := initClient(t) @@ -155,6 +179,9 @@ func TestClient_Delete(t *testing.T) { func TestClient_GetChildrenKVList(t *testing.T) { + startETCDServer(t) + defer stopETCDServer(t) + tests := tests c := initClient(t) @@ -193,6 +220,9 @@ func TestClient_GetChildrenKVList(t *testing.T) { func TestClient_Watch(t *testing.T) { + startETCDServer(t) + defer stopETCDServer(t) + tests := tests c := initClient(t) @@ -245,6 +275,9 @@ func TestClient_Watch(t *testing.T) { func TestClient_RegisterTemp(t *testing.T) { + startETCDServer(t) + defer stopETCDServer(t) + c := initClient(t) observeC := initClient(t) @@ -289,6 +322,9 @@ func TestClient_RegisterTemp(t *testing.T) { func TestClient_Valid(t *testing.T) { + startETCDServer(t) + defer stopETCDServer(t) + c := initClient(t) if c.Valid() != true { @@ -307,6 +343,10 @@ func TestClient_Valid(t *testing.T) { func TestClient_Done(t *testing.T) { + + startETCDServer(t) + defer stopETCDServer(t) + c := initClient(t) go func() { diff --git a/remoting/etcdv3/facede_test.go b/remoting/etcdv3/facede_test.go index 590d30dc2fade430ce4d2f961e008faac8718042..d7ba1cef7b48eb6de680834cd460c5174f57005e 100644 --- a/remoting/etcdv3/facede_test.go +++ b/remoting/etcdv3/facede_test.go @@ -55,6 +55,9 @@ func (r *mockFacade) IsAvailable() bool { func Test_Fascade(t *testing.T) { + startETCDServer(t) + defer stopETCDServer(t) + c := initClient(t) url, err := common.NewURL(context.Background(), "mock://127.0.0.1:2379") diff --git a/remoting/etcdv3/listener_test.go b/remoting/etcdv3/listener_test.go index b675b892fac0db14127a67883bb69daeadddb9e0..93f3d225a7cfa77b4d46c19b575d2ea2a7bb15e5 100644 --- a/remoting/etcdv3/listener_test.go +++ b/remoting/etcdv3/listener_test.go @@ -1,8 +1,6 @@ package etcdv3 import ( - "os" - "os/exec" "testing" "time" @@ -34,6 +32,9 @@ var changedData = ` func TestListener(t *testing.T) { + startETCDServer(t) + defer stopETCDServer(t) + var tests = []struct { input struct { k string @@ -85,14 +86,3 @@ func (m *mockDataListener) DataChange(eventType remoting.Event) bool { return true } -func Test_StopEtcdServer(t *testing.T){ - cmd := exec.Command("./load.sh", "stop") - cmd.Stdout= os.Stdout - cmd.Stderr = os.Stdout - cmd.Dir = "./single" - - if err := cmd.Run(); err != nil{ - t.Fatal(err) - } - -}