Search in sources :

Example 1 with SaveSnapshotClosure

use of org.apache.ignite.raft.jraft.closure.SaveSnapshotClosure in project ignite-3 by apache.

the class SnapshotExecutorTest method testDoSnapshotWithIntervalDist.

@Test
public void testDoSnapshotWithIntervalDist() throws Exception {
    final NodeOptions nodeOptions = new NodeOptions();
    nodeOptions.setSnapshotLogIndexMargin(5);
    ExecutorService testExecutor = JRaftUtils.createExecutor("test-executor", Utils.cpus());
    executorService = testExecutor;
    nodeOptions.setCommonExecutor(testExecutor);
    Mockito.when(node.getOptions()).thenReturn(nodeOptions);
    Mockito.when(fSMCaller.getLastAppliedIndex()).thenReturn(6L);
    final ArgumentCaptor<SaveSnapshotClosure> saveSnapshotClosureArg = ArgumentCaptor.forClass(SaveSnapshotClosure.class);
    Mockito.when(fSMCaller.onSnapshotSave(saveSnapshotClosureArg.capture())).thenReturn(true);
    final SynchronizedClosure done = new SynchronizedClosure();
    executor.doSnapshot(done);
    final SaveSnapshotClosure closure = saveSnapshotClosureArg.getValue();
    assertNotNull(closure);
    closure.start(raftOptions.getRaftMessagesFactory().snapshotMeta().lastIncludedIndex(6).lastIncludedTerm(1).build());
    closure.run(Status.OK());
    done.await();
    executor.join();
    assertEquals(1, executor.getLastSnapshotTerm());
    assertEquals(6, executor.getLastSnapshotIndex());
}
Also used : SynchronizedClosure(org.apache.ignite.raft.jraft.closure.SynchronizedClosure) ExecutorService(java.util.concurrent.ExecutorService) SaveSnapshotClosure(org.apache.ignite.raft.jraft.closure.SaveSnapshotClosure) NodeOptions(org.apache.ignite.raft.jraft.option.NodeOptions) Test(org.junit.jupiter.api.Test)

Example 2 with SaveSnapshotClosure

use of org.apache.ignite.raft.jraft.closure.SaveSnapshotClosure in project ignite-3 by apache.

the class SnapshotExecutorTest method testDoSnapshot.

@Test
public void testDoSnapshot() throws Exception {
    Mockito.when(fSMCaller.getLastAppliedIndex()).thenReturn(1L);
    final ArgumentCaptor<SaveSnapshotClosure> saveSnapshotClosureArg = ArgumentCaptor.forClass(SaveSnapshotClosure.class);
    Mockito.when(fSMCaller.onSnapshotSave(saveSnapshotClosureArg.capture())).thenReturn(true);
    final SynchronizedClosure done = new SynchronizedClosure();
    executor.doSnapshot(done);
    final SaveSnapshotClosure closure = saveSnapshotClosureArg.getValue();
    assertNotNull(closure);
    closure.start(raftOptions.getRaftMessagesFactory().snapshotMeta().lastIncludedIndex(2).lastIncludedTerm(1).build());
    closure.run(Status.OK());
    done.await();
    executor.join();
    assertTrue(done.getStatus().isOk());
    assertEquals(1, executor.getLastSnapshotTerm());
    assertEquals(2, executor.getLastSnapshotIndex());
}
Also used : SynchronizedClosure(org.apache.ignite.raft.jraft.closure.SynchronizedClosure) SaveSnapshotClosure(org.apache.ignite.raft.jraft.closure.SaveSnapshotClosure) Test(org.junit.jupiter.api.Test)

Example 3 with SaveSnapshotClosure

use of org.apache.ignite.raft.jraft.closure.SaveSnapshotClosure in project ignite-3 by apache.

the class FSMCallerTest method testOnSnapshotSave.

@Test
public void testOnSnapshotSave() throws Exception {
    final SnapshotWriter writer = Mockito.mock(SnapshotWriter.class);
    Mockito.when(this.logManager.getConfiguration(10)).thenReturn(TestUtils.getConfEntry("localhost:8081,localhost:8082,localhost:8083", "localhost:8081"));
    final SaveSnapshotClosure done = new SaveSnapshotClosure() {

        @Override
        public void run(final Status status) {
        }

        @Override
        public SnapshotWriter start(final SnapshotMeta meta) {
            assertEquals(10, meta.lastIncludedIndex());
            return writer;
        }
    };
    this.fsmCaller.onSnapshotSave(done);
    this.fsmCaller.flush();
    Mockito.verify(this.fsm).onSnapshotSave(writer, done);
}
Also used : Status(org.apache.ignite.raft.jraft.Status) SnapshotWriter(org.apache.ignite.raft.jraft.storage.snapshot.SnapshotWriter) SaveSnapshotClosure(org.apache.ignite.raft.jraft.closure.SaveSnapshotClosure) SnapshotMeta(org.apache.ignite.raft.jraft.entity.RaftOutter.SnapshotMeta) Test(org.junit.jupiter.api.Test)

Example 4 with SaveSnapshotClosure

use of org.apache.ignite.raft.jraft.closure.SaveSnapshotClosure in project ignite-3 by apache.

the class FSMCallerTest method testOnSnapshotSaveEmptyConf.

@Test
public void testOnSnapshotSaveEmptyConf() throws Exception {
    final CountDownLatch latch = new CountDownLatch(1);
    this.fsmCaller.onSnapshotSave(new SaveSnapshotClosure() {

        @Override
        public void run(final Status status) {
            assertFalse(status.isOk());
            assertEquals("Empty conf entry for lastAppliedIndex=10", status.getErrorMsg());
            latch.countDown();
        }

        @Override
        public SnapshotWriter start(final SnapshotMeta meta) {
            return null;
        }
    });
    latch.await();
}
Also used : Status(org.apache.ignite.raft.jraft.Status) SnapshotWriter(org.apache.ignite.raft.jraft.storage.snapshot.SnapshotWriter) SaveSnapshotClosure(org.apache.ignite.raft.jraft.closure.SaveSnapshotClosure) SnapshotMeta(org.apache.ignite.raft.jraft.entity.RaftOutter.SnapshotMeta) CountDownLatch(java.util.concurrent.CountDownLatch) Test(org.junit.jupiter.api.Test)

Aggregations

SaveSnapshotClosure (org.apache.ignite.raft.jraft.closure.SaveSnapshotClosure)4 Test (org.junit.jupiter.api.Test)4 Status (org.apache.ignite.raft.jraft.Status)2 SynchronizedClosure (org.apache.ignite.raft.jraft.closure.SynchronizedClosure)2 SnapshotMeta (org.apache.ignite.raft.jraft.entity.RaftOutter.SnapshotMeta)2 SnapshotWriter (org.apache.ignite.raft.jraft.storage.snapshot.SnapshotWriter)2 CountDownLatch (java.util.concurrent.CountDownLatch)1 ExecutorService (java.util.concurrent.ExecutorService)1 NodeOptions (org.apache.ignite.raft.jraft.option.NodeOptions)1