aboutsummaryrefslogtreecommitdiffstats
path: root/mdbc-server/src/test
diff options
context:
space:
mode:
authorBharath Balasubramanian <bharathb@research.att.com>2019-03-12 23:24:52 +0000
committerGerrit Code Review <gerrit@onap.org>2019-03-12 23:24:52 +0000
commitf61985dedb975a777bed88fb17c482d0dbb73cd8 (patch)
treee6026e3c8d75468a2c5227401ce2a9560a34d8fb /mdbc-server/src/test
parent45ffc11e5cecf8112032d9d67c9c652f4836eacd (diff)
parentb4e66e8087274a656b1301ecb55fee4af183bf36 (diff)
Merge "Remove ownership logic from mixin"
Diffstat (limited to 'mdbc-server/src/test')
-rw-r--r--mdbc-server/src/test/java/org/onap/music/mdbc/mixins/MusicMixinTest.java184
-rw-r--r--mdbc-server/src/test/java/org/onap/music/mdbc/ownership/OwnershipAndCheckpointTest.java30
2 files changed, 117 insertions, 97 deletions
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 df673c9..e8b7511 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
@@ -50,6 +50,7 @@ import org.onap.music.main.MusicCore;
import org.onap.music.mdbc.DatabasePartition;
import org.onap.music.mdbc.MDBCUtils;
import org.onap.music.mdbc.Range;
+import org.onap.music.mdbc.StateManager;
import org.onap.music.mdbc.TestUtils;
import org.onap.music.mdbc.ownership.Dag;
import org.onap.music.mdbc.ownership.DagNode;
@@ -69,6 +70,7 @@ public class MusicMixinTest {
private static Session session;
private static String cassaHost = "localhost";
private static MusicMixin mixin = null;
+ private StateManager stateManager;
@BeforeClass
public static void init() throws MusicServiceException {
@@ -107,28 +109,29 @@ public class MusicMixinTest {
Properties properties = new Properties();
properties.setProperty(MusicMixin.KEY_MUSIC_NAMESPACE,keyspace);
properties.setProperty(MusicMixin.KEY_MY_ID,mdbcServerName);
- mixin=new MusicMixin(mdbcServerName,properties);
+ mixin=new MusicMixin(stateManager, mdbcServerName,properties);
} catch (MDBCServiceException e) {
fail("error creating music mixin");
}
}
- @Test(timeout=10000)
- public void own() {
- Range range = new Range("TABLE1");
- List<Range> ranges = new ArrayList<>();
- ranges.add(range);
- final DatabasePartition partition = TestUtils.createBasicRow(range, mixin, mdbcServerName);
- TestUtils.unlockRow(keyspace,mriTableName,partition);
-
- DatabasePartition currentPartition = new DatabasePartition(MDBCUtils.generateTimebasedUniqueKey());
- try {
- mixin.own(ranges,currentPartition, MDBCUtils.generateTimebasedUniqueKey());
- } catch (MDBCServiceException e) {
- fail("failure when running own function");
- }
- }
+ //Own has been removed from musicMixin
+// @Test(timeout=10000)
+// public void own() {
+// Range range = new Range("TABLE1");
+// List<Range> ranges = new ArrayList<>();
+// ranges.add(range);
+// final DatabasePartition partition = TestUtils.createBasicRow(range, mixin, mdbcServerName);
+// TestUtils.unlockRow(keyspace,mriTableName,partition);
+//
+// DatabasePartition currentPartition = new DatabasePartition(MDBCUtils.generateTimebasedUniqueKey());
+// try {
+// mixin.own(ranges,currentPartition, MDBCUtils.generateTimebasedUniqueKey());
+// } catch (MDBCServiceException e) {
+// fail("failure when running own function");
+// }
+// }
private DatabasePartition addRow(List<Range> ranges,boolean isLatest){
final UUID uuid = MDBCUtils.generateTimebasedUniqueKey();
@@ -150,80 +153,81 @@ public class MusicMixinTest {
return partition;
}
- @Test(timeout=10000)
- public void own2() throws InterruptedException, MDBCServiceException {
- List<Range> range12 = new ArrayList<>( Arrays.asList(
- new Range("RANGE1"),
- new Range("RANGE2")
- ));
- List<Range> range34 = new ArrayList<>( Arrays.asList(
- new Range("RANGE3"),
- new Range("RANGE4")
- ));
- List<Range> range24 = new ArrayList<>( Arrays.asList(
- new Range("RANGE2"),
- new Range("RANGE4")
- ));
- List<Range> range123 = new ArrayList<>( Arrays.asList(
- new Range("RANGE1"),
- new Range("RANGE2"),
- new Range("RANGE3")
- ));
- DatabasePartition db1 = addRow(range12, false);
- DatabasePartition db2 = addRow(range34, false);
- MILLISECONDS.sleep(10);
- DatabasePartition db3 = addRow(range12, true);
- DatabasePartition db4 = addRow(range34, true);
- MILLISECONDS.sleep(10);
- DatabasePartition db5 = addRow(range24, true);
- DatabasePartition currentPartition = new DatabasePartition(MDBCUtils.generateTimebasedUniqueKey());
- MusicInterface.OwnershipReturn own = null;
- try {
- own = mixin.own(range123, currentPartition, MDBCUtils.generateTimebasedUniqueKey());
- } catch (MDBCServiceException e) {
- fail("failure when running own function");
- }
- Dag dag = own.getDag();
-
- DagNode node4 = dag.getNode(db4.getMRIIndex());
- assertFalse(node4.hasNotIncomingEdges());
- List<DagNode> outgoingEdges = new ArrayList<>(node4.getOutgoingEdges());
- assertEquals(1,outgoingEdges.size());
-
- DagNode missing = outgoingEdges.get(0);
- Set<Range> missingRanges = missing.getRangeSet();
- assertEquals(2,missingRanges.size());
- assertTrue(missingRanges.contains(new Range("RANGE1")));
- assertTrue(missingRanges.contains(new Range("RANGE3")));
- List<DagNode> outgoingEdges1 = missing.getOutgoingEdges();
- assertEquals(1,outgoingEdges1.size());
-
- DagNode finalNode = outgoingEdges1.get(0);
- assertFalse(finalNode.hasNotIncomingEdges());
- Set<Range> finalSet = finalNode.getRangeSet();
- assertEquals(3,finalSet.size());
- assertTrue(finalSet.contains(new Range("RANGE1")));
- assertTrue(finalSet.contains(new Range("RANGE2")));
- assertTrue(finalSet.contains(new Range("RANGE3")));
-
- DagNode node5 = dag.getNode(db5.getMRIIndex());
- List<DagNode> toRemoveOutEdges = node5.getOutgoingEdges();
- assertEquals(1,toRemoveOutEdges.size());
- toRemoveOutEdges.remove(finalNode);
- assertEquals(0,toRemoveOutEdges.size());
-
- MusicRangeInformationRow row = mixin.getMusicRangeInformation(own.getRangeId());
- assertTrue(row.getIsLatest());
- DatabasePartition dbPartition = row.getDBPartition();
- List<Range> snapshot = dbPartition.getSnapshot();
- assertEquals(3,snapshot.size());
- MusicRangeInformationRow node5row = mixin.getMusicRangeInformation(node5.getId());
- assertFalse(node5row.getIsLatest());
- MusicRangeInformationRow node4Row = mixin.getMusicRangeInformation(db4.getMRIIndex());
- assertFalse(node4Row.getIsLatest());
- MusicRangeInformationRow node3Row = mixin.getMusicRangeInformation(db3.getMRIIndex());
- assertFalse(node3Row.getIsLatest());
- }
+ //Own has been removed from musicMixin
+// @Test(timeout=10000)
+// public void own2() throws InterruptedException, MDBCServiceException {
+// List<Range> range12 = new ArrayList<>( Arrays.asList(
+// new Range("RANGE1"),
+// new Range("RANGE2")
+// ));
+// List<Range> range34 = new ArrayList<>( Arrays.asList(
+// new Range("RANGE3"),
+// new Range("RANGE4")
+// ));
+// List<Range> range24 = new ArrayList<>( Arrays.asList(
+// new Range("RANGE2"),
+// new Range("RANGE4")
+// ));
+// List<Range> range123 = new ArrayList<>( Arrays.asList(
+// new Range("RANGE1"),
+// new Range("RANGE2"),
+// new Range("RANGE3")
+// ));
+// DatabasePartition db1 = addRow(range12, false);
+// DatabasePartition db2 = addRow(range34, false);
+// MILLISECONDS.sleep(10);
+// DatabasePartition db3 = addRow(range12, true);
+// DatabasePartition db4 = addRow(range34, true);
+// MILLISECONDS.sleep(10);
+// DatabasePartition db5 = addRow(range24, true);
+// DatabasePartition currentPartition = new DatabasePartition(MDBCUtils.generateTimebasedUniqueKey());
+// MusicInterface.OwnershipReturn own = null;
+// try {
+// own = mixin.own(range123, currentPartition, MDBCUtils.generateTimebasedUniqueKey());
+// } catch (MDBCServiceException e) {
+// fail("failure when running own function");
+// }
+// Dag dag = own.getDag();
+//
+// DagNode node4 = dag.getNode(db4.getMRIIndex());
+// assertFalse(node4.hasNotIncomingEdges());
+// List<DagNode> outgoingEdges = new ArrayList<>(node4.getOutgoingEdges());
+// assertEquals(1,outgoingEdges.size());
+//
+// DagNode missing = outgoingEdges.get(0);
+// Set<Range> missingRanges = missing.getRangeSet();
+// assertEquals(2,missingRanges.size());
+// assertTrue(missingRanges.contains(new Range("RANGE1")));
+// assertTrue(missingRanges.contains(new Range("RANGE3")));
+// List<DagNode> outgoingEdges1 = missing.getOutgoingEdges();
+// assertEquals(1,outgoingEdges1.size());
+//
+// DagNode finalNode = outgoingEdges1.get(0);
+// assertFalse(finalNode.hasNotIncomingEdges());
+// Set<Range> finalSet = finalNode.getRangeSet();
+// assertEquals(3,finalSet.size());
+// assertTrue(finalSet.contains(new Range("RANGE1")));
+// assertTrue(finalSet.contains(new Range("RANGE2")));
+// assertTrue(finalSet.contains(new Range("RANGE3")));
+//
+// DagNode node5 = dag.getNode(db5.getMRIIndex());
+// List<DagNode> toRemoveOutEdges = node5.getOutgoingEdges();
+// assertEquals(1,toRemoveOutEdges.size());
+// toRemoveOutEdges.remove(finalNode);
+// assertEquals(0,toRemoveOutEdges.size());
+//
+// MusicRangeInformationRow row = mixin.getMusicRangeInformation(own.getRangeId());
+// assertTrue(row.getIsLatest());
+// DatabasePartition dbPartition = row.getDBPartition();
+// List<Range> snapshot = dbPartition.getSnapshot();
+// assertEquals(3,snapshot.size());
+// MusicRangeInformationRow node5row = mixin.getMusicRangeInformation(node5.getId());
+// assertFalse(node5row.getIsLatest());
+// MusicRangeInformationRow node4Row = mixin.getMusicRangeInformation(db4.getMRIIndex());
+// assertFalse(node4Row.getIsLatest());
+// MusicRangeInformationRow node3Row = mixin.getMusicRangeInformation(db3.getMRIIndex());
+// assertFalse(node3Row.getIsLatest());
+// }
@Test
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 4950484..7db973c 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
@@ -36,6 +36,8 @@ import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Ignore;
import org.junit.Test;
+import org.mockito.Mock;
+import org.mockito.Mockito;
import org.onap.music.datastore.MusicDataStore;
import org.onap.music.datastore.MusicDataStoreHandle;
import org.onap.music.exceptions.MDBCServiceException;
@@ -45,6 +47,7 @@ import org.onap.music.lockingservice.cassandra.CassaLockStore;
import org.onap.music.mdbc.DatabasePartition;
import org.onap.music.mdbc.MDBCUtils;
import org.onap.music.mdbc.Range;
+import org.onap.music.mdbc.StateManager;
import org.onap.music.mdbc.TestUtils;
import org.onap.music.mdbc.mixins.LockResult;
import org.onap.music.mdbc.mixins.MusicInterface.OwnershipReturn;
@@ -79,6 +82,11 @@ public class OwnershipAndCheckpointTest {
private static DB db;
Connection conn;
MySQLMixin mysqlMixin;
+ OwnershipAndCheckpoint ownAndCheck;
+
+ @Mock
+ StateManager stateManager = Mockito.mock(StateManager.class);
+
@BeforeClass
public static void init() throws MusicServiceException, ClassNotFoundException, ManagedProcessException {
@@ -141,9 +149,11 @@ public class OwnershipAndCheckpointTest {
Properties properties = new Properties();
properties.setProperty(MusicMixin.KEY_MY_ID,mdbcServerName);
properties.setProperty(MusicMixin.KEY_MUSIC_NAMESPACE,keyspace);
- musicMixin =new MusicMixin(mdbcServerName,properties);
+ //StateManager stateManager = new StateManager("dbUrl", properties, "serverName", "dbName");
+ ownAndCheck = new OwnershipAndCheckpoint();
+ musicMixin =new MusicMixin(stateManager, mdbcServerName,properties);
} catch (MDBCServiceException e) {
- fail("error creating music musicMixin");
+ fail("error creating music musicMixin " + e.getMessage());
}
this.conn = DriverManager.getConnection("jdbc:mariadb://localhost:"+sqlPort+"/"+DATABASE, "root", "");
this.mysqlMixin = new MySQLMixin(musicMixin, "localhost:"+sqlPort+"/"+DATABASE, conn, null);
@@ -155,7 +165,7 @@ public class OwnershipAndCheckpointTest {
String sqlOperation = "INSERT INTO "+TABLE+" (PersonID,LastName,FirstName,Address,City) VALUES "+
"(1,'SAUREZ','ENRIQUE','GATECH','ATLANTA');";
StagingTable stagingTable = new StagingTable();
- musicMixin.reloadAlreadyApplied(partition);
+ ownAndCheck.reloadAlreadyApplied(partition);
final Statement executeStatement = this.conn.createStatement();
executeStatement.execute(sqlOperation);
this.conn.commit();
@@ -170,12 +180,12 @@ public class OwnershipAndCheckpointTest {
private OwnershipReturn cleanAndOwnPartition(List<Range> ranges, UUID ownOpId) throws SQLException {
dropAndCreateTable();
- musicMixin.cleanAlreadyApplied();
+ cleanAlreadyApplied(ownAndCheck);
DatabasePartition currentPartition = new DatabasePartition(MDBCUtils.generateTimebasedUniqueKey());
OwnershipReturn own=null;
try {
- own = musicMixin.own(ranges, currentPartition, ownOpId);
+ own = ownAndCheck.own(musicMixin, ranges, currentPartition, ownOpId);
} catch (MDBCServiceException e) {
fail("failure when running own function");
}
@@ -207,7 +217,8 @@ public class OwnershipAndCheckpointTest {
public void checkpoint() throws MDBCServiceException, SQLException {
Range range =
new Range(TABLE);
- OwnershipAndCheckpoint ownAndCheck = musicMixin.getOwnAndCheck();
+ Mockito.when(stateManager.getOwnAndCheck()).thenReturn(this.ownAndCheck);
+
initDatabase(range);
List<Range> ranges = new ArrayList<>();
@@ -230,7 +241,8 @@ public class OwnershipAndCheckpointTest {
//@Ignore
public void warmup() throws MDBCServiceException, SQLException {
Range range = new Range(TABLE);
- OwnershipAndCheckpoint ownAndCheck = musicMixin.getOwnAndCheck();
+ Mockito.when(stateManager.getOwnAndCheck()).thenReturn(this.ownAndCheck);
+
initDatabase(range);
List<Range> ranges = new ArrayList<>();
@@ -249,4 +261,8 @@ public class OwnershipAndCheckpointTest {
checkData();
}
+
+ private void cleanAlreadyApplied(OwnershipAndCheckpoint ownAndCheck) {
+ ownAndCheck.getAlreadyApplied().clear();
+ }
} \ No newline at end of file