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



##########
File path: 
geode-core/src/integrationTest/java/org/apache/geode/internal/cache/event/DistributedEventTrackerIntegrationTest.java
##########
@@ -0,0 +1,146 @@
+/*
+ * 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.event;
+
+import static org.apache.geode.cache.RegionShortcut.PARTITION;
+import static org.apache.geode.cache.RegionShortcut.REPLICATE;
+import static org.apache.geode.internal.Assert.assertTrue;
+import static 
org.apache.geode.internal.cache.event.DistributedEventTracker.EVENT_HAS_PREVIOUSLY_BEEN_SEEN_PREFIX;
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.mockito.Mockito.mock;
+
+import java.io.File;
+import java.io.IOException;
+import java.nio.file.Files;
+import java.nio.file.Paths;
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.Optional;
+
+import org.junit.Before;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.experimental.categories.Category;
+import org.junit.runner.RunWith;
+import org.junit.runners.Parameterized;
+
+import org.apache.geode.cache.Operation;
+import org.apache.geode.cache.partition.PartitionRegionHelper;
+import org.apache.geode.distributed.internal.InternalDistributedSystem;
+import org.apache.geode.internal.cache.BucketRegion;
+import org.apache.geode.internal.cache.DistributedRegion;
+import org.apache.geode.internal.cache.EntryEventImpl;
+import org.apache.geode.internal.cache.EventID;
+import org.apache.geode.internal.cache.LocalRegion;
+import org.apache.geode.internal.cache.PartitionedRegion;
+import org.apache.geode.internal.cache.tier.sockets.ClientProxyMembershipID;
+import org.apache.geode.test.junit.categories.RegionsTest;
+import org.apache.geode.test.junit.rules.ServerStarterRule;
+import org.apache.geode.test.junit.rules.serializable.SerializableTestName;
+import 
org.apache.geode.test.junit.runners.CategoryWithParameterizedRunnerFactory;
+
+@RunWith(Parameterized.class)
[email protected](CategoryWithParameterizedRunnerFactory.class)
+@Category({RegionsTest.class})
+public class DistributedEventTrackerIntegrationTest {
+
+  @Parameterized.Parameters(name = "possibleDuplicate={0}")
+  public static Collection booleans() {

Review comment:
       Compiler warning here can be fixed by using `Collection<Boolean>`

##########
File path: 
geode-core/src/integrationTest/java/org/apache/geode/internal/cache/event/DistributedEventTrackerIntegrationTest.java
##########
@@ -0,0 +1,146 @@
+/*
+ * 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.event;
+
+import static org.apache.geode.cache.RegionShortcut.PARTITION;
+import static org.apache.geode.cache.RegionShortcut.REPLICATE;
+import static org.apache.geode.internal.Assert.assertTrue;
+import static 
org.apache.geode.internal.cache.event.DistributedEventTracker.EVENT_HAS_PREVIOUSLY_BEEN_SEEN_PREFIX;
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.mockito.Mockito.mock;
+
+import java.io.File;
+import java.io.IOException;
+import java.nio.file.Files;
+import java.nio.file.Paths;
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.Optional;
+
+import org.junit.Before;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.experimental.categories.Category;
+import org.junit.runner.RunWith;
+import org.junit.runners.Parameterized;
+
+import org.apache.geode.cache.Operation;
+import org.apache.geode.cache.partition.PartitionRegionHelper;
+import org.apache.geode.distributed.internal.InternalDistributedSystem;
+import org.apache.geode.internal.cache.BucketRegion;
+import org.apache.geode.internal.cache.DistributedRegion;
+import org.apache.geode.internal.cache.EntryEventImpl;
+import org.apache.geode.internal.cache.EventID;
+import org.apache.geode.internal.cache.LocalRegion;
+import org.apache.geode.internal.cache.PartitionedRegion;
+import org.apache.geode.internal.cache.tier.sockets.ClientProxyMembershipID;
+import org.apache.geode.test.junit.categories.RegionsTest;
+import org.apache.geode.test.junit.rules.ServerStarterRule;
+import org.apache.geode.test.junit.rules.serializable.SerializableTestName;
+import 
org.apache.geode.test.junit.runners.CategoryWithParameterizedRunnerFactory;
+
+@RunWith(Parameterized.class)
[email protected](CategoryWithParameterizedRunnerFactory.class)
+@Category({RegionsTest.class})
+public class DistributedEventTrackerIntegrationTest {
+
+  @Parameterized.Parameters(name = "possibleDuplicate={0}")
+  public static Collection booleans() {
+    return Arrays.asList(true, false);
+  }
+
+  @Parameterized.Parameter
+  public boolean possibleDuplicate;
+
+  @Rule
+  public SerializableTestName testName = new SerializableTestName();
+
+  @Rule
+  public ServerStarterRule server = new 
ServerStarterRule().withNoCacheServer().withLogFile();
+
+  @Before
+  public void setUp() throws Exception {
+    server.startServer();
+  }
+
+  @Test
+  public void testHasSeenEventReplicatedRegion() throws IOException {
+    // Create the replicated region
+    DistributedRegion region = (DistributedRegion) 
server.createRegion(REPLICATE,
+        testName.getMethodName().substring(0, 
testName.getMethodName().indexOf('[')));
+
+    // Invoke hasSeenEvent and verify results
+    invokeHasSeenEventAndVerifyResults(region);
+  }
+
+  @Test
+  public void testHasSeenEventPartitionedRegion() throws IOException {
+    // Create the partitioned region
+    PartitionedRegion region = (PartitionedRegion) 
server.createRegion(PARTITION,
+        testName.getMethodName().substring(0, 
testName.getMethodName().indexOf('[')));
+
+    // Assign buckets so that the BucketRegions and their EventTrackers are 
created
+    PartitionRegionHelper.assignBucketsToPartitions(region);
+
+    // Get a BucketRegion
+    BucketRegion br = region.getBucketRegion(0);
+
+    // Invoke hasSeenEvent and verify results
+    invokeHasSeenEventAndVerifyResults(br);
+  }
+
+  private void invokeHasSeenEventAndVerifyResults(DistributedRegion region)
+      throws IOException {
+    // Record an event with a high sequence number
+    recordHighSequenceNumberEvent(region);
+
+    // Create an event with a lower sequence number and possibleDuplicate set 
appropriately
+    EntryEventImpl event =
+        createEvent(region, new EventID(new byte[0], 1l, 0l));

Review comment:
       Since the `threadId` used in the constructor for the `EventID` here 
needs to be the same as that used in the constructor for the `EventID` in 
`recordHighSequenceNumberEvent()`, it might be best to extract the value to a 
constant. Also, very minor nitpick, but IntelliJ creates a warning for me that 
it's better to use upper-case L to denote long values, so it seems like a 
simple thing to fix here too.

##########
File path: 
geode-core/src/integrationTest/java/org/apache/geode/internal/cache/event/DistributedEventTrackerIntegrationTest.java
##########
@@ -0,0 +1,146 @@
+/*
+ * 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.event;
+
+import static org.apache.geode.cache.RegionShortcut.PARTITION;
+import static org.apache.geode.cache.RegionShortcut.REPLICATE;
+import static org.apache.geode.internal.Assert.assertTrue;
+import static 
org.apache.geode.internal.cache.event.DistributedEventTracker.EVENT_HAS_PREVIOUSLY_BEEN_SEEN_PREFIX;
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.mockito.Mockito.mock;
+
+import java.io.File;
+import java.io.IOException;
+import java.nio.file.Files;
+import java.nio.file.Paths;
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.Optional;
+
+import org.junit.Before;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.experimental.categories.Category;
+import org.junit.runner.RunWith;
+import org.junit.runners.Parameterized;
+
+import org.apache.geode.cache.Operation;
+import org.apache.geode.cache.partition.PartitionRegionHelper;
+import org.apache.geode.distributed.internal.InternalDistributedSystem;
+import org.apache.geode.internal.cache.BucketRegion;
+import org.apache.geode.internal.cache.DistributedRegion;
+import org.apache.geode.internal.cache.EntryEventImpl;
+import org.apache.geode.internal.cache.EventID;
+import org.apache.geode.internal.cache.LocalRegion;
+import org.apache.geode.internal.cache.PartitionedRegion;
+import org.apache.geode.internal.cache.tier.sockets.ClientProxyMembershipID;
+import org.apache.geode.test.junit.categories.RegionsTest;
+import org.apache.geode.test.junit.rules.ServerStarterRule;
+import org.apache.geode.test.junit.rules.serializable.SerializableTestName;
+import 
org.apache.geode.test.junit.runners.CategoryWithParameterizedRunnerFactory;
+
+@RunWith(Parameterized.class)
[email protected](CategoryWithParameterizedRunnerFactory.class)
+@Category({RegionsTest.class})
+public class DistributedEventTrackerIntegrationTest {
+
+  @Parameterized.Parameters(name = "possibleDuplicate={0}")
+  public static Collection booleans() {
+    return Arrays.asList(true, false);
+  }
+
+  @Parameterized.Parameter
+  public boolean possibleDuplicate;
+
+  @Rule
+  public SerializableTestName testName = new SerializableTestName();
+
+  @Rule
+  public ServerStarterRule server = new 
ServerStarterRule().withNoCacheServer().withLogFile();
+
+  @Before
+  public void setUp() throws Exception {
+    server.startServer();
+  }
+
+  @Test
+  public void testHasSeenEventReplicatedRegion() throws IOException {
+    // Create the replicated region
+    DistributedRegion region = (DistributedRegion) 
server.createRegion(REPLICATE,
+        testName.getMethodName().substring(0, 
testName.getMethodName().indexOf('[')));
+
+    // Invoke hasSeenEvent and verify results
+    invokeHasSeenEventAndVerifyResults(region);
+  }
+
+  @Test
+  public void testHasSeenEventPartitionedRegion() throws IOException {
+    // Create the partitioned region
+    PartitionedRegion region = (PartitionedRegion) 
server.createRegion(PARTITION,
+        testName.getMethodName().substring(0, 
testName.getMethodName().indexOf('[')));
+
+    // Assign buckets so that the BucketRegions and their EventTrackers are 
created
+    PartitionRegionHelper.assignBucketsToPartitions(region);
+
+    // Get a BucketRegion
+    BucketRegion br = region.getBucketRegion(0);
+
+    // Invoke hasSeenEvent and verify results
+    invokeHasSeenEventAndVerifyResults(br);
+  }
+
+  private void invokeHasSeenEventAndVerifyResults(DistributedRegion region)
+      throws IOException {
+    // Record an event with a high sequence number
+    recordHighSequenceNumberEvent(region);
+
+    // Create an event with a lower sequence number and possibleDuplicate set 
appropriately
+    EntryEventImpl event =
+        createEvent(region, new EventID(new byte[0], 1l, 0l));
+    event.setPossibleDuplicate(possibleDuplicate);
+
+    // Invoke hasSeenEvent
+    boolean hasSeenEvent = region.getEventTracker().hasSeenEvent(event);
+
+    // Assert hasSeenEvent is true
+    assertTrue(hasSeenEvent);

Review comment:
       Could this be replaced with `assertThat(hasSeenEvent).isTrue();` to keep 
all assertions using AssertJ?




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


Reply via email to