}
@Test
public void testMultiRollback() throws Throwable {
// Here we will have more than one tablespace and we will rollback them all
final QNodeHandler handler = new QNodeHandler();
SploutConfiguration config = SploutConfiguration.getTestConfig();
try {
HazelcastInstance hz = Hazelcast.newHazelcastInstance(HazelcastConfigBuilder.build(config));
CoordinationStructures coord = new CoordinationStructures(hz);
/*
* Create 5 successful versions. current-version will be set to last one.
*/
// TODO
// for(int i = 0; i < 5; i++) {
// coord.getTablespaces().put(new TablespaceVersion("t1", i), new Tablespace(null, null, i, 0l));
// coord.getTablespaces().put(new TablespaceVersion("t2", i), new Tablespace(null, null, i, 0l));
// coord.getTablespaces().put(new TablespaceVersion("t3", i), new Tablespace(null, null, i, 0l));
// }
// T1 -> current version 4
// T2 -> current version 3
// T3 -> current version 2
Map<String, Long> versionsBeingServed = new HashMap<String, Long>();
versionsBeingServed.put("t1", 4l);
versionsBeingServed.put("t2", 3l);
versionsBeingServed.put("t3", 2l);
coord.getVersionsBeingServed().put(CoordinationStructures.VERSIONS_BEING_SERVED, versionsBeingServed);
handler.init(config);
List<SwitchVersionRequest> rRequest = new ArrayList<SwitchVersionRequest>();
// T1 -> rollback to version 2
// T2 -> rollback to version 1
// T3 -> rollback to version 0
SwitchVersionRequest theRequest = new SwitchVersionRequest("t1", 2l);
rRequest.add(theRequest);
theRequest = new SwitchVersionRequest("t2", 1l);
rRequest.add(theRequest);
theRequest = new SwitchVersionRequest("t3", 0l);
rRequest.add(theRequest);
handler.rollback(rRequest);
new TestUtils.NotWaitingForeverCondition() {
@Override
public boolean endCondition() {
return
handler.getContext().getCurrentVersionsMap().get("t1") != null &&
handler.getContext().getCurrentVersionsMap().get("t1") == 2l;
}
}.waitAtMost(5000);
assertEquals(2l, (long)coord.getCopyVersionsBeingServed().get("t1"));
assertEquals(1l, (long)coord.getCopyVersionsBeingServed().get("t2"));
assertEquals(0l, (long)coord.getCopyVersionsBeingServed().get("t3"));
assertEquals(2l, (long)handler.getContext().getCurrentVersionsMap().get("t1"));
assertEquals(1l, (long)handler.getContext().getCurrentVersionsMap().get("t2"));
assertEquals(0l, (long)handler.getContext().getCurrentVersionsMap().get("t3"));
} finally {
handler.close();
Hazelcast.shutdownAll();
}
}