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 2020/07/02 17:17:08 UTC

[GitHub] [geode] DonalEvans commented on a change in pull request #5333: GEODE-8323: Process QueueRemovalMessage after queue initialized.

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



##########
File path: geode-core/src/test/java/org/apache/geode/internal/cache/ha/QueueRemovalMessageTest.java
##########
@@ -0,0 +1,207 @@
+/*
+ * 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.ha;
+
+import static org.apache.geode.util.internal.UncheckedUtils.uncheckedCast;
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.ArgumentMatchers.eq;
+import static org.mockito.Mockito.doReturn;
+import static org.mockito.Mockito.doThrow;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.never;
+import static org.mockito.Mockito.spy;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+
+import java.util.Iterator;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.concurrent.RejectedExecutionException;
+
+import org.junit.Before;
+import org.junit.Test;
+
+import org.apache.geode.cache.CacheClosedException;
+import org.apache.geode.cache.EntryNotFoundException;
+import org.apache.geode.cache.RegionDestroyedException;
+import org.apache.geode.distributed.internal.ClusterDistributionManager;
+import org.apache.geode.internal.cache.EventID;
+import org.apache.geode.internal.cache.HARegion;
+import org.apache.geode.internal.cache.InternalCache;
+
+public class QueueRemovalMessageTest {
+  private QueueRemovalMessage queueRemovalMessage;
+  private List<Object> messagesList;
+
+  private final ClusterDistributionManager dm = mock(ClusterDistributionManager.class);
+  private final InternalCache cache = mock(InternalCache.class);
+  private final String regionName1 = "region1";
+  private final String regionName2 = "region2";
+  private final HARegion region1 = mock(HARegion.class);
+  private final HARegion region2 = mock(HARegion.class);
+  private final HARegionQueue regionQueue1 = mock(HARegionQueue.class);
+  private final HARegionQueue regionQueue2 = mock(HARegionQueue.class);
+  private final EventID eventID1 = mock(EventID.class);
+  private final EventID eventID2 = mock(EventID.class);
+  private final EventID eventID3 = mock(EventID.class);
+
+
+  @Before
+  public void setup() {
+    queueRemovalMessage = spy(new QueueRemovalMessage());
+    messagesList = new LinkedList<>();
+    queueRemovalMessage.setMessagesList(messagesList);
+
+    long maxWaitTimeForInitialization = 30000;
+    when(cache.getRegion(regionName1)).thenReturn(uncheckedCast(region1));
+    when(cache.getRegion(regionName2)).thenReturn(uncheckedCast(region2));
+    when(region1.getOwnerWithWait(maxWaitTimeForInitialization)).thenReturn(regionQueue1);
+    when(region2.getOwnerWithWait(maxWaitTimeForInitialization)).thenReturn(regionQueue2);
+    when(regionQueue1.isQueueInitialized()).thenReturn(true);
+    when(regionQueue2.isQueueInitialized()).thenReturn(true);
+  }
+
+  @Test
+  public void messageProcessInvokesProcessRegionQueues() {
+    when(dm.getCache()).thenReturn(cache);
+
+    queueRemovalMessage.process(dm);
+
+    verify(queueRemovalMessage).processRegionQueues(eq(cache), any(Iterator.class));
+  }
+
+  @Test
+  public void processRegionQueuesCanProcessEachRegionQueue() {
+    addToMessagesList();
+    Iterator iterator = messagesList.iterator();
+
+    queueRemovalMessage.processRegionQueues(cache, iterator);
+
+    verify(queueRemovalMessage).processRegionQueue(iterator, regionName1, 1, regionQueue1);
+    verify(queueRemovalMessage).processRegionQueue(iterator, regionName2, 2, regionQueue2);
+    verify(queueRemovalMessage).removeQueueEvent(regionName1, regionQueue1, eventID1);
+    verify(queueRemovalMessage).removeQueueEvent(regionName2, regionQueue2, eventID2);
+    verify(queueRemovalMessage).removeQueueEvent(regionName2, regionQueue2, eventID3);
+  }
+
+  private void addToMessagesList() {
+    messagesList.add(regionName1);
+    messagesList.add(1);
+    messagesList.add(eventID1);
+    messagesList.add(regionName2);
+    messagesList.add(2);
+    messagesList.add(eventID2);
+    messagesList.add(eventID3);
+  }
+
+  @Test
+  public void canProcessRegionQueuesWithoutHARegionInCache() {
+    addToMessagesList();
+    Iterator iterator = messagesList.iterator();
+    when(cache.getRegion(regionName1)).thenReturn(null);
+
+    queueRemovalMessage.processRegionQueues(cache, iterator);
+
+    verify(queueRemovalMessage).processRegionQueue(iterator, regionName1, 1, null);
+    verify(queueRemovalMessage).processRegionQueue(iterator, regionName2, 2, regionQueue2);
+    verify(queueRemovalMessage, never()).removeQueueEvent(regionName1, regionQueue1, eventID1);
+    verify(queueRemovalMessage).removeQueueEvent(regionName2, regionQueue2, eventID2);
+    verify(queueRemovalMessage).removeQueueEvent(regionName2, regionQueue2, eventID3);
+  }
+
+  @Test
+  public void canProcessRegionQueuesWithoutHARegionQueueIsNotInitialized() {

Review comment:
       Small typo here, I think this should be "canProcessRegionQueuesWhenHARegionQueueIsNotInitialized'

##########
File path: geode-core/src/test/java/org/apache/geode/internal/cache/HARegionTest.java
##########
@@ -0,0 +1,77 @@
+/*
+ * 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.assertj.core.api.Assertions.assertThat;
+import static org.mockito.Mockito.RETURNS_DEEP_STUBS;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+
+import java.util.Collections;
+import java.util.Set;
+
+import org.junit.Before;
+import org.junit.Test;
+
+import org.apache.geode.cache.EvictionAction;
+import org.apache.geode.cache.EvictionAlgorithm;
+import org.apache.geode.cache.EvictionAttributes;
+import org.apache.geode.cache.RegionAttributes;
+import org.apache.geode.internal.cache.ha.HARegionQueue;
+
+public class HARegionTest {
+  private HARegion region;
+
+  private final InternalCache cache = mock(InternalCache.class, RETURNS_DEEP_STUBS);
+  private final RegionAttributes attributes = mock(RegionAttributes.class, RETURNS_DEEP_STUBS);
+  private final EvictionAttributes evictionAttributes =
+      mock(EvictionAttributes.class, RETURNS_DEEP_STUBS);
+
+  @Before
+  public void setup() {
+    when(attributes.getEvictionAttributes()).thenReturn(evictionAttributes);
+    when(attributes.getLoadFactor()).thenReturn(0.75f);
+    when(attributes.getConcurrencyLevel()).thenReturn(16);
+    when(evictionAttributes.getAlgorithm()).thenReturn(EvictionAlgorithm.NONE);
+    when(evictionAttributes.getAction()).thenReturn(EvictionAction.NONE);
+    Set<String> asyncEventQueueIds = Collections.singleton("id");
+    when(attributes.getAsyncEventQueueIds()).thenReturn(asyncEventQueueIds);
+    region = new HARegion("HARegionTest_region", attributes, null, cache, disabledClock());
+  }
+
+  @Test
+  public void getOwnerWithWaitReturnsHARegionQueueIfInitializedWithWait() throws Exception {
+    long timeout = 1;
+    HARegionQueue queue = mock(HARegionQueue.class);
+    when(queue.isQueueInitializedWithWait(timeout)).thenReturn(true);
+
+    region.setOwner(queue);
+
+    assertThat(region.getOwnerWithWait(timeout)).isEqualTo(queue);
+  }
+
+  @Test
+  public void getOwnerWithWaitReturnsHARegionQueueIfNotInitializedWithWait() throws Exception {

Review comment:
       This test name is a little misleading. It might be better as "getOwnerWithWaitReturnsNullIfNotInitializedWithWait"

##########
File path: geode-core/src/test/java/org/apache/geode/internal/cache/ha/QueueRemovalMessageTest.java
##########
@@ -0,0 +1,207 @@
+/*
+ * 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.ha;
+
+import static org.apache.geode.util.internal.UncheckedUtils.uncheckedCast;
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.ArgumentMatchers.eq;
+import static org.mockito.Mockito.doReturn;
+import static org.mockito.Mockito.doThrow;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.never;
+import static org.mockito.Mockito.spy;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+
+import java.util.Iterator;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.concurrent.RejectedExecutionException;
+
+import org.junit.Before;
+import org.junit.Test;
+
+import org.apache.geode.cache.CacheClosedException;
+import org.apache.geode.cache.EntryNotFoundException;
+import org.apache.geode.cache.RegionDestroyedException;
+import org.apache.geode.distributed.internal.ClusterDistributionManager;
+import org.apache.geode.internal.cache.EventID;
+import org.apache.geode.internal.cache.HARegion;
+import org.apache.geode.internal.cache.InternalCache;
+
+public class QueueRemovalMessageTest {
+  private QueueRemovalMessage queueRemovalMessage;
+  private List<Object> messagesList;
+
+  private final ClusterDistributionManager dm = mock(ClusterDistributionManager.class);
+  private final InternalCache cache = mock(InternalCache.class);
+  private final String regionName1 = "region1";
+  private final String regionName2 = "region2";
+  private final HARegion region1 = mock(HARegion.class);
+  private final HARegion region2 = mock(HARegion.class);
+  private final HARegionQueue regionQueue1 = mock(HARegionQueue.class);
+  private final HARegionQueue regionQueue2 = mock(HARegionQueue.class);
+  private final EventID eventID1 = mock(EventID.class);
+  private final EventID eventID2 = mock(EventID.class);
+  private final EventID eventID3 = mock(EventID.class);
+
+
+  @Before
+  public void setup() {
+    queueRemovalMessage = spy(new QueueRemovalMessage());
+    messagesList = new LinkedList<>();
+    queueRemovalMessage.setMessagesList(messagesList);
+
+    long maxWaitTimeForInitialization = 30000;
+    when(cache.getRegion(regionName1)).thenReturn(uncheckedCast(region1));
+    when(cache.getRegion(regionName2)).thenReturn(uncheckedCast(region2));
+    when(region1.getOwnerWithWait(maxWaitTimeForInitialization)).thenReturn(regionQueue1);
+    when(region2.getOwnerWithWait(maxWaitTimeForInitialization)).thenReturn(regionQueue2);
+    when(regionQueue1.isQueueInitialized()).thenReturn(true);
+    when(regionQueue2.isQueueInitialized()).thenReturn(true);
+  }
+
+  @Test
+  public void messageProcessInvokesProcessRegionQueues() {
+    when(dm.getCache()).thenReturn(cache);
+
+    queueRemovalMessage.process(dm);
+
+    verify(queueRemovalMessage).processRegionQueues(eq(cache), any(Iterator.class));
+  }
+
+  @Test
+  public void processRegionQueuesCanProcessEachRegionQueue() {
+    addToMessagesList();
+    Iterator iterator = messagesList.iterator();
+
+    queueRemovalMessage.processRegionQueues(cache, iterator);
+
+    verify(queueRemovalMessage).processRegionQueue(iterator, regionName1, 1, regionQueue1);
+    verify(queueRemovalMessage).processRegionQueue(iterator, regionName2, 2, regionQueue2);
+    verify(queueRemovalMessage).removeQueueEvent(regionName1, regionQueue1, eventID1);
+    verify(queueRemovalMessage).removeQueueEvent(regionName2, regionQueue2, eventID2);
+    verify(queueRemovalMessage).removeQueueEvent(regionName2, regionQueue2, eventID3);
+  }
+
+  private void addToMessagesList() {
+    messagesList.add(regionName1);
+    messagesList.add(1);
+    messagesList.add(eventID1);
+    messagesList.add(regionName2);
+    messagesList.add(2);

Review comment:
       Can the two sizes here be extracted to constants, since they're referenced in multiple 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.

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