You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@geode.apache.org by ds...@apache.org on 2017/07/18 18:26:52 UTC
[3/9] geode git commit: GEODE-3049: use mocks in tests and improve
log messages
GEODE-3049: use mocks in tests and improve log messages
Project: http://git-wip-us.apache.org/repos/asf/geode/repo
Commit: http://git-wip-us.apache.org/repos/asf/geode/commit/ba47bb28
Tree: http://git-wip-us.apache.org/repos/asf/geode/tree/ba47bb28
Diff: http://git-wip-us.apache.org/repos/asf/geode/diff/ba47bb28
Branch: refs/heads/feature/GEODE-3049
Commit: ba47bb28e921191bfccca135ccd2bc5d342dd832
Parents: f116c54
Author: Nick Reich <nr...@pivotal.io>
Authored: Tue Jun 13 17:02:22 2017 -0700
Committer: Nick Reich <nr...@pivotal.io>
Committed: Tue Jun 13 17:02:22 2017 -0700
----------------------------------------------------------------------
.../internal/cache/BucketRedundancyTracker.java | 4 +-
.../PartitionedRegionRedundancyTracker.java | 4 +-
.../internal/GlobalCacheExpirationTest.java | 242 -------------------
.../cache/BucketRedundancyTrackerTest.java | 93 ++++---
.../PartitionedRegionRedundancyTrackerTest.java | 47 ++--
5 files changed, 73 insertions(+), 317 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/geode/blob/ba47bb28/geode-core/src/main/java/org/apache/geode/internal/cache/BucketRedundancyTracker.java
----------------------------------------------------------------------
diff --git a/geode-core/src/main/java/org/apache/geode/internal/cache/BucketRedundancyTracker.java b/geode-core/src/main/java/org/apache/geode/internal/cache/BucketRedundancyTracker.java
index 4088b5a..ff53e25 100644
--- a/geode-core/src/main/java/org/apache/geode/internal/cache/BucketRedundancyTracker.java
+++ b/geode-core/src/main/java/org/apache/geode/internal/cache/BucketRedundancyTracker.java
@@ -96,7 +96,9 @@ class BucketRedundancyTracker {
regionRedundancyTracker.incrementLowRedundancyBucketCount();
redundancySatisfied = false;
}
- regionRedundancyTracker.reportBucketCount(currentBucketHosts);
+ if (redundancyEverSatisfied) {
+ regionRedundancyTracker.reportBucketCount(currentBucketHosts);
+ }
} else if (!redundancySatisfied && actualRedundancy >= targetRedundancy) {
if (redundancyEverSatisfied) {
regionRedundancyTracker.decrementLowRedundancyBucketCount();
http://git-wip-us.apache.org/repos/asf/geode/blob/ba47bb28/geode-core/src/main/java/org/apache/geode/internal/cache/PartitionedRegionRedundancyTracker.java
----------------------------------------------------------------------
diff --git a/geode-core/src/main/java/org/apache/geode/internal/cache/PartitionedRegionRedundancyTracker.java b/geode-core/src/main/java/org/apache/geode/internal/cache/PartitionedRegionRedundancyTracker.java
index 1f65ea9..e8e7a83 100644
--- a/geode-core/src/main/java/org/apache/geode/internal/cache/PartitionedRegionRedundancyTracker.java
+++ b/geode-core/src/main/java/org/apache/geode/internal/cache/PartitionedRegionRedundancyTracker.java
@@ -97,7 +97,7 @@ public class PartitionedRegionRedundancyTracker {
noCopiesBuckets++;
stats.incNoCopiesBucketCount(1);
if (noCopiesBuckets == 1) {
- logger.warn("No copies remain for " + regionPath);
+ logger.warn("All in memory copies of some data have been lost for " + regionPath);
}
}
@@ -112,6 +112,8 @@ public class PartitionedRegionRedundancyTracker {
stats.incLowRedundancyBucketCount(-1);
if (lowRedundancyBuckets == 0) {
lowestBucketCopies = targetRedundancy + 1;
+ logger.info("Configured redundancy of " + targetRedundancy + " copies has been restored to "
+ + regionPath);
}
}
http://git-wip-us.apache.org/repos/asf/geode/blob/ba47bb28/geode-core/src/test/java/org/apache/geode/distributed/internal/GlobalCacheExpirationTest.java
----------------------------------------------------------------------
diff --git a/geode-core/src/test/java/org/apache/geode/distributed/internal/GlobalCacheExpirationTest.java b/geode-core/src/test/java/org/apache/geode/distributed/internal/GlobalCacheExpirationTest.java
deleted file mode 100644
index b35054c..0000000
--- a/geode-core/src/test/java/org/apache/geode/distributed/internal/GlobalCacheExpirationTest.java
+++ /dev/null
@@ -1,242 +0,0 @@
-/*
- * 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.distributed.internal;
-
-import org.apache.geode.cache.Cache;
-import org.apache.geode.cache.DataPolicy;
-import org.apache.geode.cache.ExpirationAction;
-import org.apache.geode.cache.ExpirationAttributes;
-import org.apache.geode.cache.PartitionAttributesFactory;
-import org.apache.geode.cache.Region;
-import org.apache.geode.cache.RegionFactory;
-import org.apache.geode.cache.Scope;
-import org.apache.geode.distributed.internal.locks.DLockService;
-import org.apache.geode.internal.cache.ColocationLogger;
-import org.apache.geode.internal.cache.DistributedRegion;
-import org.apache.geode.test.dunit.Host;
-import org.apache.geode.test.dunit.SerializableRunnable;
-import org.apache.geode.test.dunit.VM;
-import org.apache.geode.test.dunit.cache.internal.JUnit4CacheTestCase;
-import org.apache.geode.test.dunit.rules.DistributedRestoreSystemProperties;
-import org.apache.geode.test.junit.categories.DistributedTest;
-import org.apache.geode.test.junit.categories.MembershipTest;
-import org.apache.logging.log4j.Level;
-import org.apache.logging.log4j.LogManager;
-import org.apache.logging.log4j.core.Appender;
-import org.apache.logging.log4j.core.LogEvent;
-import org.apache.logging.log4j.core.Logger;
-import org.junit.Assert;
-import org.junit.Rule;
-import org.junit.Test;
-import org.junit.experimental.categories.Category;
-import org.mockito.ArgumentCaptor;
-
-import java.util.Random;
-
-import static org.mockito.Mockito.when;
-import static org.mockito.Mockito.mock;
-
-@Category({DistributedTest.class, MembershipTest.class})
-public class GlobalCacheExpirationTest extends JUnit4CacheTestCase {
- private static final Logger logger = (Logger) LogManager.getLogger();
- private static ArgumentCaptor<LogEvent> loggingEventCaptor;
- @Rule
- public DistributedRestoreSystemProperties restoreSystemProperties =
- new DistributedRestoreSystemProperties();
-
- @Override
- public void preSetUp() throws Exception {
- disconnectAllFromDS();
- }
-
- static Region otherRegion;
-
- @Test
- public void TokensDereferencedOnExpirationFromGlobalCache() throws InterruptedException {
- Cache myCache = getCache();
- DistributedRegion region = (DistributedRegion) myCache.createRegionFactory()
- .setScope(Scope.GLOBAL).setDataPolicy(DataPolicy.REPLICATE)
- .setEntryTimeToLive(new ExpirationAttributes(1, ExpirationAction.DESTROY))
- .create("testRegion");
-
- region.becomeLockGrantor();
-
- Host host = Host.getHost(0);
- VM vm1 = host.getVM(1);
-
- vm1.invoke(new SerializableRunnable("Connect to distributed system") {
- public void run() {
- Cache myCache = getCache();
- otherRegion =
- myCache.createRegionFactory().setScope(Scope.GLOBAL).setDataPolicy(DataPolicy.REPLICATE)
- .setEntryTimeToLive(new ExpirationAttributes(1, ExpirationAction.DESTROY))
- .create("testRegion");
- }
- });
-
- Random rand = new Random();
- for (int i = 0; i < 10000; i++) {
- String key = Integer.toString(i);
- region.put(key, Integer.toString(rand.nextInt()));
- }
-
- Assert.assertTrue(region.size() > 0);
- vm1.invoke(new SerializableRunnable("disconnect from ds") {
- public void run() {
- Assert.assertTrue(otherRegion.size() > 0);
- }
- });
- Thread.sleep(2000);
- vm1.invoke(new SerializableRunnable("check size") {
- public void run() {
- Assert.assertEquals(0, otherRegion.size());
- }
- });
- Assert.assertTrue(region.isLockGrantor());
- Assert.assertEquals(0, region.size());
-
-
- DLockService service = (DLockService) region.getLockService();
- Assert.assertTrue(service.isLockGrantor());
- Assert.assertEquals(0, service.getStats().getTokens());
- }
-
- public static Region region1;
- public static Region region2;
-
- @Test
- public void DataConsistencyTest() throws InterruptedException {
- DistributionManager dm = (DistributionManager) getSystem().getDistributionManager();
- /*
- * Cache myCache = getCache(); RegionFactory<String, String> factory =
- * myCache.createRegionFactory(); Region<String, String> region = factory
- * .setDataPolicy(DataPolicy.PARTITION) .setPartitionAttributes(new
- * PartitionAttributesFactory<>().setRedundantCopies(1).create())
- * .create("testPartitionRegion");
- */
-
- Host host = Host.getHost(0);
- VM vm1 = host.getVM(1);
- VM vm2 = host.getVM(2);
-
- vm1.invoke(new SerializableRunnable("Connect to distributed system") {
- public void run() {
- Cache myCache = getCache();
- RegionFactory<String, String> factory = myCache.createRegionFactory();
- region1 = factory.setDataPolicy(DataPolicy.PARTITION)
- .setPartitionAttributes(
- new PartitionAttributesFactory<>().setRedundantCopies(1).create())
- .create("testPartitionRegion");
- }
- });
-
- vm2.invoke(new SerializableRunnable("Connect to distributed system") {
- public void run() {
- Cache myCache = getCache();
- RegionFactory<String, String> factory = myCache.createRegionFactory();
- region2 = factory.setDataPolicy(DataPolicy.PARTITION)
- .setPartitionAttributes(
- new PartitionAttributesFactory<>().setRedundantCopies(1).create())
- .create("testPartitionRegion");
- }
- });
-
- vm1.invoke(new SerializableRunnable("load data") {
- public void run() {
- Random rand = new Random();
- for (int i = 0; i < 1000; i++) {
- String key = Integer.toString(i);
- region1.put(key, Integer.toString(rand.nextInt()));
- }
- }
- });
-
- /*
- * for (int i = 0; i < 10; i++) { Assert.assertNotNull(regionAccessor.get(Integer.toString(i)));
- * }
- */
-
- RegionFactory<String, String> factory = getCache().createRegionFactory();
- Region regionAccessor = factory.setDataPolicy(DataPolicy.PARTITION)
- .setPartitionAttributes(
- new PartitionAttributesFactory<>().setRedundantCopies(1).setLocalMaxMemory(0).create())
- .create("testPartitionRegion");
-
- vm2.invoke(new SerializableRunnable("check size") {
- public void run() {
- Assert.assertEquals(1000, region2.size());
- }
- });
-
- vm1.invoke(new SerializableRunnable("check size") {
- public void run() {
- Assert.assertEquals(1000, region1.size());
- }
- });
-
- // regionAccessor.get("postDisconnect1Key");
-
- vm1.invoke(new SerializableRunnable("disconnect") {
- public void run() {
- region1.close();
- }
- });
-
- vm2.invoke(new SerializableRunnable("load data") {
- public void run() {
- region2.put("postDisconnect1Key", "pastDisconnect1Value");
- }
- });
-
- // Object result = regionAccessor.get("postDisconnect1Key");
- // Assert.assertNotNull(result);
- Appender mockAppender = attatchMockAppenderToLogger();
- vm2.invoke(new SerializableRunnable("disconnect") {
- public void run() {
- // getSystem().emergencyClose();
- // getSystem().disconnect();
- region2.close();
- }
- });
- ArgumentCaptor<LogEvent> loggingEventCaptor = ArgumentCaptor.forClass(LogEvent.class);
- detatchMockAppenderFromLogger(mockAppender);
- // Thread.sleep(4000);
- // Object resultPostBounce = regionAccessor.get("postDisconnect1Key");
- // Assert.assertNotNull(resultPostBounce);
-
-
- /*
- * try { Object postDisconnectResult = regionAccessor.get("1"); } catch
- * (PartitionedRegionStorageException e) { logger.log(Level.ERROR, e); }
- * System.out.println("Done");
- */
- }
-
- private Appender attatchMockAppenderToLogger() {
- Appender mockAppender = mock(Appender.class);
- when(mockAppender.getName()).thenReturn("MockAppender");
- when(mockAppender.isStarted()).thenReturn(true);
- when(mockAppender.isStopped()).thenReturn(false);
- logger.addAppender(mockAppender);
- logger.setLevel(Level.WARN);
- loggingEventCaptor = ArgumentCaptor.forClass(LogEvent.class);
- return mockAppender;
- }
-
- private void detatchMockAppenderFromLogger(Appender appender) {
- logger.removeAppender(appender);
- }
-}
http://git-wip-us.apache.org/repos/asf/geode/blob/ba47bb28/geode-core/src/test/java/org/apache/geode/internal/cache/BucketRedundancyTrackerTest.java
----------------------------------------------------------------------
diff --git a/geode-core/src/test/java/org/apache/geode/internal/cache/BucketRedundancyTrackerTest.java b/geode-core/src/test/java/org/apache/geode/internal/cache/BucketRedundancyTrackerTest.java
index 67751fc..54230b2 100644
--- a/geode-core/src/test/java/org/apache/geode/internal/cache/BucketRedundancyTrackerTest.java
+++ b/geode-core/src/test/java/org/apache/geode/internal/cache/BucketRedundancyTrackerTest.java
@@ -15,94 +15,93 @@
package org.apache.geode.internal.cache;
import static org.junit.Assert.assertEquals;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.times;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.verifyZeroInteractions;
-import org.apache.geode.cache.PartitionAttributes;
-import org.apache.geode.cache.PartitionAttributesFactory;
-import org.junit.After;
+import org.apache.geode.test.junit.categories.UnitTest;
import org.junit.Before;
import org.junit.Test;
+import org.junit.experimental.categories.Category;
+@Category(UnitTest.class)
public class BucketRedundancyTrackerTest {
private static final int TARGET_COPIES = 2;
- private PartitionedRegion region;
- private PartitionedRegionStats stats;
- private BucketRedundancyTracker redundancyTracker;
+ private PartitionedRegionRedundancyTracker regionRedundancyTracker;
+ private BucketRedundancyTracker bucketRedundancyTracker;
@Before
public void setup() {
- PartitionAttributes<Object, Object> regionAttributes = new PartitionAttributesFactory<>()
- .setTotalNumBuckets(10).setRedundantCopies(TARGET_COPIES - 1).create();
- region = (PartitionedRegion) PartitionedRegionTestHelper.createPartionedRegion("testRegion",
- regionAttributes);
- stats = region.getPrStats();
- redundancyTracker =
- new BucketRedundancyTracker(region.getRedundantCopies(), region.getRedundancyTracker());
- }
-
- @After
- public void teardown() {
- region.destroyRegion();
+ regionRedundancyTracker = mock(PartitionedRegionRedundancyTracker.class);
+ bucketRedundancyTracker =
+ new BucketRedundancyTracker(TARGET_COPIES - 1, regionRedundancyTracker);
}
@Test
public void whenRedundancyNeverMetDoesNotWarnOnLowRedundancy() {
- redundancyTracker.updateStatistics(TARGET_COPIES - 1);
- assertEquals(0, redundancyTracker.getCurrentRedundancy());
+ bucketRedundancyTracker.updateStatistics(TARGET_COPIES - 1);
+ verifyZeroInteractions(regionRedundancyTracker);
}
@Test
public void incrementsBucketCountOnLowRedundancyForBucket() {
- redundancyTracker.updateStatistics(TARGET_COPIES);
- redundancyTracker.updateStatistics(TARGET_COPIES - 1);
- assertEquals(1, stats.getLowRedundancyBucketCount());
- assertEquals(0, redundancyTracker.getCurrentRedundancy());
+ bucketRedundancyTracker.updateStatistics(TARGET_COPIES);
+ bucketRedundancyTracker.updateStatistics(TARGET_COPIES - 1);
+ verify(regionRedundancyTracker, times(1)).incrementLowRedundancyBucketCount();
+ assertEquals(0, bucketRedundancyTracker.getCurrentRedundancy());
}
@Test
public void decrementsBucketCountOnRegainingRedundancyForBucket() {
- redundancyTracker.updateStatistics(TARGET_COPIES);
- redundancyTracker.updateStatistics(TARGET_COPIES - 1);
- redundancyTracker.updateStatistics(TARGET_COPIES);
- assertEquals(0, stats.getLowRedundancyBucketCount());
- assertEquals(TARGET_COPIES - 1, redundancyTracker.getCurrentRedundancy());
+ bucketRedundancyTracker.updateStatistics(TARGET_COPIES);
+ bucketRedundancyTracker.updateStatistics(TARGET_COPIES - 1);
+ bucketRedundancyTracker.updateStatistics(TARGET_COPIES);
+ verify(regionRedundancyTracker, times(1)).decrementLowRedundancyBucketCount();
+ assertEquals(TARGET_COPIES - 1, bucketRedundancyTracker.getCurrentRedundancy());
}
@Test
public void decrementsBucketCountOnClosingBucketBelowRedundancy() {
- redundancyTracker.updateStatistics(TARGET_COPIES);
- redundancyTracker.updateStatistics(TARGET_COPIES - 1);
- redundancyTracker.closeBucket();
- assertEquals(0, redundancyTracker.getCurrentRedundancy());
+ bucketRedundancyTracker.updateStatistics(TARGET_COPIES);
+ bucketRedundancyTracker.updateStatistics(TARGET_COPIES - 1);
+ bucketRedundancyTracker.closeBucket();
+ verify(regionRedundancyTracker, times(1)).decrementLowRedundancyBucketCount();
+ assertEquals(0, bucketRedundancyTracker.getCurrentRedundancy());
}
@Test
public void decrementsBucketCountOnClosingABucketWithNoCopies() {
- redundancyTracker.updateStatistics(TARGET_COPIES);
- redundancyTracker.updateStatistics(TARGET_COPIES - 1);
- redundancyTracker.updateStatistics(0);
- redundancyTracker.closeBucket();
- assertEquals(-1, redundancyTracker.getCurrentRedundancy());
+ bucketRedundancyTracker.updateStatistics(TARGET_COPIES);
+ bucketRedundancyTracker.updateStatistics(TARGET_COPIES - 1);
+ bucketRedundancyTracker.updateStatistics(0);
+ bucketRedundancyTracker.closeBucket();
+ verify(regionRedundancyTracker, times(1)).decrementLowRedundancyBucketCount();
+ assertEquals(-1, bucketRedundancyTracker.getCurrentRedundancy());
}
@Test
public void doesNotWarnWhenNeverHadAnyCopies() {
- redundancyTracker.updateStatistics(0);
- assertEquals(-1, redundancyTracker.getCurrentRedundancy());
+ bucketRedundancyTracker.updateStatistics(0);
+ verifyZeroInteractions(regionRedundancyTracker);
+ assertEquals(-1, bucketRedundancyTracker.getCurrentRedundancy());
}
@Test
public void incrementsBucketCountOnHavingNoCopiesForBucket() {
- redundancyTracker.updateStatistics(1);
- redundancyTracker.updateStatistics(0);
- assertEquals(-1, redundancyTracker.getCurrentRedundancy());
+ bucketRedundancyTracker.updateStatistics(1);
+ bucketRedundancyTracker.updateStatistics(0);
+ verify(regionRedundancyTracker, times(1)).incrementNoCopiesBucketCount();
+ assertEquals(-1, bucketRedundancyTracker.getCurrentRedundancy());
}
@Test
public void decrementsBucketCountOnHavingAtLeastOneCopyOfBucket() {
- redundancyTracker.updateStatistics(1);
- redundancyTracker.updateStatistics(0);
- redundancyTracker.updateStatistics(1);
- assertEquals(0, redundancyTracker.getCurrentRedundancy());
+ bucketRedundancyTracker.updateStatistics(1);
+ bucketRedundancyTracker.updateStatistics(0);
+ bucketRedundancyTracker.updateStatistics(1);
+ verify(regionRedundancyTracker, times(1)).decrementNoCopiesBucketCount();
+ assertEquals(0, bucketRedundancyTracker.getCurrentRedundancy());
}
}
http://git-wip-us.apache.org/repos/asf/geode/blob/ba47bb28/geode-core/src/test/java/org/apache/geode/internal/cache/PartitionedRegionRedundancyTrackerTest.java
----------------------------------------------------------------------
diff --git a/geode-core/src/test/java/org/apache/geode/internal/cache/PartitionedRegionRedundancyTrackerTest.java b/geode-core/src/test/java/org/apache/geode/internal/cache/PartitionedRegionRedundancyTrackerTest.java
index 8f44bbe..0917835 100644
--- a/geode-core/src/test/java/org/apache/geode/internal/cache/PartitionedRegionRedundancyTrackerTest.java
+++ b/geode-core/src/test/java/org/apache/geode/internal/cache/PartitionedRegionRedundancyTrackerTest.java
@@ -16,43 +16,38 @@
package org.apache.geode.internal.cache;
import static org.junit.Assert.assertEquals;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.times;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.verifyNoMoreInteractions;
+import static org.mockito.Mockito.verifyZeroInteractions;
-import org.apache.geode.cache.PartitionAttributes;
-import org.apache.geode.cache.PartitionAttributesFactory;
-import org.junit.After;
+import org.apache.geode.test.junit.categories.UnitTest;
import org.junit.Before;
import org.junit.Test;
+import org.junit.experimental.categories.Category;
+@Category(UnitTest.class)
public class PartitionedRegionRedundancyTrackerTest {
private static final int TARGET_COPIES = 2;
private static final int TOTAL_BUCKETS = 3;
- private PartitionedRegion region;
private PartitionedRegionStats stats;
private PartitionedRegionRedundancyTracker redundancyTracker;
@Before
public void setup() {
- PartitionAttributes<Object, Object> regionAttributes = new PartitionAttributesFactory<>()
- .setTotalNumBuckets(TOTAL_BUCKETS).setRedundantCopies(TARGET_COPIES - 1).create();
- region = (PartitionedRegion) PartitionedRegionTestHelper.createPartionedRegion("testRegion",
- regionAttributes);
- stats = region.getPrStats();
- redundancyTracker = new PartitionedRegionRedundancyTracker(region.getTotalNumberOfBuckets(),
- region.getRedundantCopies(), stats, region.getFullPath());
- }
-
- @After
- public void teardown() {
- region.destroyRegion();
+ stats = mock(PartitionedRegionStats.class);
+ redundancyTracker = new PartitionedRegionRedundancyTracker(TOTAL_BUCKETS, TARGET_COPIES - 1,
+ stats, "testRegion");
}
@Test
public void incrementsAndDecrementsLowRedundancyBucketCount() {
redundancyTracker.incrementLowRedundancyBucketCount();
- assertEquals(1, stats.getLowRedundancyBucketCount());
+ verify(stats, times(1)).incLowRedundancyBucketCount(1);
redundancyTracker.decrementLowRedundancyBucketCount();
- assertEquals(0, stats.getLowRedundancyBucketCount());
+ verify(stats, times(1)).incLowRedundancyBucketCount(-1);
}
@Test
@@ -61,23 +56,23 @@ public class PartitionedRegionRedundancyTrackerTest {
for (int i = 0; i < TOTAL_BUCKETS; i++) {
redundancyTracker.incrementLowRedundancyBucketCount();
}
- assertEquals(TOTAL_BUCKETS, stats.getLowRedundancyBucketCount());
+ verify(stats, times(TOTAL_BUCKETS)).incLowRedundancyBucketCount(1);
redundancyTracker.incrementLowRedundancyBucketCount();
- assertEquals(TOTAL_BUCKETS, stats.getLowRedundancyBucketCount());
+ verifyNoMoreInteractions(stats);
}
@Test
public void willNotDecrementLowRedundancyBucketCountBelowZero() {
redundancyTracker.decrementLowRedundancyBucketCount();
- assertEquals(0, stats.getLowRedundancyBucketCount());
+ verifyZeroInteractions(stats);
}
@Test
public void incrementsAndDecrementsNoCopiesBucketCount() {
redundancyTracker.incrementNoCopiesBucketCount();
- assertEquals(1, stats.getNoCopiesBucketCount());
+ verify(stats, times(1)).incNoCopiesBucketCount(1);
redundancyTracker.decrementNoCopiesBucketCount();
- assertEquals(0, stats.getNoCopiesBucketCount());
+ verify(stats, times(1)).incNoCopiesBucketCount(-1);
}
@Test
@@ -86,15 +81,15 @@ public class PartitionedRegionRedundancyTrackerTest {
for (int i = 0; i < TOTAL_BUCKETS; i++) {
redundancyTracker.incrementNoCopiesBucketCount();
}
- assertEquals(TOTAL_BUCKETS, stats.getNoCopiesBucketCount());
+ verify(stats, times(TOTAL_BUCKETS)).incNoCopiesBucketCount(1);
redundancyTracker.incrementNoCopiesBucketCount();
- assertEquals(TOTAL_BUCKETS, stats.getNoCopiesBucketCount());
+ verifyNoMoreInteractions(stats);
}
@Test
public void willNotDecrementNoCopiesBucketCountBelowZero() {
redundancyTracker.decrementNoCopiesBucketCount();
- assertEquals(0, stats.getNoCopiesBucketCount());
+ verify(stats, times(0)).incNoCopiesBucketCount(-1);
}
@Test