You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@geode.apache.org by la...@apache.org on 2018/12/17 21:50:56 UTC
[geode] 02/04: GEODE-6177: wait for queue processing in test
This is an automated email from the ASF dual-hosted git repository.
ladyvader pushed a commit to branch develop
in repository https://gitbox.apache.org/repos/asf/geode.git
commit 10668f55003176efc3695e337fade94c0e554fac
Author: Ryan McMahon <rm...@pivotal.io>
AuthorDate: Fri Dec 14 16:02:30 2018 -0800
GEODE-6177: wait for queue processing in test
---
.../wan/misc/NewWanAuthenticationDUnitTest.java | 79 +++++++++++++++-------
.../wan/GatewaySenderEventRemoteDispatcher.java | 26 ++++---
2 files changed, 73 insertions(+), 32 deletions(-)
diff --git a/geode-wan/src/distributedTest/java/org/apache/geode/internal/cache/wan/misc/NewWanAuthenticationDUnitTest.java b/geode-wan/src/distributedTest/java/org/apache/geode/internal/cache/wan/misc/NewWanAuthenticationDUnitTest.java
index e31acbb..c4cb5f2 100644
--- a/geode-wan/src/distributedTest/java/org/apache/geode/internal/cache/wan/misc/NewWanAuthenticationDUnitTest.java
+++ b/geode-wan/src/distributedTest/java/org/apache/geode/internal/cache/wan/misc/NewWanAuthenticationDUnitTest.java
@@ -25,6 +25,7 @@ import static org.apache.geode.test.dunit.Assert.assertNotNull;
import static org.apache.geode.test.dunit.Assert.assertTrue;
import java.util.Properties;
+import java.util.concurrent.atomic.LongAdder;
import org.apache.logging.log4j.Logger;
import org.junit.Before;
@@ -37,6 +38,7 @@ import org.apache.geode.distributed.DistributedMember;
import org.apache.geode.distributed.DistributedSystem;
import org.apache.geode.distributed.internal.DistributionConfig;
import org.apache.geode.internal.Assert;
+import org.apache.geode.internal.cache.wan.GatewaySenderEventRemoteDispatcher;
import org.apache.geode.internal.cache.wan.WANTestBase;
import org.apache.geode.internal.logging.LogService;
import org.apache.geode.security.AuthInitialize;
@@ -208,7 +210,7 @@ public class NewWanAuthenticationDUnitTest extends WANTestBase {
sender.invoke(() -> {
startSender(senderId);
- doPutsAndVerifyQueue(regionName, numPuts, false, numPuts);
+ doPutsAndVerifyQueueSizeAfterProcessing(regionName, numPuts, false, true, false);
});
receiver.invoke(() -> validateRegionSize(regionName, 0));
@@ -244,7 +246,7 @@ public class NewWanAuthenticationDUnitTest extends WANTestBase {
sender.invoke(() -> {
startSender(senderId);
- doPutsAndVerifyQueue(regionName, numPuts, false, numPuts);
+ doPutsAndVerifyQueueSizeAfterProcessing(regionName, numPuts, false, true, false);
});
receiver.invoke(() -> validateRegionSize(regionName, 0));
@@ -257,7 +259,7 @@ public class NewWanAuthenticationDUnitTest extends WANTestBase {
});
sender.invoke(() -> {
- doPutsAndVerifyQueue(regionName, numPuts, true, 0);
+ doPutsAndVerifyQueueSizeAfterProcessing(regionName, numPuts, true, false, true);
});
receiver.invoke(() -> validateRegionSize(regionName, numPuts));
@@ -281,17 +283,7 @@ public class NewWanAuthenticationDUnitTest extends WANTestBase {
sender.invoke(() -> {
createSecuredCache(senderSecurityProps, null, lnPort);
createReplicatedRegion(regionName, senderId, isOffHeap());
- try {
- /*
- * Setting the gateway-connection-retry-interval to 0 ensures that the Dispatcher and
- * AckReader eagerly retry connections, so we may detect any issues with the retry logic
- * early.
- */
- System.setProperty(gatewayConnectionRetryIntervalConfigParameter, "0");
- createSender(senderId, 2, false, 100, 10, false, false, null, true);
- } finally {
- System.clearProperty(gatewayConnectionRetryIntervalConfigParameter);
- }
+ createSender(senderId, 2, false, 100, 10, false, false, null, true);
});
receiver.invoke(() -> {
@@ -300,7 +292,7 @@ public class NewWanAuthenticationDUnitTest extends WANTestBase {
sender.invoke(() -> {
startSender(senderId);
- doPutsAndVerifyQueue(regionName, numPuts, true, 0);
+ doPutsAndVerifyQueueSizeAfterProcessing(regionName, numPuts, true, false, true);
});
receiver.invoke(() -> validateRegionSize(regionName, numPuts));
@@ -315,7 +307,7 @@ public class NewWanAuthenticationDUnitTest extends WANTestBase {
});
sender.invoke(() -> {
- doPutsAndVerifyQueue(regionName, numPuts, false, numPuts);
+ doPutsAndVerifyQueueSizeAfterProcessing(regionName, numPuts, false, true, true);
});
receiver.invoke(() -> validateRegionSize(regionName, 0));
@@ -329,8 +321,12 @@ public class NewWanAuthenticationDUnitTest extends WANTestBase {
});
sender.invoke(() -> {
- // Data should be able to flow properly after valid credentials have been restored.
- doPutsAndVerifyQueue(regionName, numPuts, true, 0);
+ /*
+ * Data should be able to flow properly after valid credentials have been restored.
+ * No more puts are needed because we already have numPuts queued from when credentials
+ * were invalid (see above).
+ */
+ doPutsAndVerifyQueueSizeAfterProcessing(regionName, 0, true, false, true);
});
receiver.invoke(() -> validateRegionSize(regionName, numPuts));
@@ -411,12 +407,49 @@ public class NewWanAuthenticationDUnitTest extends WANTestBase {
// sender.invoke(() -> verifyDifferentServerInGetCredentialCall());
}
- private void doPutsAndVerifyQueue(final String regionName, final int numPuts,
- final boolean shouldBeConnected,
- final int expectedQueueSize) {
- doPuts(regionName, numPuts);
+ private void doPutsAndVerifyQueueSizeAfterProcessing(final String regionName, final int numPuts,
+ final boolean shouldBeConnected,
+ final boolean isQueueBlocked,
+ final boolean isAckThreadRunning) {
+ if (isQueueBlocked) {
+ // caller is assuming that queue processing will not make progress
+ try {
+ final LongAdder dispatchAttempts = new LongAdder();
+ final LongAdder ackReadAttempts = new LongAdder();
+
+ GatewaySenderEventRemoteDispatcher.messageProcessingAttempted = isAck -> {
+ if (isAck)
+ ackReadAttempts.increment();
+ else
+ dispatchAttempts.increment();
+ };
+
+ doPuts(regionName, numPuts);
+
+ /*
+ * The game here is to ensure that both the dispatcher thread and the ack reader thread
+ * each get at least one whack at processing (a batch or an ack, respectively).
+ * Note: both those conditions aren't obviously necessary from our method signature, but
+ * trust us: callers rely on that guarantee! (the "Processing" in the method name
+ * implies that _both_ threads tried).
+ *
+ * Notice the particular awfulness of the second term in the conditional below. Callers
+ * have to send us a flag to tell us that the ack reader thread is not running so we know
+ * not to look for its attempts.
+ */
+ await().until(() -> dispatchAttempts.sum() > 0 &&
+ (!isAckThreadRunning || ackReadAttempts.sum() > 0));
+
+ checkQueueSize(senderId, numPuts);
+ } finally {
+ GatewaySenderEventRemoteDispatcher.messageProcessingAttempted = isAck -> {};
+ }
+ } else {
+ doPuts(regionName, numPuts);
+ // caller is assuming queue will drain eventually
+ checkQueueSize(senderId, 0);
+ }
verifyRunningWithConnectedState(senderId, shouldBeConnected);
- checkQueueSize(senderId, expectedQueueSize);
}
private void createSecuredReceiver(Integer nyPort, String regionName,
diff --git a/geode-wan/src/main/java/org/apache/geode/internal/cache/wan/GatewaySenderEventRemoteDispatcher.java b/geode-wan/src/main/java/org/apache/geode/internal/cache/wan/GatewaySenderEventRemoteDispatcher.java
index 6951e32..eda2865 100644
--- a/geode-wan/src/main/java/org/apache/geode/internal/cache/wan/GatewaySenderEventRemoteDispatcher.java
+++ b/geode-wan/src/main/java/org/apache/geode/internal/cache/wan/GatewaySenderEventRemoteDispatcher.java
@@ -19,6 +19,7 @@ import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.concurrent.locks.ReentrantReadWriteLock;
+import java.util.function.Consumer;
import org.apache.logging.log4j.Logger;
@@ -60,6 +61,14 @@ public class GatewaySenderEventRemoteDispatcher implements GatewaySenderEventDis
private ReentrantReadWriteLock connectionLifeCycleLock = new ReentrantReadWriteLock();
+ /*
+ * Called after each attempt at processing an outbound (dispatch) or inbound (ack)
+ * message, whether the attempt is successful or not. The purpose is testability.
+ * Without this hook, negative tests, can't ensure that message processing was
+ * attempted, so they wouldn't know how long to wait for some sort of failure.
+ */
+ public static Consumer<Boolean> messageProcessingAttempted = isAck -> {};
+
/**
* This count is reset to 0 each time a successful connection is made.
*/
@@ -129,7 +138,10 @@ public class GatewaySenderEventRemoteDispatcher implements GatewaySenderEventDis
} else {
logAndStopProcessor(ex);
}
+ } finally {
+ messageProcessingAttempted.accept(true);
}
+
return ack;
}
@@ -163,6 +175,8 @@ public class GatewaySenderEventRemoteDispatcher implements GatewaySenderEventDis
throw e;
} catch (Exception e) {
logAndStopProcessor(e);
+ } finally {
+ messageProcessingAttempted.accept(false);
}
return success;
}
@@ -821,11 +835,8 @@ public class GatewaySenderEventRemoteDispatcher implements GatewaySenderEventDis
private static class RecoverableExceptionPredicates {
- /**
- * Certain exception types are considered recoverable when reading an acknowledgement.
- */
static boolean isRecoverableWhenReadingAck(final Exception ex) {
- /**
+ /*
* It is considered non-recoverable if the PDX registry files are deleted from the sending
* side of a WAN Gateway. This is determined by checking if the cause of the
* {@link ServerConnectivityException} is caused by a {@link PdxRegistryMismatchException}
@@ -835,11 +846,8 @@ public class GatewaySenderEventRemoteDispatcher implements GatewaySenderEventDis
&& !(ex.getCause() instanceof PdxRegistryMismatchException));
}
- /**
- * Certain exception types are considered recoverable when dispatching a batch.
- */
static boolean isRecoverableWhenDispatchingBatch(final Throwable t) {
- /**
+ /*
* We consider {@link ServerConnectivityException} to be a temporary connectivity issue and
* is therefore recoverable. The {@link IllegalStateException} can occur if off-heap is used,
* and a GatewaySenderEventImpl is serialized after being freed. This can happen if the
@@ -855,7 +863,7 @@ public class GatewaySenderEventRemoteDispatcher implements GatewaySenderEventDis
* reading an acknowledgement.
*/
private static boolean isRecoverableInAllCases(final Throwable t) {
- /**
+ /*
* {@link IOException} and {@link ConnectionDestroyedException} can occur
* due to temporary network issues and therefore are recoverable.
* {@link GemFireSecurityException} represents an inability to authenticate with the