当前位置: 首页>>代码示例>>Java>>正文


Java SaveSnapshotSuccess类代码示例

本文整理汇总了Java中akka.persistence.SaveSnapshotSuccess的典型用法代码示例。如果您正苦于以下问题:Java SaveSnapshotSuccess类的具体用法?Java SaveSnapshotSuccess怎么用?Java SaveSnapshotSuccess使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


SaveSnapshotSuccess类属于akka.persistence包,在下文中一共展示了SaveSnapshotSuccess类的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: handleSnapshotMessage

import akka.persistence.SaveSnapshotSuccess; //导入依赖的package包/类
boolean handleSnapshotMessage(Object message, ActorRef sender) {
    if (message instanceof ApplySnapshot) {
        onApplySnapshot((ApplySnapshot) message);
    } else if (message instanceof SaveSnapshotSuccess) {
        onSaveSnapshotSuccess((SaveSnapshotSuccess) message);
    } else if (message instanceof SaveSnapshotFailure) {
        onSaveSnapshotFailure((SaveSnapshotFailure) message);
    } else if (message instanceof CaptureSnapshotReply) {
        onCaptureSnapshotReply((CaptureSnapshotReply) message);
    } else if (COMMIT_SNAPSHOT.equals(message)) {
        context.getSnapshotManager().commit(-1, -1);
    } else if (message instanceof GetSnapshot) {
        onGetSnapshot(sender);
    } else {
        return false;
    }

    return true;
}
 
开发者ID:hashsdn,项目名称:hashsdn-controller,代码行数:20,代码来源:RaftActorSnapshotMessageSupport.java

示例2: handleSnapshotMessage

import akka.persistence.SaveSnapshotSuccess; //导入依赖的package包/类
private void handleSnapshotMessage(final Object message) {
    if (message instanceof SaveSnapshotFailure) {
        LOG.error("{}: failed to persist state", persistenceId(), ((SaveSnapshotFailure) message).cause());
        persisting = false;
        self().tell(PoisonPill.getInstance(), ActorRef.noSender());
    } else if (message instanceof SaveSnapshotSuccess) {
        LOG.debug("{}: got command: {}", persistenceId(), message);
        SaveSnapshotSuccess saved = (SaveSnapshotSuccess)message;
        deleteSnapshots(new SnapshotSelectionCriteria(saved.metadata().sequenceNr(),
                saved.metadata().timestamp() - 1, 0L, 0L));
        persisting = false;
        unstash();
    } else {
        LOG.debug("{}: stashing command {}", persistenceId(), message);
        stash();
    }
}
 
开发者ID:hashsdn,项目名称:hashsdn-controller,代码行数:18,代码来源:BucketStoreActor.java

示例3: onReceiveCommand

import akka.persistence.SaveSnapshotSuccess; //导入依赖的package包/类
@Override
AbstractClientActorBehavior<?> onReceiveCommand(final Object command) {
    if (command instanceof SaveSnapshotFailure) {
        LOG.error("{}: failed to persist state", persistenceId(), ((SaveSnapshotFailure) command).cause());
        return null;
    } else if (command instanceof SaveSnapshotSuccess) {
        LOG.debug("{}: got command: {}", persistenceId(), command);
        SaveSnapshotSuccess saved = (SaveSnapshotSuccess)command;
        context().deleteSnapshots(new SnapshotSelectionCriteria(saved.metadata().sequenceNr(),
                saved.metadata().timestamp() - 1, 0L, 0L));
        return this;
    } else if (command instanceof DeleteSnapshotsSuccess) {
        LOG.debug("{}: got command: {}", persistenceId(), command);
    } else if (command instanceof DeleteSnapshotsFailure) {
        // Not treating this as a fatal error.
        LOG.warn("{}: failed to delete prior snapshots", persistenceId(),
                ((DeleteSnapshotsFailure) command).cause());
    } else {
        LOG.debug("{}: stashing command {}", persistenceId(), command);
        context().stash();
        return this;
    }

    context().unstash();
    return context().createBehavior(myId);
}
 
开发者ID:hashsdn,项目名称:hashsdn-controller,代码行数:27,代码来源:SavingClientActorBehavior.java

示例4: testStatePersistedAfterSnapshotPersisted

import akka.persistence.SaveSnapshotSuccess; //导入依赖的package包/类
@Test
public void testStatePersistedAfterSnapshotPersisted() {

    send2InitialPayloads();

    // Block these messages initially so we can control the sequence.
    follower1Actor.underlyingActor().startDropMessages(AppendEntries.class);

    final MockPayload payload2 = sendPayloadData(leaderActor, "two");

    // This should trigger a snapshot.
    final MockPayload payload3 = sendPayloadData(leaderActor, "three");

    // Send another payload.
    final MockPayload payload4 = sendPayloadData(leaderActor, "four");

    MessageCollectorActor.expectMatching(follower1CollectorActor, AppendEntries.class, 3);

    // Wait for snapshot complete.
    MessageCollectorActor.expectFirstMatching(leaderCollectorActor, SaveSnapshotSuccess.class);

    // Now deliver the AppendEntries to the follower
    follower1Actor.underlyingActor().stopDropMessages(AppendEntries.class);

    MessageCollectorActor.expectMatching(leaderCollectorActor, ApplyJournalEntries.class, 1);

    reinstateLeaderActor();

    assertEquals("Leader snapshot term", currentTerm, leaderContext.getReplicatedLog().getSnapshotTerm());
    assertEquals("Leader snapshot index", 1, leaderContext.getReplicatedLog().getSnapshotIndex());
    assertEquals("Leader journal log size", 3, leaderContext.getReplicatedLog().size());
    assertEquals("Leader journal last index", 4, leaderContext.getReplicatedLog().lastIndex());
    assertEquals("Leader commit index", 4, leaderContext.getCommitIndex());
    assertEquals("Leader last applied", 4, leaderContext.getLastApplied());

    assertEquals("Leader state", Arrays.asList(payload0, payload1, payload2, payload3, payload4),
            leaderActor.underlyingActor().getState());
}
 
开发者ID:hashsdn,项目名称:hashsdn-controller,代码行数:39,代码来源:RecoveryIntegrationTest.java

示例5: testOnSaveSnapshotSuccess

import akka.persistence.SaveSnapshotSuccess; //导入依赖的package包/类
@Test
public void testOnSaveSnapshotSuccess() {

    long sequenceNumber = 100;
    long timeStamp = 1234L;
    sendMessageToSupport(new SaveSnapshotSuccess(new SnapshotMetadata("foo", sequenceNumber, timeStamp)));

    verify(mockSnapshotManager).commit(eq(sequenceNumber), eq(timeStamp));
}
 
开发者ID:hashsdn,项目名称:hashsdn-controller,代码行数:10,代码来源:RaftActorSnapshotMessageSupportTest.java

示例6: testStatePersistedBetweenSnapshotCaptureAndPersist

import akka.persistence.SaveSnapshotSuccess; //导入依赖的package包/类
@Test
public void testStatePersistedBetweenSnapshotCaptureAndPersist() {

    send2InitialPayloads();

    // Block these messages initially so we can control the sequence.
    leaderActor.underlyingActor().startDropMessages(CaptureSnapshotReply.class);
    follower1Actor.underlyingActor().startDropMessages(AppendEntries.class);

    final MockPayload payload2 = sendPayloadData(leaderActor, "two");

    // This should trigger a snapshot.
    final MockPayload payload3 = sendPayloadData(leaderActor, "three");

    MessageCollectorActor.expectMatching(follower1CollectorActor, AppendEntries.class, 3);

    // Send another payload.
    final MockPayload payload4 = sendPayloadData(leaderActor, "four");

    // Now deliver the AppendEntries to the follower
    follower1Actor.underlyingActor().stopDropMessages(AppendEntries.class);

    MessageCollectorActor.expectMatching(leaderCollectorActor, ApplyJournalEntries.class, 1);

    // Now deliver the CaptureSnapshotReply to the leader.
    CaptureSnapshotReply captureSnapshotReply = MessageCollectorActor.expectFirstMatching(
            leaderCollectorActor, CaptureSnapshotReply.class);
    leaderActor.underlyingActor().stopDropMessages(CaptureSnapshotReply.class);
    leaderActor.tell(captureSnapshotReply, leaderActor);

    // Wait for snapshot complete.
    MessageCollectorActor.expectFirstMatching(leaderCollectorActor, SaveSnapshotSuccess.class);

    reinstateLeaderActor();

    assertEquals("Leader snapshot term", currentTerm, leaderContext.getReplicatedLog().getSnapshotTerm());
    assertEquals("Leader snapshot index", 1, leaderContext.getReplicatedLog().getSnapshotIndex());
    assertEquals("Leader journal log size", 3, leaderContext.getReplicatedLog().size());
    assertEquals("Leader journal last index", 4, leaderContext.getReplicatedLog().lastIndex());
    assertEquals("Leader commit index", 4, leaderContext.getCommitIndex());
    assertEquals("Leader last applied", 4, leaderContext.getLastApplied());

    assertEquals("Leader state", Arrays.asList(payload0, payload1, payload2, payload3, payload4),
            leaderActor.underlyingActor().getState());
}
 
开发者ID:hashsdn,项目名称:hashsdn-controller,代码行数:46,代码来源:RecoveryIntegrationTest.java

示例7: testFollowerRecoveryAfterInstallSnapshot

import akka.persistence.SaveSnapshotSuccess; //导入依赖的package包/类
@Test
public void testFollowerRecoveryAfterInstallSnapshot() throws Exception {

    send2InitialPayloads();

    leader = leaderActor.underlyingActor().getCurrentBehavior();

    follower2Actor = newTestRaftActor(follower2Id, ImmutableMap.of(leaderId, testActorPath(leaderId)),
            newFollowerConfigParams());
    follower2CollectorActor = follower2Actor.underlyingActor().collectorActor();

    leaderActor.tell(new SetPeerAddress(follower2Id, follower2Actor.path().toString()), ActorRef.noSender());

    final MockPayload payload2 = sendPayloadData(leaderActor, "two");

    // Verify the leader applies the 3rd payload state.
    MessageCollectorActor.expectMatching(leaderCollectorActor, ApplyJournalEntries.class, 1);

    MessageCollectorActor.expectMatching(follower2CollectorActor, ApplyJournalEntries.class, 1);

    assertEquals("Leader commit index", 2, leaderContext.getCommitIndex());
    assertEquals("Leader last applied", 2, leaderContext.getLastApplied());
    assertEquals("Leader snapshot index", 1, leaderContext.getReplicatedLog().getSnapshotIndex());
    assertEquals("Leader replicatedToAllIndex", 1, leader.getReplicatedToAllIndex());

    killActor(follower2Actor);

    InMemoryJournal.clear();

    follower2Actor = newTestRaftActor(follower2Id, ImmutableMap.of(leaderId, testActorPath(leaderId)),
            newFollowerConfigParams());
    TestRaftActor follower2Underlying = follower2Actor.underlyingActor();
    follower2CollectorActor = follower2Underlying.collectorActor();
    follower2Context = follower2Underlying.getRaftActorContext();

    leaderActor.tell(new SetPeerAddress(follower2Id, follower2Actor.path().toString()), ActorRef.noSender());

    // The leader should install a snapshot so wait for the follower to receive ApplySnapshot.
    MessageCollectorActor.expectFirstMatching(follower2CollectorActor, ApplySnapshot.class);

    // Wait for the follower to persist the snapshot.
    MessageCollectorActor.expectFirstMatching(follower2CollectorActor, SaveSnapshotSuccess.class);

    final List<MockPayload> expFollowerState = Arrays.asList(payload0, payload1, payload2);

    assertEquals("Follower commit index", 2, follower2Context.getCommitIndex());
    assertEquals("Follower last applied", 2, follower2Context.getLastApplied());
    assertEquals("Follower snapshot index", 2, follower2Context.getReplicatedLog().getSnapshotIndex());
    assertEquals("Follower state", expFollowerState, follower2Underlying.getState());

    killActor(follower2Actor);

    follower2Actor = newTestRaftActor(follower2Id, ImmutableMap.of(leaderId, testActorPath(leaderId)),
            newFollowerConfigParams());

    follower2Underlying = follower2Actor.underlyingActor();
    follower2Underlying.waitForRecoveryComplete();
    follower2Context = follower2Underlying.getRaftActorContext();

    assertEquals("Follower commit index", 2, follower2Context.getCommitIndex());
    assertEquals("Follower last applied", 2, follower2Context.getLastApplied());
    assertEquals("Follower snapshot index", 2, follower2Context.getReplicatedLog().getSnapshotIndex());
    assertEquals("Follower state", expFollowerState, follower2Underlying.getState());
}
 
开发者ID:hashsdn,项目名称:hashsdn-controller,代码行数:65,代码来源:RecoveryIntegrationTest.java

示例8: testRaftActorForwardsToRaftActorSnapshotMessageSupport

import akka.persistence.SaveSnapshotSuccess; //导入依赖的package包/类
@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));
}
 
开发者ID:hashsdn,项目名称:hashsdn-controller,代码行数:52,代码来源:RaftActorTest.java

示例9: onSaveSnapshotSuccess

import akka.persistence.SaveSnapshotSuccess; //导入依赖的package包/类
private void onSaveSnapshotSuccess(final SaveSnapshotSuccess successMessage) {
    LOG.debug("{} saved ShardManager snapshot successfully. Deleting the prev snapshot if available",
        persistenceId());
    deleteSnapshots(new SnapshotSelectionCriteria(scala.Long.MaxValue(), successMessage.metadata().timestamp() - 1,
        0, 0));
}
 
开发者ID:hashsdn,项目名称:hashsdn-controller,代码行数:7,代码来源:ShardManager.java

示例10: onSaveSnapshotSuccess

import akka.persistence.SaveSnapshotSuccess; //导入依赖的package包/类
private void onSaveSnapshotSuccess(SaveSnapshotSuccess success) {
    long sequenceNumber = success.metadata().sequenceNr();

    log.info("{}: SaveSnapshotSuccess received for snapshot, sequenceNr: {}", context.getId(), sequenceNumber);

    context.getSnapshotManager().commit(sequenceNumber, success.metadata().timestamp());
}
 
开发者ID:hashsdn,项目名称:hashsdn-controller,代码行数:8,代码来源:RaftActorSnapshotMessageSupport.java

示例11: testJournalReplayAfterSnapshotWithSingleNode

import akka.persistence.SaveSnapshotSuccess; //导入依赖的package包/类
@Test
public void testJournalReplayAfterSnapshotWithSingleNode() throws Exception {

    String persistenceId = factory.generateActorId("singleNode");
    TestActorRef<AbstractRaftActorIntegrationTest.TestRaftActor> singleNodeActorRef =
            newTestRaftActor(persistenceId, ImmutableMap.<String, String>builder().build(), leaderConfigParams);

    waitUntilLeader(singleNodeActorRef);

    ActorRef singleNodeCollectorActor = singleNodeActorRef.underlyingActor().collectorActor();
    final RaftActorContext singleNodeContext = singleNodeActorRef.underlyingActor().getRaftActorContext();

    InMemoryJournal.addWriteMessagesCompleteLatch(persistenceId, 6, ApplyJournalEntries.class);

    final MockRaftActorContext.MockPayload payload0 = sendPayloadData(singleNodeActorRef, "zero");
    final MockRaftActorContext.MockPayload payload1 = sendPayloadData(singleNodeActorRef, "one");
    final MockRaftActorContext.MockPayload payload2 = sendPayloadData(singleNodeActorRef, "two");

    MessageCollectorActor.expectMatching(singleNodeCollectorActor, ApplyJournalEntries.class, 3);

    // this should trigger a snapshot
    final MockRaftActorContext.MockPayload payload3 = sendPayloadData(singleNodeActorRef, "three");

    MessageCollectorActor.expectMatching(singleNodeCollectorActor, ApplyJournalEntries.class, 4);

    //add 2 more
    final MockRaftActorContext.MockPayload payload4 = sendPayloadData(singleNodeActorRef, "four");
    final MockRaftActorContext.MockPayload payload5 = sendPayloadData(singleNodeActorRef, "five");


    // Wait for snapshot complete.
    MessageCollectorActor.expectFirstMatching(singleNodeCollectorActor, SaveSnapshotSuccess.class);

    MessageCollectorActor.expectMatching(singleNodeCollectorActor, ApplyJournalEntries.class, 6);

    assertEquals("Last applied", 5, singleNodeContext.getLastApplied());

    assertEquals("Incorrect State after snapshot success is received ", Lists.newArrayList(payload0, payload1,
            payload2, payload3, payload4, payload5), singleNodeActorRef.underlyingActor().getState());

    InMemoryJournal.waitForWriteMessagesComplete(persistenceId);

    // we get 2 log entries (4 and 5 indexes) and 3 ApplyJournalEntries (for 3, 4, and 5 indexes)
    assertEquals(5, InMemoryJournal.get(persistenceId).size());

    List<Snapshot> persistedSnapshots = InMemorySnapshotStore.getSnapshots(persistenceId, Snapshot.class);
    assertEquals(1, persistedSnapshots.size());

    List<Object> snapshottedState = MockRaftActor.fromState(persistedSnapshots.get(0).getState());
    assertEquals("Incorrect Snapshot", Lists.newArrayList(payload0, payload1, payload2, payload3),
            snapshottedState);

    //recovery logic starts
    killActor(singleNodeActorRef);

    singleNodeActorRef = newTestRaftActor(persistenceId,
            ImmutableMap.<String, String>builder().build(), leaderConfigParams);

    singleNodeActorRef.underlyingActor().waitForRecoveryComplete();

    assertEquals("Incorrect State after Recovery ", Lists.newArrayList(payload0, payload1, payload2, payload3,
            payload4, payload5), singleNodeActorRef.underlyingActor().getState());

}
 
开发者ID:hashsdn,项目名称:hashsdn-controller,代码行数:65,代码来源:RecoveryIntegrationSingleNodeTest.java


注:本文中的akka.persistence.SaveSnapshotSuccess类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。