From 885a7bea8709bece6244990cbeba9b1cccc40ddc Mon Sep 17 00:00:00 2001 From: Enrique Saurez Date: Tue, 29 Jan 2019 23:43:49 -0500 Subject: Improve serialization and table own Reimplement benchmark Improve serialization using proto Change staging table structure Change-Id: Ic13787f81eb7443807efde0e407ab3a4c71a5d64 Issue-ID: MUSIC-327 Signed-off-by: Enrique Saurez --- .../java/org/onap/music/mdbc/MDBCUtilsTest.java | 58 ++++------------------ .../org/onap/music/mdbc/mixins/MusicMixinTest.java | 16 +++--- .../mdbc/ownership/OwnershipAndCheckpointTest.java | 26 ++++++---- 3 files changed, 37 insertions(+), 63 deletions(-) (limited to 'mdbc-server/src/test') diff --git a/mdbc-server/src/test/java/org/onap/music/mdbc/MDBCUtilsTest.java b/mdbc-server/src/test/java/org/onap/music/mdbc/MDBCUtilsTest.java index 676d760..a9cf88a 100755 --- a/mdbc-server/src/test/java/org/onap/music/mdbc/MDBCUtilsTest.java +++ b/mdbc-server/src/test/java/org/onap/music/mdbc/MDBCUtilsTest.java @@ -23,73 +23,35 @@ import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; import java.io.IOException; +import java.nio.ByteBuffer; import java.util.HashMap; +import java.util.HashSet; import org.json.JSONObject; import org.junit.Ignore; import org.junit.Test; +import org.onap.music.exceptions.MDBCServiceException; import org.onap.music.mdbc.tables.OperationType; import org.onap.music.mdbc.tables.StagingTable; -@Ignore public class MDBCUtilsTest { - @Test - public void toStringTest1() { - StagingTable table = new StagingTable(); - table.addOperation(OperationType.INSERT,(new JSONObject(new String[]{"test3", "Test4"})).toString(), - (new JSONObject(new String[]{"test_key", "test_value"})).toString()); - String output=null; - try { - output = MDBCUtils.toString(table); - } catch (IOException e) { - e.printStackTrace(); - fail(); - } - assertTrue(output!=null); - assertTrue(!output.isEmpty()); - } - @Test - public void toStringTest2() { - HashMap mapToSerialize = new HashMap<>(); + public void toStringTest1() { StagingTable table = new StagingTable(); - table.addOperation(OperationType.INSERT,(new JSONObject(new String[]{"test3", "Test4"}).toString()), - (new JSONObject(new String[]{"test_key", "test_value"})).toString()); - mapToSerialize.put("table",table); - String output=null; try { - output = MDBCUtils.toString(mapToSerialize); - } catch (IOException e) { - e.printStackTrace(); - fail(); - } - assertTrue(output!=null); - assertTrue(!output.isEmpty()); - } - - @Test - public void toStringTest3() { - String testStr = "test"; - OperationType typeTest = OperationType.INSERT; - String output=null; - try { - output = MDBCUtils.toString(testStr); - } catch (IOException e) { - e.printStackTrace(); + table.addOperation(new Range("TABLE1"),OperationType.INSERT,(new JSONObject(new String[]{"test3", "Test4"})).toString(),null); + } catch (MDBCServiceException e) { fail(); } - assertTrue(output!=null); - assertTrue(!output.isEmpty()); - output=null; + ByteBuffer output=null; try { - output = MDBCUtils.toString(typeTest); - } catch (IOException e) { + output = table.getSerializedStagingAndClean(); + } catch (MDBCServiceException e) { e.printStackTrace(); fail(); } assertTrue(output!=null); - assertTrue(!output.isEmpty()); + assertTrue(output.toString().length() > 0); } - } diff --git a/mdbc-server/src/test/java/org/onap/music/mdbc/mixins/MusicMixinTest.java b/mdbc-server/src/test/java/org/onap/music/mdbc/mixins/MusicMixinTest.java index 8a185ea..df673c9 100644 --- a/mdbc-server/src/test/java/org/onap/music/mdbc/mixins/MusicMixinTest.java +++ b/mdbc-server/src/test/java/org/onap/music/mdbc/mixins/MusicMixinTest.java @@ -77,11 +77,11 @@ public class MusicMixinTest { } catch (Exception e) { System.out.println(e); } - - cluster = new Cluster.Builder().addContactPoint(cassaHost).withPort(9142).build(); + cluster=EmbeddedCassandraServerHelper.getCluster(); + //cluster = new Cluster.Builder().addContactPoint(cassaHost).withPort(9142).build(); cluster.getConfiguration().getSocketOptions().setReadTimeoutMillis(20000); assertNotNull("Invalid configuration for cassandra", cluster); - session = cluster.connect(); + session = EmbeddedCassandraServerHelper.getSession(); assertNotNull("Invalid configuration for cassandra", session); MusicDataStoreHandle.mDstoreHandle = new MusicDataStore(cluster, session); @@ -92,8 +92,12 @@ public class MusicMixinTest { @AfterClass public static void close() throws MusicServiceException, MusicQueryException { //TODO: shutdown cassandra - session.close(); - cluster.close(); + mixin=null; + try { + EmbeddedCassandraServerHelper.cleanEmbeddedCassandra(); + } + catch(NullPointerException e){ + } } @Before @@ -146,7 +150,7 @@ public class MusicMixinTest { return partition; } - @Test(timeout=1000) + @Test(timeout=10000) public void own2() throws InterruptedException, MDBCServiceException { List range12 = new ArrayList<>( Arrays.asList( new Range("RANGE1"), diff --git a/mdbc-server/src/test/java/org/onap/music/mdbc/ownership/OwnershipAndCheckpointTest.java b/mdbc-server/src/test/java/org/onap/music/mdbc/ownership/OwnershipAndCheckpointTest.java index 0c2a804..4950484 100644 --- a/mdbc-server/src/test/java/org/onap/music/mdbc/ownership/OwnershipAndCheckpointTest.java +++ b/mdbc-server/src/test/java/org/onap/music/mdbc/ownership/OwnershipAndCheckpointTest.java @@ -61,7 +61,7 @@ public class OwnershipAndCheckpointTest { final private static String mtdTableName = "musictxdigest"; final private static String mdbcServerName = "name"; public static final String DATABASE = "mdbcTest"; - public static final String TABLE= "Persons"; + public static final String TABLE= "PERSONS"; public static final String CREATE_TABLE = "CREATE TABLE IF NOT EXISTS " + TABLE + " (\n" + " PersonID int,\n" + " LastName varchar(255),\n" + @@ -87,10 +87,11 @@ public class OwnershipAndCheckpointTest { } catch (Exception e) { fail(e.getMessage()); } - cluster = new Cluster.Builder().addContactPoint(cassaHost).withPort(9142).build(); + cluster=EmbeddedCassandraServerHelper.getCluster(); + //cluster = new Cluster.Builder().addContactPoint(cassaHost).withPort(9142).build(); cluster.getConfiguration().getSocketOptions().setReadTimeoutMillis(20000); assertNotNull("Invalid configuration for cassandra", cluster); - session = cluster.connect(); + session = EmbeddedCassandraServerHelper.getSession(); assertNotNull("Invalid configuration for cassandra", session); Class.forName("org.mariadb.jdbc.Driver"); MusicDataStoreHandle.mDstoreHandle = new MusicDataStore(cluster, session); @@ -105,9 +106,13 @@ public class OwnershipAndCheckpointTest { @AfterClass public static void close() throws MusicServiceException, MusicQueryException, ManagedProcessException { //TODO: shutdown cassandra - session.close(); - cluster.close(); + musicMixin=null; db.stop(); + try { + EmbeddedCassandraServerHelper.cleanEmbeddedCassandra(); + } + catch(NullPointerException e){ + } } private void dropTable() throws SQLException { @@ -149,7 +154,8 @@ public class OwnershipAndCheckpointTest { final DatabasePartition partition = TestUtils.createBasicRow(range, musicMixin, mdbcServerName); String sqlOperation = "INSERT INTO "+TABLE+" (PersonID,LastName,FirstName,Address,City) VALUES "+ "(1,'SAUREZ','ENRIQUE','GATECH','ATLANTA');"; - HashMap stagingTable = new HashMap<>(); + StagingTable stagingTable = new StagingTable(); + musicMixin.reloadAlreadyApplied(partition); final Statement executeStatement = this.conn.createStatement(); executeStatement.execute(sqlOperation); this.conn.commit(); @@ -164,6 +170,7 @@ public class OwnershipAndCheckpointTest { private OwnershipReturn cleanAndOwnPartition(List ranges, UUID ownOpId) throws SQLException { dropAndCreateTable(); + musicMixin.cleanAlreadyApplied(); DatabasePartition currentPartition = new DatabasePartition(MDBCUtils.generateTimebasedUniqueKey()); OwnershipReturn own=null; @@ -196,9 +203,10 @@ public class OwnershipAndCheckpointTest { } @Test - @Ignore + //@Ignore public void checkpoint() throws MDBCServiceException, SQLException { - Range range = new Range(TABLE); + Range range = + new Range(TABLE); OwnershipAndCheckpoint ownAndCheck = musicMixin.getOwnAndCheck(); initDatabase(range); @@ -219,7 +227,7 @@ public class OwnershipAndCheckpointTest { } @Test - @Ignore + //@Ignore public void warmup() throws MDBCServiceException, SQLException { Range range = new Range(TABLE); OwnershipAndCheckpoint ownAndCheck = musicMixin.getOwnAndCheck(); -- cgit 1.2.3-korg