fixed replication operation queueing in Replicator; adjusted PrematureOperationReceiptTest to fail with unfixed queueing

This commit is contained in:
Axel Uhl
2014-11-20 11:25:06 +01:00
parent 26ef1fc4c3
commit 5439757b13
3 changed files with 22 additions and 8 deletions
@@ -45,21 +45,29 @@ public class PrematureOperationReceiptTest extends AbstractServerReplicationTest
final int[] discardThresholds = new int[] { 17, 23 };
CreateFlexibleLeaderboard createTestLeaderboard = new CreateFlexibleLeaderboard(leaderboardName, null, discardThresholds, new LowPoint(), null);
assertNull(master.getLeaderboardByName(leaderboardName));
replicationService.initialLoad(); // serialize the master state before the operation has been applied
master.apply(createTestLeaderboard);
final Leaderboard masterLeaderboard = master.getLeaderboardByName(leaderboardName);
assertNotNull(masterLeaderboard);
Thread.sleep(1000); // wait 1s for JMS to deliver the message and the message to be applied
final Leaderboard nonExistingReplicaLeaderboard = replica.getLeaderboardByName(leaderboardName);
assertNull(nonExistingReplicaLeaderboard); // because replicator is still suspended
replicationService.initialLoad();
{
final Leaderboard nonExistingReplicaLeaderboard = replica.getLeaderboardByName(leaderboardName);
assertNull(nonExistingReplicaLeaderboard); // because replicator is still suspended
}
{
final Leaderboard replicaLeaderboard = replica.getLeaderboardByName(leaderboardName);
assertNull(replicaLeaderboard); // because replicator is still suspended
}
replicator.setSuspended(false);
synchronized (replicator) {
while (!replicator.isQueueEmpty()) {
replicator.wait();
}
}
final Leaderboard replicaLeaderboard = replica.getLeaderboardByName(leaderboardName);
assertNotNull(replicaLeaderboard);
{
final Leaderboard replicaLeaderboard = replica.getLeaderboardByName(leaderboardName);
assertNotNull(replicaLeaderboard);
}
}
}
@@ -163,7 +163,7 @@ public class TrackRaceReplicationTest extends AbstractServerReplicationTest {
receivedStartAndEndOfTracking = master.getTrackedRace(raceIdentifier).getStartOfTracking() != null &&
master.getTrackedRace(raceIdentifier).getEndOfTracking() != null;
}
Thread.sleep(3000); // kept failing several times for a 1000ms timeout
Thread.sleep(1000);
logger.info("verifying replica's state");
TrackedRace replicaTrackedRace = replica.getTrackedRace(raceIdentifier);
assertEquals(masterTrackedRace.getStartOfTracking(), replicaTrackedRace.getStartOfTracking());
@@ -171,7 +171,7 @@ public class TrackRaceReplicationTest extends AbstractServerReplicationTest {
MillisecondsTimePoint now = MillisecondsTimePoint.now();
assertFalse(now.equals(replicaTrackedRace.getStartOfRace()));
((DynamicTrackedRace) masterTrackedRace).setStartTimeReceived(now);
Thread.sleep(3000);
Thread.sleep(1000);
assertEquals(now, replicaTrackedRace.getStartOfRace());
}
@@ -6,6 +6,7 @@ import java.io.EOFException;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.lang.reflect.Field;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
@@ -311,7 +312,12 @@ public class Replicator implements Runnable {
}
private synchronized void queue(OperationWithResult<?, ?> operation, Replicable<?, ?> replicable) {
List<Pair<String, OperationWithResult<?, ?>>> queue = queueByReplicableIdAsString.get(replicable.getId().toString());
final String replicableIdAsString = replicable.getId().toString();
List<Pair<String, OperationWithResult<?, ?>>> queue = queueByReplicableIdAsString.get(replicableIdAsString);
if (queue == null) {
queue = new ArrayList<>();
queueByReplicableIdAsString.put(replicableIdAsString, queue);
}
if (queue.isEmpty()) {
notifyAll();
}