import akka.dispatch.Dispatchers;
import akka.testkit.JavaTestKit;
import akka.testkit.TestActorRef;
-import com.google.common.base.Predicate;
-import com.google.common.base.Supplier;
import com.google.common.collect.ImmutableMap;
import com.google.common.util.concurrent.Uninterruptibles;
import java.util.ArrayList;
import org.opendaylight.controller.cluster.raft.utils.InMemoryJournal;
import org.opendaylight.controller.cluster.raft.utils.InMemorySnapshotStore;
import org.opendaylight.controller.cluster.raft.utils.MessageCollectorActor;
+import org.opendaylight.yangtools.concepts.Identifier;
+import org.opendaylight.yangtools.util.AbstractStringIdentifier;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import scala.concurrent.duration.FiniteDuration;
*/
public abstract class AbstractRaftActorIntegrationTest extends AbstractActorTest {
+ private static final class MockIdentifier extends AbstractStringIdentifier<MockIdentifier> {
+ private static final long serialVersionUID = 1L;
+
+ protected MockIdentifier(String string) {
+ super(string);
+ }
+ }
+
public static class SetPeerAddress {
private final String peerId;
private final String peerAddress;
}
void setMockTotalMemory(final long mockTotalMemory) {
- if(mockTotalMemory > 0) {
- getRaftActorContext().setTotalMemoryRetriever(new Supplier<Long>() {
- @Override
- public Long get() {
- return mockTotalMemory;
- }
-
- });
- } else {
- getRaftActorContext().setTotalMemoryRetriever(null);
- }
+ getRaftActorContext().setTotalMemoryRetriever(mockTotalMemory > 0 ? () -> mockTotalMemory : null);
}
@Override
public void handleCommand(Object message) {
if(message instanceof MockPayload) {
MockPayload payload = (MockPayload)message;
- super.persistData(collectorActor, payload.toString(), payload);
+ super.persistData(collectorActor, new MockIdentifier(payload.toString()), payload);
return;
}
}
}
+ protected static final int SNAPSHOT_CHUNK_SIZE = 100;
+
protected final Logger testLog = LoggerFactory.getLogger(getClass());
protected final TestActorFactory factory = new TestActorFactory(getSystem());
configParams.setSnapshotBatchCount(snapshotBatchCount);
configParams.setSnapshotDataThresholdPercentage(70);
configParams.setIsolatedLeaderCheckInterval(new FiniteDuration(1, TimeUnit.DAYS));
+ configParams.setSnapshotChunkSize(SNAPSHOT_CHUNK_SIZE);
return configParams;
}
}
protected void verifyApplyJournalEntries(ActorRef actor, final long expIndex) {
- MessageCollectorActor.expectFirstMatching(actor, ApplyJournalEntries.class, new Predicate<ApplyJournalEntries>() {
- @Override
- public boolean apply(ApplyJournalEntries msg) {
- return msg.getToIndex() == expIndex;
- }
- });
+ MessageCollectorActor.expectFirstMatching(actor, ApplyJournalEntries.class, msg -> msg.getToIndex() == expIndex);
}
@SuppressWarnings("unchecked")
protected void verifyApplyState(ApplyState applyState, ActorRef expClientActor,
String expId, long expTerm, long expIndex, MockPayload payload) {
assertEquals("ApplyState getClientActor", expClientActor, applyState.getClientActor());
- assertEquals("ApplyState getIdentifier", expId, applyState.getIdentifier());
+
+ final Identifier id = expId == null ? null : new MockIdentifier(expId);
+ assertEquals("ApplyState getIdentifier", id, applyState.getIdentifier());
ReplicatedLogEntry replicatedLogEntry = applyState.getReplicatedLogEntry();
verifyReplicatedLogEntry(replicatedLogEntry, expTerm, expIndex, payload);
}