Search in sources :

Example 1 with SnapshotMetadata

use of akka.persistence.SnapshotMetadata in project controller by opendaylight.

the class LocalSnapshotStoreTest method testDoLoadAsync.

@Test
public void testDoLoadAsync() throws IOException {
    createSnapshotFile(PERSISTENCE_ID, "one", 0, 1000);
    createSnapshotFile(PERSISTENCE_ID, "two", 1, 2000);
    createSnapshotFile(PERSISTENCE_ID, "three", 1, 3000);
    createSnapshotFile(PREFIX_BASED_SHARD_PERSISTENCE_ID, "foo", 0, 1000);
    createSnapshotFile(PREFIX_BASED_SHARD_PERSISTENCE_ID, "bar", 1, 2000);
    createSnapshotFile(PREFIX_BASED_SHARD_PERSISTENCE_ID, "foobar", 1, 3000);
    createSnapshotFile("member-1-shard-default-oper", "foo", 0, 1000);
    createSnapshotFile("member-1-shard-toaster-oper", "foo", 0, 1000);
    new File(SNAPSHOT_DIR, "other").createNewFile();
    new File(SNAPSHOT_DIR, "other-1485349217290").createNewFile();
    SnapshotMetadata metadata3 = new SnapshotMetadata(PERSISTENCE_ID, 1, 3000);
    TestKit probe = new TestKit(system);
    snapshotStore.tell(new LoadSnapshot(PERSISTENCE_ID, SnapshotSelectionCriteria.latest(), Long.MAX_VALUE), probe.getRef());
    LoadSnapshotResult result = probe.expectMsgClass(LoadSnapshotResult.class);
    Option<SelectedSnapshot> possibleSnapshot = result.snapshot();
    assertEquals("SelectedSnapshot present", TRUE, possibleSnapshot.nonEmpty());
    assertEquals("SelectedSnapshot metadata", metadata3, possibleSnapshot.get().metadata());
    assertEquals("SelectedSnapshot snapshot", "three", possibleSnapshot.get().snapshot());
    snapshotStore.tell(new LoadSnapshot(PREFIX_BASED_SHARD_PERSISTENCE_ID, SnapshotSelectionCriteria.latest(), Long.MAX_VALUE), probe.getRef());
    result = probe.expectMsgClass(LoadSnapshotResult.class);
    possibleSnapshot = result.snapshot();
    SnapshotMetadata prefixBasedShardMetada3 = new SnapshotMetadata(PREFIX_BASED_SHARD_PERSISTENCE_ID, 1, 3000);
    assertEquals("SelectedSnapshot present", TRUE, possibleSnapshot.nonEmpty());
    assertEquals("SelectedSnapshot metadata", prefixBasedShardMetada3, possibleSnapshot.get().metadata());
    assertEquals("SelectedSnapshot snapshot", "foobar", possibleSnapshot.get().snapshot());
}
Also used : LoadSnapshot(akka.persistence.SnapshotProtocol.LoadSnapshot) LoadSnapshotResult(akka.persistence.SnapshotProtocol.LoadSnapshotResult) SelectedSnapshot(akka.persistence.SelectedSnapshot) SnapshotMetadata(akka.persistence.SnapshotMetadata) TestKit(akka.testkit.javadsl.TestKit) File(java.io.File) Test(org.junit.Test)

Example 2 with SnapshotMetadata

use of akka.persistence.SnapshotMetadata in project controller by opendaylight.

the class LocalSnapshotStoreTest method testDoLoadAsyncWithRetry.

@Test
public void testDoLoadAsyncWithRetry() throws IOException {
    createSnapshotFile(PERSISTENCE_ID, "one", 0, 1000);
    createSnapshotFile(PERSISTENCE_ID, null, 1, 2000);
    SnapshotMetadata metadata = new SnapshotMetadata(PERSISTENCE_ID, 0, 1000);
    TestKit probe = new TestKit(system);
    snapshotStore.tell(new LoadSnapshot(PERSISTENCE_ID, SnapshotSelectionCriteria.latest(), Long.MAX_VALUE), probe.getRef());
    LoadSnapshotResult result = probe.expectMsgClass(LoadSnapshotResult.class);
    Option<SelectedSnapshot> possibleSnapshot = result.snapshot();
    assertEquals("SelectedSnapshot present", TRUE, possibleSnapshot.nonEmpty());
    assertEquals("SelectedSnapshot metadata", metadata, possibleSnapshot.get().metadata());
    assertEquals("SelectedSnapshot snapshot", "one", possibleSnapshot.get().snapshot());
}
Also used : LoadSnapshot(akka.persistence.SnapshotProtocol.LoadSnapshot) LoadSnapshotResult(akka.persistence.SnapshotProtocol.LoadSnapshotResult) SelectedSnapshot(akka.persistence.SelectedSnapshot) SnapshotMetadata(akka.persistence.SnapshotMetadata) TestKit(akka.testkit.javadsl.TestKit) Test(org.junit.Test)

Example 3 with SnapshotMetadata

use of akka.persistence.SnapshotMetadata in project controller by opendaylight.

the class RaftActorTest method testRaftActorForwardsToRaftActorRecoverySupport.

@Test
public void testRaftActorForwardsToRaftActorRecoverySupport() {
    String persistenceId = factory.generateActorId("leader-");
    DefaultConfigParamsImpl config = new DefaultConfigParamsImpl();
    config.setHeartBeatInterval(new FiniteDuration(1, TimeUnit.DAYS));
    TestActorRef<MockRaftActor> mockActorRef = factory.createTestActor(MockRaftActor.props(persistenceId, Collections.<String, String>emptyMap(), config), persistenceId);
    MockRaftActor mockRaftActor = mockActorRef.underlyingActor();
    // Wait for akka's recovery to complete so it doesn't interfere.
    mockRaftActor.waitForRecoveryComplete();
    RaftActorRecoverySupport mockSupport = mock(RaftActorRecoverySupport.class);
    mockRaftActor.setRaftActorRecoverySupport(mockSupport);
    Snapshot snapshot = Snapshot.create(ByteState.of(new byte[] { 1 }), Collections.<ReplicatedLogEntry>emptyList(), 3, 1, 3, 1, -1, null, null);
    SnapshotOffer snapshotOffer = new SnapshotOffer(new SnapshotMetadata("test", 6, 12345), snapshot);
    mockRaftActor.handleRecover(snapshotOffer);
    ReplicatedLogEntry logEntry = new SimpleReplicatedLogEntry(1, 1, new MockRaftActorContext.MockPayload("1", 5));
    mockRaftActor.handleRecover(logEntry);
    ApplyJournalEntries applyJournalEntries = new ApplyJournalEntries(2);
    mockRaftActor.handleRecover(applyJournalEntries);
    DeleteEntries deleteEntries = new DeleteEntries(1);
    mockRaftActor.handleRecover(deleteEntries);
    UpdateElectionTerm updateElectionTerm = new UpdateElectionTerm(5, "member2");
    mockRaftActor.handleRecover(updateElectionTerm);
    verify(mockSupport).handleRecoveryMessage(same(snapshotOffer), any(PersistentDataProvider.class));
    verify(mockSupport).handleRecoveryMessage(same(logEntry), any(PersistentDataProvider.class));
    verify(mockSupport).handleRecoveryMessage(same(applyJournalEntries), any(PersistentDataProvider.class));
    verify(mockSupport).handleRecoveryMessage(same(deleteEntries), any(PersistentDataProvider.class));
    verify(mockSupport).handleRecoveryMessage(same(updateElectionTerm), any(PersistentDataProvider.class));
}
Also used : DeleteEntries(org.opendaylight.controller.cluster.raft.persisted.DeleteEntries) FiniteDuration(scala.concurrent.duration.FiniteDuration) MockPayload(org.opendaylight.controller.cluster.raft.MockRaftActorContext.MockPayload) ByteString(com.google.protobuf.ByteString) ApplySnapshot(org.opendaylight.controller.cluster.raft.base.messages.ApplySnapshot) Snapshot(org.opendaylight.controller.cluster.raft.persisted.Snapshot) GetSnapshot(org.opendaylight.controller.cluster.raft.client.messages.GetSnapshot) PersistentDataProvider(org.opendaylight.controller.cluster.PersistentDataProvider) NonPersistentDataProvider(org.opendaylight.controller.cluster.NonPersistentDataProvider) SimpleReplicatedLogEntry(org.opendaylight.controller.cluster.raft.persisted.SimpleReplicatedLogEntry) SnapshotMetadata(akka.persistence.SnapshotMetadata) SimpleReplicatedLogEntry(org.opendaylight.controller.cluster.raft.persisted.SimpleReplicatedLogEntry) ApplyJournalEntries(org.opendaylight.controller.cluster.raft.persisted.ApplyJournalEntries) SnapshotOffer(akka.persistence.SnapshotOffer) UpdateElectionTerm(org.opendaylight.controller.cluster.raft.persisted.UpdateElectionTerm) Test(org.junit.Test)

Example 4 with SnapshotMetadata

use of akka.persistence.SnapshotMetadata in project controller by opendaylight.

the class RaftActorTest method testRaftActorForwardsToRaftActorSnapshotMessageSupport.

@Test
public void testRaftActorForwardsToRaftActorSnapshotMessageSupport() {
    String persistenceId = factory.generateActorId("leader-");
    DefaultConfigParamsImpl config = new DefaultConfigParamsImpl();
    config.setHeartBeatInterval(new FiniteDuration(1, TimeUnit.DAYS));
    RaftActorSnapshotMessageSupport mockSupport = mock(RaftActorSnapshotMessageSupport.class);
    TestActorRef<MockRaftActor> mockActorRef = factory.createTestActor(MockRaftActor.builder().id(persistenceId).config(config).snapshotMessageSupport(mockSupport).props());
    MockRaftActor mockRaftActor = mockActorRef.underlyingActor();
    // Wait for akka's recovery to complete so it doesn't interfere.
    mockRaftActor.waitForRecoveryComplete();
    ApplySnapshot applySnapshot = new ApplySnapshot(mock(Snapshot.class));
    doReturn(true).when(mockSupport).handleSnapshotMessage(same(applySnapshot), any(ActorRef.class));
    mockRaftActor.handleCommand(applySnapshot);
    CaptureSnapshotReply captureSnapshotReply = new CaptureSnapshotReply(ByteState.empty(), java.util.Optional.empty());
    doReturn(true).when(mockSupport).handleSnapshotMessage(same(captureSnapshotReply), any(ActorRef.class));
    mockRaftActor.handleCommand(captureSnapshotReply);
    SaveSnapshotSuccess saveSnapshotSuccess = new SaveSnapshotSuccess(new SnapshotMetadata("", 0L, 0L));
    doReturn(true).when(mockSupport).handleSnapshotMessage(same(saveSnapshotSuccess), any(ActorRef.class));
    mockRaftActor.handleCommand(saveSnapshotSuccess);
    SaveSnapshotFailure saveSnapshotFailure = new SaveSnapshotFailure(new SnapshotMetadata("", 0L, 0L), new Throwable());
    doReturn(true).when(mockSupport).handleSnapshotMessage(same(saveSnapshotFailure), any(ActorRef.class));
    mockRaftActor.handleCommand(saveSnapshotFailure);
    doReturn(true).when(mockSupport).handleSnapshotMessage(same(RaftActorSnapshotMessageSupport.COMMIT_SNAPSHOT), any(ActorRef.class));
    mockRaftActor.handleCommand(RaftActorSnapshotMessageSupport.COMMIT_SNAPSHOT);
    doReturn(true).when(mockSupport).handleSnapshotMessage(same(GetSnapshot.INSTANCE), any(ActorRef.class));
    mockRaftActor.handleCommand(GetSnapshot.INSTANCE);
    verify(mockSupport).handleSnapshotMessage(same(applySnapshot), any(ActorRef.class));
    verify(mockSupport).handleSnapshotMessage(same(captureSnapshotReply), any(ActorRef.class));
    verify(mockSupport).handleSnapshotMessage(same(saveSnapshotSuccess), any(ActorRef.class));
    verify(mockSupport).handleSnapshotMessage(same(saveSnapshotFailure), any(ActorRef.class));
    verify(mockSupport).handleSnapshotMessage(same(RaftActorSnapshotMessageSupport.COMMIT_SNAPSHOT), any(ActorRef.class));
    verify(mockSupport).handleSnapshotMessage(same(GetSnapshot.INSTANCE), any(ActorRef.class));
}
Also used : CaptureSnapshotReply(org.opendaylight.controller.cluster.raft.base.messages.CaptureSnapshotReply) ApplySnapshot(org.opendaylight.controller.cluster.raft.base.messages.ApplySnapshot) ActorRef(akka.actor.ActorRef) TestActorRef(akka.testkit.TestActorRef) FiniteDuration(scala.concurrent.duration.FiniteDuration) ByteString(com.google.protobuf.ByteString) SaveSnapshotFailure(akka.persistence.SaveSnapshotFailure) ApplySnapshot(org.opendaylight.controller.cluster.raft.base.messages.ApplySnapshot) Snapshot(org.opendaylight.controller.cluster.raft.persisted.Snapshot) GetSnapshot(org.opendaylight.controller.cluster.raft.client.messages.GetSnapshot) SnapshotMetadata(akka.persistence.SnapshotMetadata) SaveSnapshotSuccess(akka.persistence.SaveSnapshotSuccess) Test(org.junit.Test)

Example 5 with SnapshotMetadata

use of akka.persistence.SnapshotMetadata in project controller by opendaylight.

the class RaftActorRecoverySupportTest method testDataRecoveredWithPersistenceDisabled.

@Test
public void testDataRecoveredWithPersistenceDisabled() {
    doNothing().when(mockCohort).applyRecoverySnapshot(anyObject());
    doReturn(false).when(mockPersistence).isRecoveryApplicable();
    doReturn(10L).when(mockPersistentProvider).getLastSequenceNumber();
    Snapshot snapshot = Snapshot.create(new MockSnapshotState(Arrays.asList(new MockPayload("1"))), Collections.<ReplicatedLogEntry>emptyList(), 3, 1, 3, 1, -1, null, null);
    SnapshotOffer snapshotOffer = new SnapshotOffer(new SnapshotMetadata("test", 6, 12345), snapshot);
    sendMessageToSupport(snapshotOffer);
    sendMessageToSupport(new UpdateElectionTerm(5, "member2"));
    sendMessageToSupport(new SimpleReplicatedLogEntry(4, 1, new MockRaftActorContext.MockPayload("4")));
    sendMessageToSupport(new SimpleReplicatedLogEntry(5, 1, new MockRaftActorContext.MockPayload("5")));
    sendMessageToSupport(new ApplyJournalEntries(4));
    sendMessageToSupport(new DeleteEntries(5));
    assertEquals("Journal log size", 0, context.getReplicatedLog().size());
    assertEquals("Last index", -1, context.getReplicatedLog().lastIndex());
    assertEquals("Last applied", -1, context.getLastApplied());
    assertEquals("Commit index", -1, context.getCommitIndex());
    assertEquals("Snapshot term", -1, context.getReplicatedLog().getSnapshotTerm());
    assertEquals("Snapshot index", -1, context.getReplicatedLog().getSnapshotIndex());
    assertEquals("Current term", 5, context.getTermInformation().getCurrentTerm());
    assertEquals("Voted For", "member2", context.getTermInformation().getVotedFor());
    sendMessageToSupport(RecoveryCompleted.getInstance(), true);
    verify(mockCohort, never()).applyRecoverySnapshot(anyObject());
    verify(mockCohort, never()).getRestoreFromSnapshot();
    verifyNoMoreInteractions(mockCohort);
    verify(mockPersistentProvider).deleteMessages(10L);
}
Also used : MockSnapshotState(org.opendaylight.controller.cluster.raft.MockRaftActor.MockSnapshotState) Snapshot(org.opendaylight.controller.cluster.raft.persisted.Snapshot) SnapshotMetadata(akka.persistence.SnapshotMetadata) SimpleReplicatedLogEntry(org.opendaylight.controller.cluster.raft.persisted.SimpleReplicatedLogEntry) ApplyJournalEntries(org.opendaylight.controller.cluster.raft.persisted.ApplyJournalEntries) SnapshotOffer(akka.persistence.SnapshotOffer) DeleteEntries(org.opendaylight.controller.cluster.raft.persisted.DeleteEntries) UpdateElectionTerm(org.opendaylight.controller.cluster.raft.persisted.UpdateElectionTerm) MockPayload(org.opendaylight.controller.cluster.raft.MockRaftActorContext.MockPayload) Test(org.junit.Test)

Aggregations

SnapshotMetadata (akka.persistence.SnapshotMetadata)12 Test (org.junit.Test)11 SelectedSnapshot (akka.persistence.SelectedSnapshot)5 Snapshot (org.opendaylight.controller.cluster.raft.persisted.Snapshot)5 SnapshotOffer (akka.persistence.SnapshotOffer)4 MockPayload (org.opendaylight.controller.cluster.raft.MockRaftActorContext.MockPayload)4 LoadSnapshot (akka.persistence.SnapshotProtocol.LoadSnapshot)3 LoadSnapshotResult (akka.persistence.SnapshotProtocol.LoadSnapshotResult)3 TestKit (akka.testkit.javadsl.TestKit)3 File (java.io.File)3 MockSnapshotState (org.opendaylight.controller.cluster.raft.MockRaftActor.MockSnapshotState)3 SimpleReplicatedLogEntry (org.opendaylight.controller.cluster.raft.persisted.SimpleReplicatedLogEntry)3 SaveSnapshotFailure (akka.persistence.SaveSnapshotFailure)2 SaveSnapshotSuccess (akka.persistence.SaveSnapshotSuccess)2 ByteString (com.google.protobuf.ByteString)2 ApplySnapshot (org.opendaylight.controller.cluster.raft.base.messages.ApplySnapshot)2 GetSnapshot (org.opendaylight.controller.cluster.raft.client.messages.GetSnapshot)2 ApplyJournalEntries (org.opendaylight.controller.cluster.raft.persisted.ApplyJournalEntries)2 DeleteEntries (org.opendaylight.controller.cluster.raft.persisted.DeleteEntries)2 UpdateElectionTerm (org.opendaylight.controller.cluster.raft.persisted.UpdateElectionTerm)2