You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@geode.apache.org by nn...@apache.org on 2018/03/16 17:16:59 UTC

[geode] branch develop updated: GEODE-4827: CQ not added to cq map on exception (#1602)

This is an automated email from the ASF dual-hosted git repository.

nnag 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 c5b4401  GEODE-4827: CQ not added to cq map on exception (#1602)
c5b4401 is described below

commit c5b44019dd21847f9f79fc1fbfcf78df70f660e0
Author: Nabarun Nag <na...@users.noreply.github.com>
AuthorDate: Fri Mar 16 10:16:56 2018 -0700

    GEODE-4827: CQ not added to cq map on exception (#1602)
    
            * Log level set to info when FilterProfile gets an exception while registering CQ
    	* Before, when there is an exception while registering cq like while cache closing the cq's base region is null
    	* There is an exception which is logged in debug level but execution continues and adds the cq to the cp map with base region set to null
    	* This results in a NullPointerException while closing cq as methods are executed on null region
    	* Now the operation to put the cq into the cq map is inside a if check for null cq base region.
---
 .../apache/geode/internal/cache/FilterProfile.java | 25 +++++---
 .../FilterProfileNullCqBaseRegionJUnitTest.java    | 74 ++++++++++++++++++++++
 2 files changed, 89 insertions(+), 10 deletions(-)

diff --git a/geode-core/src/main/java/org/apache/geode/internal/cache/FilterProfile.java b/geode-core/src/main/java/org/apache/geode/internal/cache/FilterProfile.java
index 84ab0b7..8a2e884 100755
--- a/geode-core/src/main/java/org/apache/geode/internal/cache/FilterProfile.java
+++ b/geode-core/src/main/java/org/apache/geode/internal/cache/FilterProfile.java
@@ -817,6 +817,11 @@ public class FilterProfile implements DataSerializableFixedID {
     return (serverCqName + this.hashCode());
   }
 
+  void processRegisterCq(String serverCqName, ServerCQ ServerCQ, boolean addToCqMap) {
+    processRegisterCq(serverCqName, ServerCQ, addToCqMap, GemFireCacheImpl.getInstance());
+  }
+
+
   /**
    * adds a new CQ to this profile during a delta operation or deserialization
    *
@@ -824,32 +829,32 @@ public class FilterProfile implements DataSerializableFixedID {
    * @param ServerCQ the new query object
    * @param addToCqMap whether to add the query to this.cqs
    */
-  void processRegisterCq(String serverCqName, ServerCQ ServerCQ, boolean addToCqMap) {
+  void processRegisterCq(String serverCqName, ServerCQ ServerCQ, boolean addToCqMap,
+      GemFireCacheImpl cache) {
     ServerCQ cq = (ServerCQ) ServerCQ;
     try {
-      CqService cqService = GemFireCacheImpl.getInstance().getCqService();
+      CqService cqService = cache.getCqService();
       cqService.start();
       cq.setCqService(cqService);
       CqStateImpl cqState = (CqStateImpl) cq.getState();
       cq.setName(generateCqName(serverCqName));
       cq.registerCq(null, null, cqState.getState());
     } catch (Exception ex) {
-      // Change it to Info level.
-      if (logger.isDebugEnabled()) {
-        logger.debug("Error while initializing the CQs with FilterProfile for CQ {}, Error : {}",
-            serverCqName, ex.getMessage(), ex);
-      }
+      logger.info("Error while initializing the CQs with FilterProfile for CQ {}, Error : {}",
+          serverCqName, ex.getMessage(), ex);
+
     }
     if (logger.isDebugEnabled()) {
       logger.debug("Adding CQ to remote members FilterProfile using name: {}", serverCqName);
     }
-    if (addToCqMap) {
-      this.cqs.put(serverCqName, cq);
-    }
 
     // The region's FilterProfile is accessed through CQ reference as the
     // region is not set on the FilterProfile created for the peer nodes.
     if (cq.getCqBaseRegion() != null) {
+      if (addToCqMap) {
+        this.cqs.put(serverCqName, cq);
+      }
+
       FilterProfile pf = cq.getCqBaseRegion().getFilterProfile();
       if (pf != null) {
         pf.incCqCount();
diff --git a/geode-core/src/test/java/org/apache/geode/internal/cache/FilterProfileNullCqBaseRegionJUnitTest.java b/geode-core/src/test/java/org/apache/geode/internal/cache/FilterProfileNullCqBaseRegionJUnitTest.java
new file mode 100644
index 0000000..179cf0e
--- /dev/null
+++ b/geode-core/src/test/java/org/apache/geode/internal/cache/FilterProfileNullCqBaseRegionJUnitTest.java
@@ -0,0 +1,74 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more contributor license
+ * agreements. See the NOTICE file distributed with this work for additional information regarding
+ * copyright ownership. The ASF licenses this file to You under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the License. You may obtain a
+ * copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software distributed under the License
+ * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
+ * or implied. See the License for the specific language governing permissions and limitations under
+ * the License.
+ */
+package org.apache.geode.internal.cache;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.fail;
+import static org.mockito.ArgumentMatchers.anyInt;
+import static org.mockito.ArgumentMatchers.eq;
+import static org.mockito.Mockito.doNothing;
+import static org.mockito.Mockito.doThrow;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+
+import java.util.Collections;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.experimental.categories.Category;
+
+import org.apache.geode.cache.query.CqException;
+import org.apache.geode.cache.query.RegionNotFoundException;
+import org.apache.geode.cache.query.internal.CqStateImpl;
+import org.apache.geode.cache.query.internal.cq.CqService;
+import org.apache.geode.cache.query.internal.cq.ServerCQ;
+import org.apache.geode.test.junit.categories.UnitTest;
+
+@Category(UnitTest.class)
+public class FilterProfileNullCqBaseRegionJUnitTest {
+
+  private FilterProfile filterProfile;
+  private CqService mockCqService;
+  private GemFireCacheImpl mockCache;
+  private CqStateImpl cqState;
+  private ServerCQ serverCQ;
+
+  @Before
+  public void setUp() {
+    mockCache = mock(GemFireCacheImpl.class);
+    mockCqService = mock(CqService.class);
+    cqState = mock(CqStateImpl.class);
+    serverCQ = mock(ServerCQ.class);
+
+    when(mockCache.getCqService()).thenReturn(mockCqService);
+    doNothing().when(mockCqService).start();
+    when(mockCache.getCacheServers()).thenReturn(Collections.emptyList());
+    when(serverCQ.getState()).thenReturn(cqState);
+    when(serverCQ.getCqBaseRegion()).thenReturn(null);
+
+  }
+
+  @Test
+  public void whenCqBaseRegionIsNullThenTheCqShouldNotBeAddedToTheCqMap()
+      throws CqException, RegionNotFoundException {
+    doThrow(RegionNotFoundException.class).when(serverCQ).registerCq(eq(null), eq(null), anyInt());
+
+    filterProfile = new FilterProfile();
+    filterProfile.processRegisterCq("TestCq", serverCQ, true, mockCache);
+    assertEquals(0, filterProfile.getCqMap().size());
+    filterProfile.processCloseCq("TestCq");
+
+  }
+}

-- 
To stop receiving notification emails like this one, please contact
nnag@apache.org.