[ 
https://issues.apache.org/jira/browse/GEODE-8293?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17225409#comment-17225409
 ] 

ASF GitHub Bot commented on GEODE-8293:
---------------------------------------

kohlmu-pivotal commented on a change in pull request #5620:
URL: https://github.com/apache/geode/pull/5620#discussion_r516386386



##########
File path: 
geode-cq/src/distributedTest/java/org/apache/geode/cache/query/cq/CQMetricsDUnitTest.java
##########
@@ -0,0 +1,169 @@
+/*
+ * 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.cache.query.cq;
+
+import static org.apache.geode.test.awaitility.GeodeAwaitility.await;
+import static org.apache.geode.test.dunit.rules.ClusterStartupRule.getCache;
+import static org.assertj.core.api.Assertions.assertThat;
+
+import java.io.Serializable;
+
+import org.junit.Before;
+import org.junit.Rule;
+import org.junit.Test;
+
+import org.apache.geode.cache.Cache;
+import org.apache.geode.cache.Region;
+import org.apache.geode.cache.client.ClientCache;
+import org.apache.geode.cache.client.ClientCacheFactory;
+import org.apache.geode.cache.client.ClientRegionShortcut;
+import org.apache.geode.cache.query.CqAttributes;
+import org.apache.geode.cache.query.CqAttributesFactory;
+import org.apache.geode.cache.query.CqEvent;
+import org.apache.geode.cache.query.CqListener;
+import org.apache.geode.cache.query.CqServiceStatistics;
+import org.apache.geode.cache.query.QueryService;
+import org.apache.geode.cache.query.data.Portfolio;
+import org.apache.geode.management.DistributedSystemMXBean;
+import org.apache.geode.management.ManagementService;
+import org.apache.geode.test.dunit.rules.ClusterStartupRule;
+import org.apache.geode.test.dunit.rules.MemberVM;
+import org.apache.geode.test.junit.rules.GfshCommandRule;
+
+public class CQMetricsDUnitTest {
+
+  private CqAttributes cqa;
+  private QueryService qs;
+  private TestCqListener testListener;
+  private MemberVM locator, server1, server2;
+
+  @Rule
+  public ClusterStartupRule cluster = new ClusterStartupRule(5);
+
+  @Rule
+  public GfshCommandRule gfsh = new GfshCommandRule();
+
+  @Before
+  public void setUpServers() throws Exception {
+    locator = cluster.startLocatorVM(0, l -> 
l.withoutClusterConfigurationService());
+    server1 = cluster.startServerVM(1, locator.getPort());
+    server2 = cluster.startServerVM(2, locator.getPort());
+
+    ClientCache clientCache = createClientCache(locator.getPort());
+    Region region =
+        
clientCache.createClientRegionFactory(ClientRegionShortcut.CACHING_PROXY).create("region");
+
+    qs = clientCache.getQueryService();
+    CqAttributesFactory cqaf = new CqAttributesFactory();
+    testListener = new TestCqListener();
+    cqaf.addCqListener(testListener);
+
+    cqa = cqaf.create();
+    gfsh.connectAndVerify(locator);
+  }
+
+  @Test
+  public void testStopCq() throws Exception {
+    gfsh.executeAndAssertThat("create region --name=region --type=PARTITION")
+        .statusIsSuccess();
+    qs.newCq("Select * from /region r where r.ID = 1", cqa).execute();
+
+    server1.invoke(() -> populateRegion(0, 100));
+
+    locator.invoke(() -> {
+      Cache cache = getCache();
+      ManagementService service = 
ManagementService.getManagementService(cache);
+      DistributedSystemMXBean dsmbean = service.getDistributedSystemMXBean();
+      await().untilAsserted(() -> 
assertThat(dsmbean.getActiveCQCount()).isEqualTo(2));
+    });
+
+    // stop cq
+    qs.stopCqs();
+
+    locator.invoke(() -> {
+      Cache cache = getCache();
+      ManagementService service = 
ManagementService.getManagementService(cache);
+      DistributedSystemMXBean dsmbean = service.getDistributedSystemMXBean();
+      await().untilAsserted(() -> 
assertThat(dsmbean.getActiveCQCount()).isEqualTo(0));
+    });
+
+    checkActiveCqCount(server1, 0);
+    checkActiveCqCount(server2, 0);
+  }
+
+  @Test
+  public void testCloseCq() throws Exception {
+    gfsh.executeAndAssertThat("create region --name=region --type=PARTITION")
+        .statusIsSuccess();
+    qs.newCq("Select * from /region r where r.ID = 1", cqa).execute();
+
+    server1.invoke(() -> populateRegion(0, 100));
+
+    locator.invoke(() -> {
+      Cache cache = getCache();
+      ManagementService service = 
ManagementService.getManagementService(cache);
+      DistributedSystemMXBean dsmbean = service.getDistributedSystemMXBean();
+      await().untilAsserted(() -> 
assertThat(dsmbean.getActiveCQCount()).isEqualTo(2));
+    });
+
+    // close cq
+    qs.closeCqs();
+
+    locator.invoke(() -> {
+      Cache cache = getCache();
+      ManagementService service = 
ManagementService.getManagementService(cache);
+      DistributedSystemMXBean dsmbean = service.getDistributedSystemMXBean();
+      await().untilAsserted(() -> 
assertThat(dsmbean.getActiveCQCount()).isEqualTo(0));

Review comment:
       Please provide a timeout. I tested it with `timeout(30, 
TimeUnit.SECONDS)`. This way, this test will terminate in a "reasonable" time.

##########
File path: 
geode-cq/src/distributedTest/java/org/apache/geode/cache/query/cq/CQMetricsDUnitTest.java
##########
@@ -0,0 +1,169 @@
+/*
+ * 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.cache.query.cq;
+
+import static org.apache.geode.test.awaitility.GeodeAwaitility.await;
+import static org.apache.geode.test.dunit.rules.ClusterStartupRule.getCache;
+import static org.assertj.core.api.Assertions.assertThat;
+
+import java.io.Serializable;
+
+import org.junit.Before;
+import org.junit.Rule;
+import org.junit.Test;
+
+import org.apache.geode.cache.Cache;
+import org.apache.geode.cache.Region;
+import org.apache.geode.cache.client.ClientCache;
+import org.apache.geode.cache.client.ClientCacheFactory;
+import org.apache.geode.cache.client.ClientRegionShortcut;
+import org.apache.geode.cache.query.CqAttributes;
+import org.apache.geode.cache.query.CqAttributesFactory;
+import org.apache.geode.cache.query.CqEvent;
+import org.apache.geode.cache.query.CqListener;
+import org.apache.geode.cache.query.CqServiceStatistics;
+import org.apache.geode.cache.query.QueryService;
+import org.apache.geode.cache.query.data.Portfolio;
+import org.apache.geode.management.DistributedSystemMXBean;
+import org.apache.geode.management.ManagementService;
+import org.apache.geode.test.dunit.rules.ClusterStartupRule;
+import org.apache.geode.test.dunit.rules.MemberVM;
+import org.apache.geode.test.junit.rules.GfshCommandRule;
+
+public class CQMetricsDUnitTest {
+
+  private CqAttributes cqa;
+  private QueryService qs;
+  private TestCqListener testListener;
+  private MemberVM locator, server1, server2;
+
+  @Rule
+  public ClusterStartupRule cluster = new ClusterStartupRule(5);
+
+  @Rule
+  public GfshCommandRule gfsh = new GfshCommandRule();
+
+  @Before
+  public void setUpServers() throws Exception {
+    locator = cluster.startLocatorVM(0, l -> 
l.withoutClusterConfigurationService());
+    server1 = cluster.startServerVM(1, locator.getPort());
+    server2 = cluster.startServerVM(2, locator.getPort());
+
+    ClientCache clientCache = createClientCache(locator.getPort());
+    Region region =
+        
clientCache.createClientRegionFactory(ClientRegionShortcut.CACHING_PROXY).create("region");
+
+    qs = clientCache.getQueryService();
+    CqAttributesFactory cqaf = new CqAttributesFactory();
+    testListener = new TestCqListener();
+    cqaf.addCqListener(testListener);
+
+    cqa = cqaf.create();
+    gfsh.connectAndVerify(locator);
+  }
+
+  @Test
+  public void testStopCq() throws Exception {
+    gfsh.executeAndAssertThat("create region --name=region --type=PARTITION")
+        .statusIsSuccess();
+    qs.newCq("Select * from /region r where r.ID = 1", cqa).execute();
+
+    server1.invoke(() -> populateRegion(0, 100));
+
+    locator.invoke(() -> {
+      Cache cache = getCache();
+      ManagementService service = 
ManagementService.getManagementService(cache);
+      DistributedSystemMXBean dsmbean = service.getDistributedSystemMXBean();
+      await().untilAsserted(() -> 
assertThat(dsmbean.getActiveCQCount()).isEqualTo(2));
+    });
+
+    // stop cq
+    qs.stopCqs();
+
+    locator.invoke(() -> {
+      Cache cache = getCache();
+      ManagementService service = 
ManagementService.getManagementService(cache);
+      DistributedSystemMXBean dsmbean = service.getDistributedSystemMXBean();
+      await().untilAsserted(() -> 
assertThat(dsmbean.getActiveCQCount()).isEqualTo(0));
+    });
+
+    checkActiveCqCount(server1, 0);
+    checkActiveCqCount(server2, 0);
+  }
+
+  @Test
+  public void testCloseCq() throws Exception {
+    gfsh.executeAndAssertThat("create region --name=region --type=PARTITION")
+        .statusIsSuccess();
+    qs.newCq("Select * from /region r where r.ID = 1", cqa).execute();
+
+    server1.invoke(() -> populateRegion(0, 100));
+
+    locator.invoke(() -> {
+      Cache cache = getCache();
+      ManagementService service = 
ManagementService.getManagementService(cache);
+      DistributedSystemMXBean dsmbean = service.getDistributedSystemMXBean();
+      await().untilAsserted(() -> 
assertThat(dsmbean.getActiveCQCount()).isEqualTo(2));

Review comment:
       Please provide a timeout. I tested it with `timeout(30, 
TimeUnit.SECONDS)`. This way, this test will terminate in a "reasonable" time.

##########
File path: 
geode-cq/src/distributedTest/java/org/apache/geode/cache/query/cq/CQMetricsDUnitTest.java
##########
@@ -0,0 +1,169 @@
+/*
+ * 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.cache.query.cq;
+
+import static org.apache.geode.test.awaitility.GeodeAwaitility.await;
+import static org.apache.geode.test.dunit.rules.ClusterStartupRule.getCache;
+import static org.assertj.core.api.Assertions.assertThat;
+
+import java.io.Serializable;
+
+import org.junit.Before;
+import org.junit.Rule;
+import org.junit.Test;
+
+import org.apache.geode.cache.Cache;
+import org.apache.geode.cache.Region;
+import org.apache.geode.cache.client.ClientCache;
+import org.apache.geode.cache.client.ClientCacheFactory;
+import org.apache.geode.cache.client.ClientRegionShortcut;
+import org.apache.geode.cache.query.CqAttributes;
+import org.apache.geode.cache.query.CqAttributesFactory;
+import org.apache.geode.cache.query.CqEvent;
+import org.apache.geode.cache.query.CqListener;
+import org.apache.geode.cache.query.CqServiceStatistics;
+import org.apache.geode.cache.query.QueryService;
+import org.apache.geode.cache.query.data.Portfolio;
+import org.apache.geode.management.DistributedSystemMXBean;
+import org.apache.geode.management.ManagementService;
+import org.apache.geode.test.dunit.rules.ClusterStartupRule;
+import org.apache.geode.test.dunit.rules.MemberVM;
+import org.apache.geode.test.junit.rules.GfshCommandRule;
+
+public class CQMetricsDUnitTest {
+
+  private CqAttributes cqa;
+  private QueryService qs;
+  private TestCqListener testListener;
+  private MemberVM locator, server1, server2;
+
+  @Rule
+  public ClusterStartupRule cluster = new ClusterStartupRule(5);
+
+  @Rule
+  public GfshCommandRule gfsh = new GfshCommandRule();
+
+  @Before
+  public void setUpServers() throws Exception {
+    locator = cluster.startLocatorVM(0, l -> 
l.withoutClusterConfigurationService());
+    server1 = cluster.startServerVM(1, locator.getPort());
+    server2 = cluster.startServerVM(2, locator.getPort());
+
+    ClientCache clientCache = createClientCache(locator.getPort());
+    Region region =
+        
clientCache.createClientRegionFactory(ClientRegionShortcut.CACHING_PROXY).create("region");
+
+    qs = clientCache.getQueryService();
+    CqAttributesFactory cqaf = new CqAttributesFactory();
+    testListener = new TestCqListener();
+    cqaf.addCqListener(testListener);
+
+    cqa = cqaf.create();
+    gfsh.connectAndVerify(locator);
+  }
+
+  @Test
+  public void testStopCq() throws Exception {
+    gfsh.executeAndAssertThat("create region --name=region --type=PARTITION")
+        .statusIsSuccess();
+    qs.newCq("Select * from /region r where r.ID = 1", cqa).execute();
+
+    server1.invoke(() -> populateRegion(0, 100));
+
+    locator.invoke(() -> {
+      Cache cache = getCache();
+      ManagementService service = 
ManagementService.getManagementService(cache);
+      DistributedSystemMXBean dsmbean = service.getDistributedSystemMXBean();
+      await().untilAsserted(() -> 
assertThat(dsmbean.getActiveCQCount()).isEqualTo(2));
+    });
+
+    // stop cq
+    qs.stopCqs();
+
+    locator.invoke(() -> {
+      Cache cache = getCache();
+      ManagementService service = 
ManagementService.getManagementService(cache);
+      DistributedSystemMXBean dsmbean = service.getDistributedSystemMXBean();
+      await().untilAsserted(() -> 
assertThat(dsmbean.getActiveCQCount()).isEqualTo(0));
+    });
+
+    checkActiveCqCount(server1, 0);
+    checkActiveCqCount(server2, 0);
+  }
+
+  @Test
+  public void testCloseCq() throws Exception {
+    gfsh.executeAndAssertThat("create region --name=region --type=PARTITION")
+        .statusIsSuccess();
+    qs.newCq("Select * from /region r where r.ID = 1", cqa).execute();
+
+    server1.invoke(() -> populateRegion(0, 100));
+
+    locator.invoke(() -> {
+      Cache cache = getCache();
+      ManagementService service = 
ManagementService.getManagementService(cache);
+      DistributedSystemMXBean dsmbean = service.getDistributedSystemMXBean();
+      await().untilAsserted(() -> 
assertThat(dsmbean.getActiveCQCount()).isEqualTo(2));
+    });
+
+    // close cq
+    qs.closeCqs();
+
+    locator.invoke(() -> {
+      Cache cache = getCache();
+      ManagementService service = 
ManagementService.getManagementService(cache);
+      DistributedSystemMXBean dsmbean = service.getDistributedSystemMXBean();
+      await().untilAsserted(() -> 
assertThat(dsmbean.getActiveCQCount()).isEqualTo(0));
+    });
+  }
+
+  private class TestCqListener implements CqListener, Serializable {
+    public int onEventCalls = 0;
+
+    @Override
+    public void onEvent(CqEvent aCqEvent) {
+      onEventCalls++;
+    }
+
+    @Override
+    public void onError(CqEvent aCqEvent) {}
+
+    @Override
+    public void close() {}
+  }
+
+  private static void populateRegion(int startingId, int endingId) {
+    Region exampleRegion = getCache().getRegion("region");
+    for (int i = startingId; i < endingId; i++) {
+      exampleRegion.put("" + i, new Portfolio(i));
+    }
+  }
+
+  private ClientCache createClientCache(Integer locator1Port) {
+    ClientCacheFactory ccf = new ClientCacheFactory();
+    ccf.addPoolLocator("localhost", locator1Port);
+    ccf.setPoolSubscriptionEnabled(true);
+    return ccf.create();
+  }
+
+  private void checkActiveCqCount(MemberVM vm, int expectedResult) {
+    vm.invoke(() -> {
+      QueryService queryService = getCache().getQueryService();
+      CqServiceStatistics cqServiceStats = queryService.getCqStatistics();
+      await()

Review comment:
       Please provide a timeout. I tested it with `timeout(30, 
TimeUnit.SECONDS)`. This way, this test will terminate in a "reasonable" time.

##########
File path: 
geode-cq/src/distributedTest/java/org/apache/geode/cache/query/cq/CQMetricsDUnitTest.java
##########
@@ -0,0 +1,169 @@
+/*
+ * 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.cache.query.cq;
+
+import static org.apache.geode.test.awaitility.GeodeAwaitility.await;
+import static org.apache.geode.test.dunit.rules.ClusterStartupRule.getCache;
+import static org.assertj.core.api.Assertions.assertThat;
+
+import java.io.Serializable;
+
+import org.junit.Before;
+import org.junit.Rule;
+import org.junit.Test;
+
+import org.apache.geode.cache.Cache;
+import org.apache.geode.cache.Region;
+import org.apache.geode.cache.client.ClientCache;
+import org.apache.geode.cache.client.ClientCacheFactory;
+import org.apache.geode.cache.client.ClientRegionShortcut;
+import org.apache.geode.cache.query.CqAttributes;
+import org.apache.geode.cache.query.CqAttributesFactory;
+import org.apache.geode.cache.query.CqEvent;
+import org.apache.geode.cache.query.CqListener;
+import org.apache.geode.cache.query.CqServiceStatistics;
+import org.apache.geode.cache.query.QueryService;
+import org.apache.geode.cache.query.data.Portfolio;
+import org.apache.geode.management.DistributedSystemMXBean;
+import org.apache.geode.management.ManagementService;
+import org.apache.geode.test.dunit.rules.ClusterStartupRule;
+import org.apache.geode.test.dunit.rules.MemberVM;
+import org.apache.geode.test.junit.rules.GfshCommandRule;
+
+public class CQMetricsDUnitTest {
+
+  private CqAttributes cqa;
+  private QueryService qs;
+  private TestCqListener testListener;
+  private MemberVM locator, server1, server2;
+
+  @Rule
+  public ClusterStartupRule cluster = new ClusterStartupRule(5);
+
+  @Rule
+  public GfshCommandRule gfsh = new GfshCommandRule();
+
+  @Before
+  public void setUpServers() throws Exception {
+    locator = cluster.startLocatorVM(0, l -> 
l.withoutClusterConfigurationService());
+    server1 = cluster.startServerVM(1, locator.getPort());
+    server2 = cluster.startServerVM(2, locator.getPort());
+
+    ClientCache clientCache = createClientCache(locator.getPort());
+    Region region =
+        
clientCache.createClientRegionFactory(ClientRegionShortcut.CACHING_PROXY).create("region");
+
+    qs = clientCache.getQueryService();
+    CqAttributesFactory cqaf = new CqAttributesFactory();
+    testListener = new TestCqListener();
+    cqaf.addCqListener(testListener);
+
+    cqa = cqaf.create();
+    gfsh.connectAndVerify(locator);
+  }
+
+  @Test
+  public void testStopCq() throws Exception {
+    gfsh.executeAndAssertThat("create region --name=region --type=PARTITION")
+        .statusIsSuccess();
+    qs.newCq("Select * from /region r where r.ID = 1", cqa).execute();
+
+    server1.invoke(() -> populateRegion(0, 100));
+
+    locator.invoke(() -> {
+      Cache cache = getCache();
+      ManagementService service = 
ManagementService.getManagementService(cache);
+      DistributedSystemMXBean dsmbean = service.getDistributedSystemMXBean();
+      await().untilAsserted(() -> 
assertThat(dsmbean.getActiveCQCount()).isEqualTo(2));
+    });
+
+    // stop cq
+    qs.stopCqs();
+
+    locator.invoke(() -> {
+      Cache cache = getCache();
+      ManagementService service = 
ManagementService.getManagementService(cache);
+      DistributedSystemMXBean dsmbean = service.getDistributedSystemMXBean();
+      await().untilAsserted(() -> 
assertThat(dsmbean.getActiveCQCount()).isEqualTo(0));

Review comment:
       Please provide a timeout. I tested it with `timeout(30, 
TimeUnit.SECONDS)`. This way, this test will terminate in a "reasonable" time.

##########
File path: 
geode-cq/src/distributedTest/java/org/apache/geode/cache/query/cq/CQMetricsDUnitTest.java
##########
@@ -0,0 +1,169 @@
+/*
+ * 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.cache.query.cq;
+
+import static org.apache.geode.test.awaitility.GeodeAwaitility.await;
+import static org.apache.geode.test.dunit.rules.ClusterStartupRule.getCache;
+import static org.assertj.core.api.Assertions.assertThat;
+
+import java.io.Serializable;
+
+import org.junit.Before;
+import org.junit.Rule;
+import org.junit.Test;
+
+import org.apache.geode.cache.Cache;
+import org.apache.geode.cache.Region;
+import org.apache.geode.cache.client.ClientCache;
+import org.apache.geode.cache.client.ClientCacheFactory;
+import org.apache.geode.cache.client.ClientRegionShortcut;
+import org.apache.geode.cache.query.CqAttributes;
+import org.apache.geode.cache.query.CqAttributesFactory;
+import org.apache.geode.cache.query.CqEvent;
+import org.apache.geode.cache.query.CqListener;
+import org.apache.geode.cache.query.CqServiceStatistics;
+import org.apache.geode.cache.query.QueryService;
+import org.apache.geode.cache.query.data.Portfolio;
+import org.apache.geode.management.DistributedSystemMXBean;
+import org.apache.geode.management.ManagementService;
+import org.apache.geode.test.dunit.rules.ClusterStartupRule;
+import org.apache.geode.test.dunit.rules.MemberVM;
+import org.apache.geode.test.junit.rules.GfshCommandRule;
+
+public class CQMetricsDUnitTest {
+
+  private CqAttributes cqa;
+  private QueryService qs;
+  private TestCqListener testListener;
+  private MemberVM locator, server1, server2;
+
+  @Rule
+  public ClusterStartupRule cluster = new ClusterStartupRule(5);
+
+  @Rule
+  public GfshCommandRule gfsh = new GfshCommandRule();
+
+  @Before
+  public void setUpServers() throws Exception {
+    locator = cluster.startLocatorVM(0, l -> 
l.withoutClusterConfigurationService());
+    server1 = cluster.startServerVM(1, locator.getPort());
+    server2 = cluster.startServerVM(2, locator.getPort());
+
+    ClientCache clientCache = createClientCache(locator.getPort());
+    Region region =
+        
clientCache.createClientRegionFactory(ClientRegionShortcut.CACHING_PROXY).create("region");
+
+    qs = clientCache.getQueryService();
+    CqAttributesFactory cqaf = new CqAttributesFactory();
+    testListener = new TestCqListener();
+    cqaf.addCqListener(testListener);
+
+    cqa = cqaf.create();
+    gfsh.connectAndVerify(locator);
+  }
+
+  @Test
+  public void testStopCq() throws Exception {
+    gfsh.executeAndAssertThat("create region --name=region --type=PARTITION")
+        .statusIsSuccess();
+    qs.newCq("Select * from /region r where r.ID = 1", cqa).execute();
+
+    server1.invoke(() -> populateRegion(0, 100));
+
+    locator.invoke(() -> {
+      Cache cache = getCache();
+      ManagementService service = 
ManagementService.getManagementService(cache);
+      DistributedSystemMXBean dsmbean = service.getDistributedSystemMXBean();
+      await().untilAsserted(() -> 
assertThat(dsmbean.getActiveCQCount()).isEqualTo(2));

Review comment:
       Please provide a timeout. I tested it with `timeout(30, 
TimeUnit.SECONDS)`. This way, this test will terminate in a "reasonable" time.

##########
File path: 
geode-cq/src/main/java/org/apache/geode/cache/query/cq/internal/ServerCQImpl.java
##########
@@ -203,7 +203,7 @@ public void registerCq(ClientProxyMembershipID 
p_clientProxyId, CacheClientNotif
     this.updateCqCreateStats();
 
     // Initialize the state of CQ.
-    if (this.cqState.getState() != p_cqState) {
+    if (this.cqState.getState() != p_cqState || ccn == null) {

Review comment:
       Please rename `ccn` to `cacheClientNotifier`... Just small changes to 
increase the code cleanliness.




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


> activeCQCount has negative value
> --------------------------------
>
>                 Key: GEODE-8293
>                 URL: https://issues.apache.org/jira/browse/GEODE-8293
>             Project: Geode
>          Issue Type: Bug
>          Components: statistics
>            Reporter: Mario Kevo
>            Assignee: Mario Kevo
>            Priority: Major
>              Labels: pull-request-available
>
> In case you have more than one server in the system and you close CQ there 
> will be negative value of active cqs.
> The problem is when you started more than one server and execute cq on it. In 
> that case we got incCqsActive on one server, but when it is closed we have 
> decCqsActive on both servers.
> {code:java}
> gfsh>show metrics --categories=query
> Cluster-wide MetricsCategory |      Metric      | Value
> -------- | ---------------- | -----
> query    | activeCQCount    | 1
>          | queryRequestRate | 0.0
> {code}
> After cq is closed or stopped:
> {code:java}
> gfsh>show metrics --categories=query
> Cluster-wide Metrics
> Category |      Metric      | Value
> -------- | ---------------- | -----
> query    | activeCQCount    | -1
>          | queryRequestRate | 0.0
> {code}



--
This message was sent by Atlassian Jira
(v8.3.4#803005)

Reply via email to