refactor AbstractServerReplicationTest to enable tests with multiple replicable services in future

This commit is contained in:
Fredrik Teschke committed 2015-02-13 20:28:45 +01:00
1 parent df3b798bda
commit de39d6a40a
14 files changed
+260 -114

No files matched your search

@@ -35,8 +35,9 @@ public abstract class AbstractLogReplicationTest<LogT extends AbstractLog<EventT
/**
* Uses a new master that loads the existing regatta and race log to append an event to the race log. This will store it to the DB so that if the original
* master re-loads the race log it should see the new race log event.
* @throws Exception
*/
protected void addEventToDB(RaceLogIdentifier raceLogIdentifier, RaceLogRaceStatusEvent createRaceStatusEvent, String regattaName, String raceColumnName, String fleetName) {
protected void addEventToDB(RaceLogIdentifier raceLogIdentifier, RaceLogRaceStatusEvent createRaceStatusEvent, String regattaName, String raceColumnName, String fleetName) throws Exception {
final RacingEventServiceImpl temporaryMaster = createNewMaster();
Regatta regatta = temporaryMaster.getRegatta(new RegattaName(regattaName+" ("+BOAT_CLASS_NAME_49er+")"));
Series series = regatta.getSeries().iterator().next();
@@ -11,32 +11,43 @@ import com.sap.sailing.server.RacingEventService;
import com.sap.sailing.server.impl.RacingEventServiceImpl;
import com.sap.sse.mongodb.MongoDBService;
public abstract class AbstractServerReplicationTest extends com.sap.sse.replication.testsupport.AbstractServerReplicationTest<RacingEventService, RacingEventServiceImpl> {
protected MongoDBService mongoDBService;
protected MongoObjectFactory mongoObjectFactory;
public abstract class AbstractServerReplicationTest extends com.sap.sse.replication.testsupport.AbstractServerWithSingleServiceReplicationTest<RacingEventService, RacingEventServiceImpl> {
protected ServerReplicationTestSetUp testSetUp;
/**
* Drops the test DB, if <code>dropDB</code> is <code>true</code> and requests the DB to start.
*/
@Override
protected void persistenceSetUp(boolean dropDB) {
mongoDBService = MongoDBService.INSTANCE;
if (dropDB) {
mongoDBService.getDB().dropDatabase();
}
mongoObjectFactory = PersistenceFactory.INSTANCE.getMongoObjectFactory(mongoDBService);
public AbstractServerReplicationTest() {
super(new ServerReplicationTestSetUp());
testSetUp = (ServerReplicationTestSetUp) super.testSetUp;
}
protected RacingEventServiceImpl createNewMaster() {
return new RacingEventServiceImpl(PersistenceFactory.INSTANCE.getDomainObjectFactory(mongoDBService,
DomainFactory.INSTANCE), mongoObjectFactory, MediaDBFactory.INSTANCE.getMediaDB(mongoDBService),
EmptyWindStore.INSTANCE, EmptyGPSFixStore.INSTANCE);
}
protected RacingEventServiceImpl createNewReplica() {
return new RacingEventServiceImpl(PersistenceFactory.INSTANCE.getDomainObjectFactory(mongoDBService,
// replica gets its own base DomainFactory:
new DomainFactoryImpl()), mongoObjectFactory, MediaDBFactory.INSTANCE.getMediaDB(mongoDBService),
EmptyWindStore.INSTANCE, EmptyGPSFixStore.INSTANCE);
protected static class ServerReplicationTestSetUp extends com.sap.sse.replication.testsupport.AbstractServerReplicationTestSetUp<RacingEventService, RacingEventServiceImpl> {
protected MongoDBService mongoDBService;
protected MongoObjectFactory mongoObjectFactory;
/**
* Drops the test DB, if <code>dropDB</code> is <code>true</code> and requests the DB to start.
*/
@Override
protected void persistenceSetUp(boolean dropDB) {
mongoDBService = MongoDBService.INSTANCE;
if (dropDB) {
mongoDBService.getDB().dropDatabase();
}
mongoObjectFactory = PersistenceFactory.INSTANCE.getMongoObjectFactory(mongoDBService);
}
@Override
public RacingEventServiceImpl createNewMaster() {
return new RacingEventServiceImpl(PersistenceFactory.INSTANCE.getDomainObjectFactory(mongoDBService,
DomainFactory.INSTANCE), mongoObjectFactory, MediaDBFactory.INSTANCE.getMediaDB(mongoDBService),
EmptyWindStore.INSTANCE, EmptyGPSFixStore.INSTANCE);
}
@Override
public RacingEventServiceImpl createNewReplica() {
return new RacingEventServiceImpl(PersistenceFactory.INSTANCE.getDomainObjectFactory(mongoDBService,
// replica gets its own base DomainFactory:
new DomainFactoryImpl()), mongoObjectFactory, MediaDBFactory.INSTANCE.getMediaDB(mongoDBService),
EmptyWindStore.INSTANCE, EmptyGPSFixStore.INSTANCE);
}
}
}
@@ -81,16 +81,20 @@ public class ConnectionResetAndReconnectTest extends AbstractServerReplicationTe
}
@Before
@Override
public void setUp() throws Exception {
try {
Pair<com.sap.sse.replication.testsupport.AbstractServerReplicationTest.ReplicationServiceTestImpl<RacingEventService>, ReplicationMasterDescriptor> result = basicSetUp(/* dropDB */ true,
/* master=null means create a new one */ null, /* replica=null means create a new one */null);
masterDescriptor = MasterReplicationDescriptorMock.from(result.getB());
} catch (Exception e) {
e.printStackTrace();
tearDown();
protected static class ServerReplicationTestSetUp extends
com.sap.sailing.server.replication.test.AbstractServerReplicationTest.ServerReplicationTestSetUp {
@Before
@Override
public void setUp() throws Exception {
try {
Pair<ReplicationServiceTestImpl<RacingEventService>, ReplicationMasterDescriptor> result = basicSetUp(
/* dropDB */true,
/* master=null means create a new one */null, /* replica=null means create a new one */null);
masterDescriptor = MasterReplicationDescriptorMock.from(result.getB());
} catch (Exception e) {
e.printStackTrace();
tearDown();
}
}
}
@@ -102,7 +106,7 @@ public class ConnectionResetAndReconnectTest extends AbstractServerReplicationTe
/* until here both instances should have the same in-memory state.
* now lets add an event on master and stop the messaging queue. */
stopMessagingExchange();
replicaReplicator.startToReplicateFrom(masterDescriptor);
testSetUp.getReplicaReplicator().startToReplicateFrom(testSetUp.getMasterDescriptor());
Event event = addEventOnMaster();
Thread.sleep(1000); // wait for master queue to get filled
assertNull(replica.getEvent(event.getId()));
@@ -46,6 +46,7 @@ import com.sap.sse.common.impl.MillisecondsTimePoint;
import com.sap.sse.mongodb.MongoDBService;
import com.sap.sse.replication.ReplicationMasterDescriptor;
import com.sap.sse.replication.ReplicationService;
import com.sap.sse.replication.testsupport.AbstractServerReplicationTestSetUp.ReplicationServiceTestImpl;
public class DelayedLeaderboardCorrectionsReplicationTest extends AbstractServerReplicationTest {
private static final Logger logger = Logger.getLogger(DelayedLeaderboardCorrectionsReplicationTest.class.getName());
@@ -115,7 +116,7 @@ public class DelayedLeaderboardCorrectionsReplicationTest extends AbstractServer
masterLeaderboardReloaded.getRaceColumnByName(Q2), MillisecondsTimePoint.now()));
// replicate the re-loaded environment
Pair<com.sap.sse.replication.testsupport.AbstractServerReplicationTest.ReplicationServiceTestImpl<RacingEventService>, ReplicationMasterDescriptor> descriptors = basicSetUp(
Pair<ReplicationServiceTestImpl<RacingEventService>, ReplicationMasterDescriptor> descriptors = basicSetUp(
/* dropDB */false, master, replica);
replicaReplicator = descriptors.getA();
masterDescriptor = descriptors.getB();
@@ -73,9 +73,10 @@ import com.sap.sse.common.impl.MillisecondsDurationImpl;
import com.sap.sse.common.impl.MillisecondsTimePoint;
import com.sap.sse.replication.ReplicationMasterDescriptor;
import com.sap.sse.replication.impl.ReplicationReceiver;
import com.sap.sse.replication.testsupport.AbstractServerReplicationTestSetUp.ReplicationServiceTestImpl;
public class InitialLoadReplicationObjectIdentityTest extends AbstractServerReplicationTest {
private Pair<com.sap.sse.replication.testsupport.AbstractServerReplicationTest.ReplicationServiceTestImpl<RacingEventService>, ReplicationMasterDescriptor> replicationDescriptorPair;
private Pair<ReplicationServiceTestImpl<RacingEventService>, ReplicationMasterDescriptor> replicationDescriptorPair;
/**
* Drops the test DB. Sets up master and replica, starts the JMS message broker and registers the replica with the master.
@@ -84,10 +85,10 @@ public class InitialLoadReplicationObjectIdentityTest extends AbstractServerRepl
@Override
public void setUp() throws Exception {
persistenceSetUp(/* dropDB */ true);
this.master = new RacingEventServiceImpl(PersistenceFactory.INSTANCE.getDomainObjectFactory(mongoDBService, DomainFactory.INSTANCE), PersistenceFactory.INSTANCE
.getMongoObjectFactory(mongoDBService), MediaDBFactory.INSTANCE.getMediaDB(mongoDBService), EmptyWindStore.INSTANCE, EmptyGPSFixStore.INSTANCE);
this.replica = new RacingEventServiceImpl(PersistenceFactory.INSTANCE.getDomainObjectFactory(mongoDBService, DomainFactory.INSTANCE), PersistenceFactory.INSTANCE
.getMongoObjectFactory(mongoDBService), MediaDBFactory.INSTANCE.getMediaDB(mongoDBService), EmptyWindStore.INSTANCE, EmptyGPSFixStore.INSTANCE);
this.master = new RacingEventServiceImpl(PersistenceFactory.INSTANCE.getDomainObjectFactory(testSetUp.mongoDBService, DomainFactory.INSTANCE), PersistenceFactory.INSTANCE
.getMongoObjectFactory(testSetUp.mongoDBService), MediaDBFactory.INSTANCE.getMediaDB(testSetUp.mongoDBService), EmptyWindStore.INSTANCE, EmptyGPSFixStore.INSTANCE);
this.replica = new RacingEventServiceImpl(PersistenceFactory.INSTANCE.getDomainObjectFactory(testSetUp.mongoDBService, DomainFactory.INSTANCE), PersistenceFactory.INSTANCE
.getMongoObjectFactory(testSetUp.mongoDBService), MediaDBFactory.INSTANCE.getMediaDB(testSetUp.mongoDBService), EmptyWindStore.INSTANCE, EmptyGPSFixStore.INSTANCE);
}
private void performReplicationSetup() throws Exception {
@@ -15,6 +15,7 @@ import com.sap.sailing.server.operationaltransformation.CreateFlexibleLeaderboar
import com.sap.sse.common.Util.Pair;
import com.sap.sse.replication.ReplicationMasterDescriptor;
import com.sap.sse.replication.impl.ReplicationReceiver;
import com.sap.sse.replication.testsupport.AbstractServerReplicationTestSetUp.ReplicationServiceTestImpl;
public class PrematureOperationReceiptTest extends AbstractServerReplicationTest {
private ReplicationReceiver replicator;
@@ -25,7 +26,7 @@ public class PrematureOperationReceiptTest extends AbstractServerReplicationTest
@Before
@Override
public void setUp() throws Exception {
Pair<com.sap.sse.replication.testsupport.AbstractServerReplicationTest.ReplicationServiceTestImpl<RacingEventService>, ReplicationMasterDescriptor> result =
Pair<ReplicationServiceTestImpl<RacingEventService>, ReplicationMasterDescriptor> result =
basicSetUp(/* dropDB */ true, /* master=null means create a new one */ null, /* replica=null means create a new one */ null);
replicator = replicaReplicator.startToReplicateFromButDontYetFetchInitialLoad(result.getB(), /* startReplicatorSuspended */ true);
}
@@ -47,10 +47,11 @@ import com.sap.sse.common.Util;
import com.sap.sse.common.Util.Pair;
import com.sap.sse.common.impl.MillisecondsTimePoint;
import com.sap.sse.replication.ReplicationMasterDescriptor;
import com.sap.sse.replication.testsupport.AbstractServerReplicationTestSetUp.ReplicationServiceTestImpl;
public class RaceLogReplicationTest extends AbstractLogReplicationTest<RaceLog, RaceLogEvent, RaceLogEventVisitor> {
private Pair<com.sap.sse.replication.testsupport.AbstractServerReplicationTest.ReplicationServiceTestImpl<RacingEventService>, ReplicationMasterDescriptor> replicationDescriptorPair;
private Pair<ReplicationServiceTestImpl<RacingEventService>, ReplicationMasterDescriptor> replicationDescriptorPair;
private RaceLogEvent raceLogEvent;
private RaceLogEvent anotherRaceLogEvent;
@@ -217,7 +218,7 @@ public class RaceLogReplicationTest extends AbstractLogReplicationTest<RaceLog,
* has been added to the DB and then race log is re-loaded on the master, the events added through the DB also show up on the replica.
*/
@Test
public void testRaceLogReloadReplication() throws ClassNotFoundException, IOException, InterruptedException {
public void testRaceLogReloadReplication() throws Exception {
final String regattaName = "Test";
final String seriesName = "Default";
final String fleetName = "Default";
@@ -22,11 +22,12 @@ import com.sap.sse.common.TimePoint;
import com.sap.sse.common.Util.Pair;
import com.sap.sse.common.impl.MillisecondsTimePoint;
import com.sap.sse.replication.ReplicationMasterDescriptor;
import com.sap.sse.replication.testsupport.AbstractServerReplicationTestSetUp.ReplicationServiceTestImpl;
public class RegattaLogReplicationTest extends
AbstractLogReplicationTest<RegattaLog, RegattaLogEvent, RegattaLogEventVisitor> {
private Pair<com.sap.sse.replication.testsupport.AbstractServerReplicationTest.ReplicationServiceTestImpl<RacingEventService>, ReplicationMasterDescriptor> replicationDescriptorPair;
private Pair<ReplicationServiceTestImpl<RacingEventService>, ReplicationMasterDescriptor> replicationDescriptorPair;
private RegattaLogEvent regattaLogEvent;
// private RegattaLogEvent anotherRegattaLogEvent;