Code review comment: try (CloseableRegistry closeableRegistry = new CloseableRegistry()) to avoid finally clause.

Code before review:
public void testCalculateTotalBuffersSize() throws IOException {
int numberOfRemoteChannels = 2;
int numberOfLocalChannels = 0;
int buffersPerChannel = 2;
int extraNetworkBuffersPerGate = 8;
CloseableRegistry closeableRegistry = new CloseableRegistry();
NettyShuffleEnvironment network = new NettyShuffleEnvironmentBuilder()
.setNetworkBuffersPerChannel(buffersPerChannel)
.setFloatingNetworkBuffersPerGate(extraNetworkBuffersPerGate)
.build();
Tuple3<SingleInputGate, List<RemoteInputChannel>, List<LocalInputChannel>> tuple1 = buildInputGate(
network,
numberOfRemoteChannels,
numberOfLocalChannels);
SingleInputGate inputGate1 = tuple1.f0;
closeableRegistry.registerCloseable(network::close);
closeableRegistry.registerCloseable(inputGate1::close);
try {
SingleInputGate[] inputGates = new SingleInputGate[]{inputGate1};
FloatingBuffersUsageGauge floatingBuffersUsageGauge = new FloatingBuffersUsageGauge(inputGates);
ExclusiveBuffersUsageGauge exclusiveBuffersUsageGauge = new ExclusiveBuffersUsageGauge(inputGates);
CreditBasedInputBuffersUsageGauge inputBufferPoolUsageGauge = new CreditBasedInputBuffersUsageGauge(
floatingBuffersUsageGauge,
exclusiveBuffersUsageGauge,
inputGates);
assertEquals(extraNetworkBuffersPerGate, floatingBuffersUsageGauge.calculateTotalBuffers(inputGate1));
assertEquals(numberOfRemoteChannels * buffersPerChannel, exclusiveBuffersUsageGauge.calculateTotalBuffers(inputGate1));
assertEquals(numberOfRemoteChannels * buffersPerChannel + extraNetworkBuffersPerGate, inputBufferPoolUsageGauge.calculateTotalBuffers(inputGate1));
} finally {
closeableRegistry.close();
}
}

Line under review: try {

Code after addressing the review:
public void testCalculateTotalBuffersSize() throws IOException {
int numberOfRemoteChannels = 2;
int numberOfLocalChannels = 0;
int numberOfBufferPerChannel = 2;
int numberOfBuffersPerGate = 8;
NettyShuffleEnvironment network = new NettyShuffleEnvironmentBuilder()
.setNetworkBuffersPerChannel(numberOfBufferPerChannel)
.setFloatingNetworkBuffersPerGate(numberOfBuffersPerGate)
.build();
SingleInputGate inputGate1 = buildInputGate(
network,
numberOfRemoteChannels,
numberOfLocalChannels).f0;
SingleInputGate[] inputGates = new SingleInputGate[]{inputGate1};
FloatingBuffersUsageGauge floatingBuffersUsageGauge = new FloatingBuffersUsageGauge(inputGates);
ExclusiveBuffersUsageGauge exclusiveBuffersUsageGauge = new ExclusiveBuffersUsageGauge(inputGates);
CreditBasedInputBuffersUsageGauge inputBufferPoolUsageGauge = new CreditBasedInputBuffersUsageGauge(
floatingBuffersUsageGauge,
exclusiveBuffersUsageGauge,
inputGates);
try (CloseableRegistry closeableRegistry = new CloseableRegistry()) {
closeableRegistry.registerCloseable(network::close);
closeableRegistry.registerCloseable(inputGate1::close);
assertEquals(numberOfBuffersPerGate, floatingBuffersUsageGauge.calculateTotalBuffers(inputGate1));
assertEquals(numberOfRemoteChannels * numberOfBufferPerChannel, exclusiveBuffersUsageGauge.calculateTotalBuffers(inputGate1));
assertEquals(numberOfRemoteChannels * numberOfBufferPerChannel + numberOfBuffersPerGate, inputBufferPoolUsageGauge.calculateTotalBuffers(inputGate1));
}
}