use of org.apache.flink.util.function.ThrowingConsumer in project flink by apache.
the class SequentialChannelStateReaderImplTest method withResultPartitions.
private void withResultPartitions(ThrowingConsumer<BufferWritingResultPartition[], Exception> action) throws Exception {
int segmentsToAllocate = parLevel * parLevel * buffersPerChannel;
NetworkBufferPool networkBufferPool = new NetworkBufferPool(segmentsToAllocate, bufferSize);
BufferWritingResultPartition[] resultPartitions = range(0, parLevel).mapToObj(i -> new ResultPartitionBuilder().setResultPartitionIndex(i).setNumberOfSubpartitions(parLevel).setNetworkBufferPool(networkBufferPool).build()).toArray(BufferWritingResultPartition[]::new);
try {
for (ResultPartition resultPartition : resultPartitions) {
resultPartition.setup();
}
action.accept(resultPartitions);
} finally {
for (ResultPartition resultPartition : resultPartitions) {
resultPartition.close();
}
try {
assertEquals(segmentsToAllocate, networkBufferPool.getNumberOfAvailableMemorySegments());
} finally {
networkBufferPool.destroyAllBufferPools();
networkBufferPool.destroy();
}
}
}
use of org.apache.flink.util.function.ThrowingConsumer in project flink by apache.
the class FineGrainedSlotManagerTest method testAccessMetricValueDuringItsUnregister.
private void testAccessMetricValueDuringItsUnregister(ThrowingConsumer<SlotManager, Exception> closeFn) throws Exception {
final AtomicInteger registeredMetrics = new AtomicInteger();
final MetricRegistry metricRegistry = TestingMetricRegistry.builder().setRegisterConsumer((a, b, c) -> registeredMetrics.incrementAndGet()).setUnregisterConsumer((a, b, c) -> registeredMetrics.decrementAndGet()).build();
final Context context = new Context();
context.setSlotManagerMetricGroup(SlotManagerMetricGroup.create(metricRegistry, "localhost"));
context.runTest(() -> {
// sanity check to ensure metrics were actually registered
assertThat(registeredMetrics.get(), greaterThan(0));
context.runInMainThreadAndWait(() -> {
try {
closeFn.accept(context.getSlotManager());
} catch (Exception e) {
fail("Error when closing slot manager.");
}
});
assertThat(registeredMetrics.get(), is(0));
});
}
use of org.apache.flink.util.function.ThrowingConsumer in project flink by apache.
the class DeclarativeSlotManagerTest method testAccessMetricValueDuringItsUnregister.
private void testAccessMetricValueDuringItsUnregister(ThrowingConsumer<SlotManager, Exception> closeFn) throws Exception {
final AtomicInteger registeredMetrics = new AtomicInteger();
final MetricRegistry metricRegistry = TestingMetricRegistry.builder().setRegisterConsumer((a, b, c) -> registeredMetrics.incrementAndGet()).setUnregisterConsumer((a, b, c) -> registeredMetrics.decrementAndGet()).build();
final DeclarativeSlotManager slotManager = createDeclarativeSlotManagerBuilder().setSlotManagerMetricGroup(SlotManagerMetricGroup.create(metricRegistry, "localhost")).buildAndStartWithDirectExec();
// sanity check to ensure metrics were actually registered
assertThat(registeredMetrics.get(), greaterThan(0));
closeFn.accept(slotManager);
assertThat(registeredMetrics.get(), is(0));
}
Aggregations