use of com.alipay.sofa.jraft.util.Endpoint in project sofa-jraft by sofastack.
the class LocalSnapshotReaderTest method setup.
@Override
@Before
public void setup() throws Exception {
super.setup();
this.path = this.path + File.separator + Snapshot.JRAFT_SNAPSHOT_PREFIX + snapshotIndex;
FileUtils.forceMkdir(new File(path));
this.table = new LocalSnapshotMetaTable(new RaftOptions());
this.table.addFile("testFile", LocalFileMetaOutter.LocalFileMeta.newBuilder().setChecksum("test").build());
table.saveToFile(path + File.separator + Snapshot.JRAFT_SNAPSHOT_META_FILE);
this.reader = new LocalSnapshotReader(snapshotStorage, null, new Endpoint("localhost", 8081), new RaftOptions(), path);
assertTrue(this.reader.init(null));
}
use of com.alipay.sofa.jraft.util.Endpoint in project sofa-jraft by sofastack.
the class BaseCliRequestProcessorTest method testManyNodes.
@Test
public void testManyNodes() {
Node node1 = Mockito.mock(Node.class);
Mockito.when(node1.getGroupId()).thenReturn("test");
Mockito.when(node1.getNodeId()).thenReturn(new NodeId("test", new PeerId("localhost", 8081)));
NodeOptions opts = new NodeOptions();
Mockito.when(node1.getOptions()).thenReturn(opts);
NodeManager.getInstance().addAddress(new Endpoint("localhost", 8081));
NodeManager.getInstance().add(node1);
Node node2 = Mockito.mock(Node.class);
Mockito.when(node2.getGroupId()).thenReturn("test");
Mockito.when(node2.getNodeId()).thenReturn(new NodeId("test", new PeerId("localhost", 8082)));
Mockito.when(node2.getOptions()).thenReturn(opts);
NodeManager.getInstance().addAddress(new Endpoint("localhost", 8082));
NodeManager.getInstance().add(node2);
this.processor = new MockCliRequestProcessor(null, "test");
this.processor.handleRequest(asyncContext, TestUtils.createPingRequest());
ErrorResponse resp = (ErrorResponse) asyncContext.getResponseObject();
assertNotNull(resp);
assertEquals(RaftError.EINVAL.getNumber(), resp.getErrorCode());
assertEquals("Peer must be specified since there're 2 nodes in group test", resp.getErrorMsg());
}
use of com.alipay.sofa.jraft.util.Endpoint 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())));
}
use of com.alipay.sofa.jraft.util.Endpoint in project sofa-jraft by sofastack.
the class BoltRaftRpcFactory method createRpcServer.
@Override
public RpcServer createRpcServer(final Endpoint endpoint, final ConfigHelper<RpcServer> helper) {
final int port = Requires.requireNonNull(endpoint, "endpoint").getPort();
Requires.requireTrue(port > 0 && port < 0xFFFF, "port out of range:" + port);
final com.alipay.remoting.rpc.RpcServer boltImpl = new com.alipay.remoting.rpc.RpcServer(port, true, false);
final RpcServer rpcServer = new BoltRpcServer(boltImpl);
if (helper != null) {
helper.config(rpcServer);
}
return rpcServer;
}
use of com.alipay.sofa.jraft.util.Endpoint in project sofa-jraft by sofastack.
the class Server1 method main.
public static void main(final String[] args) {
final PlacementDriverOptions pdOpts = PlacementDriverOptionsConfigured.newConfigured().withFake(// use a fake pd
true).config();
final StoreEngineOptions storeOpts = //
StoreEngineOptionsConfigured.newConfigured().withStorageType(StorageType.RocksDB).withRocksDBOptions(RocksDBOptionsConfigured.newConfigured().withDbPath(Configs.DB_PATH).config()).withRaftDataPath(Configs.RAFT_DATA_PATH).withServerAddress(new Endpoint("127.0.0.1", 8181)).config();
final RheaKVStoreOptions opts = //
RheaKVStoreOptionsConfigured.newConfigured().withClusterName(//
Configs.CLUSTER_NAME).withUseParallelCompress(//
true).withInitialServerList(Configs.ALL_NODE_ADDRESSES).withStoreEngineOptions(//
storeOpts).withPlacementDriverOptions(//
pdOpts).config();
System.out.println(opts);
final Node node = new Node(opts);
node.start();
Runtime.getRuntime().addShutdownHook(new Thread(node::stop));
System.out.println("server1 start OK");
}
Aggregations