mirror of
https://github.com/eclipse-sailing-analytics/sailing-analytics.git
synced 2026-09-20 04:35:32 +00:00
refactor AbstractServerReplicationTest to enable tests with multiple replicable services in future
This commit is contained in:
+2
-1
@@ -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();
|
||||
|
||||
+14
-3
@@ -11,7 +11,15 @@ 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> {
|
||||
public abstract class AbstractServerReplicationTest extends com.sap.sse.replication.testsupport.AbstractServerWithSingleServiceReplicationTest<RacingEventService, RacingEventServiceImpl> {
|
||||
protected ServerReplicationTestSetUp testSetUp;
|
||||
|
||||
public AbstractServerReplicationTest() {
|
||||
super(new ServerReplicationTestSetUp());
|
||||
testSetUp = (ServerReplicationTestSetUp) super.testSetUp;
|
||||
}
|
||||
|
||||
protected static class ServerReplicationTestSetUp extends com.sap.sse.replication.testsupport.AbstractServerReplicationTestSetUp<RacingEventService, RacingEventServiceImpl> {
|
||||
protected MongoDBService mongoDBService;
|
||||
protected MongoObjectFactory mongoObjectFactory;
|
||||
|
||||
@@ -27,16 +35,19 @@ public abstract class AbstractServerReplicationTest extends com.sap.sse.replicat
|
||||
mongoObjectFactory = PersistenceFactory.INSTANCE.getMongoObjectFactory(mongoDBService);
|
||||
}
|
||||
|
||||
protected RacingEventServiceImpl createNewMaster() {
|
||||
@Override
|
||||
public RacingEventServiceImpl createNewMaster() {
|
||||
return new RacingEventServiceImpl(PersistenceFactory.INSTANCE.getDomainObjectFactory(mongoDBService,
|
||||
DomainFactory.INSTANCE), mongoObjectFactory, MediaDBFactory.INSTANCE.getMediaDB(mongoDBService),
|
||||
EmptyWindStore.INSTANCE, EmptyGPSFixStore.INSTANCE);
|
||||
}
|
||||
|
||||
protected RacingEventServiceImpl createNewReplica() {
|
||||
@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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+7
-3
@@ -81,18 +81,22 @@ public class ConnectionResetAndReconnectTest extends AbstractServerReplicationTe
|
||||
|
||||
}
|
||||
|
||||
protected static class ServerReplicationTestSetUp extends
|
||||
com.sap.sailing.server.replication.test.AbstractServerReplicationTest.ServerReplicationTestSetUp {
|
||||
@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);
|
||||
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();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testReplicaLoosingConnectionToExchangeQueue() throws Exception {
|
||||
@@ -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()));
|
||||
|
||||
+2
-1
@@ -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();
|
||||
|
||||
+6
-5
@@ -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 {
|
||||
|
||||
+2
-1
@@ -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);
|
||||
}
|
||||
|
||||
+3
-2
@@ -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";
|
||||
|
||||
+2
-1
@@ -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;
|
||||
|
||||
+10
-4
@@ -10,10 +10,15 @@ import com.sap.sse.filestorage.impl.EmptyFileStorageServicePropertyStoreImpl;
|
||||
import com.sap.sse.filestorage.impl.FileStorageManagementServiceImpl;
|
||||
import com.sap.sse.filestorage.testsupport.DummyFileStorageService;
|
||||
import com.sap.sse.mongodb.MongoDBService;
|
||||
import com.sap.sse.replication.testsupport.AbstractServerReplicationTest;
|
||||
import com.sap.sse.replication.testsupport.AbstractServerWithSingleServiceReplicationTest;
|
||||
|
||||
public abstract class AbstractFileStorageManagementServiceReplicationTest extends
|
||||
AbstractServerReplicationTest<FileStorageManagementService, FileStorageManagementServiceImpl> {
|
||||
AbstractServerWithSingleServiceReplicationTest<FileStorageManagementService, FileStorageManagementServiceImpl> {
|
||||
public AbstractFileStorageManagementServiceReplicationTest() {
|
||||
super(new ServerReplicationTestSetUp());
|
||||
}
|
||||
|
||||
private static class ServerReplicationTestSetUp extends com.sap.sse.replication.testsupport.AbstractServerReplicationTestSetUp<FileStorageManagementService, FileStorageManagementServiceImpl> {
|
||||
private MongoDBService mongoDBService;
|
||||
|
||||
@Override
|
||||
@@ -31,7 +36,7 @@ public abstract class AbstractFileStorageManagementServiceReplicationTest extend
|
||||
}
|
||||
|
||||
@Override
|
||||
protected FileStorageManagementServiceImpl createNewMaster() throws MalformedURLException, IOException,
|
||||
public FileStorageManagementServiceImpl createNewMaster() throws MalformedURLException, IOException,
|
||||
InterruptedException {
|
||||
FileStorageManagementServiceImpl result = createNewService();
|
||||
FileStorageService serviceOnMaster = result.getAvailableFileStorageServices()[0];
|
||||
@@ -41,7 +46,7 @@ public abstract class AbstractFileStorageManagementServiceReplicationTest extend
|
||||
}
|
||||
|
||||
@Override
|
||||
protected FileStorageManagementServiceImpl createNewReplica() {
|
||||
public FileStorageManagementServiceImpl createNewReplica() {
|
||||
return createNewService();
|
||||
}
|
||||
|
||||
@@ -49,4 +54,5 @@ public abstract class AbstractFileStorageManagementServiceReplicationTest extend
|
||||
protected void persistenceTearDown() {
|
||||
mongoDBService.getDB().dropDatabase();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+39
-14
@@ -22,8 +22,6 @@ import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
import java.util.zip.GZIPOutputStream;
|
||||
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Rule;
|
||||
import org.junit.rules.Timeout;
|
||||
|
||||
@@ -42,10 +40,12 @@ import com.sap.sse.replication.impl.ReplicationReceiver;
|
||||
import com.sap.sse.replication.impl.ReplicationServiceImpl;
|
||||
import com.sap.sse.replication.impl.SingletonReplicablesProvider;
|
||||
|
||||
public abstract class AbstractServerReplicationTest<ReplicableInterface extends Replicable<?, ?>, ReplicableImpl extends ReplicableInterface> {
|
||||
private static final Logger logger = Logger.getLogger(AbstractServerReplicationTest.class.getName());
|
||||
public abstract class AbstractServerReplicationTestSetUp<ReplicableInterface extends Replicable<?, ?>, ReplicableImpl extends ReplicableInterface> {
|
||||
private static final Logger logger = Logger.getLogger(AbstractServerReplicationTestSetUp.class.getName());
|
||||
|
||||
protected static final int SERVLET_PORT = 9990;
|
||||
protected static final int DEFAULT_SERVLET_PORT = 9990;
|
||||
|
||||
private final int servletPort;
|
||||
protected ReplicableImpl replica;
|
||||
protected ReplicableImpl master;
|
||||
protected ReplicationServiceTestImpl<ReplicableInterface> replicaReplicator;
|
||||
@@ -53,6 +53,14 @@ public abstract class AbstractServerReplicationTest<ReplicableInterface extends
|
||||
private ReplicationServiceImpl masterReplicator;
|
||||
protected ReplicationMasterDescriptor masterDescriptor;
|
||||
|
||||
protected AbstractServerReplicationTestSetUp() {
|
||||
servletPort = DEFAULT_SERVLET_PORT;
|
||||
}
|
||||
|
||||
protected AbstractServerReplicationTestSetUp(int servletPort) {
|
||||
this.servletPort = servletPort;
|
||||
}
|
||||
|
||||
@Rule public Timeout AbstractTracTracLiveTestTimeout = new Timeout(5 * 60 * 1000); // timeout after 5 minutes
|
||||
private Thread initialLoadTestServerThread;
|
||||
|
||||
@@ -64,7 +72,6 @@ public abstract class AbstractServerReplicationTest<ReplicableInterface extends
|
||||
* or {@link ReplicationServiceTestImpl#startToReplicateFromButDontYetFetchInitialLoad(ReplicationMasterDescriptor, boolean)}
|
||||
* on the first component returned by {@link #basicSetUp(boolean, Replicable, Replicable)}.
|
||||
*/
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
try {
|
||||
Pair<ReplicationServiceTestImpl<ReplicableInterface>, ReplicationMasterDescriptor> result = basicSetUp(
|
||||
@@ -120,9 +127,9 @@ public abstract class AbstractServerReplicationTest<ReplicableInterface extends
|
||||
masterReplicator.registerReplica(replicaDescriptor);
|
||||
// connect to exchange host and local server running as master
|
||||
// master server and exchange host can be two different hosts
|
||||
masterDescriptor = new ReplicationMasterDescriptorImpl(exchangeHost, exchangeName, 0, UUID.randomUUID().toString(), "localhost", SERVLET_PORT);
|
||||
masterDescriptor = new ReplicationMasterDescriptorImpl(exchangeHost, exchangeName, 0, UUID.randomUUID().toString(), "localhost", servletPort);
|
||||
ReplicationServiceTestImpl<ReplicableInterface> replicaReplicator = new ReplicationServiceTestImpl<ReplicableInterface>(exchangeName, exchangeHost, rim, replicaDescriptor,
|
||||
this.replica, this.master, masterReplicator, masterDescriptor);
|
||||
this.replica, this.master, masterReplicator, masterDescriptor, servletPort);
|
||||
Pair<ReplicationServiceTestImpl<ReplicableInterface>, ReplicationMasterDescriptor> result = new Pair<>(replicaReplicator, masterDescriptor);
|
||||
logger.info("starting initial load transmission servlet for "+getClass().getName());
|
||||
initialLoadTestServerThread = replicaReplicator.startInitialLoadTransmissionServlet();
|
||||
@@ -136,16 +143,15 @@ public abstract class AbstractServerReplicationTest<ReplicableInterface extends
|
||||
* any initialization that {@link #persistenceSetUp(boolean)} may have performed can be assumed to have taken place in the implementations
|
||||
* of this method.
|
||||
*/
|
||||
abstract protected ReplicableImpl createNewMaster() throws Exception;
|
||||
protected abstract ReplicableImpl createNewMaster() throws Exception;
|
||||
|
||||
/**
|
||||
* Creates a new replica replicable instance. This method is called only after {@link #persistenceSetUp(boolean)} has been called. Therefore,
|
||||
* any initialization that {@link #persistenceSetUp(boolean)} may have performed can be assumed to have taken place in the implementations
|
||||
* of this method.
|
||||
*/
|
||||
abstract protected ReplicableImpl createNewReplica();
|
||||
protected abstract ReplicableImpl createNewReplica() throws Exception;
|
||||
|
||||
@After
|
||||
public void tearDown() throws Exception {
|
||||
logger.info("starting to tearDown() test");
|
||||
persistenceTearDown();
|
||||
@@ -160,7 +166,7 @@ public abstract class AbstractServerReplicationTest<ReplicableInterface extends
|
||||
try {
|
||||
if (initialLoadTestServerThread != null) {
|
||||
logger.info("found non-null initialLoadTestServerThread that we'll now try to stop...");
|
||||
URLConnection urlConnection = new URL("http://localhost:"+SERVLET_PORT+"/STOP").openConnection(); // stop the initial load test server thread
|
||||
URLConnection urlConnection = new URL("http://localhost:"+servletPort+"/STOP").openConnection(); // stop the initial load test server thread
|
||||
urlConnection.getInputStream().close();
|
||||
logger.info("sent and closed STOP request");
|
||||
initialLoadTestServerThread.join(10000 /* wait 10s */);
|
||||
@@ -191,16 +197,19 @@ public abstract class AbstractServerReplicationTest<ReplicableInterface extends
|
||||
private final ReplicaDescriptor replicaDescriptor;
|
||||
private final ReplicationService masterReplicationService;
|
||||
private final ReplicationMasterDescriptor masterDescriptor;
|
||||
private final int servletPort;
|
||||
|
||||
public ReplicationServiceTestImpl(String exchangeName, String exchangeHost, ReplicationInstancesManager replicationInstancesManager,
|
||||
ReplicaDescriptor replicaDescriptor, ReplicableInterface replica,
|
||||
ReplicableInterface master, ReplicationService masterReplicationService, ReplicationMasterDescriptor masterDescriptor)
|
||||
ReplicableInterface master, ReplicationService masterReplicationService, ReplicationMasterDescriptor masterDescriptor,
|
||||
int servletPort)
|
||||
throws IOException {
|
||||
super(exchangeName, exchangeHost, 0, replicationInstancesManager, new SingletonReplicablesProvider(replica));
|
||||
this.replicaDescriptor = replicaDescriptor;
|
||||
this.master = master;
|
||||
this.masterReplicationService = masterReplicationService;
|
||||
this.masterDescriptor = masterDescriptor;
|
||||
this.servletPort = servletPort;
|
||||
}
|
||||
|
||||
private Thread startInitialLoadTransmissionServlet() throws InterruptedException {
|
||||
@@ -209,7 +218,7 @@ public abstract class AbstractServerReplicationTest<ReplicableInterface extends
|
||||
public void run() {
|
||||
ServerSocket ss = null;
|
||||
try {
|
||||
ss = new ServerSocket(SERVLET_PORT);
|
||||
ss = new ServerSocket(servletPort);
|
||||
synchronized (listening) {
|
||||
listening[0] = true;
|
||||
listening.notifyAll();
|
||||
@@ -317,4 +326,20 @@ public abstract class AbstractServerReplicationTest<ReplicableInterface extends
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public ReplicableImpl getReplica() {
|
||||
return replica;
|
||||
}
|
||||
|
||||
public ReplicableImpl getMaster() {
|
||||
return master;
|
||||
}
|
||||
|
||||
public ReplicationServiceTestImpl<ReplicableInterface> getReplicaReplicator() {
|
||||
return replicaReplicator;
|
||||
}
|
||||
|
||||
public ReplicationMasterDescriptor getMasterDescriptor() {
|
||||
return masterDescriptor;
|
||||
}
|
||||
}
|
||||
+25
@@ -0,0 +1,25 @@
|
||||
package com.sap.sse.replication.testsupport;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
|
||||
public abstract class AbstractServerWithMultipleServicesReplicationTest {
|
||||
protected final Set<AbstractServerReplicationTestSetUp<?, ?>> testSetUps = new HashSet<>();
|
||||
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
for (AbstractServerReplicationTestSetUp<?, ?> testSetUp : testSetUps) {
|
||||
testSetUp.setUp();
|
||||
}
|
||||
}
|
||||
|
||||
@After
|
||||
public void tearDown() throws Exception {
|
||||
for (AbstractServerReplicationTestSetUp<?, ?> testSetUp : testSetUps) {
|
||||
testSetUp.tearDown();
|
||||
}
|
||||
}
|
||||
}
|
||||
+63
@@ -0,0 +1,63 @@
|
||||
package com.sap.sse.replication.testsupport;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
|
||||
import com.sap.sse.common.Util.Pair;
|
||||
import com.sap.sse.replication.Replicable;
|
||||
import com.sap.sse.replication.ReplicationMasterDescriptor;
|
||||
import com.sap.sse.replication.testsupport.AbstractServerReplicationTestSetUp.ReplicationServiceTestImpl;
|
||||
|
||||
public abstract class AbstractServerWithSingleServiceReplicationTest<ReplicableInterface extends Replicable<?, ?>, ReplicableImpl extends ReplicableInterface> {
|
||||
protected final AbstractServerReplicationTestSetUp<ReplicableInterface, ReplicableImpl> testSetUp;
|
||||
protected ReplicableImpl replica;
|
||||
protected ReplicableImpl master;
|
||||
protected ReplicationServiceTestImpl<ReplicableInterface> replicaReplicator;
|
||||
protected ReplicationMasterDescriptor masterDescriptor;
|
||||
|
||||
|
||||
public AbstractServerWithSingleServiceReplicationTest(AbstractServerReplicationTestSetUp<ReplicableInterface, ReplicableImpl> testSetUp) {
|
||||
this.testSetUp = testSetUp;
|
||||
}
|
||||
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
testSetUp.setUp();
|
||||
master = testSetUp.getMaster();
|
||||
replica = testSetUp.getReplica();
|
||||
replicaReplicator = testSetUp.getReplicaReplicator();
|
||||
masterDescriptor = testSetUp.getMasterDescriptor();
|
||||
}
|
||||
|
||||
protected Pair<ReplicationServiceTestImpl<ReplicableInterface>, ReplicationMasterDescriptor> basicSetUp(boolean dropDB,
|
||||
ReplicableImpl master, ReplicableImpl replica) throws Exception {
|
||||
return testSetUp.basicSetUp(dropDB, master, replica);
|
||||
}
|
||||
|
||||
@After
|
||||
public void tearDown() throws Exception {
|
||||
testSetUp.tearDown();
|
||||
}
|
||||
|
||||
protected ReplicableImpl createNewMaster() throws Exception {
|
||||
return testSetUp.createNewMaster();
|
||||
}
|
||||
|
||||
protected ReplicableImpl createNewReplica() throws Exception {
|
||||
return testSetUp.createNewReplica();
|
||||
}
|
||||
|
||||
protected void persistenceSetUp(boolean dropDB) {
|
||||
testSetUp.persistenceSetUp(dropDB);
|
||||
}
|
||||
|
||||
protected void persistenceTearDown() {
|
||||
testSetUp.persistenceTearDown();
|
||||
}
|
||||
|
||||
public void stopReplicatingToMaster() throws IOException {
|
||||
testSetUp.stopReplicatingToMaster();
|
||||
}
|
||||
}
|
||||
@@ -12,4 +12,4 @@ Require-Bundle: org.junit4;bundle-version="4.8.2",
|
||||
com.rabbitmq.client,
|
||||
org.mongodb.mongo-java-driver;bundle-version="2.13.0",
|
||||
com.sap.sse.replication.testsupport,
|
||||
com.sap.sse.replication.testsupport
|
||||
com.sap.sse.mail.replication.testsupport
|
||||
|
||||
+8
-2
@@ -4,12 +4,17 @@ import java.io.IOException;
|
||||
import java.net.MalformedURLException;
|
||||
|
||||
import com.sap.sse.mongodb.MongoDBService;
|
||||
import com.sap.sse.replication.testsupport.AbstractServerReplicationTest;
|
||||
import com.sap.sse.replication.testsupport.AbstractServerWithSingleServiceReplicationTest;
|
||||
import com.sap.sse.security.SecurityService;
|
||||
import com.sap.sse.security.impl.SecurityServiceImpl;
|
||||
import com.sap.sse.security.userstore.mongodb.UserStoreImpl;
|
||||
|
||||
public abstract class AbstractSecurityReplicationTest extends AbstractServerReplicationTest<SecurityService, SecurityServiceImpl> {
|
||||
public abstract class AbstractSecurityReplicationTest extends AbstractServerWithSingleServiceReplicationTest<SecurityService, SecurityServiceImpl> {
|
||||
public AbstractSecurityReplicationTest() {
|
||||
super(new ServerReplicationTestSetUp());
|
||||
}
|
||||
|
||||
private static class ServerReplicationTestSetUp extends com.sap.sse.replication.testsupport.AbstractServerReplicationTestSetUp<SecurityService, SecurityServiceImpl> {
|
||||
private MongoDBService mongoDBService;
|
||||
|
||||
@Override
|
||||
@@ -31,4 +36,5 @@ public abstract class AbstractSecurityReplicationTest extends AbstractServerRepl
|
||||
protected SecurityServiceImpl createNewReplica() {
|
||||
return new SecurityServiceImpl(new UserStoreImpl());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user