From 023e0b5018247f02e05dbed3f91c495161fde814 Mon Sep 17 00:00:00 2001 From: Fiete Ostkamp Date: Wed, 12 Jun 2024 16:53:33 +0200 Subject: Support exporting to the kryo format in the dataSnapshot script - add support for the kryo format when creating a database snapshot Issue-ID: AAI-3872 Change-Id: Iba085f7227bbfcb928370443c2e0eac95e49bb9c Signed-off-by: Fiete Ostkamp --- .../onap/aai/datasnapshot/DataSnapshotTest.java | 62 ++++++++++++++++------ 1 file changed, 46 insertions(+), 16 deletions(-) (limited to 'src/test') diff --git a/src/test/java/org/onap/aai/datasnapshot/DataSnapshotTest.java b/src/test/java/org/onap/aai/datasnapshot/DataSnapshotTest.java index 9d74651..cc61e99 100644 --- a/src/test/java/org/onap/aai/datasnapshot/DataSnapshotTest.java +++ b/src/test/java/org/onap/aai/datasnapshot/DataSnapshotTest.java @@ -56,7 +56,7 @@ public class DataSnapshotTest extends AAISetup { private JanusGraphTransaction currentTransaction; private List vertexes; - + private static final int DELAYSINGLETHREADTEST = 90; @Rule @@ -126,15 +126,13 @@ public class DataSnapshotTest extends AAISetup { assertThat(outputCapture.toString(), containsString("graphson had no data.")); } - - @Ignore("Unit test failing temporarily ignore") @Test public void testTakeSnapshotAndItShouldCreateASnapshotFileWithOneVertex() throws IOException, InterruptedException { String logsFolder = System.getProperty("AJSC_HOME") + "/logs/data/dataSnapshots/"; Set preSnapshotFiles = Files.walk(Paths.get(logsFolder)).collect(Collectors.toSet()); - + // previous test may have the same generated file name, this wait will ensure a new name is used for this test System.out.println("delay generation, seconds " + DELAYSINGLETHREADTEST); Thread.sleep(DELAYSINGLETHREADTEST*1000); @@ -149,7 +147,7 @@ public class DataSnapshotTest extends AAISetup { Set postSnapshotFiles = Files.walk(Paths.get(logsFolder)).collect(Collectors.toSet()); - assertThat(postSnapshotFiles.size(), is(37)); + assertThat(postSnapshotFiles.size(), is(preSnapshotFiles.size() +1)); postSnapshotFiles.removeAll(preSnapshotFiles); List snapshotPathList = postSnapshotFiles.stream().collect(Collectors.toList()); @@ -158,7 +156,39 @@ public class DataSnapshotTest extends AAISetup { List fileContents = Files.readAllLines(snapshotPathList.get(0)); assertThat(fileContents.get(0), containsString("id")); } - + + @Test + public void testTakeKryoSnapshotAndItShouldCreateASnapshotFileWithOneVertex() throws IOException, InterruptedException { + + String logsFolder = System.getProperty("AJSC_HOME") + "/logs/data/dataSnapshots/"; + + Set preSnapshotFiles = Files.walk(Paths.get(logsFolder)).collect(Collectors.toSet()); + + // previous test may have the same generated file name, this wait will ensure a new name is used for this test + System.out.println("delay generation, seconds " + DELAYSINGLETHREADTEST); + Thread.sleep(DELAYSINGLETHREADTEST*100); + // Run the clear dataSnapshot and this time it should fail + //String [] args = {"JUST_TAKE_SNAPSHOT"}; >> default behavior is now to use 15 threads + // To just get one file, you have to tell it to just use one. + String [] args = {"-c","THREADED_SNAPSHOT", "-threadCount" ,"1", "-snapshotType" , "gryo"}; + + DataSnapshot.main(args); + + // Add sleep so the file actually gets created with the data + + Set postSnapshotFiles = Files.walk(Paths.get(logsFolder)).collect(Collectors.toSet()); + + assertThat(postSnapshotFiles.size(), is(preSnapshotFiles.size() +1)); + boolean gryoSnapshotExists = postSnapshotFiles.stream() + .map(Path::toString) + .anyMatch(name -> name.endsWith("gryo")); + assertTrue(gryoSnapshotExists); + postSnapshotFiles.removeAll(preSnapshotFiles); + List snapshotPathList = postSnapshotFiles.stream().collect(Collectors.toList()); + + assertThat(snapshotPathList.size(), is(1)); + } + @Test public void testTakeSnapshotMultiAndItShouldCreateMultipleSnapshotFiles() throws IOException { @@ -180,27 +210,27 @@ public class DataSnapshotTest extends AAISetup { long totalVerts = 5000; int threadCt = 15; long maxNodesPerFile = 120000; - - int fileCt = DataSnapshot.figureOutFileCount( totalVerts, threadCt, + + int fileCt = DataSnapshot.figureOutFileCount( totalVerts, threadCt, maxNodesPerFile ); assertThat( fileCt, is(15)); - + totalVerts = 5000; threadCt = 15; maxNodesPerFile = 100; - fileCt = DataSnapshot.figureOutFileCount( totalVerts, threadCt, + fileCt = DataSnapshot.figureOutFileCount( totalVerts, threadCt, maxNodesPerFile ); assertThat( fileCt, is(60)); - + totalVerts = 1500; threadCt = 15; maxNodesPerFile = 100; - fileCt = DataSnapshot.figureOutFileCount( totalVerts, threadCt, + fileCt = DataSnapshot.figureOutFileCount( totalVerts, threadCt, maxNodesPerFile ); - assertThat( fileCt, is(15)); - + assertThat( fileCt, is(15)); + } - + @Test public void testTakeSnapshotMultiWithDebugAndItShouldCreateMultipleSnapshotFiles() throws IOException { @@ -224,7 +254,7 @@ public class DataSnapshotTest extends AAISetup { // Run the clear dataSnapshot and this time it should fail String [] args = {"-c","THREADED_SNAPSHOT", "-threadCount","foo","-debugFlag", "DEBUG"}; - + DataSnapshot.main(args); // For this test if there is only one vertex in the graph, not sure if it will create multiple files -- cgit 1.2.3-korg