Search in sources :

Example 6 with RaftOptions

use of org.apache.ignite.raft.jraft.option.RaftOptions in project ignite-3 by apache.

the class LocalSnapshotWriterTest method setup.

@BeforeEach
public void setup() throws Exception {
    opts = new RaftOptions();
    this.writer = new LocalSnapshotWriter(path.toString(), snapshotStorage, opts);
    assertTrue(this.writer.init(null));
}
Also used : RaftOptions(org.apache.ignite.raft.jraft.option.RaftOptions) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 7 with RaftOptions

use of org.apache.ignite.raft.jraft.option.RaftOptions in project ignite-3 by apache.

the class LocalSnapshotCopierTest method setup.

@BeforeEach
public void setup() throws Exception {
    this.timerManager = new TimerManager(5);
    this.raftOptions = new RaftOptions();
    this.writer = new LocalSnapshotWriter(this.path.toString(), this.snapshotStorage, this.raftOptions);
    this.reader = new LocalSnapshotReader(this.snapshotStorage, null, new Endpoint("localhost", 8081), this.raftOptions, this.path.toString());
    Mockito.when(this.snapshotStorage.open()).thenReturn(this.reader);
    Mockito.when(this.snapshotStorage.create(true)).thenReturn(this.writer);
    this.table = new LocalSnapshotMetaTable(this.raftOptions);
    this.table.addFile("testFile", raftOptions.getRaftMessagesFactory().localFileMeta().checksum("test").build());
    this.table.setMeta(raftOptions.getRaftMessagesFactory().snapshotMeta().lastIncludedIndex(1).lastIncludedTerm(1).build());
    this.uri = "remote://" + this.hostPort + "/" + this.readerId;
    this.copier = new LocalSnapshotCopier();
    this.copyOpts = new CopyOptions();
    Mockito.when(this.raftClientService.connect(new Endpoint("localhost", 8081))).thenReturn(true);
    nodeOptions = new NodeOptions();
    nodeOptions.setCommonExecutor(JRaftUtils.createExecutor("test-executor", Utils.cpus()));
    assertTrue(this.copier.init(this.uri, new SnapshotCopierOptions(this.raftClientService, this.timerManager, this.raftOptions, nodeOptions)));
    this.copier.setStorage(this.snapshotStorage);
}
Also used : RaftOptions(org.apache.ignite.raft.jraft.option.RaftOptions) SnapshotCopierOptions(org.apache.ignite.raft.jraft.option.SnapshotCopierOptions) Endpoint(org.apache.ignite.raft.jraft.util.Endpoint) CopyOptions(org.apache.ignite.raft.jraft.option.CopyOptions) NodeOptions(org.apache.ignite.raft.jraft.option.NodeOptions) TimerManager(org.apache.ignite.raft.jraft.core.TimerManager) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 8 with RaftOptions

use of org.apache.ignite.raft.jraft.option.RaftOptions in project ignite-3 by apache.

the class SnapshotExecutorTest method setup.

@BeforeEach
public void setup() throws Exception {
    timerManager = new TimerManager(5);
    raftOptions = new RaftOptions();
    writer = new LocalSnapshotWriter(path.toString(), snapshotStorage, raftOptions);
    reader = new LocalSnapshotReader(snapshotStorage, null, new Endpoint("localhost", 8081), raftOptions, path.toString());
    Mockito.lenient().when(snapshotStorage.open()).thenReturn(reader);
    Mockito.lenient().when(snapshotStorage.create(true)).thenReturn(writer);
    table = new LocalSnapshotMetaTable(raftOptions);
    table.addFile("testFile", raftOptions.getRaftMessagesFactory().localFileMeta().checksum("test").build());
    table.setMeta(raftOptions.getRaftMessagesFactory().snapshotMeta().lastIncludedIndex(1).lastIncludedTerm(1).build());
    uri = "remote://" + hostPort + "/" + readerId;
    copyOpts = new CopyOptions();
    Mockito.when(node.getRaftOptions()).thenReturn(new RaftOptions());
    options = new NodeOptions();
    options.setCommonExecutor(JRaftUtils.createExecutor("test-executor", Utils.cpus()));
    options.setScheduler(timerManager);
    Mockito.when(node.getOptions()).thenReturn(options);
    Mockito.when(node.getRpcClientService()).thenReturn(raftClientService);
    Mockito.when(node.getServiceFactory()).thenReturn(new DefaultJRaftServiceFactory());
    executor = new SnapshotExecutorImpl();
    final SnapshotExecutorOptions opts = new SnapshotExecutorOptions();
    opts.setFsmCaller(fSMCaller);
    opts.setInitTerm(0);
    opts.setNode(node);
    opts.setLogManager(logManager);
    opts.setUri(path.toString());
    addr = new Endpoint("localhost", 8081);
    opts.setAddr(addr);
    assertTrue(executor.init(opts));
}
Also used : RaftOptions(org.apache.ignite.raft.jraft.option.RaftOptions) Endpoint(org.apache.ignite.raft.jraft.util.Endpoint) LocalSnapshotMetaTable(org.apache.ignite.raft.jraft.storage.snapshot.local.LocalSnapshotMetaTable) LocalSnapshotReader(org.apache.ignite.raft.jraft.storage.snapshot.local.LocalSnapshotReader) SnapshotExecutorImpl(org.apache.ignite.raft.jraft.storage.snapshot.SnapshotExecutorImpl) CopyOptions(org.apache.ignite.raft.jraft.option.CopyOptions) NodeOptions(org.apache.ignite.raft.jraft.option.NodeOptions) DefaultJRaftServiceFactory(org.apache.ignite.raft.jraft.core.DefaultJRaftServiceFactory) TimerManager(org.apache.ignite.raft.jraft.core.TimerManager) LocalSnapshotWriter(org.apache.ignite.raft.jraft.storage.snapshot.local.LocalSnapshotWriter) SnapshotExecutorOptions(org.apache.ignite.raft.jraft.option.SnapshotExecutorOptions) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 9 with RaftOptions

use of org.apache.ignite.raft.jraft.option.RaftOptions in project ignite-3 by apache.

the class LocalRaftMetaStorageTest method testGetAndSetReload.

@Test
public void testGetAndSetReload() {
    assertEquals(0, this.raftMetaStorage.getTerm());
    assertTrue(this.raftMetaStorage.getVotedFor().isEmpty());
    this.raftMetaStorage.setTerm(99);
    assertEquals(99, this.raftMetaStorage.getTerm());
    assertTrue(this.raftMetaStorage.getVotedFor().isEmpty());
    assertTrue(this.raftMetaStorage.setVotedFor(new PeerId("localhost", 8081)));
    assertEquals(99, this.raftMetaStorage.getTerm());
    assertEquals(new PeerId("localhost", 8081), this.raftMetaStorage.getVotedFor());
    assertTrue(this.raftMetaStorage.setTermAndVotedFor(100, new PeerId("localhost", 8083)));
    assertEquals(100, this.raftMetaStorage.getTerm());
    assertEquals(new PeerId("localhost", 8083), this.raftMetaStorage.getVotedFor());
    this.raftMetaStorage = new LocalRaftMetaStorage(this.path.toString(), new RaftOptions());
    Mockito.when(this.node.getNodeMetrics()).thenReturn(null);
    this.raftMetaStorage.init(newOptions());
    assertEquals(100, this.raftMetaStorage.getTerm());
    assertEquals(new PeerId("localhost", 8083), this.raftMetaStorage.getVotedFor());
}
Also used : RaftOptions(org.apache.ignite.raft.jraft.option.RaftOptions) PeerId(org.apache.ignite.raft.jraft.entity.PeerId) BaseStorageTest(org.apache.ignite.raft.jraft.storage.BaseStorageTest) Test(org.junit.jupiter.api.Test)

Example 10 with RaftOptions

use of org.apache.ignite.raft.jraft.option.RaftOptions in project ignite-3 by apache.

the class RemoteFileCopierTest method testInit.

@Test
public void testInit() {
    Mockito.when(rpcService.connect(new Endpoint("localhost", 8081))).thenReturn(true);
    assertTrue(copier.init("remote://localhost:8081/999", null, new SnapshotCopierOptions(rpcService, timerManager, new RaftOptions(), new NodeOptions())));
    assertEquals(999, copier.getReaderId());
    assertEquals("localhost", copier.getEndpoint().getIp());
    assertEquals(8081, copier.getEndpoint().getPort());
}
Also used : RaftOptions(org.apache.ignite.raft.jraft.option.RaftOptions) SnapshotCopierOptions(org.apache.ignite.raft.jraft.option.SnapshotCopierOptions) Endpoint(org.apache.ignite.raft.jraft.util.Endpoint) NodeOptions(org.apache.ignite.raft.jraft.option.NodeOptions) Test(org.junit.jupiter.api.Test)

Aggregations

RaftOptions (org.apache.ignite.raft.jraft.option.RaftOptions)23 BeforeEach (org.junit.jupiter.api.BeforeEach)12 Test (org.junit.jupiter.api.Test)11 NodeOptions (org.apache.ignite.raft.jraft.option.NodeOptions)8 Endpoint (org.apache.ignite.raft.jraft.util.Endpoint)8 PeerId (org.apache.ignite.raft.jraft.entity.PeerId)6 LocalFileMetaOutter (org.apache.ignite.raft.jraft.entity.LocalFileMetaOutter)4 File (java.io.File)3 ByteBuffer (java.nio.ByteBuffer)3 TimerManager (org.apache.ignite.raft.jraft.core.TimerManager)3 CopyOptions (org.apache.ignite.raft.jraft.option.CopyOptions)3 SnapshotCopierOptions (org.apache.ignite.raft.jraft.option.SnapshotCopierOptions)3 CompletableFuture (java.util.concurrent.CompletableFuture)2 CountDownLatch (java.util.concurrent.CountDownLatch)2 ExecutorService (java.util.concurrent.ExecutorService)2 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)2 AtomicReference (java.util.concurrent.atomic.AtomicReference)2 Node (org.apache.ignite.raft.jraft.Node)2 ConfigurationManager (org.apache.ignite.raft.jraft.conf.ConfigurationManager)2 RpcClientEx (org.apache.ignite.raft.jraft.rpc.RpcClientEx)2