You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@geode.apache.org by bs...@apache.org on 2018/08/27 22:24:12 UTC
[geode] branch develop updated: GEODE-5646 Client throws
ToDataException when locator is shutting down
This is an automated email from the ASF dual-hosted git repository.
bschuchardt pushed a commit to branch develop
in repository https://gitbox.apache.org/repos/asf/geode.git
The following commit(s) were added to refs/heads/develop by this push:
new 3651a9a GEODE-5646 Client throws ToDataException when locator is shutting down
3651a9a is described below
commit 3651a9a9b3819948da18e02b7fc64c3493f6d886
Author: Bruce Schuchardt <bs...@pivotal.io>
AuthorDate: Mon Aug 27 15:22:47 2018 -0700
GEODE-5646 Client throws ToDataException when locator is shutting down
Catch and handle ToDataException. Reviewed by mhanson
---
.../AutoConnectionSourceImplJUnitTest.java | 24 ++++++++++++++++++++++
.../client/internal/AutoConnectionSourceImpl.java | 16 +++++++++++++--
2 files changed, 38 insertions(+), 2 deletions(-)
diff --git a/geode-core/src/integrationTest/java/org/apache/geode/cache/client/internal/AutoConnectionSourceImplJUnitTest.java b/geode-core/src/integrationTest/java/org/apache/geode/cache/client/internal/AutoConnectionSourceImplJUnitTest.java
index 6176e13..3758049 100644
--- a/geode-core/src/integrationTest/java/org/apache/geode/cache/client/internal/AutoConnectionSourceImplJUnitTest.java
+++ b/geode-core/src/integrationTest/java/org/apache/geode/cache/client/internal/AutoConnectionSourceImplJUnitTest.java
@@ -19,6 +19,11 @@ import static org.apache.geode.distributed.ConfigurationProperties.MCAST_PORT;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.fail;
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.ArgumentMatchers.isA;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.verify;
+import static org.powermock.api.mockito.PowerMockito.when;
import java.io.IOException;
import java.net.ConnectException;
@@ -47,6 +52,7 @@ import org.junit.contrib.java.lang.system.RestoreSystemProperties;
import org.junit.experimental.categories.Category;
import org.apache.geode.CancelCriterion;
+import org.apache.geode.ToDataException;
import org.apache.geode.cache.Cache;
import org.apache.geode.cache.CacheFactory;
import org.apache.geode.cache.GemFireCache;
@@ -57,6 +63,7 @@ import org.apache.geode.cache.client.SubscriptionNotEnabledException;
import org.apache.geode.cache.client.internal.locator.ClientConnectionRequest;
import org.apache.geode.cache.client.internal.locator.ClientConnectionResponse;
import org.apache.geode.cache.client.internal.locator.LocatorListResponse;
+import org.apache.geode.cache.client.internal.locator.ServerLocationRequest;
import org.apache.geode.cache.query.QueryService;
import org.apache.geode.distributed.DistributedSystem;
import org.apache.geode.distributed.internal.DistributionConfig;
@@ -74,6 +81,7 @@ import org.apache.geode.internal.cache.tier.InternalClientMembership;
import org.apache.geode.internal.cache.tier.sockets.TcpServerFactory;
import org.apache.geode.management.membership.ClientMembershipEvent;
import org.apache.geode.management.membership.ClientMembershipListener;
+import org.apache.geode.test.dunit.NetworkUtils;
import org.apache.geode.test.junit.categories.ClientServerTest;
@SuppressWarnings("deprecation")
@@ -234,6 +242,22 @@ public class AutoConnectionSourceImplJUnitTest {
}
@Test
+ public void testSourceHandlesToDataException() throws IOException, ClassNotFoundException {
+ TcpClient mockConnection = mock(TcpClient.class);
+ when(mockConnection.requestToServer(isA(InetSocketAddress.class), any(Object.class),
+ isA(Integer.class), isA(Boolean.class))).thenThrow(new ToDataException("testing"));
+ try {
+ InetSocketAddress address = new InetSocketAddress(NetworkUtils.getServerHostName(), 1234);
+ source.queryOneLocatorUsingConnection(new HostAddress(address, "locator[1234]"), mock(
+ ServerLocationRequest.class), mockConnection);
+ verify(mockConnection).requestToServer(isA(InetSocketAddress.class),
+ isA(ServerLocationRequest.class), isA(Integer.class), isA(Boolean.class));
+ } catch (NoAvailableLocatorsException expected) {
+ // do nothing
+ }
+ }
+
+ @Test
public void testServerLocationUsedInListenerNotification() throws Exception {
final ClientMembershipEvent[] listenerEvents = new ClientMembershipEvent[1];
diff --git a/geode-core/src/main/java/org/apache/geode/cache/client/internal/AutoConnectionSourceImpl.java b/geode-core/src/main/java/org/apache/geode/cache/client/internal/AutoConnectionSourceImpl.java
index efb39d6..a1c87a4 100644
--- a/geode-core/src/main/java/org/apache/geode/cache/client/internal/AutoConnectionSourceImpl.java
+++ b/geode-core/src/main/java/org/apache/geode/cache/client/internal/AutoConnectionSourceImpl.java
@@ -32,6 +32,7 @@ import java.util.concurrent.atomic.AtomicReference;
import org.apache.logging.log4j.Logger;
+import org.apache.geode.ToDataException;
import org.apache.geode.cache.client.NoAvailableLocatorsException;
import org.apache.geode.cache.client.internal.PoolImpl.PoolTask;
import org.apache.geode.cache.client.internal.locator.ClientConnectionRequest;
@@ -188,10 +189,17 @@ public class AutoConnectionSourceImpl implements ConnectionSource {
private ServerLocationResponse queryOneLocator(HostAddress locator,
ServerLocationRequest request) {
+ return queryOneLocatorUsingConnection(locator, request, tcpClient);
+ }
+
+
+ ServerLocationResponse queryOneLocatorUsingConnection(HostAddress locator,
+ ServerLocationRequest request,
+ TcpClient locatorConnection) {
Object returnObj = null;
try {
pool.getStats().incLocatorRequests();
- returnObj = tcpClient.requestToServer(locator.getSocketInetAddressNoLookup(), request,
+ returnObj = locatorConnection.requestToServer(locator.getSocketInetAddressNoLookup(), request,
connectionTimeout, true);
ServerLocationResponse response = (ServerLocationResponse) returnObj;
pool.getStats().incLocatorResponses();
@@ -199,7 +207,11 @@ public class AutoConnectionSourceImpl implements ConnectionSource {
reportLiveLocator(locator.getSocketInetAddressNoLookup());
}
return response;
- } catch (IOException ioe) {
+ } catch (IOException | ToDataException ioe) {
+ if (ioe instanceof ToDataException) {
+ logger.warn("Encountered ToDataException when communicating with a locator. "
+ + "This is expected if the locator is shutting down.", ioe);
+ }
reportDeadLocator(locator.getSocketInetAddressNoLookup(), ioe);
updateLocatorInLocatorList(locator);
return null;