diff options
Diffstat (limited to 'mdbc-server/src/test')
4 files changed, 91 insertions, 10 deletions
diff --git a/mdbc-server/src/test/java/org/onap/music/mdbc/MdbcTestUtils.java b/mdbc-server/src/test/java/org/onap/music/mdbc/MdbcTestUtils.java index 96806a3..626b6ca 100644 --- a/mdbc-server/src/test/java/org/onap/music/mdbc/MdbcTestUtils.java +++ b/mdbc-server/src/test/java/org/onap/music/mdbc/MdbcTestUtils.java @@ -206,7 +206,7 @@ public class MdbcTestUtils { } } - public static void cleanDatabase(DBType type){ + public static void stopDatabase(DBType type){ switch(type) { case MySQL: stopMySql(); diff --git a/mdbc-server/src/test/java/org/onap/music/mdbc/mixins/MySQLMixinTest.java b/mdbc-server/src/test/java/org/onap/music/mdbc/mixins/MySQLMixinTest.java index 1e42d1e..cf23305 100644 --- a/mdbc-server/src/test/java/org/onap/music/mdbc/mixins/MySQLMixinTest.java +++ b/mdbc-server/src/test/java/org/onap/music/mdbc/mixins/MySQLMixinTest.java @@ -20,16 +20,25 @@ package org.onap.music.mdbc.mixins; +import java.util.HashSet; +import java.util.Map; import java.util.Properties; +import java.util.Set; +import org.apache.commons.lang3.tuple.Pair; import org.junit.*; - +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; import java.sql.Connection; import java.sql.DriverManager; import java.sql.SQLException; +import java.sql.Statement; +import org.onap.music.mdbc.MDBCUtils; import org.onap.music.mdbc.MdbcTestUtils; import org.onap.music.mdbc.MdbcTestUtils.DBType; +import org.onap.music.mdbc.Range; import org.onap.music.mdbc.mixins.MySQLMixin; - +import org.onap.music.mdbc.tables.MriReference; +import org.onap.music.mdbc.tables.MusicTxDigestId; import ch.vorburger.mariadb4j.DB; public class MySQLMixinTest { @@ -60,7 +69,7 @@ public class MySQLMixinTest { @AfterClass public static void close() throws Exception { - MdbcTestUtils.cleanDatabase(DBType.MySQL); + MdbcTestUtils.stopDatabase(DBType.MySQL); } @Before @@ -70,9 +79,81 @@ public class MySQLMixinTest { this.mysqlMixin = new MySQLMixin(null, null, conn, info); } - @Test - public void testGetDataBaseName() throws SQLException { - Assert.assertEquals(MdbcTestUtils.getMariaDBDBName().toUpperCase(), mysqlMixin.getDatabaseName()); - } + + @After + public void afterEachTest() throws SQLException { + clearTables(); + } + + @Test + public void testGetDataBaseName() throws SQLException { + assertEquals(MdbcTestUtils.getMariaDBDBName(), mysqlMixin.getDatabaseName()); + } + + @Test + public void testGetTableSet() throws SQLException { + Set<Range> rangesAdded = new HashSet<>(); + rangesAdded.add(new Range("TEST.RANGER")); + rangesAdded.add(new Range("TEST.RANGES")); + Statement st = conn.createStatement(); + for (Range r: rangesAdded) { + st.execute("CREATE TABLE " + r + " (name VARCHAR(20));"); + } + st.close(); + Set<Range> ranges = mysqlMixin.getSQLRangeSet(); + + assertTrue(ranges.containsAll(rangesAdded)); + assertTrue(rangesAdded.containsAll(ranges)); + } + + @Test + public void testCkpt() throws SQLException { + createTables(); + + Range r1 = new Range(MdbcTestUtils.mariaDBDatabaseName + ".RANGER"); + MriReference mri1 = new MriReference(MDBCUtils.generateUniqueKey()); + MusicTxDigestId i1 = new MusicTxDigestId(mri1.index, MDBCUtils.generateUniqueKey(), 1); + Pair<MriReference, MusicTxDigestId> digestId = Pair.of(mri1, i1); + mysqlMixin.updateCheckpointLocations(r1, digestId); + + Range r2 = new Range(MdbcTestUtils.mariaDBDatabaseName + ".RANGES"); + MriReference mri2 = new MriReference(MDBCUtils.generateUniqueKey()); + MusicTxDigestId i2 = new MusicTxDigestId(mri2.index, MDBCUtils.generateUniqueKey(), 2); + Pair<MriReference, MusicTxDigestId> p2 = Pair.of(mri2, i2); + mysqlMixin.updateCheckpointLocations(r2, p2); + + Map<Range, Pair<MriReference, MusicTxDigestId>> ckptmap = mysqlMixin.getCheckpointLocations(); + assertTrue(ckptmap.containsKey(r1)); + assertEquals(mri1.getIndex(), ckptmap.get(r1).getLeft().getIndex()); + assertEquals(i1.transactionId, ckptmap.get(r1).getRight().transactionId); + + assertTrue(ckptmap.containsKey(r2)); + assertEquals(mri2.getIndex(), ckptmap.get(r2).getLeft().getIndex()); + assertEquals(i2.transactionId, ckptmap.get(r2).getRight().transactionId); + } + + private void createTables() throws SQLException { + Statement st = conn.createStatement(); + st.execute("CREATE TABLE RANGER (name VARCHAR(20));"); + st.execute("CREATE TABLE RANGES (name VARCHAR(20));"); + st.close(); + //need to re-initiate the tables + this.mysqlMixin.initTables(); + } + + + private void clearTables() throws SQLException { + Set<Range> ranges = mysqlMixin.getSQLRangeSet(); + Statement st = conn.createStatement(); + for (Range r: ranges) { + try { + st.execute("DROP TABLE " + r + ";"); + } catch (SQLException e) { + System.out.println("Trouble dropping: " + r); + e.printStackTrace(); + } + } + st.close(); + } } diff --git a/mdbc-server/src/test/java/org/onap/music/mdbc/mixins/PostgresMixinTest.java b/mdbc-server/src/test/java/org/onap/music/mdbc/mixins/PostgresMixinTest.java index 457e3b9..1ee8de7 100644 --- a/mdbc-server/src/test/java/org/onap/music/mdbc/mixins/PostgresMixinTest.java +++ b/mdbc-server/src/test/java/org/onap/music/mdbc/mixins/PostgresMixinTest.java @@ -67,7 +67,7 @@ public class PostgresMixinTest { public static void close(){ //TODO: shutdown cassandra mixin=null; - MdbcTestUtils.cleanDatabase(DBType.POSTGRES); + MdbcTestUtils.stopDatabase(DBType.POSTGRES); MdbcTestUtils.stopCassandra(); } 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 e131caa..c0e7c50 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 @@ -96,7 +96,7 @@ public class OwnershipAndCheckpointTest { public static void close() throws MusicServiceException, MusicQueryException, ManagedProcessException { //TODO: shutdown cassandra musicMixin=null; - MdbcTestUtils.cleanDatabase(DBType.MySQL); + MdbcTestUtils.stopDatabase(DBType.MySQL); MdbcTestUtils.stopCassandra(); } |