geode-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dschnei...@apache.org
Subject [1/4] geode git commit: GEODE-2860: Refactor use of EventTracker
Date Wed, 12 Jul 2017 18:50:11 GMT
Repository: geode
Updated Branches:
  refs/heads/feature/GEODE-2860 [created] b7b02bfcd


http://git-wip-us.apache.org/repos/asf/geode/blob/0e215d4b/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/0e215d4b/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());
+  }
+
+}


Mime
View raw message