geode-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From kh...@apache.org
Subject [2/9] geode git commit: GEODE-2860: Refactor use of EventTracker
Date Tue, 18 Jul 2017 14:15:28 GMT
http://git-wip-us.apache.org/repos/asf/geode/blob/3f9be9a7/geode-core/src/test/java/org/apache/geode/internal/cache/event/EventTrackerExpiryTaskTest.java
----------------------------------------------------------------------
diff --git a/geode-core/src/test/java/org/apache/geode/internal/cache/event/EventTrackerExpiryTaskTest.java
b/geode-core/src/test/java/org/apache/geode/internal/cache/event/EventTrackerExpiryTaskTest.java
new file mode 100644
index 0000000..1f969ef
--- /dev/null
+++ b/geode-core/src/test/java/org/apache/geode/internal/cache/event/EventTrackerExpiryTaskTest.java
@@ -0,0 +1,94 @@
+/*
+ * 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.junit.Assert.assertEquals;
+import static org.mockito.Mockito.mock;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.experimental.categories.Category;
+
+import org.apache.geode.CancelCriterion;
+import org.apache.geode.internal.cache.InternalCache;
+import org.apache.geode.internal.cache.ha.ThreadIdentifier;
+import org.apache.geode.test.junit.categories.UnitTest;
+
+@Category(UnitTest.class)
+public class EventTrackerExpiryTaskTest {
+  private static final long TIME_TO_LIVE = 100;
+
+  private EventTrackerExpiryTask task;
+
+  @Before
+  public void setup() {
+    task = new EventTrackerExpiryTask(TIME_TO_LIVE);
+  }
+
+  @Test
+  public void hasNoTrackersWhenInitialized() {
+    assertEquals(0, task.getNumberOfTrackers());
+  }
+
+  @Test
+  public void addsTrackersCorrectly() {
+    task.addTracker(NonDistributedEventTracker.getInstance());
+    assertEquals(1, task.getNumberOfTrackers());
+  }
+
+  @Test
+  public void removedTrackersCorrectly() {
+    task.addTracker(NonDistributedEventTracker.getInstance());
+    task.removeTracker(NonDistributedEventTracker.getInstance());
+    assertEquals(0, task.getNumberOfTrackers());
+  }
+
+  @Test
+  public void removesExpiredSequenceIdHolder() {
+    DistributedEventTracker tracker = constructTestTracker();
+    task.addTracker(tracker);
+    EventSequenceNumberHolder sequenceIdHolder = new EventSequenceNumberHolder(0L, null);
+    tracker.recordSequenceNumber(new ThreadIdentifier(new byte[0], 0L), sequenceIdHolder);
+    sequenceIdHolder.setEndOfLifeTimestamp(System.currentTimeMillis() - TIME_TO_LIVE);
+    task.run2();
+    assertEquals(0, tracker.getRecordedEvents().size());
+  }
+
+  @Test
+  public void doesNotRemoveNonExpiredSequenceIdHolder() {
+    DistributedEventTracker tracker = constructTestTracker();
+    task.addTracker(tracker);
+    EventSequenceNumberHolder sequenceIdHolder = new EventSequenceNumberHolder(0L, null);
+    tracker.recordSequenceNumber(new ThreadIdentifier(new byte[0], 0L), sequenceIdHolder);
+    sequenceIdHolder.setEndOfLifeTimestamp(System.currentTimeMillis() + 10000);
+    task.run2();
+    assertEquals(1, tracker.getRecordedEvents().size());
+  }
+
+  @Test
+  public void doesNotRemoveNewSequenceIdHolder() {
+    DistributedEventTracker tracker = constructTestTracker();
+    task.addTracker(tracker);
+    EventSequenceNumberHolder sequenceIdHolder = new EventSequenceNumberHolder(0L, null);
+    tracker.recordSequenceNumber(new ThreadIdentifier(new byte[0], 0L), sequenceIdHolder);
+    task.run2();
+    assertEquals(1, tracker.getRecordedEvents().size());
+  }
+
+  private DistributedEventTracker constructTestTracker() {
+    return new DistributedEventTracker(mock(InternalCache.class), mock(CancelCriterion.class),
+        "test region");
+  }
+}

http://git-wip-us.apache.org/repos/asf/geode/blob/3f9be9a7/geode-core/src/test/java/org/apache/geode/internal/cache/event/NonDistributedEventTrackerTest.java
----------------------------------------------------------------------
diff --git a/geode-core/src/test/java/org/apache/geode/internal/cache/event/NonDistributedEventTrackerTest.java
b/geode-core/src/test/java/org/apache/geode/internal/cache/event/NonDistributedEventTrackerTest.java
new file mode 100644
index 0000000..7ba531f
--- /dev/null
+++ b/geode-core/src/test/java/org/apache/geode/internal/cache/event/NonDistributedEventTrackerTest.java
@@ -0,0 +1,89 @@
+/*
+ * 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.junit.Assert.*;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.times;
+import static org.mockito.Mockito.verify;
+
+import org.junit.Test;
+import org.junit.experimental.categories.Category;
+
+import org.apache.geode.distributed.DistributedMember;
+import org.apache.geode.internal.cache.EventID;
+import org.apache.geode.internal.cache.InternalCacheEvent;
+import org.apache.geode.test.junit.categories.UnitTest;
+
+@Category(UnitTest.class)
+public class NonDistributedEventTrackerTest {
+  private NonDistributedEventTracker tracker = NonDistributedEventTracker.getInstance();
+
+  @Test
+  public void getStateReturnsNull() {
+    assertNull(tracker.getState());
+  }
+
+  @Test
+  public void hasSeenEventReturnsFalse() {
+    assertFalse(tracker.hasSeenEvent(mock(InternalCacheEvent.class)));
+    assertFalse(tracker.hasSeenEvent(mock(EventID.class)));
+    assertFalse(tracker.hasSeenEvent(mock(EventID.class), mock(InternalCacheEvent.class)));
+  }
+
+  @Test
+  public void findVersionTagForSequenceReturnsNull() {
+    assertNull(tracker.findVersionTagForSequence(mock(EventID.class)));
+  }
+
+  @Test
+  public void findVersionTagForBulkOpReturnsNull() {
+    assertNull(tracker.findVersionTagForBulkOp(mock(EventID.class)));
+  }
+
+  @Test
+  public void returnsCorrectName() {
+    assertEquals(NonDistributedEventTracker.NAME, tracker.getName());
+  }
+
+  @Test
+  public void syncBulkOpExecutesProvidedRunnable() {
+    Runnable runnable = mock(Runnable.class);
+    tracker.syncBulkOp(runnable, mock(EventID.class), false);
+    tracker.syncBulkOp(runnable, mock(EventID.class), true);
+    verify(runnable, times(2)).run();
+  }
+
+  @Test
+  public void isInitializedReturnsTrue() {
+    assertTrue(tracker.isInitialized());
+  }
+
+  @Test
+  public void isInitialImageProviderReturnsFalse() {
+    assertFalse(tracker.isInitialImageProvider(mock(DistributedMember.class)));
+  }
+
+  @Test
+  public void getRecordedBulkOpVersionTagsReturnsNull() {
+    assertNull(tracker.getRecordedBulkOpVersionTags());
+  }
+
+  @Test
+  public void getRecordedEventsReturnsNull() {
+    assertNull(tracker.getRecordedEvents());
+  }
+
+}

http://git-wip-us.apache.org/repos/asf/geode/blob/3f9be9a7/geode-core/src/test/resources/org/apache/geode/codeAnalysis/sanctionedDataSerializables.txt
----------------------------------------------------------------------
diff --git a/geode-core/src/test/resources/org/apache/geode/codeAnalysis/sanctionedDataSerializables.txt
b/geode-core/src/test/resources/org/apache/geode/codeAnalysis/sanctionedDataSerializables.txt
index b84ac39..e2a708d 100644
--- a/geode-core/src/test/resources/org/apache/geode/codeAnalysis/sanctionedDataSerializables.txt
+++ b/geode-core/src/test/resources/org/apache/geode/codeAnalysis/sanctionedDataSerializables.txt
@@ -1103,8 +1103,8 @@ fromData,24,2a2bb7001e2a2bb8001fb500042a2bb900200100b50002b1
 toData,24,2a2bb700212ab400042bb800222b2ab40002b900230200b1
 
 org/apache/geode/internal/cache/InitialImageOperation$RequestImageMessage,2
-fromData,98,2a2bb700b42a2bb800b5b500172a2bb900b60100b500022a2bb900b70100b500552a2bb900b70100b500032a2bb900b70100b5004b2a2bb800b8c000b9b5003a2a2bb800b8c000bab500262a2bb800b8c000bbb5003b2a2bb800b8c000bcb50030b1
-toData,86,2a2bb700bd2ab400172bb800be2b2ab40002b900bf02002b2ab40055b900c002002b2ab40003b900c002002b2ab4004bb900c002002ab4003a2bb800c12ab400262bb800c12ab4003b2bb800c12ab400302bb800c1b1
+fromData,98,2a2bb700b52a2bb800b6b500172a2bb900b70100b500022a2bb900b80100b500552a2bb900b80100b500032a2bb900b80100b5004b2a2bb800b9c000bab5003a2a2bb800b9c000bbb500262a2bb800b9c000bcb5003b2a2bb800b9c000bdb50030b1
+toData,86,2a2bb700be2ab400172bb800bf2b2ab40002b900c002002b2ab40055b900c102002b2ab40003b900c102002b2ab4004bb900c102002ab4003a2bb800c22ab400262bb800c22ab4003b2bb800c22ab400302bb800c2b1
 
 org/apache/geode/internal/cache/InitialImageOperation$RequestRVVMessage,2
 fromData,34,2a2bb7001e2a2bb8001fb500052a2bb900200100b500022a2bb900210100b50003b1
@@ -1447,6 +1447,10 @@ org/apache/geode/internal/cache/control/ResourceAdvisor$ResourceProfileMessage,2
 fromData,84,2a2bb7001d2a2bb9001e0100b500032bb9001e01003d1c029f00362a1cbd0004b50005033e1d2ab40005bea20020bb000459b7001f3a0419042bb800202ab400051d190453840301a7ffdda700082a01b50005b1
 toData,71,2a2bb700212b2ab40003b9002202002ab40005c6002c2b2ab40005beb900220200033d1c2ab40005bea200132ab400051c322bb80023840201a7ffeaa7000a2b02b900220200b1
 
+org/apache/geode/internal/cache/event/EventSequenceNumberHolder,2
+fromData,22,2a2bb900100100b500042a2bb80011c00012b50005b1
+toData,19,2b2ab40004b9001303002ab400052bb80014b1
+
 org/apache/geode/internal/cache/execute/FunctionRemoteContext,2
 fromData,95,2bb800084d2cc100099900252a03b500072a2cc00009b8000ab500022ab40002c7001b2a2cc00009b5000ba700102a2cc0000cb500022a04b500072a2bb80008b500032a2bb8000db500042a2bb8000db500052a2bb8000eb6000fb50006b1
 toData,73,2ab4000799000e2ab400022bb80010a700102ab40002b9001101002bb800102ab400032bb800102ab40004c000122bb800132ab40005c000122bb800132ab40006b800142bb80015b1


Mime
View raw message