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

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

jinmeiliao commented on a change in pull request #5677:
URL: https://github.com/apache/geode/pull/5677#discussion_r513832133



##########
File path: 
geode-cq/src/distributedTest/java/org/apache/geode/internal/cache/PartitionRegionClearMessageQueueDUnitTest.java
##########
@@ -0,0 +1,165 @@
+/*
+ * 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.apache.geode.test.dunit.rules.ClusterStartupRule.getCache;
+import static org.assertj.core.api.Assertions.assertThat;
+
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.List;
+import java.util.concurrent.atomic.AtomicBoolean;
+
+import org.junit.BeforeClass;
+import org.junit.ClassRule;
+import org.junit.Test;
+
+import org.apache.geode.cache.Operation;
+import org.apache.geode.cache.Region;
+import org.apache.geode.cache.RegionShortcut;
+import org.apache.geode.cache.client.ClientRegionShortcut;
+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.CqQuery;
+import org.apache.geode.cache.query.QueryService;
+import org.apache.geode.internal.cache.tier.sockets.CacheClientNotifier;
+import org.apache.geode.internal.cache.tier.sockets.CacheClientProxy;
+import org.apache.geode.test.dunit.rules.ClusterStartupRule;
+import org.apache.geode.test.dunit.rules.MemberVM;
+import org.apache.geode.test.junit.rules.ClientCacheRule;
+
+public class PartitionRegionClearMessageQueueDUnitTest {
+  public static final String NAME = "testRegion";
+  protected static MemberVM locator;
+  protected static MemberVM server1, server2, server3, accessor;
+  protected static List<MemberVM> servers;
+
+  @ClassRule
+  public static ClusterStartupRule cluster = new ClusterStartupRule(5);
+
+  @ClassRule
+  public static ClientCacheRule client = new ClientCacheRule();
+
+  @BeforeClass
+  public static void setUp() throws Exception {
+    locator = cluster.startLocatorVM(0);
+    int locatorPort = locator.getPort();
+    server1 = cluster.startServerVM(1,
+        s -> 
s.withConnectionToLocator(locatorPort).withRegion(RegionShortcut.PARTITION, 
NAME));
+    server2 = cluster.startServerVM(2,
+        s -> 
s.withConnectionToLocator(locatorPort).withRegion(RegionShortcut.PARTITION, 
NAME));
+    server3 = cluster.startServerVM(3,
+        s -> 
s.withConnectionToLocator(locatorPort).withRegion(RegionShortcut.PARTITION, 
NAME));
+    accessor = cluster.startServerVM(4, s -> 
s.withConnectionToLocator(locatorPort)
+        .withRegion(RegionShortcut.PARTITION_PROXY, NAME));
+
+    servers = Arrays.asList(server1, server2, server3, accessor);
+
+    
client.withLocatorConnection(locatorPort).withPoolSubscription(true).createCache();
+    client.getCache()
+        .createClientRegionFactory(ClientRegionShortcut.CACHING_PROXY)
+        .create(NAME);
+  }
+
+  @Test
+  public void clearMessageSentToClientWithRegisteredInterest() throws 
Exception {
+    Region<Object, Object> testRegion = client.getCache().getRegion(NAME);
+
+    assertThat(testRegion).isEmpty();
+    server1.invoke(() -> addRecord(10));
+    // verify that before register for interest, client region has no data
+    assertThat(testRegion).hasSize(0);
+
+    // verify that after register for interest, client region has data now.
+    testRegion.registerInterestForAllKeys();
+    assertThat(testRegion).hasSize(10);
+
+    // do PR clear on a server that has no client proxy, hence no HARegionQueue
+    Boolean cleared = false;
+    for (int i = 0; i < servers.size(); i++) {
+      cleared = servers.get(i).invoke(
+          
PartitionRegionClearMessageQueueDUnitTest::clearRegionOnNoClientProxyMember);
+      if (cleared) {
+        break;
+      }
+    }
+
+    // verify that clear is called on a server
+    assertThat(cleared).isTrue();
+    // verify that the PR clear message is still delivered to the client
+    assertThat(testRegion).hasSize(0);
+  }
+
+  private static void addRecord(int size) {
+    Region<Object, Object> region = getTestRegion();
+    for (int i = 0; i < size; i++) {
+      region.put(i, "value" + i);
+    }
+  }
+
+  @Test
+  public void clearMessageSentToClientWithCQ() throws Exception {
+    QueryService queryService = 
client.getCache().getDefaultPool().getQueryService();
+    CqAttributesFactory cqaFactory = new CqAttributesFactory();
+    AtomicBoolean clearEventReceived = new AtomicBoolean(false);
+    cqaFactory.addCqListener(new CqListener() {
+      @Override
+      public void onEvent(CqEvent aCqEvent) {
+        Operation baseOperation = aCqEvent.getBaseOperation();
+        if (baseOperation.isClear()) {
+          clearEventReceived.set(true);
+        }
+      }
+
+      @Override
+      public void onError(CqEvent aCqEvent) {}
+    });
+
+    CqQuery cqQuery =
+        queryService.newCq("select * from /" + NAME, cqaFactory.create());
+    cqQuery.execute();
+
+    server1.invoke(() -> addRecord(10));
+
+    Boolean cleared = false;
+    for (int i = 0; i < servers.size(); i++) {
+      cleared = servers.get(i).invoke(
+          
PartitionRegionClearMessageQueueDUnitTest::clearRegionOnNoClientProxyMember);
+      if (cleared) {
+        break;
+      }
+    }
+
+    // verify that clear is called on a server
+    assertThat(cleared).isTrue();
+    // verify that the PR clear message is still delivered to the client
+    assertThat(clearEventReceived.get()).isTrue();
+  }
+
+  private static boolean clearRegionOnNoClientProxyMember() {
+    Collection<CacheClientProxy> clientProxies =
+        CacheClientNotifier.getInstance().getClientProxies();
+    if (clientProxies.isEmpty()) {

Review comment:
       the story is to verify that clear message is sent on the region level, 
i.e. even if the clear is done on a member that has no message dispatcher, the 
message should still be sent to the client. if a server has no `clientProxy` 
then it definitely won't have the `messageDispatcher`.




----------------------------------------------------------------
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


> PR.clear notify client should let the queue holder member to notify
> -------------------------------------------------------------------
>
>                 Key: GEODE-7858
>                 URL: https://issues.apache.org/jira/browse/GEODE-7858
>             Project: Geode
>          Issue Type: Improvement
>            Reporter: Xiaojian Zhou
>            Priority: Major
>              Labels: GeodeCommons, pull-request-available
>
> PR.clear needs to notify client at PR level, but the coordinator member maybe 
> not the HARegionQueue holder. Need to find and let the queue holder member to 
> notify. 



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

Reply via email to