From 2df8fa3a40d55cecadfc366c4687e893aaa62ad3 Mon Sep 17 00:00:00 2001 From: Nicole00 Date: Thu, 4 Nov 2021 10:22:38 +0800 Subject: [PATCH] update ssl test --- .../client/graph/data/TestDataFromServer.java | 16 +-------- .../nebula/client/meta/MockNebulaGraph.java | 24 +++++++++++-- .../nebula/client/meta/TestMetaClient.java | 30 +++------------- .../nebula/client/meta/TestMetaManager.java | 35 +++++-------------- .../client/storage/MockStorageData.java | 22 ++++++++++-- .../client/storage/StorageClientTest.java | 26 +++----------- 6 files changed, 59 insertions(+), 94 deletions(-) diff --git a/client/src/test/java/com/vesoft/nebula/client/graph/data/TestDataFromServer.java b/client/src/test/java/com/vesoft/nebula/client/graph/data/TestDataFromServer.java index 0718e985c..5140f7e0c 100644 --- a/client/src/test/java/com/vesoft/nebula/client/graph/data/TestDataFromServer.java +++ b/client/src/test/java/com/vesoft/nebula/client/graph/data/TestDataFromServer.java @@ -555,9 +555,6 @@ public void testSelfSignedSsl() { Session sslSession = null; NebulaPool sslPool = new NebulaPool(); try { - Runtime runtime = Runtime.getRuntime(); - runtime.exec("docker-compose -f src/test/resources/docker-compose" - + "-selfsigned.yaml up -d"); NebulaPoolConfig nebulaSslPoolConfig = new NebulaPoolConfig(); nebulaSslPoolConfig.setMaxConnSize(100); @@ -566,8 +563,7 @@ public void testSelfSignedSsl() { "src/test/resources/ssl/selfsigned.pem", "src/test/resources/ssl/selfsigned.key", "vesoft")); - TimeUnit.SECONDS.sleep(45); - Assert.assertTrue(sslPool.init(Arrays.asList(new HostAddress("127.0.0.1", 8669)), + Assert.assertTrue(sslPool.init(Arrays.asList(new HostAddress("127.0.0.1", 7669)), nebulaSslPoolConfig)); sslSession = sslPool.getSession("root", "nebula", true); @@ -577,9 +573,6 @@ public void testSelfSignedSsl() { .getJSONObject(0).getJSONArray("row").toJSONString(); String exp = "[1]"; Assert.assertEquals(rowData, exp); - - runtime.exec("docker-compose -f src/test/resources/docker-compose" - + "-selfsigned.yaml down").waitFor(60, TimeUnit.SECONDS); } catch (Exception e) { e.printStackTrace(); assert false; @@ -596,10 +589,6 @@ public void testCASignedSsl() { Session sslSession = null; NebulaPool sslPool = new NebulaPool(); try { - Runtime runtime = Runtime.getRuntime(); - runtime.exec("docker-compose -f src/test/resources/docker-compose" - + "-casigned.yaml up -d"); - NebulaPoolConfig nebulaSslPoolConfig = new NebulaPoolConfig(); nebulaSslPoolConfig.setMaxConnSize(100); nebulaSslPoolConfig.setEnableSsl(true); @@ -607,7 +596,6 @@ public void testCASignedSsl() { "src/test/resources/ssl/casigned.pem", "src/test/resources/ssl/casigned.crt", "src/test/resources/ssl/casigned.key")); - TimeUnit.SECONDS.sleep(45); Assert.assertTrue(sslPool.init(Arrays.asList(new HostAddress("127.0.0.1", 8669)), nebulaSslPoolConfig)); sslSession = sslPool.getSession("root", "nebula", true); @@ -619,8 +607,6 @@ public void testCASignedSsl() { String exp = "[1]"; Assert.assertEquals(rowData, exp); - runtime.exec("docker-compose -f src/test/resources/docker-compose" - + "-casigned.yaml down").waitFor(60, TimeUnit.SECONDS); } catch (Exception e) { e.printStackTrace(); assert false; diff --git a/client/src/test/java/com/vesoft/nebula/client/meta/MockNebulaGraph.java b/client/src/test/java/com/vesoft/nebula/client/meta/MockNebulaGraph.java index 0e50e7094..1e8585b6f 100644 --- a/client/src/test/java/com/vesoft/nebula/client/meta/MockNebulaGraph.java +++ b/client/src/test/java/com/vesoft/nebula/client/meta/MockNebulaGraph.java @@ -63,6 +63,24 @@ public static String createSpace() { return exec; } + public static String createSpaceCA() { + String exec = "CREATE SPACE IF NOT EXISTS testMetaCA(partition_num=10, " + + "vid_type=fixed_string(8));" + + "USE testMetaCA;" + + "CREATE TAG IF NOT EXISTS person(name string, age int);" + + "CREATE EDGE IF NOT EXISTS friend(likeness double);"; + return exec; + } + + public static String createSpaceSelf() { + String exec = "CREATE SPACE IF NOT EXISTS testMetaSelf(partition_num=10, " + + "vid_type=fixed_string(8));" + + "USE testMetaSelf;" + + "CREATE TAG IF NOT EXISTS person(name string, age int);" + + "CREATE EDGE IF NOT EXISTS friend(likeness double);"; + return exec; + } + public static void createMultiVersionTagAndEdge() { NebulaPoolConfig nebulaPoolConfig = new NebulaPoolConfig(); nebulaPoolConfig.setMaxConnSize(100); @@ -117,7 +135,7 @@ public static void createSpaceWithCASSL() { pool.init(addresses, nebulaPoolConfig); session = pool.getSession("root", "nebula", true); - ResultSet resp = session.execute(createSpace()); + ResultSet resp = session.execute(createSpaceCA()); if (!resp.isSucceeded()) { LOGGER.error("create space failed, {}", resp.getErrorMessage()); assert (false); @@ -143,13 +161,13 @@ public static void createSpaceWithSelfSSL() { "src/test/resources/ssl/selfsigned.pem", "src/test/resources/ssl/selfsigned.key", "vesoft")); - List addresses = Arrays.asList(new HostAddress("127.0.0.1", 8669)); + List addresses = Arrays.asList(new HostAddress("127.0.0.1", 7669)); NebulaPool pool = new NebulaPool(); Session session = null; try { pool.init(addresses, nebulaPoolConfig); session = pool.getSession("root", "nebula", true); - ResultSet resp = session.execute(createSpace()); + ResultSet resp = session.execute(createSpaceSelf()); if (!resp.isSucceeded()) { LOGGER.error("create space failed, {}", resp.getErrorMessage()); assert (false); diff --git a/client/src/test/java/com/vesoft/nebula/client/meta/TestMetaClient.java b/client/src/test/java/com/vesoft/nebula/client/meta/TestMetaClient.java index aa1d9cd1d..a450883f4 100644 --- a/client/src/test/java/com/vesoft/nebula/client/meta/TestMetaClient.java +++ b/client/src/test/java/com/vesoft/nebula/client/meta/TestMetaClient.java @@ -142,12 +142,8 @@ public void testListOnlineHosts() { } public void testCASignedSSLMetaClient() { - String startCmd = "docker-compose -f src/test/resources/docker-compose-casigned.yaml up -d"; - String stopCmd = "docker-compose -f src/test/resources/docker-compose-casigned.yaml down"; - Runtime runtime = Runtime.getRuntime(); MetaClient metaClient = null; try { - runtime.exec(startCmd).waitFor(60, TimeUnit.SECONDS); // mock data with CA ssl MockNebulaGraph.createSpaceWithCASSL(); @@ -161,9 +157,9 @@ public void testCASignedSSLMetaClient() { 3000, 1, 1, true, sslParam); metaClient.connect(); - List tags = metaClient.getTags("testMeta"); + List tags = metaClient.getTags("testMetaCA"); Assert.assertTrue(tags.size() >= 1); - assert (metaClient.getTag("testMeta", "person") != null); + assert (metaClient.getTag("testMetaCA", "person") != null); } catch (Exception e) { LOGGER.error("test CA signed ssl meta client failed, ", e); assert (false); @@ -171,23 +167,12 @@ public void testCASignedSSLMetaClient() { if (metaClient != null) { metaClient.close(); } - try { - runtime.exec(stopCmd).waitFor(60, TimeUnit.SECONDS); - } catch (InterruptedException | IOException e) { - e.printStackTrace(); - } } } public void testSelfSignedSSLMetaClient() { - String startCmd = - "docker-compose -f src/test/resources/docker-compose-selfsigned.yaml up -d"; - String stopCmd = "docker-compose -f src/test/resources/docker-compose-selfsigned.yaml down"; - MetaClient metaClient = null; - Runtime runtime = Runtime.getRuntime(); try { - runtime.exec(startCmd).waitFor(60, TimeUnit.SECONDS); // mock data with Self ssl MockNebulaGraph.createSpaceWithSelfSSL(); @@ -196,13 +181,13 @@ public void testSelfSignedSSLMetaClient() { "src/test/resources/ssl/selfsigned.pem", "src/test/resources/ssl/selfsigned.key", "vesoft"); - metaClient = new MetaClient(Arrays.asList(new HostAddress(address, 8559)), + metaClient = new MetaClient(Arrays.asList(new HostAddress(address, 7559)), 3000, 1, 1, true, sslParam); metaClient.connect(); - List tags = metaClient.getTags("testMeta"); + List tags = metaClient.getTags("testMetaSelf"); Assert.assertTrue(tags.size() >= 1); - assert (metaClient.getTag("testMeta", "person") != null); + assert (metaClient.getTag("testMetaSelf", "person") != null); } catch (Exception e) { LOGGER.error("test Self signed ssl meta client failed, ", e); assert (false); @@ -210,11 +195,6 @@ public void testSelfSignedSSLMetaClient() { if (metaClient != null) { metaClient.close(); } - try { - runtime.exec(stopCmd).waitFor(60, TimeUnit.SECONDS); - } catch (Exception e) { - e.printStackTrace(); - } } } } diff --git a/client/src/test/java/com/vesoft/nebula/client/meta/TestMetaManager.java b/client/src/test/java/com/vesoft/nebula/client/meta/TestMetaManager.java index 21592d7ae..992f38c75 100644 --- a/client/src/test/java/com/vesoft/nebula/client/meta/TestMetaManager.java +++ b/client/src/test/java/com/vesoft/nebula/client/meta/TestMetaManager.java @@ -12,6 +12,7 @@ import com.vesoft.nebula.client.graph.data.SSLParam; import com.vesoft.nebula.client.graph.data.SelfSignedSSLParam; import com.vesoft.nebula.client.graph.exception.ClientServerIncompatibleException; +import com.vesoft.nebula.client.util.ProcessUtil; import com.vesoft.nebula.meta.EdgeItem; import com.vesoft.nebula.meta.SpaceItem; import com.vesoft.nebula.meta.TagItem; @@ -120,12 +121,8 @@ public void testMultiVersionSchema() throws ClientServerIncompatibleException { public void testCASignedSSLMetaManager() { - Runtime runtime = Runtime.getRuntime(); MetaManager metaManager = null; try { - runtime.exec( - "docker-compose -f src/test/resources/docker-compose-casigned.yaml up -d") - .waitFor(45, TimeUnit.SECONDS); // mock data with CA ssl MockNebulaGraph.createSpaceWithCASSL(); @@ -139,9 +136,9 @@ public void testCASignedSSLMetaManager() { 8559)), 3000, 1, 1, true, sslParam); - assert (metaManager.getSpaceId("testMeta") > 0); - SpaceItem spaceItem = metaManager.getSpace("testMeta"); - assert Objects.equals("testMeta", new String(spaceItem.properties.getSpace_name())); + assert (metaManager.getSpaceId("testMetaCA") > 0); + SpaceItem spaceItem = metaManager.getSpace("testMetaCA"); + assert Objects.equals("testMetaCA", new String(spaceItem.properties.getSpace_name())); Assert.assertEquals(8, spaceItem.properties.getVid_type().getType_length()); Assert.assertEquals(10, spaceItem.properties.getPartition_num()); @@ -158,23 +155,12 @@ public void testCASignedSSLMetaManager() { if (metaManager != null) { metaManager.close(); } - try { - runtime.exec("docker-compose -f src/test/resources/docker-compose" - + "-casigned.yaml down").waitFor(60, TimeUnit.SECONDS); - } catch (InterruptedException | IOException e) { - e.printStackTrace(); - } } } public void testSelfSignedSSLMetaClient() { - String startCmd = - "docker-compose -f src/test/resources/docker-compose-selfsigned.yaml up -d"; - String stopCmd = "docker-compose -f src/test/resources/docker-compose-selfsigned.yaml down"; - Runtime runtime = Runtime.getRuntime(); MetaManager metaManager = null; try { - runtime.exec(startCmd).waitFor(45, TimeUnit.SECONDS); // mock data with Self ssl MockNebulaGraph.createSpaceWithSelfSSL(); @@ -183,12 +169,12 @@ public void testSelfSignedSSLMetaClient() { "src/test/resources/ssl/selfsigned.pem", "src/test/resources/ssl/selfsigned.key", "vesoft"); - metaManager = new MetaManager(Arrays.asList(new HostAddress("127.0.0.1", 8559)), + metaManager = new MetaManager(Arrays.asList(new HostAddress("127.0.0.1", 7559)), 3000, 1, 1, true, sslParam); - assert (metaManager.getSpaceId("testMeta") > 0); - SpaceItem spaceItem = metaManager.getSpace("testMeta"); - assert Objects.equals("testMeta", new String(spaceItem.properties.getSpace_name())); + assert (metaManager.getSpaceId("testMetaSelf") > 0); + SpaceItem spaceItem = metaManager.getSpace("testMetaSelf"); + assert Objects.equals("testMetaSelf", new String(spaceItem.properties.getSpace_name())); Assert.assertEquals(8, spaceItem.properties.getVid_type().getType_length()); Assert.assertEquals(10, spaceItem.properties.getPartition_num()); @@ -206,11 +192,6 @@ public void testSelfSignedSSLMetaClient() { if (metaManager != null) { metaManager.close(); } - try { - runtime.exec(stopCmd).waitFor(60, TimeUnit.SECONDS); - } catch (InterruptedException | IOException e) { - e.printStackTrace(); - } } } } diff --git a/client/src/test/java/com/vesoft/nebula/client/storage/MockStorageData.java b/client/src/test/java/com/vesoft/nebula/client/storage/MockStorageData.java index a628e29ad..f8bdfea92 100644 --- a/client/src/test/java/com/vesoft/nebula/client/storage/MockStorageData.java +++ b/client/src/test/java/com/vesoft/nebula/client/storage/MockStorageData.java @@ -68,6 +68,24 @@ public static String createSpace() { return exec; } + public static String createSpaceCa() { + String exec = "CREATE SPACE IF NOT EXISTS testStorageCA(partition_num=10," + + "vid_type=fixed_string(8));" + + "USE testStorageCA;" + + "CREATE TAG IF NOT EXISTS person(name string, age int);" + + "CREATE EDGE IF NOT EXISTS friend(likeness double);"; + return exec; + } + + public static String createSpaceSelf() { + String exec = "CREATE SPACE IF NOT EXISTS testStorageSelf(partition_num=10," + + "vid_type=fixed_string(8));" + + "USE testStorageSelf;" + + "CREATE TAG IF NOT EXISTS person(name string, age int);" + + "CREATE EDGE IF NOT EXISTS friend(likeness double);"; + return exec; + } + public static String insertData() { String exec = "INSERT VERTEX person(name, age) VALUES " + "\"1\":(\"Tom\", 18), " @@ -100,7 +118,7 @@ public static void mockCASslData() { pool.init(addresses, nebulaPoolConfig); session = pool.getSession("root", "nebula", true); - ResultSet resp = session.execute(createSpace()); + ResultSet resp = session.execute(createSpaceCa()); try { Thread.sleep(6000); } catch (InterruptedException e) { @@ -140,7 +158,7 @@ public static void mockSelfSslData() { pool.init(addresses, nebulaPoolConfig); session = pool.getSession("root", "nebula", true); - ResultSet resp = session.execute(createSpace()); + ResultSet resp = session.execute(createSpaceSelf()); try { Thread.sleep(5000); diff --git a/client/src/test/java/com/vesoft/nebula/client/storage/StorageClientTest.java b/client/src/test/java/com/vesoft/nebula/client/storage/StorageClientTest.java index dff3276c8..22f0e16a4 100644 --- a/client/src/test/java/com/vesoft/nebula/client/storage/StorageClientTest.java +++ b/client/src/test/java/com/vesoft/nebula/client/storage/StorageClientTest.java @@ -18,6 +18,7 @@ import com.vesoft.nebula.client.storage.scan.ScanEdgeResultIterator; import com.vesoft.nebula.client.storage.scan.ScanVertexResult; import com.vesoft.nebula.client.storage.scan.ScanVertexResultIterator; +import com.vesoft.nebula.client.util.ProcessUtil; import java.io.IOException; import java.io.UnsupportedEncodingException; import java.util.Arrays; @@ -368,14 +369,10 @@ public void testScanEdgeWithAllCols() { @Test public void testCASignedSSL() { - String startCmd = "docker-compose -f src/test/resources/docker-compose-casigned.yaml up -d"; - String stopCmd = "docker-compose -f src/test/resources/docker-compose-casigned.yaml down"; // start nebula service with ssl enable List address = null; StorageClient sslClient = null; - Runtime runtime = Runtime.getRuntime(); try { - runtime.exec(startCmd).waitFor(60, TimeUnit.SECONDS); address = Arrays.asList(new HostAddress(ip, 8559)); // mock graph data @@ -389,7 +386,7 @@ public void testCASignedSSL() { sslClient.connect(); ScanVertexResultIterator resultIterator = sslClient.scanVertex( - "testStorage", + "testStorageCA", "person"); while (resultIterator.hasNext()) { ScanVertexResult result = null; @@ -443,26 +440,17 @@ public void testCASignedSSL() { } } } - // stop nebula service - try { - runtime.exec(stopCmd).waitFor(60, TimeUnit.SECONDS); - } catch (InterruptedException | IOException e) { - e.printStackTrace(); - } } @Test public void testSelfSignedSSL() { - String startCmd = - "docker-compose -f src/test/resources/docker-compose-selfsigned.yaml up -d"; - String stopCmd = "docker-compose -f src/test/resources/docker-compose-selfsigned.yaml down"; // start nebula service with ssl enable List address = null; StorageClient sslClient = null; Runtime runtime = Runtime.getRuntime(); try { - runtime.exec(startCmd).waitFor(60, TimeUnit.SECONDS); + address = Arrays.asList(new HostAddress(ip, 8559)); // mock graph data @@ -476,7 +464,7 @@ public void testSelfSignedSSL() { sslClient.connect(); ScanVertexResultIterator resultIterator = sslClient.scanVertex( - "testStorage", + "testStorageSelf", "person"); assertIterator(resultIterator); } catch (Exception e) { @@ -489,12 +477,6 @@ public void testSelfSignedSSL() { } catch (Exception e) { e.printStackTrace(); } - try { - // stop nebula service - runtime.exec(stopCmd).waitFor(60, TimeUnit.SECONDS); - } catch (Exception e) { - e.printStackTrace(); - } } } }