Index: src/test/java/org/apache/jackrabbit/oak/util/ApproximateCounterTest.java IDEA additional info: Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP <+>UTF-8 =================================================================== --- src/test/java/org/apache/jackrabbit/oak/util/ApproximateCounterTest.java (revision 1671809) +++ src/test/java/org/apache/jackrabbit/oak/util/ApproximateCounterTest.java (revision ) @@ -16,14 +16,46 @@ */ package org.apache.jackrabbit.oak.util; +import static org.apache.jackrabbit.oak.plugins.memory.EmptyNodeState.EMPTY_NODE; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertTrue; import java.util.Random; +import org.apache.jackrabbit.oak.NodeStoreFixture; +import org.apache.jackrabbit.oak.OakBaseTest; +import org.apache.jackrabbit.oak.spi.state.NodeBuilder; import org.junit.Test; -public class ApproximateCounterTest { +public class ApproximateCounterTest extends OakBaseTest { + + public static final long COUNT_SYNC_TEST_COUNT = 100; + public static final long COUNT_SYNC_ADJUST_INVOCATIONS_COUNT = 1000; + + public ApproximateCounterTest(NodeStoreFixture fixture) { + super(fixture); + } + + @Test + public void adjustCountSync() { + int exceedingCounts = 0; + + for (int testIdx = 0 ; testIdx < COUNT_SYNC_TEST_COUNT ; testIdx ++) { + NodeBuilder mockNodeBuilder = EMPTY_NODE.builder(); + + for (int i = 0 ; i < COUNT_SYNC_ADJUST_INVOCATIONS_COUNT ; i++) { + ApproximateCounter.adjustCountSync(mockNodeBuilder, 1); + } + + long count = ApproximateCounter.getCountSync(mockNodeBuilder.getNodeState()); + + if (count > 2 * COUNT_SYNC_ADJUST_INVOCATIONS_COUNT) { + exceedingCounts ++; + } + } + + assertEquals("Returned count exceeds 2 X invocations count!", 0, exceedingCounts); + } @Test public void veryHighResolution() {