geode-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From zho...@apache.org
Subject [geode] 01/01: GEODE-6149: when client's cache is closing, its GetClientPRMetaDataOp could end up with NPE
Date Wed, 05 Dec 2018 19:09:43 GMT
This is an automated email from the ASF dual-hosted git repository.

zhouxj pushed a commit to branch feature/GEODE-6149
in repository https://gitbox.apache.org/repos/asf/geode.git

commit b13401c12ae53cc8356ba8f051eb10124d4680af
Author: zhouxh <gzhou@pivotal.io>
AuthorDate: Wed Dec 5 11:08:32 2018 -0800

    GEODE-6149: when client's cache is closing, its GetClientPRMetaDataOp could end up with
NPE
---
 .../client/internal/GetClientPRMetaDataOp.java     |  5 ++++
 .../internal/GetClientPRMetaDataOpJUnitTest.java   | 32 ++++++++++++++++++++++
 2 files changed, 37 insertions(+)

diff --git a/geode-core/src/main/java/org/apache/geode/cache/client/internal/GetClientPRMetaDataOp.java
b/geode-core/src/main/java/org/apache/geode/cache/client/internal/GetClientPRMetaDataOp.java
index c82860d..5b676a0 100755
--- a/geode-core/src/main/java/org/apache/geode/cache/client/internal/GetClientPRMetaDataOp.java
+++ b/geode-core/src/main/java/org/apache/geode/cache/client/internal/GetClientPRMetaDataOp.java
@@ -95,6 +95,11 @@ public class GetClientPRMetaDataOp {
           }
           int numParts = msg.getNumberOfParts();
           ClientPartitionAdvisor advisor = cms.getClientPartitionAdvisor(regionFullPath);
+          if (advisor == null) {
+            logger.debug(
+                "GetClientPRMetaDataOpImpl#processResponse: advisor is null, which could
be due to cache is closed. Not to update PR meta data.");
+            return null;
+          }
           for (int i = 0; i < numParts; i++) {
             Object result = msg.getPart(i).getObject();
             List<BucketServerLocation66> locations = (List<BucketServerLocation66>)
result;
diff --git a/geode-core/src/test/java/org/apache/geode/cache/client/internal/GetClientPRMetaDataOpJUnitTest.java
b/geode-core/src/test/java/org/apache/geode/cache/client/internal/GetClientPRMetaDataOpJUnitTest.java
new file mode 100644
index 0000000..535d794
--- /dev/null
+++ b/geode-core/src/test/java/org/apache/geode/cache/client/internal/GetClientPRMetaDataOpJUnitTest.java
@@ -0,0 +1,32 @@
+package org.apache.geode.cache.client.internal;
+
+import static org.junit.Assert.assertNull;
+import static org.mockito.Mockito.doReturn;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.spy;
+import static org.mockito.Mockito.when;
+
+import org.junit.Test;
+
+import org.apache.geode.cache.Cache;
+import org.apache.geode.internal.cache.tier.MessageType;
+import org.apache.geode.internal.cache.tier.sockets.Message;
+
+public class GetClientPRMetaDataOpJUnitTest {
+  @Test
+  public void processResponseWhenCacheClosedShuouldReturnNull() throws Exception {
+    Cache cache = mock(Cache.class);
+    ClientMetadataService cms = new ClientMetadataService(cache);
+    cms = spy(cms);
+    doReturn(true).when(cache).isClosed();
+
+    Message msg = mock(Message.class);
+    GetClientPRMetaDataOp.GetClientPRMetaDataOpImpl op =
+        new GetClientPRMetaDataOp.GetClientPRMetaDataOpImpl("testRegion", cms);
+    op = spy(op);
+
+    when(msg.getMessageType()).thenReturn(MessageType.RESPONSE_CLIENT_PR_METADATA);
+
+    assertNull(op.processResponse(msg));
+  }
+}


Mime
View raw message