public RaftClient createClient(RaftPeerId leaderId) { return createClient(leaderId, group); }
Sender(RaftPeerId leaderId, CountDownLatch latch, int numMsg) { this.latch = latch; this.client = cluster.createClient(leaderId); msgs = generateMsgs(numMsg); }
static void sendMessageInNewThread(MiniRaftCluster cluster, RaftPeerId leaderId, SimpleMessage... messages) { new Thread(() -> { try (final RaftClient client = cluster.createClient(leaderId)) { for (SimpleMessage mssg: messages) { client.send(mssg); } } catch (Exception e) { e.printStackTrace(); } }).start(); }
public RaftClient createClient(RaftPeerId leaderId, RaftGroup group, ClientId clientId) { return createClient(leaderId, group, clientId, getDefaultRetryPolicy()); }
RaftClientReply sendMessages(int n, MiniRaftCluster cluster) throws Exception { LOG.info("sendMessages: " + n); RaftClientReply reply = null; try(final RaftClient client = cluster.createClient()) { for(int i = 0; i < n; i++) { reply = client.send(Message.valueOf("m" + i)); } } return reply; }
private void runTestMultiRaftGroup(int[] idIndex, int chosen) throws Exception { final CheckedBiConsumer<MiniRaftCluster, RaftGroup, IOException> checker = (cluster, group) -> { try (final RaftClient client = cluster.createClient(group)) { TestArithmetic.runTestPythagorean(client, start.getAndAdd(2*count), count); } }; ReinitializationBaseTest.runTestReinitializeMultiGroups( cluster, idIndex, chosen, checker); } }
private void runTestMultiRaftGroup(int[] idIndex, int chosen) throws Exception { final CheckedBiConsumer<MiniRaftCluster, RaftGroup, IOException> checker = (cluster, group) -> { try (final RaftClient client = cluster.createClient(group)) { TestArithmetic.runTestPythagorean(client, start.getAndAdd(2*count), count); } }; GroupManagementBaseTest.runMultiGroupTest( cluster, idIndex, chosen, checker); } }
static void sendMessageInNewThread(MiniRaftCluster cluster, SimpleMessage... messages) { RaftPeerId leaderId = cluster.getLeader().getId(); new Thread(() -> { try (final RaftClient client = cluster.createClient(leaderId)) { for (SimpleMessage mssg: messages) { client.send(mssg); } } catch (Exception e) { e.printStackTrace(); } }).start(); } }
public void setConfiguration(RaftPeer... peers) throws IOException { try(RaftClient client = createClient()) { LOG.info("Start changing the configuration: {}", Arrays.asList(peers)); final RaftClientReply reply = client.setConfiguration(peers); Preconditions.assertTrue(reply.isSuccess()); } }
public void setConfiguration(RaftPeer... peers) throws IOException { try(RaftClient client = createClient()) { LOG.info("Start changing the configuration: {}", Arrays.asList(peers)); final RaftClientReply reply = client.setConfiguration(peers); Preconditions.assertTrue(reply.isSuccess()); } }
static void writeSomething(Supplier<Message> newMessage, MiniRaftCluster cluster) throws Exception { try(final RaftClient client = cluster.createClient()) { // write some messages for(int i = 0; i < 10; i++) { Assert.assertTrue(client.send(newMessage.get()).isSuccess()); } } }
void runTestLogAppenderBufferCapacity(CLUSTER cluster) throws Exception { final RaftPeerId leaderId = RaftTestUtil.waitForLeader(cluster).getId(); byte[] bytes = new byte[8192]; Arrays.fill(bytes, (byte) 1); SimpleMessage msg = new SimpleMessage(new String(bytes)); try (RaftClient client = cluster.createClient(leaderId)) { testFailureCase("testLogAppenderBufferCapacity", () -> client.send(msg), StateMachineException.class, RaftLogIOException.class); } } }
@Test public void testPythagorean() throws Exception { setAndStart(cluster); try (final RaftClient client = cluster.createClient()) { runTestPythagorean(client, 3, 10); } }
RaftClientReply sendMessages(int n, MiniRaftCluster cluster) throws Exception { LOG.info("sendMessages: " + n); final RaftPeerId leader = RaftTestUtil.waitForLeader(cluster).getId(); RaftClientReply reply = null; try(final RaftClient client = cluster.createClient(leader)) { for(int i = 0; i < n; i++) { reply = client.send(Message.valueOf("m" + i)); } } return reply; }
@Test public void testGaussLegendre() throws Exception { setAndStart(cluster); try (final RaftClient client = cluster.createClient()) { runGaussLegendre(client); } }
@Test public void testPythagorean() throws Exception { setAndStart(cluster); try (final RaftClient client = cluster.createClient()) { runTestPythagorean(client, 3, 10); } }
@Test public void testGaussLegendre() throws Exception { setAndStart(cluster); try (final RaftClient client = cluster.createClient()) { runGaussLegendre(client); } }
public RaftServerImpl getLeaderAndSendFirstMessage(boolean ignoreException) throws IOException { final RaftServerImpl leader = getLeader(); try(RaftClient client = createClient(leader.getId())) { client.send(new RaftTestUtil.SimpleMessage("first msg to make leader ready")); } catch (IOException e) { if (!ignoreException) { throw e; } } return leader; }
public RaftServerImpl getLeaderAndSendFirstMessage(boolean ignoreException) throws IOException { final RaftServerImpl leader = getLeader(); try(RaftClient client = createClient(leader.getId())) { client.send(new RaftTestUtil.SimpleMessage("first msg to make leader ready")); } catch (IOException e) { if (!ignoreException) { throw e; } } return leader; }
@Test public void testHandleStateMachineException() throws Exception { setAndStart(cluster); final RaftPeerId leaderId = cluster.getLeader().getId(); try(final RaftClient client = cluster.createClient(leaderId)) { client.send(new SimpleMessage("m")); fail("Exception expected"); } catch (StateMachineException e) { e.printStackTrace(); Assert.assertTrue(e.getCause().getMessage().contains("Fake Exception")); } }