Search in sources :

Example 1 with TimerManager

use of com.alipay.sofa.jraft.core.TimerManager in project sofa-jraft by sofastack.

the class SnapshotExecutorTest 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.copyOpts = new CopyOptions();
    Mockito.when(this.node.getRaftOptions()).thenReturn(new RaftOptions());
    Mockito.when(this.node.getOptions()).thenReturn(new NodeOptions());
    Mockito.when(this.node.getRpcService()).thenReturn(this.raftClientService);
    Mockito.when(this.node.getTimerManager()).thenReturn(this.timerManager);
    Mockito.when(this.node.getServiceFactory()).thenReturn(DefaultJRaftServiceFactory.newInstance());
    this.executor = new SnapshotExecutorImpl();
    final SnapshotExecutorOptions opts = new SnapshotExecutorOptions();
    opts.setFsmCaller(this.fSMCaller);
    opts.setInitTerm(0);
    opts.setNode(this.node);
    opts.setLogManager(this.logManager);
    opts.setUri(this.path);
    this.addr = new Endpoint("localhost", 8081);
    opts.setAddr(this.addr);
    assertTrue(this.executor.init(opts));
}
Also used : RaftOptions(com.alipay.sofa.jraft.option.RaftOptions) Endpoint(com.alipay.sofa.jraft.util.Endpoint) LocalSnapshotMetaTable(com.alipay.sofa.jraft.storage.snapshot.local.LocalSnapshotMetaTable) LocalSnapshotReader(com.alipay.sofa.jraft.storage.snapshot.local.LocalSnapshotReader) SnapshotExecutorImpl(com.alipay.sofa.jraft.storage.snapshot.SnapshotExecutorImpl) CopyOptions(com.alipay.sofa.jraft.option.CopyOptions) NodeOptions(com.alipay.sofa.jraft.option.NodeOptions) TimerManager(com.alipay.sofa.jraft.core.TimerManager) LocalSnapshotWriter(com.alipay.sofa.jraft.storage.snapshot.local.LocalSnapshotWriter) SnapshotExecutorOptions(com.alipay.sofa.jraft.option.SnapshotExecutorOptions) Before(org.junit.Before)

Example 2 with TimerManager

use of com.alipay.sofa.jraft.core.TimerManager 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 3 with TimerManager

use of com.alipay.sofa.jraft.core.TimerManager in project sofa-jraft by sofastack.

the class CopySessionTest method setup.

@Before
public void setup() {
    this.timerManager = new TimerManager(5);
    this.copyOpts = new CopyOptions();
    this.rb = RpcRequests.GetFileRequest.newBuilder();
    this.rb.setReaderId(99);
    this.rb.setFilename("data");
    this.raftOpts = new RaftOptions();
    this.session = new CopySession(rpcService, timerManager, null, raftOpts, rb, address);
    this.session.setCopyOptions(copyOpts);
}
Also used : RaftOptions(com.alipay.sofa.jraft.option.RaftOptions) CopyOptions(com.alipay.sofa.jraft.option.CopyOptions) TimerManager(com.alipay.sofa.jraft.core.TimerManager) Before(org.junit.Before)

Example 4 with TimerManager

use of com.alipay.sofa.jraft.core.TimerManager in project sofa-jraft by sofastack.

the class RemoteFileCopierTest method setup.

@Before
public void setup() {
    this.timerManager = new TimerManager(5);
    copier = new RemoteFileCopier();
}
Also used : TimerManager(com.alipay.sofa.jraft.core.TimerManager) Before(org.junit.Before)

Aggregations

TimerManager (com.alipay.sofa.jraft.core.TimerManager)4 Before (org.junit.Before)4 CopyOptions (com.alipay.sofa.jraft.option.CopyOptions)3 RaftOptions (com.alipay.sofa.jraft.option.RaftOptions)3 NodeOptions (com.alipay.sofa.jraft.option.NodeOptions)2 Endpoint (com.alipay.sofa.jraft.util.Endpoint)2 SnapshotCopierOptions (com.alipay.sofa.jraft.option.SnapshotCopierOptions)1 SnapshotExecutorOptions (com.alipay.sofa.jraft.option.SnapshotExecutorOptions)1 SnapshotExecutorImpl (com.alipay.sofa.jraft.storage.snapshot.SnapshotExecutorImpl)1 LocalSnapshotMetaTable (com.alipay.sofa.jraft.storage.snapshot.local.LocalSnapshotMetaTable)1 LocalSnapshotReader (com.alipay.sofa.jraft.storage.snapshot.local.LocalSnapshotReader)1 LocalSnapshotWriter (com.alipay.sofa.jraft.storage.snapshot.local.LocalSnapshotWriter)1