kirklund commented on a change in pull request #6869:
URL: https://github.com/apache/geode/pull/6869#discussion_r709379553



##########
File path: 
geode-core/src/test/java/org/apache/geode/internal/cache/tier/sockets/ClientUpdateMessageImplTest.java
##########
@@ -109,4 +135,96 @@ private ClientUpdateMessageImpl 
getTestClientUpdateMessage() {
     when(localRegion.getName()).thenReturn(regionName);
     return new ClientUpdateMessageImpl(EnumListenerEvent.AFTER_CREATE, null, 
null);
   }
+
+  @Test
+  public void addClientCqCanBeExecutedConcurrently() throws Exception {
+    ClientUpdateMessageImpl clientUpdateMessageImpl = new 
ClientUpdateMessageImpl();
+
+    int numOfEvents = 4;
+    int[] cqEvents = new int[numOfEvents];
+    String[] cqNames = new String[numOfEvents];
+    ClientProxyMembershipID[] clients = new 
ClientProxyMembershipID[numOfEvents];
+    prepareCqInfo(numOfEvents, cqEvents, cqNames, clients);
+
+    addClientCqConcurrently(clientUpdateMessageImpl, numOfEvents, cqEvents, 
cqNames, clients);
+
+    assertThat(clientUpdateMessageImpl.getClientCqs().size()).isEqualTo(2);
+    
assertThat(clientUpdateMessageImpl.getClientCqs().get(client1)).isInstanceOf(
+        ClientUpdateMessageImpl.CqNameToOpHashMap.class);
+    ClientUpdateMessageImpl.CqNameToOpHashMap client1Cqs =
+        (ClientUpdateMessageImpl.CqNameToOpHashMap) 
clientUpdateMessageImpl.getClientCqs()
+            .get(client1);
+    for (int i = 0; i < 3; i++) {
+      assertThat(client1Cqs.get("cqName" + i)).isEqualTo(i);
+    }
+
+    
assertThat(clientUpdateMessageImpl.getClientCqs().get(client2)).isInstanceOf(
+        ClientUpdateMessageImpl.CqNameToOpSingleEntry.class);
+    ClientUpdateMessageImpl.CqNameToOpSingleEntry client2Cqs =
+        (ClientUpdateMessageImpl.CqNameToOpSingleEntry) 
clientUpdateMessageImpl.getClientCqs()
+            .get(client2);
+    assertThat(client2Cqs.isEmpty()).isFalse();
+  }
+
+  private void prepareCqInfo(int numOfEvents, int[] cqEvents, String[] cqNames,
+      ClientProxyMembershipID[] clients) {
+    for (int i = 0; i < numOfEvents; i++) {
+      cqEvents[i] = i;
+      cqNames[i] = "cqName" + i;
+      if (i < 3) {
+        clients[i] = client1;
+      } else {
+        clients[i] = client2;
+      }
+    }
+  }
+
+  private void addClientCqConcurrently(ClientUpdateMessageImpl 
clientUpdateMessageImpl,
+      int numOfEvents, int[] cqEvents, String[] cqNames, 
ClientProxyMembershipID[] clients)
+      throws InterruptedException, java.util.concurrent.ExecutionException {
+    List<Future<Void>> futures = new ArrayList<>();
+    for (int i = 0; i < numOfEvents; i++) {
+      ClientProxyMembershipID client = clients[i];
+      String cqName = cqNames[i];
+      int cqEvent = cqEvents[i];
+      futures.add(executorService
+          .submit(() -> clientUpdateMessageImpl.addClientCq(client, cqName, 
cqEvent)));
+    }
+    for (Future<Void> future : futures) {
+      future.get();
+    }
+  }
+
+  @Test
+  public void addOrSetClientCqsCanSetIfCqsMapIsNull() {
+    ClientUpdateMessageImpl clientUpdateMessageImpl = new 
ClientUpdateMessageImpl();
+
+    clientUpdateMessageImpl.addOrSetClientCqs(client1, clientCqs);
+
+    assertThat(clientUpdateMessageImpl.getClientCqs()).isEqualTo(clientCqs);
+  }
+
+  @Test
+  public void addOrSetClientCqsCanAddCqsIfCqsMapNotNull() {
+    ClientUpdateMessageImpl clientUpdateMessageImpl = new 
ClientUpdateMessageImpl();
+    ClientProxyMembershipID clientProxyMembershipID = 
mock(ClientProxyMembershipID.class);
+    clientUpdateMessageImpl.addClientCq(clientProxyMembershipID, "cqName", 10);
+
+    clientUpdateMessageImpl.addOrSetClientCqs(client1, clientCqs);
+
+    assertThat(clientUpdateMessageImpl.getClientCqs().size()).isEqualTo(2);

Review comment:
       `ClientUpdateMessageImpl.getClientCqs()` returns a map, so it would be 
better to use the `Map` assertions everywhere instead of `int` or `boolean` 
assertions:
   ```
   assertThat(clientUpdateMessageImpl.getClientCqs()).hasSize(2);
   ```

##########
File path: 
geode-cq/src/distributedTest/java/org/apache/geode/cache/query/cq/dunit/CqDUnitTest.java
##########
@@ -0,0 +1,228 @@
+/*
+ * 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.dunit;
+
+import static junit.framework.TestCase.assertEquals;

Review comment:
       You should use AssertJ instead. Also, this is the really old JUnit 
package structure. The newer packaging is `org.junit.**`. Just convert to using 
`assertThat`:
   ```
   import static org.assertj.core.api.Assertions.assertThat;
   ```
   There's even an IntelliJ plugin called Assertions2Assertj. It's not perfect 
so you'll want to review the results of what it changes. But it's helpful on 
big tests.




-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


Reply via email to