Skip to content

Commit

Permalink
[hotfix][runtime] CodeStyle correction for NetworkBufferPoolTest
Browse files Browse the repository at this point in the history
  • Loading branch information
akalash authored and dawidwys committed Feb 25, 2022
1 parent cb3dfb5 commit 44da40f
Showing 1 changed file with 14 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,7 @@
import org.apache.flink.runtime.execution.CancelTaskException;
import org.apache.flink.util.TestLogger;

import org.hamcrest.MatcherAssert;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
import org.junit.rules.Timeout;

import java.io.IOException;
import java.time.Duration;
Expand All @@ -44,13 +40,13 @@
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicReference;

import static org.apache.flink.util.Preconditions.checkNotNull;
import static org.hamcrest.CoreMatchers.instanceOf;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.CoreMatchers.nullValue;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.hasProperty;
import static org.hamcrest.core.IsCollectionContaining.hasItem;
Expand All @@ -60,17 +56,13 @@
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertThat;
import static org.junit.Assert.assertThrows;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;

/** Tests for {@link NetworkBufferPool}. */
public class NetworkBufferPoolTest extends TestLogger {

@Rule public ExpectedException expectedException = ExpectedException.none();

@Rule public Timeout timeout = new Timeout(10, TimeUnit.SECONDS);

@Test
public void testCreatePoolAfterDestroy() {
try {
Expand Down Expand Up @@ -343,20 +335,20 @@ public void testSegmentsUsage() throws IOException {

assertEquals(20, globalPool.getNumberOfRequestedMemorySegments());
assertEquals(40, globalPool.getRequestedSegmentsUsage());
MatcherAssert.assertThat(globalPool.getUsageWarning(), equalTo(Optional.empty()));
assertThat(globalPool.getUsageWarning(), equalTo(Optional.empty()));

closeableRegistry.registerCloseable(
(globalPool.createBufferPool(5, Integer.MAX_VALUE))::lazyDestroy);

assertEquals(30, globalPool.getNumberOfRequestedMemorySegments());
assertEquals(60, globalPool.getRequestedSegmentsUsage());
MatcherAssert.assertThat(globalPool.getUsageWarning(), equalTo(Optional.empty()));
assertThat(globalPool.getUsageWarning(), equalTo(Optional.empty()));

closeableRegistry.registerCloseable((globalPool.createBufferPool(10, 30))::lazyDestroy);

assertEquals(60, globalPool.getNumberOfRequestedMemorySegments());
assertEquals(120, globalPool.getRequestedSegmentsUsage());
MatcherAssert.assertThat(
assertThat(
globalPool.getUsageWarning(),
equalTo(
Optional.of(
Expand All @@ -367,13 +359,13 @@ public void testSegmentsUsage() throws IOException {
+ "totalMemory=6.250kb (6400 bytes), "
+ "requestedMemory=7.500kb (7680 bytes), "
+ "missingMemory=1.250kb (1280 bytes))")));
MatcherAssert.assertThat(globalPool.getUsageWarning(), equalTo(Optional.empty()));
assertThat(globalPool.getUsageWarning(), equalTo(Optional.empty()));

BufferPool bufferPool2 = globalPool.createBufferPool(10, 20);

assertEquals(80, globalPool.getNumberOfRequestedMemorySegments());
assertEquals(160, globalPool.getRequestedSegmentsUsage());
MatcherAssert.assertThat(
assertThat(
globalPool.getUsageWarning(),
equalTo(
Optional.of(
Expand All @@ -391,10 +383,10 @@ public void testSegmentsUsage() throws IOException {
assertEquals(40, globalPool.getNumberOfRequestedMemorySegments());
assertEquals(40 * 128, globalPool.getRequestedMemory());
assertEquals(80, globalPool.getRequestedSegmentsUsage());
MatcherAssert.assertThat(
assertThat(
globalPool.getUsageWarning(),
equalTo(Optional.of("Memory usage [80%] went back to normal")));
MatcherAssert.assertThat(globalPool.getUsageWarning(), equalTo(Optional.empty()));
assertThat(globalPool.getUsageWarning(), equalTo(Optional.empty()));
}
}

Expand Down Expand Up @@ -503,10 +495,9 @@ public void go() throws IOException {

segment.free();

expectedException.expect(IllegalStateException.class);
expectedException.expectMessage("destroyed");
try {
asyncRequest.sync();
Exception ex = assertThrows(IllegalStateException.class, asyncRequest::sync);
assertTrue(ex.getMessage().contains("destroyed"));
} finally {
globalPool.destroy();
}
Expand Down Expand Up @@ -587,11 +578,9 @@ public void go() throws Exception {

asyncRequest.start();

expectedException.expect(IOException.class);
expectedException.expectMessage("Timeout");

try {
asyncRequest.sync();
Exception ex = assertThrows(IOException.class, asyncRequest::sync);
assertTrue(ex.getMessage().contains("Timeout"));
} finally {
globalPool.destroy();
}
Expand Down Expand Up @@ -752,7 +741,7 @@ public void testBlockingRequestFromMultiLocalBufferPool()
// wait until all available buffers are requested
while (segmentsRequested.size() + segments.size() + exclusiveSegments.size()
< numBuffers) {
Thread.sleep(100);
Thread.sleep(10);
assertNull(cause.get());
}

Expand Down

0 comments on commit 44da40f

Please sign in to comment.