org.apache.ratis.util.function.CheckedBiConsumer Java Examples
The following examples show how to use
org.apache.ratis.util.function.CheckedBiConsumer.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: TestMultiRaftGroup.java From incubator-ratis with Apache License 2.0 | 5 votes |
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); }
Example #2
Source File: TestMultiRaftGroup.java From ratis with Apache License 2.0 | 5 votes |
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); }
Example #3
Source File: TestOzoneContainerRatis.java From hadoop-ozone with Apache License 2.0 | 4 votes |
private static void runTest( String testName, RpcType rpc, int numNodes, CheckedBiConsumer<Long, XceiverClientSpi, Exception> test) throws Exception { LOG.info("{}(rpc={}, numNodes={}", testName, rpc, numNodes); // create Ozone clusters final OzoneConfiguration conf = newOzoneConfiguration(); RatisTestHelper.initRatisConf(rpc, conf); final MiniOzoneCluster cluster = MiniOzoneCluster.newBuilder(conf) .setNumDatanodes(numNodes) .build(); try { cluster.waitForClusterToBeReady(); final String containerName = OzoneUtils.getRequestID(); final List<HddsDatanodeService> datanodes = cluster.getHddsDatanodes(); final Pipeline pipeline = MockPipeline.createPipeline( CollectionUtils.as(datanodes, HddsDatanodeService::getDatanodeDetails)); LOG.info("pipeline={}", pipeline); // Create Ratis cluster // final String ratisId = "ratis1"; // final PipelineManager manager = RatisManagerImpl.newRatisManager(conf); // manager.createPipeline(ratisId, pipeline.getNodes()); // LOG.info("Created RatisCluster " + ratisId); // // // check Ratis cluster members // final List<DatanodeDetails> dns = manager.getMembers(ratisId); // Assert.assertEquals(pipeline.getNodes(), dns); // // // run test // final XceiverClientSpi client = XceiverClientRatis // .newXceiverClientRatis( // pipeline, conf); // test.accept(containerName, client); } finally { cluster.shutdown(); } }
Example #4
Source File: TestContainerServer.java From hadoop-ozone with Apache License 2.0 | 4 votes |
static void runTestClientServer( int numDatanodes, CheckedBiConsumer<Pipeline, OzoneConfiguration, IOException> initConf, CheckedBiFunction<Pipeline, OzoneConfiguration, XceiverClientSpi, IOException> createClient, CheckedBiFunction<DatanodeDetails, OzoneConfiguration, XceiverServerSpi, IOException> createServer, CheckedBiConsumer<DatanodeDetails, Pipeline, IOException> initServer) throws Exception { final List<XceiverServerSpi> servers = new ArrayList<>(); XceiverClientSpi client = null; String containerName = OzoneUtils.getRequestID(); try { final Pipeline pipeline = MockPipeline.createPipeline(numDatanodes); initConf.accept(pipeline, CONF); for (DatanodeDetails dn : pipeline.getNodes()) { final XceiverServerSpi s = createServer.apply(dn, CONF); servers.add(s); s.start(); initServer.accept(dn, pipeline); } client = createClient.apply(pipeline, CONF); client.connect(); final ContainerCommandRequestProto request = ContainerTestHelper .getCreateContainerRequest( ContainerTestHelper.getTestContainerID(), pipeline); Assert.assertNotNull(request.getTraceID()); ContainerCommandResponseProto response = client.sendCommand(request); } finally { if (client != null) { client.close(); } servers.stream().forEach(XceiverServerSpi::stop); } }
Example #5
Source File: TestCSMMetrics.java From hadoop-ozone with Apache License 2.0 | 4 votes |
static void runContainerStateMachineMetrics( int numDatanodes, BiConsumer<Pipeline, OzoneConfiguration> initConf, TestCSMMetrics.CheckedBiFunction<Pipeline, OzoneConfiguration, XceiverClientSpi, IOException> createClient, TestCSMMetrics.CheckedBiFunction<DatanodeDetails, OzoneConfiguration, XceiverServerSpi, IOException> createServer, CheckedBiConsumer<DatanodeDetails, Pipeline, IOException> initServer) throws Exception { final List<XceiverServerSpi> servers = new ArrayList<>(); XceiverClientSpi client = null; String containerName = OzoneUtils.getRequestID(); try { final Pipeline pipeline = MockPipeline.createPipeline(numDatanodes); final OzoneConfiguration conf = new OzoneConfiguration(); initConf.accept(pipeline, conf); for (DatanodeDetails dn : pipeline.getNodes()) { final XceiverServerSpi s = createServer.apply(dn, conf); servers.add(s); s.start(); initServer.accept(dn, pipeline); } client = createClient.apply(pipeline, conf); client.connect(); // Before Read Chunk/Write Chunk MetricsRecordBuilder metric = getMetrics(CSMMetrics.SOURCE_NAME + RaftGroupId.valueOf(pipeline.getId().getId()).toString()); assertCounter("NumWriteStateMachineOps", 0L, metric); assertCounter("NumReadStateMachineOps", 0L, metric); assertCounter("NumApplyTransactionOps", 0L, metric); assertCounter("NumBytesWrittenCount", 0L, metric); assertCounter("NumBytesCommittedCount", 0L, metric); assertCounter("NumStartTransactionVerifyFailures", 0L, metric); assertCounter("NumContainerNotOpenVerifyFailures", 0L, metric); assertCounter("WriteChunkNumOps", 0L, metric); double applyTransactionLatency = getDoubleGauge( "ApplyTransactionAvgTime", metric); assertTrue(applyTransactionLatency == 0.0); double writeStateMachineLatency = getDoubleGauge( "WriteStateMachineDataAvgTime", metric); assertTrue(writeStateMachineLatency == 0.0); // Write Chunk BlockID blockID = ContainerTestHelper.getTestBlockID(ContainerTestHelper. getTestContainerID()); ContainerProtos.ContainerCommandRequestProto writeChunkRequest = ContainerTestHelper.getWriteChunkRequest( pipeline, blockID, 1024, null); ContainerCommandResponseProto response = client.sendCommand(writeChunkRequest); Assert.assertEquals(ContainerProtos.Result.SUCCESS, response.getResult()); metric = getMetrics(CSMMetrics.SOURCE_NAME + RaftGroupId.valueOf(pipeline.getId().getId()).toString()); assertCounter("NumWriteStateMachineOps", 1L, metric); assertCounter("NumBytesWrittenCount", 1024L, metric); assertCounter("NumApplyTransactionOps", 1L, metric); assertCounter("NumBytesCommittedCount", 1024L, metric); assertCounter("NumStartTransactionVerifyFailures", 0L, metric); assertCounter("NumContainerNotOpenVerifyFailures", 0L, metric); assertCounter("WriteChunkNumOps", 1L, metric); //Read Chunk ContainerProtos.ContainerCommandRequestProto readChunkRequest = ContainerTestHelper.getReadChunkRequest(pipeline, writeChunkRequest .getWriteChunk()); response = client.sendCommand(readChunkRequest); Assert.assertEquals(ContainerProtos.Result.SUCCESS, response.getResult()); metric = getMetrics(CSMMetrics.SOURCE_NAME + RaftGroupId.valueOf(pipeline.getId().getId()).toString()); assertCounter("NumQueryStateMachineOps", 1L, metric); assertCounter("NumApplyTransactionOps", 1L, metric); applyTransactionLatency = getDoubleGauge( "ApplyTransactionAvgTime", metric); assertTrue(applyTransactionLatency > 0.0); writeStateMachineLatency = getDoubleGauge( "WriteStateMachineDataAvgTime", metric); assertTrue(writeStateMachineLatency > 0.0); } finally { if (client != null) { client.close(); } servers.stream().forEach(XceiverServerSpi::stop); } }