You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@geode.apache.org by GitBox <gi...@apache.org> on 2022/03/30 00:48:31 UTC

[GitHub] [geode] DonalEvans commented on a change in pull request #7442: GEODE-9704: Ensure that register interest is called before ready for events

DonalEvans commented on a change in pull request #7442:
URL: https://github.com/apache/geode/pull/7442#discussion_r837999289



##########
File path: geode-core/src/distributedTest/java/org/apache/geode/internal/cache/tier/sockets/DurableRegistrationDUnitTest.java
##########
@@ -345,6 +338,15 @@ public void run2() throws CacheException {
     durableClientVM
         .invoke(() -> DurableRegistrationDUnitTest.registerKey(K2, Boolean.FALSE));
 
+
+    // Step 9: Send clientReady message

Review comment:
       This comment and the one above it on line 330 are now out of order.

##########
File path: geode-core/src/distributedTest/java/org/apache/geode/internal/cache/tier/sockets/DurableRegistrationDUnitTest.java
##########
@@ -284,6 +278,14 @@ public void run2() throws CacheException {
     durableClientVM
         .invoke(() -> DurableRegistrationDUnitTest.registerKey(K4, Boolean.TRUE));
 
+    // Send clientReady message
+    durableClientVM.invoke(new CacheSerializableRunnable("Send clientReady") {
+      @Override
+      public void run2() throws CacheException {
+        CacheServerTestUtil.getCache().readyForEvents();
+      }
+    });

Review comment:
       While you're modifying this test, some warnings about deprecated methods and UUIDs can be avoided by changing this to:
   ```
       durableClientVM.invoke("Send clientReady",
           () -> CacheServerTestUtil.getCache().readyForEvents());
   ```

##########
File path: geode-core/src/integrationTest/java/org/apache/geode/cache/client/internal/QueueManagerJUnitTest.java
##########
@@ -294,6 +298,84 @@ public void testAddToConnectionListCallsCloseConnectionOpWithKeepAliveTrue2() {
     assertThat(connection.keepAlive).isTrue();
   }
 
+  @Test
+  public void recoverPrimaryRegistersBeforeSendingReady() {
+    Set<ServerLocation> excludedServers = new HashSet<>();
+    excludedServers.add(new ServerLocation("localhost", 1));
+    excludedServers.add(new ServerLocation("localhost", 2));
+    excludedServers.add(new ServerLocation("localhost", 3));
+    factory.addConnection(0, 0, 1);
+    factory.addConnection(0, 0, 2);
+    factory.addConnection(0, 0, 3);
+
+    LocalRegion testRegion = mock(LocalRegion.class);
+
+    InternalPool pool = new RecoveryDummyPool();
+    ServerRegionProxy serverRegionProxy = new ServerRegionProxy("region", pool);
+
+    when(testRegion.getServerProxy()).thenReturn(serverRegionProxy);
+    RegionAttributes regionAttributes = mock(RegionAttributes.class);
+    when(testRegion.getAttributes()).thenReturn(regionAttributes);
+    when(regionAttributes.getDataPolicy()).thenReturn(DataPolicy.DEFAULT);
+
+    createRegisterInterestTracker(pool, testRegion);
+
+    manager = new QueueManagerImpl(pool, endpoints, source, factory, 2,
+        20, logger, ClientProxyMembershipID.getNewProxyMembership(ds));
+    manager.start(background);
+    manager.setSendClientReady();
+    manager.clearQueueConnections();
+    factory.addConnection(0, 0, 4);
+    manager.recoverPrimary(excludedServers);
+
+    assertThat(opList.get(0)).isInstanceOf(RegisterInterestListOp.RegisterInterestListOpImpl.class);
+    assertThat(opList.get(1)).isInstanceOf(RegisterInterestListOp.RegisterInterestListOpImpl.class);
+    assertThat(opList.get(2)).isInstanceOf(RegisterInterestListOp.RegisterInterestListOpImpl.class);
+    assertThat(opList.get(3)).isInstanceOf(RegisterInterestListOp.RegisterInterestListOpImpl.class);
+    assertThat(opList.get(4)).isInstanceOf(ReadyForEventsOp.ReadyForEventsOpImpl.class);
+  }
+
+  private void createRegisterInterestTracker(InternalPool localPool,
+      LocalRegion localRegion) {
+    final RegisterInterestTracker registerInterestTracker = localPool.getRITracker();
+
+    final ConcurrentHashMap<String, RegisterInterestTracker.RegionInterestEntry> keysConcurrentMap =
+        new ConcurrentHashMap<>();
+    when(registerInterestTracker.getRegionToInterestsMap(eq(InterestType.KEY), anyBoolean(),
+        anyBoolean())).thenReturn(
+            keysConcurrentMap);
+    RegisterInterestTracker.RegionInterestEntry registerInterestEntry =
+        new RegisterInterestTracker.RegionInterestEntry(
+            localRegion);
+
+    registerInterestEntry.getInterests().put("bob", InterestResultPolicy.NONE);
+    keysConcurrentMap.put("testRegion", registerInterestEntry);
+
+    final ConcurrentHashMap<String, RegisterInterestTracker.RegionInterestEntry> regexConcurrentMap =
+        new ConcurrentHashMap<>();
+    when(registerInterestTracker.getRegionToInterestsMap(eq(InterestType.REGULAR_EXPRESSION),
+        anyBoolean(), anyBoolean())).thenReturn(
+            regexConcurrentMap);
+
+    final ConcurrentHashMap<String, RegisterInterestTracker.RegionInterestEntry> filterClassConcurrentMap =
+        new ConcurrentHashMap<>();
+    when(registerInterestTracker.getRegionToInterestsMap(eq(InterestType.FILTER_CLASS),
+        anyBoolean(), anyBoolean())).thenReturn(
+            filterClassConcurrentMap);
+
+    final ConcurrentHashMap<String, RegisterInterestTracker.RegionInterestEntry> cqConcurrentMap =
+        new ConcurrentHashMap<>();
+    when(registerInterestTracker.getRegionToInterestsMap(eq(InterestType.CQ), anyBoolean(),
+        anyBoolean())).thenReturn(
+            cqConcurrentMap);
+
+    final ConcurrentHashMap<String, RegisterInterestTracker.RegionInterestEntry> oqlQueryConcurrentMap =
+        new ConcurrentHashMap<>();
+    when(registerInterestTracker.getRegionToInterestsMap(eq(InterestType.OQL_QUERY), anyBoolean(),
+        anyBoolean())).thenReturn(
+            oqlQueryConcurrentMap);

Review comment:
       This can be simplified considerably to:
   ```
       for (InterestType interestType : InterestType.values()) {
         final ConcurrentHashMap<String, RegisterInterestTracker.RegionInterestEntry> concurrentMap =
             new ConcurrentHashMap<>();
         when(registerInterestTracker.getRegionToInterestsMap(eq(interestType), anyBoolean(),
             anyBoolean()))
             .thenReturn(concurrentMap);
         if (interestType.equals(InterestType.KEY))  {
           RegisterInterestTracker.RegionInterestEntry registerInterestEntry =
               new RegisterInterestTracker.RegionInterestEntry(localRegion);
   
           registerInterestEntry.getInterests().put("bob", InterestResultPolicy.NONE);
           concurrentMap.put("testRegion", registerInterestEntry);
         }
       }
   ```

##########
File path: geode-core/src/integrationTest/java/org/apache/geode/cache/client/internal/QueueManagerJUnitTest.java
##########
@@ -238,17 +245,14 @@ public void testWaitForPrimary() {
     manager.start(background);
     manager.getAllConnections().getPrimary().destroy();
 
-    Throwable thrown = catchThrowable(() -> {
-      manager.getAllConnections().getPrimary();
-    });
+    Throwable thrown = catchThrowable(() -> manager.getAllConnections().getPrimary());
     assertThat(thrown).isInstanceOf(NoSubscriptionServersAvailableException.class);

Review comment:
       This can be simplified to:
   ```
       assertThatThrownBy(() -> manager.getAllConnections().getPrimary())
           .isInstanceOf(NoSubscriptionServersAvailableException.class);
   ```

##########
File path: geode-core/src/test/java/org/apache/geode/internal/cache/LocalRegionUpdateTest.java
##########
@@ -0,0 +1,151 @@
+/*
+ * 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.internal.statistics.StatisticsClockFactory.disabledClock;
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.ArgumentMatchers.anyBoolean;
+import static org.mockito.ArgumentMatchers.anyLong;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.spy;
+import static org.mockito.Mockito.times;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+
+import java.util.function.Function;
+
+import org.junit.Before;
+import org.junit.Rule;
+import org.junit.Test;
+import org.mockito.junit.MockitoJUnit;
+import org.mockito.junit.MockitoRule;
+import org.mockito.quality.Strictness;
+
+import org.apache.geode.cache.AttributesFactory;
+import org.apache.geode.cache.DataPolicy;
+import org.apache.geode.cache.InterestPolicy;
+import org.apache.geode.cache.InterestResultPolicy;
+import org.apache.geode.cache.RegionAttributes;
+import org.apache.geode.cache.SubscriptionAttributes;
+import org.apache.geode.cache.client.internal.PoolImpl;
+import org.apache.geode.cache.client.internal.RegisterInterestTracker;
+import org.apache.geode.cache.client.internal.ServerRegionProxy;
+import org.apache.geode.distributed.internal.DSClock;
+import org.apache.geode.distributed.internal.InternalDistributedSystem;
+import org.apache.geode.internal.cache.tier.InterestType;
+
+public class LocalRegionUpdateTest {
+  private InternalDataView internalDataView;
+  private LocalRegion region;
+  private RegisterInterestTracker registerInterestTracker;
+
+  @Rule
+  public MockitoRule mockitoRule = MockitoJUnit.rule().strictness(Strictness.STRICT_STUBS);
+
+  @Before
+  public void setUp() {
+    internalDataView = mock(InternalDataView.class);
+
+    EntryEventFactory entryEventFactory = mock(EntryEventFactory.class);
+    InternalCache cache = mock(InternalCache.class);
+    InternalDistributedSystem internalDistributedSystem = mock(InternalDistributedSystem.class);
+    InternalRegionArguments internalRegionArguments = mock(InternalRegionArguments.class);
+
+    LocalRegion.RegionMapConstructor regionMapConstructor =
+        mock(LocalRegion.RegionMapConstructor.class);
+    Function<LocalRegion, RegionPerfStats> regionPerfStatsFactory = localRegion -> {
+      localRegion.getLocalSize();
+      return mock(RegionPerfStats.class);
+    };
+
+    final PoolImpl poolImpl = mock(PoolImpl.class);
+    SubscriptionAttributes subscriptionAttributes =
+        new SubscriptionAttributes(InterestPolicy.ALL);
+
+
+    when(cache.getInternalDistributedSystem()).thenReturn(internalDistributedSystem);
+    when(internalDistributedSystem.getClock()).thenReturn(mock(DSClock.class));
+
+    when(regionMapConstructor.create(any(), any(), any())).thenReturn(mock(RegionMap.class));
+
+
+    AttributesFactory<Object, Object> regionAttributesFactory = new AttributesFactory<>();
+    regionAttributesFactory.setDataPolicy(DataPolicy.NORMAL);
+    regionAttributesFactory.setPoolName("Pool1");
+    regionAttributesFactory.setConcurrencyChecksEnabled(false);
+    regionAttributesFactory.setSubscriptionAttributes(subscriptionAttributes);
+    RegionAttributes<Object, Object> regionAttributes =
+        regionAttributesFactory.createRegionAttributes();
+
+    registerInterestTracker = new RegisterInterestTracker();
+    when(poolImpl.getRITracker()).thenReturn(registerInterestTracker);
+
+    ServerRegionProxy serverRegionProxy = mock(ServerRegionProxy.class);
+    when(serverRegionProxy.getPool()).thenReturn(poolImpl);
+    LocalRegion.ServerRegionProxyConstructor proxyConstructor = region -> serverRegionProxy;
+
+    AbstractRegion.PoolFinder poolFinder = poolName -> poolImpl;
+
+    region = spy(new LocalRegion("region", regionAttributes, null, cache,
+        internalRegionArguments, internalDataView, regionMapConstructor, proxyConstructor,
+        entryEventFactory, poolFinder, regionPerfStatsFactory, disabledClock()));
+
+  }
+
+  /*
+   * As indicated by the name this code tests the basicBridgeClientUpdate method's
+   * fork where it checks to see if the interestResultPolicy is NONE, then it will
+   * call basicUpdate.
+   */
+  @Test
+  public void basicBridgeClientUpdateChecksInterestResultPolicyNoneThenUpdates() {
+    Object key = new Object();
+    Object value = new Object();
+
+    registerInterestTracker.addSingleInterest(region, key, InterestType.KEY,
+        InterestResultPolicy.NONE, true, false);
+
+    region.basicBridgeClientUpdate(null, key, value, new byte[] {'0'}, true,
+        null, true, false, new EntryEventImpl(),
+        new EventID(new byte[] {1}, 1, 1));
+
+    verify(internalDataView, times(1)).putEntry(any(), anyBoolean(),

Review comment:
       The `times(1)` here is not necessary, as that's the default behaviour of the `verify()` method with no second argument.

##########
File path: geode-core/src/distributedTest/java/org/apache/geode/internal/cache/tier/sockets/DurableRegistrationDUnitTest.java
##########
@@ -345,6 +338,15 @@ public void run2() throws CacheException {
     durableClientVM
         .invoke(() -> DurableRegistrationDUnitTest.registerKey(K2, Boolean.FALSE));
 
+
+    // Step 9: Send clientReady message
+    durableClientVM.invoke(new CacheSerializableRunnable("Send clientReady") {
+      @Override
+      public void run2() throws CacheException {
+        CacheServerTestUtil.getCache().readyForEvents();
+      }
+    });

Review comment:
       See above comment about changing this to have fewer warnings.

##########
File path: geode-core/src/test/java/org/apache/geode/internal/cache/LocalRegionUpdateTest.java
##########
@@ -0,0 +1,151 @@
+/*
+ * 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.internal.statistics.StatisticsClockFactory.disabledClock;
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.ArgumentMatchers.anyBoolean;
+import static org.mockito.ArgumentMatchers.anyLong;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.spy;
+import static org.mockito.Mockito.times;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+
+import java.util.function.Function;
+
+import org.junit.Before;
+import org.junit.Rule;
+import org.junit.Test;
+import org.mockito.junit.MockitoJUnit;
+import org.mockito.junit.MockitoRule;
+import org.mockito.quality.Strictness;
+
+import org.apache.geode.cache.AttributesFactory;
+import org.apache.geode.cache.DataPolicy;
+import org.apache.geode.cache.InterestPolicy;
+import org.apache.geode.cache.InterestResultPolicy;
+import org.apache.geode.cache.RegionAttributes;
+import org.apache.geode.cache.SubscriptionAttributes;
+import org.apache.geode.cache.client.internal.PoolImpl;
+import org.apache.geode.cache.client.internal.RegisterInterestTracker;
+import org.apache.geode.cache.client.internal.ServerRegionProxy;
+import org.apache.geode.distributed.internal.DSClock;
+import org.apache.geode.distributed.internal.InternalDistributedSystem;
+import org.apache.geode.internal.cache.tier.InterestType;
+
+public class LocalRegionUpdateTest {
+  private InternalDataView internalDataView;
+  private LocalRegion region;
+  private RegisterInterestTracker registerInterestTracker;
+
+  @Rule
+  public MockitoRule mockitoRule = MockitoJUnit.rule().strictness(Strictness.STRICT_STUBS);
+
+  @Before
+  public void setUp() {
+    internalDataView = mock(InternalDataView.class);
+
+    EntryEventFactory entryEventFactory = mock(EntryEventFactory.class);
+    InternalCache cache = mock(InternalCache.class);
+    InternalDistributedSystem internalDistributedSystem = mock(InternalDistributedSystem.class);
+    InternalRegionArguments internalRegionArguments = mock(InternalRegionArguments.class);
+
+    LocalRegion.RegionMapConstructor regionMapConstructor =
+        mock(LocalRegion.RegionMapConstructor.class);
+    Function<LocalRegion, RegionPerfStats> regionPerfStatsFactory = localRegion -> {
+      localRegion.getLocalSize();
+      return mock(RegionPerfStats.class);
+    };
+
+    final PoolImpl poolImpl = mock(PoolImpl.class);
+    SubscriptionAttributes subscriptionAttributes =
+        new SubscriptionAttributes(InterestPolicy.ALL);
+
+
+    when(cache.getInternalDistributedSystem()).thenReturn(internalDistributedSystem);
+    when(internalDistributedSystem.getClock()).thenReturn(mock(DSClock.class));
+
+    when(regionMapConstructor.create(any(), any(), any())).thenReturn(mock(RegionMap.class));
+
+
+    AttributesFactory<Object, Object> regionAttributesFactory = new AttributesFactory<>();
+    regionAttributesFactory.setDataPolicy(DataPolicy.NORMAL);
+    regionAttributesFactory.setPoolName("Pool1");
+    regionAttributesFactory.setConcurrencyChecksEnabled(false);
+    regionAttributesFactory.setSubscriptionAttributes(subscriptionAttributes);
+    RegionAttributes<Object, Object> regionAttributes =
+        regionAttributesFactory.createRegionAttributes();

Review comment:
       Use of deprecated methods here can be avoided by using:
   ```
       InternalRegionFactory<Object, Object> regionFactory = new InternalRegionFactory<>(cache);
       regionFactory.setDataPolicy(DataPolicy.NORMAL);
       regionFactory.setPoolName("Pool1");
       regionFactory.setConcurrencyChecksEnabled(false);
       regionFactory.setSubscriptionAttributes(subscriptionAttributes);
       RegionAttributes<Object, Object> regionAttributes =
           regionFactory.getCreateAttributes();
   ```

##########
File path: geode-core/src/main/java/org/apache/geode/cache/client/internal/QueueManagerImpl.java
##########
@@ -109,6 +111,11 @@
   private ScheduledExecutorService recoveryThread;
   private volatile boolean sentClientReady;
 
+  @VisibleForTesting
+  void clearQueueConnections() {

Review comment:
       Since this method is only ever called in a test, it should probably be annotated `@TestOnly`




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

To unsubscribe, e-mail: notifications-unsubscribe@geode.apache.org

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