Search in sources :

Example 1 with SnapshotCopierOptions

use of com.alipay.sofa.jraft.option.SnapshotCopierOptions in project sofa-jraft by sofastack.

the class LocalSnapshotCopierTest method setup.

@Override
@Before
public void setup() throws Exception {
    super.setup();
    this.timerManager = new TimerManager(5);
    this.raftOptions = new RaftOptions();
    this.writer = new LocalSnapshotWriter(this.path, this.snapshotStorage, this.raftOptions);
    this.reader = new LocalSnapshotReader(this.snapshotStorage, null, new Endpoint("localhost", 8081), this.raftOptions, this.path);
    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", LocalFileMetaOutter.LocalFileMeta.newBuilder().setChecksum("test").build());
    this.table.setMeta(RaftOutter.SnapshotMeta.newBuilder().setLastIncludedIndex(1).setLastIncludedTerm(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);
    assertTrue(this.copier.init(this.uri, new SnapshotCopierOptions(this.raftClientService, this.timerManager, this.raftOptions, new NodeOptions())));
    this.copier.setStorage(this.snapshotStorage);
}
Also used : RaftOptions(com.alipay.sofa.jraft.option.RaftOptions) SnapshotCopierOptions(com.alipay.sofa.jraft.option.SnapshotCopierOptions) Endpoint(com.alipay.sofa.jraft.util.Endpoint) CopyOptions(com.alipay.sofa.jraft.option.CopyOptions) NodeOptions(com.alipay.sofa.jraft.option.NodeOptions) TimerManager(com.alipay.sofa.jraft.core.TimerManager) Before(org.junit.Before)

Example 2 with SnapshotCopierOptions

use of com.alipay.sofa.jraft.option.SnapshotCopierOptions in project sofa-jraft by sofastack.

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());
    Assert.assertEquals("localhost", copier.getEndpoint().getIp());
    Assert.assertEquals(8081, copier.getEndpoint().getPort());
}
Also used : RaftOptions(com.alipay.sofa.jraft.option.RaftOptions) SnapshotCopierOptions(com.alipay.sofa.jraft.option.SnapshotCopierOptions) Endpoint(com.alipay.sofa.jraft.util.Endpoint) NodeOptions(com.alipay.sofa.jraft.option.NodeOptions) Test(org.junit.Test)

Example 3 with SnapshotCopierOptions

use of com.alipay.sofa.jraft.option.SnapshotCopierOptions in project sofa-jraft by sofastack.

the class SnapshotExecutorImpl method newCopierOpts.

private SnapshotCopierOptions newCopierOpts() {
    final SnapshotCopierOptions copierOpts = new SnapshotCopierOptions();
    copierOpts.setNodeOptions(this.node.getOptions());
    copierOpts.setRaftClientService(this.node.getRpcService());
    copierOpts.setTimerManager(this.node.getTimerManager());
    copierOpts.setRaftOptions(this.node.getRaftOptions());
    return copierOpts;
}
Also used : SnapshotCopierOptions(com.alipay.sofa.jraft.option.SnapshotCopierOptions)

Example 4 with SnapshotCopierOptions

use of com.alipay.sofa.jraft.option.SnapshotCopierOptions in project sofa-jraft by sofastack.

the class RemoteFileCopierTest method testInitFail.

@Test
public void testInitFail() {
    Mockito.when(rpcService.connect(new Endpoint("localhost", 8081))).thenReturn(false);
    assertFalse(copier.init("remote://localhost:8081/999", null, new SnapshotCopierOptions(rpcService, timerManager, new RaftOptions(), new NodeOptions())));
}
Also used : RaftOptions(com.alipay.sofa.jraft.option.RaftOptions) SnapshotCopierOptions(com.alipay.sofa.jraft.option.SnapshotCopierOptions) Endpoint(com.alipay.sofa.jraft.util.Endpoint) NodeOptions(com.alipay.sofa.jraft.option.NodeOptions) Test(org.junit.Test)

Aggregations

SnapshotCopierOptions (com.alipay.sofa.jraft.option.SnapshotCopierOptions)4 NodeOptions (com.alipay.sofa.jraft.option.NodeOptions)3 RaftOptions (com.alipay.sofa.jraft.option.RaftOptions)3 Endpoint (com.alipay.sofa.jraft.util.Endpoint)3 Test (org.junit.Test)2 TimerManager (com.alipay.sofa.jraft.core.TimerManager)1 CopyOptions (com.alipay.sofa.jraft.option.CopyOptions)1 Before (org.junit.Before)1