From f5fda9fc321bbd29eef19f653ba5d157b76a83b1 Mon Sep 17 00:00:00 2001 From: fanqq Date: Mon, 1 Jun 2015 18:10:54 +0800 Subject: [PATCH] update test --- .../zeus/integration/IntegrationTest.java | 67 +++++++++++++++---- .../com/ctrip/zeus/nginx/ConfWriterTest.java | 5 +- .../com/ctrip/zeus/nginx/ServerConfTest.java | 17 +++-- .../ctrip/zeus/nginx/UpstreamsConfTest.java | 17 +++-- .../com/ctrip/zeus/service/StatusTest.java | 35 ++++------ 5 files changed, 92 insertions(+), 49 deletions(-) diff --git a/src/test/java/com/ctrip/zeus/integration/IntegrationTest.java b/src/test/java/com/ctrip/zeus/integration/IntegrationTest.java index ae742f5e..c3a150c0 100644 --- a/src/test/java/com/ctrip/zeus/integration/IntegrationTest.java +++ b/src/test/java/com/ctrip/zeus/integration/IntegrationTest.java @@ -21,10 +21,10 @@ import java.util.List; */ public class IntegrationTest { -// private static final String host = "http://10.2.25.83:8099"; + private static final String host = "http://10.2.27.21:8099"; - private static final String host = "http://127.0.0.1:8099"; - private static final String hostip = "10.2.25.83"; +// private static final String host = "http://127.0.0.1:8099"; + private static final String hostip = "10.2.27.21"; private static final String slb1_server_0 = "10.2.25.83"; private static final String slb1_server_1 = "10.2.27.21"; private static final String slb1_server_2 = "10.2.25.96"; @@ -35,30 +35,69 @@ public class IntegrationTest { @Before - public void before() { + public void before() throws IOException { + Group groupres = null; + String groupstr = null; for (int i = 1; i < 11; i++) { - reqClient.getstr("/api/app/delete?appName=__Test_app" + i); + groupstr = reqClient.getstr("/api/group/get/__Test_app"+i); + groupres = DefaultJsonParser.parse(Group.class, groupstr); + if (groupres!=null) + { + reqClient.getstr("/api/group/delete?groupId=" + groupres.getId()); + } } - reqClient.getstr("/api/slb/delete?slbName=" + slb1_name); - reqClient.getstr("/api/slb/delete?slbName=" + slb2_name); + + String slb_res = reqClient.getstr("/api/slb/get/" + slb1_name); + Slb slb_res_obj = DefaultJsonParser.parse(Slb.class, slb_res); + if (slb_res_obj!=null) + { + reqClient.getstr("/api/slb/delete?slbId=" + slb_res_obj.getId()); + } + + slb_res = reqClient.getstr("/api/slb/get/" + slb2_name); + slb_res_obj = DefaultJsonParser.parse(Slb.class, slb_res); + if (slb_res_obj!=null) + { + reqClient.getstr("/api/slb/delete?slbId=" + slb_res_obj.getId()); + } } @After - public void after() { + public void after() throws IOException { + + Group groupres = null; + String groupstr = null; for (int i = 1; i < 11; i++) { - reqClient.getstr("/api/app/delete?appName=__Test_app" + i); + groupstr = reqClient.getstr("/api/group/get/__Test_app"+i); + groupres = DefaultJsonParser.parse(Group.class, groupstr); + if (groupres!=null) + { + reqClient.getstr("/api/group/delete?groupId=" + groupres.getId()); + } } - reqClient.getstr("/api/slb/delete?slbName=" + slb1_name); - reqClient.getstr("/api/slb/delete?slbName=" + slb2_name); + + String slb_res = reqClient.getstr("/api/slb/get/" + slb1_name); + if (slb_res!=null) + { + Slb slb_res_obj = DefaultJsonParser.parse(Slb.class, slb_res); + reqClient.getstr("/api/slb/delete?slbId=" + slb_res_obj.getId()); + } + + slb_res = reqClient.getstr("/api/slb/get/" + slb2_name); + if (slb_res!=null) + { + Slb slb_res_obj = DefaultJsonParser.parse(Slb.class, slb_res); + reqClient.getstr("/api/slb/delete?slbId=" + slb_res_obj.getId()); + } - String res = reqClient.getstr("/api/app/get/__Test_app2"); + String res = reqClient.getstr("/api/group/get/__Test_app2"); Assert.assertEquals(true,res.isEmpty()); - reqClient.markPass("/api/app/delete"); + reqClient.markPass("/api/group/delete"); res = reqClient.getstr("/api/slb/get/" + slb2_name); Assert.assertEquals(true,res.isEmpty()); @@ -139,7 +178,7 @@ public class IntegrationTest { reqClient.markPass("/api/slb/get/"+ slb1_name); reqClient.markPass("/api/slb/get/"+ slb2_name); //activate test slbs - reqClient.getstr("/api/conf/activate?slbName=__Test_slb1&slbName=__Test_slb2"); + reqClient.getstr("/api/conf/activateByName?slbName=__Test_slb1&slbName=__Test_slb2"); List groups = new ArrayList<>(); for (int i = 0 ; i < 10 ; i++ ) diff --git a/src/test/java/com/ctrip/zeus/nginx/ConfWriterTest.java b/src/test/java/com/ctrip/zeus/nginx/ConfWriterTest.java index 69648c94..85074171 100644 --- a/src/test/java/com/ctrip/zeus/nginx/ConfWriterTest.java +++ b/src/test/java/com/ctrip/zeus/nginx/ConfWriterTest.java @@ -6,7 +6,6 @@ import com.ctrip.zeus.service.build.conf.ServerConf; import com.ctrip.zeus.service.build.conf.UpstreamsConf; import org.junit.Test; -import java.io.IOException; import java.util.ArrayList; import java.util.HashSet; import java.util.List; @@ -18,7 +17,7 @@ public class ConfWriterTest { String slbName = "default"; Slb slb = new Slb(); VirtualServer vs002 = new VirtualServer().setName("vs002").setPort("80").setSsl(false) - .addDomain(new Domain().setName("hotel.ctrip.com")); + .addDomain(new Domain().setName("hotel.ctrip.com")).setId(2L); slb.setName(slbName).setNginxBin("/usr/local/nginx/bin").setNginxConf("d:/nginx/conf").setNginxWorkerProcesses(1) .addVip(new Vip().setIp("192.168.1.3")) .addSlbServer(new SlbServer().setHostName("slb001a").setIp("192.168.10.1").setEnable(true)) @@ -27,7 +26,7 @@ public class ConfWriterTest { .addVirtualServer(new VirtualServer().setName("vs003").setPort("80").setSsl(false) .addDomain(new Domain().setName("m.ctrip.com")) .addDomain(new Domain().setName("m2.ctrip.com"))) - .setStatus("TEST"); + .setStatus("TEST").setId(1L); String groupName = "testApp"; Group group = new Group(); diff --git a/src/test/java/com/ctrip/zeus/nginx/ServerConfTest.java b/src/test/java/com/ctrip/zeus/nginx/ServerConfTest.java index d85a54ba..997e454f 100644 --- a/src/test/java/com/ctrip/zeus/nginx/ServerConfTest.java +++ b/src/test/java/com/ctrip/zeus/nginx/ServerConfTest.java @@ -12,7 +12,7 @@ public class ServerConfTest { public void testGenerate() throws Exception { VirtualServer vs = new VirtualServer().setName("vs002").setPort("80").setSsl(false) .addDomain(new Domain().setName("hotel.ctrip.com")) - .addDomain(new Domain().setName("flight.ctrip.com")); + .addDomain(new Domain().setName("flight.ctrip.com")).setId(2L); String groupName = "testApp"; Group group = new Group(); @@ -24,14 +24,21 @@ public class ServerConfTest { .setFailTimeout(30).setMaxFails(2).setPort(80).setWeight(2)) .addGroupServer(new GroupServer().setIp("192.168.20.2") .setFailTimeout(30).setMaxFails(2).setPort(80).setWeight(2)) - .addGroupSlb(new GroupSlb().setSlbName("default").setSlbId(1L).setVirtualServer(new VirtualServer().setName("vs002").setPort("80") - .setSsl(false).addDomain(new Domain().setName("hotel.ctrip.com"))).setPath("/hotel")) - ; + .addGroupSlb(new GroupSlb().setSlbName("default").setSlbId(1L).setVirtualServer(vs).setPath("/hotel")).setSsl(true); + Slb slb = new Slb().setName("default").setNginxBin("/usr/local/nginx/bin").setNginxConf("d:/nginx/conf").setNginxWorkerProcesses(1) + .addVip(new Vip().setIp("192.168.1.3")) + .addSlbServer(new SlbServer().setHostName("slb001a").setIp("192.168.10.1").setEnable(true)) + .addSlbServer(new SlbServer().setHostName("slb003").setIp("192.168.10.3").setEnable(true)) + .addVirtualServer(vs) + .addVirtualServer(new VirtualServer().setName("vs003").setPort("80").setSsl(false) + .addDomain(new Domain().setName("m.ctrip.com")) + .addDomain(new Domain().setName("m2.ctrip.com"))) + .setStatus("TEST").setId(1L); ArrayList groups = new ArrayList<>(); groups.add(group); - System.out.println(ServerConf.generate(new Slb().setName("default"), vs, groups)); + System.out.println(ServerConf.generate(slb, vs, groups)); } } \ No newline at end of file diff --git a/src/test/java/com/ctrip/zeus/nginx/UpstreamsConfTest.java b/src/test/java/com/ctrip/zeus/nginx/UpstreamsConfTest.java index 9d23e670..d5653950 100644 --- a/src/test/java/com/ctrip/zeus/nginx/UpstreamsConfTest.java +++ b/src/test/java/com/ctrip/zeus/nginx/UpstreamsConfTest.java @@ -13,7 +13,7 @@ public class UpstreamsConfTest { public void testGenerate() throws Exception { VirtualServer vs = new VirtualServer().setName("vs002").setPort("80").setSsl(false) .addDomain(new Domain().setName("hotel.ctrip.com")) - .addDomain(new Domain().setName("flight.ctrip.com")); + .addDomain(new Domain().setName("flight.ctrip.com")).setId(2L); String groupName = "testApp"; Group group = new Group(); @@ -26,13 +26,22 @@ public class UpstreamsConfTest { .addGroupServer(new GroupServer().setIp("192.168.20.2") .setFailTimeout(30).setMaxFails(2).setPort(80).setWeight(2)) .addGroupSlb(new GroupSlb().setSlbName("default").setSlbId(1L).setVirtualServer(new VirtualServer().setName("vs002").setPort("80") - .setSsl(false).addDomain(new Domain().setName("hotel.ctrip.com"))).setPath("/hotel")) - ; + .setSsl(false).addDomain(new Domain().setName("hotel.ctrip.com"))).setPath("/hotel")).setSsl(true); + + Slb slb = new Slb().setName("default").setNginxBin("/usr/local/nginx/bin").setNginxConf("d:/nginx/conf").setNginxWorkerProcesses(1) + .addVip(new Vip().setIp("192.168.1.3")) + .addSlbServer(new SlbServer().setHostName("slb001a").setIp("192.168.10.1").setEnable(true)) + .addSlbServer(new SlbServer().setHostName("slb003").setIp("192.168.10.3").setEnable(true)) + .addVirtualServer(vs) + .addVirtualServer(new VirtualServer().setName("vs003").setPort("80").setSsl(false) + .addDomain(new Domain().setName("m.ctrip.com")) + .addDomain(new Domain().setName("m2.ctrip.com"))) + .setStatus("TEST").setId(1L); ArrayList groups = new ArrayList<>(); groups.add(group); - System.out.println(UpstreamsConf.generate(new Slb().setName("default"), vs, groups, new HashSet(), new HashSet())); + System.out.println(UpstreamsConf.generate(slb, vs, groups, new HashSet(), new HashSet())); } } \ No newline at end of file diff --git a/src/test/java/com/ctrip/zeus/service/StatusTest.java b/src/test/java/com/ctrip/zeus/service/StatusTest.java index 9e71eb1e..43965a80 100644 --- a/src/test/java/com/ctrip/zeus/service/StatusTest.java +++ b/src/test/java/com/ctrip/zeus/service/StatusTest.java @@ -62,29 +62,18 @@ public class StatusTest extends AbstractAPITest { } }); - new ReqClient("http://127.0.0.1:8099").post("/api/conf/activate", "{\n" + - " \"conf-slb-names\": [\n" + - " {\n" + - " \"slbId\": \"" + slb.getId() + "\"\n" + - " }\n" + - " ],\n" + - " \"conf-group-names\": [\n" + - " {\n" + - " \"groupId\": \"" + group.getId() + "\"\n" + - " }\n" + - " ]\n" + - "}\n"); - - String responseup = new ReqClient("http://127.0.0.1:8099/api/op/upServer?ip=101.2.6.201").getstr(); - String responsedown = new ReqClient("http://127.0.0.1:8099/api/op/downServer?ip=101.2.6.201").getstr(); - System.out.println(responseup); - System.out.println(responsedown); - - String responseupM = new ReqClient("http://127.0.0.1:8099/api/op/upMember?groupName=Test&ip=101.2.6.201").getstr(); - String responsedownM = new ReqClient("http://127.0.0.1:8099/api/op/downMember?groupName=Test&ip=101.2.6.201").getstr(); - - System.out.println(responseupM); - System.out.println(responsedownM); +// new ReqClient("http://127.0.0.1:8099").get("/api/conf/activateByName?slbName=default&groupName=Test"); +// +// String responseup = new ReqClient("http://127.0.0.1:8099/api/op/upServer?ip=101.2.6.201").getstr(); +// String responsedown = new ReqClient("http://127.0.0.1:8099/api/op/downServer?ip=101.2.6.201").getstr(); +// System.out.println(responseup); +// System.out.println(responsedown); +// +// String responseupM = new ReqClient("http://127.0.0.1:8099/api/op/upMemberByName?groupName=Test&ip=101.2.6.201").getstr(); +// String responsedownM = new ReqClient("http://127.0.0.1:8099/api/op/downMemberByName?groupName=Test&ip=101.2.6.201").getstr(); +// +// System.out.println(responseupM); +// System.out.println(responsedownM); } private Group generateGroup(String groupName) {