Skip to content

Commit

Permalink
[FLINK-4398] [query] Fix race in KvStateServerHandlerTest
Browse files Browse the repository at this point in the history
Successful request are reported asynchronously after the Netty channel
write has succeeded. The test checked the number of successful requests
too early.
  • Loading branch information
uce committed Nov 2, 2016
1 parent 2b369d3 commit b4bf99d
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
import java.io.IOException;
import java.util.Objects;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.TimeUnit;

/**
* This handler dispatches asynchronous tasks, which query {@link KvState}
Expand Down Expand Up @@ -286,7 +287,8 @@ private class QueryResultWriteListener implements ChannelFutureListener {

@Override
public void operationComplete(ChannelFuture future) throws Exception {
long durationMillis = (System.nanoTime() - creationNanos) / 1_000_000;
long durationNanos = System.nanoTime() - creationNanos;
long durationMillis = TimeUnit.MILLISECONDS.convert(durationNanos, TimeUnit.NANOSECONDS);

if (future.isSuccess()) {
stats.reportSuccessfulRequest(durationMillis);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;

import static org.junit.Assert.assertEquals;
Expand Down Expand Up @@ -150,6 +151,13 @@ public void testSimpleQuery() throws Exception {
assertEquals(expectedValue, actualValue);

assertEquals(stats.toString(), 1, stats.getNumRequests());

// Wait for async successful request report
long deadline = System.nanoTime() + TimeUnit.NANOSECONDS.convert(30, TimeUnit.SECONDS);
while (stats.getNumSuccessful() != 1 && System.nanoTime() <= deadline) {
Thread.sleep(10);
}

assertEquals(stats.toString(), 1, stats.getNumSuccessful());
}

Expand Down

0 comments on commit b4bf99d

Please sign in to comment.