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 2021/09/14 22:48:39 UTC
[GitHub] [geode] pivotal-eshu opened a new pull request #6869: GEODE-9596: Avoid creating multiple cq maps in ClientUpdateMessage
pivotal-eshu opened a new pull request #6869:
URL: https://github.com/apache/geode/pull/6869
* This can occur if HAContainer enables eviction.
* Also addClientCq can be accessed concurrently by intialization threads during queue registration.
<!-- Thank you for submitting a contribution to Apache Geode. -->
<!-- In order to streamline the review of the contribution we ask you
to ensure the following steps have been taken:
-->
### For all changes:
- [ ] Is there a JIRA ticket associated with this PR? Is it referenced in the commit message?
- [ ] Has your PR been rebased against the latest commit within the target branch (typically `develop`)?
- [ ] Is your initial contribution a single, squashed commit?
- [ ] Does `gradlew build` run cleanly?
- [ ] Have you written or updated unit tests to verify your changes?
- [ ] If adding new dependencies to the code, are these dependencies licensed in a way that is compatible for inclusion under [ASF 2.0](http://www.apache.org/legal/resolved.html#category-a)?
<!-- Note:
Please ensure that once the PR is submitted, check Concourse for build issues and
submit an update to your PR as soon as possible. If you need help, please send an
email to dev@geode.apache.org.
-->
--
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
[GitHub] [geode] kirklund commented on a change in pull request #6869: GEODE-9596: Avoid creating multiple cq maps in ClientUpdateMessage
Posted by GitBox <gi...@apache.org>.
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: notifications-unsubscribe@geode.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [geode] pivotal-eshu merged pull request #6869: GEODE-9596: Avoid creating multiple cq maps in ClientUpdateMessage
Posted by GitBox <gi...@apache.org>.
pivotal-eshu merged pull request #6869:
URL: https://github.com/apache/geode/pull/6869
--
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