This is an automated email from the ASF dual-hosted git repository.
adar pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/kudu.git
commit 0b80b0abae99c56db20e96249981a48886c56d33
Author: Adar Dembo <adar@cloudera.com>
AuthorDate: Wed Jan 30 17:09:56 2019 -0800
[java] fix ITClient test retrying
ITClient is flaky due to KUDU-2390, but it's also unable to retry upon
failure. I think this is caused by the static error latch which isn't reset
in between test runs. There's no reason for it to be static; I'm guessing
it's a holdover from when the minicluster state was static.
I also added an @After to close the client instance used by the test, which
will hopefully reduce the amount of log pollution in the retries.
Change-Id: I4a9f6a27541de02bbc8cf9dc3ba72824a6324a08
Reviewed-on: http://gerrit.cloudera.org:8080/12321
Tested-by: Kudu Jenkins
Reviewed-by: Grant Henke <granthenke@apache.org>
Reviewed-by: Alexey Serbin <aserbin@cloudera.com>
---
.../test/java/org/apache/kudu/client/ITClient.java | 57 +++++++++++++---------
1 file changed, 34 insertions(+), 23 deletions(-)
diff --git a/java/kudu-client/src/test/java/org/apache/kudu/client/ITClient.java b/java/kudu-client/src/test/java/org/apache/kudu/client/ITClient.java
index 06f25f8..e28c1f2 100644
--- a/java/kudu-client/src/test/java/org/apache/kudu/client/ITClient.java
+++ b/java/kudu-client/src/test/java/org/apache/kudu/client/ITClient.java
@@ -24,6 +24,7 @@ import java.util.concurrent.TimeUnit;
import com.google.common.collect.ImmutableList;
import org.apache.kudu.test.KuduTestHarness;
+import org.junit.After;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Rule;
@@ -57,15 +58,16 @@ public class ITClient {
private static final String TABLE_NAME =
ITClient.class.getName() + "-" + System.currentTimeMillis();
+
// One error and we stop the test.
- private static final CountDownLatch KEEP_RUNNING_LATCH = new CountDownLatch(1);
+ private final CountDownLatch keepRunningLatch = new CountDownLatch(1);
// Latch used to track if an error occurred and we need to stop the test early.
- private static final CountDownLatch ERROR_LATCH = new CountDownLatch(1);
+ private final CountDownLatch errorLatch = new CountDownLatch(1);
- private static KuduClient localClient;
- private static AsyncKuduClient localAsyncClient;
- private static KuduTable table;
- private static long runtimeInSeconds;
+ private KuduClient localClient;
+ private AsyncKuduClient localAsyncClient;
+ private KuduTable table;
+ private long runtimeInSeconds;
private volatile long sharedWriteTimestamp;
@@ -97,6 +99,15 @@ public class ITClient {
table = localClient.createTable(TABLE_NAME, getBasicSchema(), builder);
}
+ @After
+ public void tearDown() throws Exception {
+ if (localClient != null) {
+ localClient.shutdown();
+ // No need to explicitly shutdown the async client,
+ // shutting down the sync client effectively does that.
+ }
+ }
+
@Test(timeout = TEST_TIMEOUT_SECONDS)
public void test() throws Exception {
@@ -117,11 +128,11 @@ public class ITClient {
}
// await() returns yes if the latch reaches 0, we don't want that.
- Assert.assertFalse("Look for the last ERROR line in the log that comes from ITCLient",
- ERROR_LATCH.await(runtimeInSeconds, TimeUnit.SECONDS));
+ Assert.assertFalse("Look for the last ERROR line in the log that comes from ITClient",
+ errorLatch.await(runtimeInSeconds, TimeUnit.SECONDS));
// Indicate we want to stop, then wait a little bit for it to happen.
- KEEP_RUNNING_LATCH.countDown();
+ keepRunningLatch.countDown();
for (Thread thread : threads) {
// Give plenty of time for threads to stop.
@@ -140,7 +151,7 @@ public class ITClient {
*/
private void reportError(String message, Exception exception) {
LOG.error(message, exception);
- ERROR_LATCH.countDown();
+ errorLatch.countDown();
}
/**
@@ -153,11 +164,11 @@ public class ITClient {
@Override
public void run() {
try {
- KEEP_RUNNING_LATCH.await(2, TimeUnit.SECONDS);
+ keepRunningLatch.await(2, TimeUnit.SECONDS);
} catch (InterruptedException e) {
return;
}
- while (KEEP_RUNNING_LATCH.getCount() > 0) {
+ while (keepRunningLatch.getCount() > 0) {
try {
boolean shouldContinue;
int randomInt = random.nextInt(3);
@@ -172,7 +183,7 @@ public class ITClient {
if (!shouldContinue) {
return;
}
- KEEP_RUNNING_LATCH.await(5, TimeUnit.SECONDS);
+ keepRunningLatch.await(5, TimeUnit.SECONDS);
} catch (InterruptedException e) {
return;
}
@@ -195,7 +206,7 @@ public class ITClient {
connections.get(random.nextInt(connections.size())).disconnect();
} catch (Exception e) {
- if (KEEP_RUNNING_LATCH.getCount() == 0) {
+ if (keepRunningLatch.getCount() == 0) {
// Likely shutdown() related.
return false;
}
@@ -248,7 +259,7 @@ public class ITClient {
@Override
public void run() {
session.setExternalConsistencyMode(ExternalConsistencyMode.CLIENT_PROPAGATED);
- while (KEEP_RUNNING_LATCH.getCount() > 0) {
+ while (keepRunningLatch.getCount() > 0) {
try {
OperationResponse resp = session.apply(createBasicSchemaInsert(table, currentRowKey));
if (hasRowErrorAndReport(resp)) {
@@ -276,7 +287,7 @@ public class ITClient {
}
}
} catch (Exception e) {
- if (KEEP_RUNNING_LATCH.getCount() == 0) {
+ if (keepRunningLatch.getCount() == 0) {
// Likely shutdown() related.
return;
}
@@ -315,7 +326,7 @@ public class ITClient {
@Override
public void run() {
- while (KEEP_RUNNING_LATCH.getCount() > 0) {
+ while (keepRunningLatch.getCount() > 0) {
boolean shouldContinue;
@@ -335,7 +346,7 @@ public class ITClient {
if (lastRowCount == 0) {
try {
- KEEP_RUNNING_LATCH.await(50, TimeUnit.MILLISECONDS);
+ keepRunningLatch.await(50, TimeUnit.MILLISECONDS);
} catch (InterruptedException e) {
// Test is stopping.
return;
@@ -390,7 +401,7 @@ public class ITClient {
DeadlineTracker deadlineTracker = new DeadlineTracker();
deadlineTracker.setDeadline(DEFAULT_SLEEP);
- while (KEEP_RUNNING_LATCH.getCount() > 0 && !deadlineTracker.timedOut())
{
+ while (keepRunningLatch.getCount() > 0 && !deadlineTracker.timedOut()) {
KuduScanner scanner = getScannerBuilder().build();
try {
@@ -406,13 +417,13 @@ public class ITClient {
}
return true;
} else {
- reportError("Row count unexpectedly decreased from " + lastRowCount + "to " + rowCount,
+ reportError("Row count unexpectedly decreased from " + lastRowCount + " to " +
rowCount,
null);
}
// Due to the lack of KUDU-430, we need to loop for a while.
try {
- KEEP_RUNNING_LATCH.await(50, TimeUnit.MILLISECONDS);
+ keepRunningLatch.await(50, TimeUnit.MILLISECONDS);
} catch (InterruptedException e) {
// No need to do anything, we'll exit the loop once we test getCount() in the condition.
}
@@ -462,9 +473,9 @@ public class ITClient {
@Override
public void uncaughtException(Thread t, Throwable e) {
// Only report an error if we're still running, else we'll spam the log.
- if (KEEP_RUNNING_LATCH.getCount() != 0) {
+ if (keepRunningLatch.getCount() != 0) {
reportError("Uncaught exception", new Exception(e));
}
}
}
-}
\ No newline at end of file
+}
|