@Override TestCounter get(CounterManager manager, String name) { return new StrongTestCounter(manager.getStrongCounter(name)); } },
@Override TestCounter get(CounterManager manager, String name) { return new StrongTestCounter(manager.getStrongCounter(name)); } },
@Override protected StrongTestCounter createCounter(CounterManager counterManager, String counterName, CounterConfiguration configuration) { counterManager.defineCounter(counterName, configuration); return new StrongTestCounter(counterManager.getStrongCounter(counterName)); }
public CounterHandler(RemoteCacheManager cacheManager, Sequence sequence) { CounterManager counterManager = RemoteCounterManagerFactory.asCounterManager( cacheManager ); counterName = sequence.getExportIdentifier(); if ( !counterManager.isDefined( counterName ) ) { defineCounter( counterManager, counterName, sequence.getInitialValue() ); } counter = counterManager.getStrongCounter( counterName ); }
@Override void assertCounterNameAndConfiguration(String counterName, CounterConfiguration configuration) { allCounterManagerSupplier.get().forEach(counterManager -> { StrongCounter counter = counterManager.getStrongCounter(counterName); assertEquals(counterName, counter.getName()); assertEquals(configuration, counter.getConfiguration()); }); }
private long getValue(CounterManager counterManager) { switch (type) { case WEAK: return counterManager.getWeakCounter(name).getValue(); case BOUNDED_STRONG: case UNBOUNDED_STRONG: return counterManager.getStrongCounter(name).sync().getValue(); } throw new IllegalStateException(); } }
private long getStrongCounterValue(String name) { return awaitCounterOperation(counterManager(0).getStrongCounter(name).getValue()); }
private void resetStrongCounter(String name) { awaitCounterOperation(counterManager(0).getStrongCounter(name).reset()); }
@Override public StrongCounter defineAndCreateCounter(String counterName, long initialValue) { final CounterManager counterManager = counterManagerSupplier.get(); assertTrue( counterManager.defineCounter(counterName, builder(UNBOUNDED_STRONG).initialValue(initialValue).build())); return counterManager.getStrongCounter(counterName); }
@Override protected TestCounter createCounter(CounterManager counterManager, String counterName) { counterManager.defineCounter(counterName, CounterConfiguration.builder(CounterType.UNBOUNDED_STRONG).build()); return new StrongTestCounter(counterManager.getStrongCounter(counterName)); } }
private void incrementCounter(CounterManager counterManager) { switch (type) { case UNBOUNDED_STRONG: case BOUNDED_STRONG: counterManager.getStrongCounter(name).sync().incrementAndGet(); break; case WEAK: counterManager.getWeakCounter(name).sync().increment(); break; } }
private StrongCounter createCounter(CounterManager counterManager, String counterName, long min, long max) { counterManager.defineCounter(counterName, CounterConfiguration.builder(CounterType.BOUNDED_STRONG).lowerBound(min).upperBound(max).build()); return counterManager.getStrongCounter(counterName); } }
@Override public TestCounter getCounter(EmbeddedCacheManager manager, String counterName) { CounterManager counterManager = asCounterManager(manager); counterManager .defineCounter(counterName, CounterConfiguration.builder(CounterType.UNBOUNDED_STRONG).build()); return new StrongTestCounter(counterManager.getStrongCounter(counterName)); } },
private void addToStrongCounter(String name, long delta, boolean exception) { CompletableFuture<Long> result = counterManager(0).getStrongCounter(name).addAndGet(delta); if (exception) { expectException(CounterOutOfBoundsException.class, () -> awaitCounterOperation(result)); } else { awaitCounterOperation(result); } }
@Override protected StrongTestCounter createCounter(CounterManager counterManager, String counterName, long initialValue) { counterManager.defineCounter(counterName, CounterConfiguration.builder(CounterType.UNBOUNDED_STRONG).initialValue(initialValue).build()); return new StrongTestCounter(counterManager.getStrongCounter(counterName)); }
@Override public void testCompareAndSet(Method method) { final String counterName = method.getName(); final CounterManager counterManager = counterManagerSupplier.get(); assertTrue(counterManager.defineCounter(counterName, builder(UNBOUNDED_STRONG).initialValue(2).build())); StrongCounter counter = counterManager.getStrongCounter(counterName); assertFalse(awaitCounterOperation(counter.compareAndSet(0, 1))); assertTrue(awaitCounterOperation(counter.compareAndSet(2, 3))); }
@Override public void testCompareAndSwap(Method method) { final String counterName = method.getName(); final CounterManager counterManager = counterManagerSupplier.get(); assertTrue(counterManager.defineCounter(counterName, builder(UNBOUNDED_STRONG).initialValue(3).build())); StrongCounter counter = counterManager.getStrongCounter(counterName); assertEquals(3, (long) awaitCounterOperation(counter.compareAndSwap(0, 1))); assertEquals(3, (long) awaitCounterOperation(counter.compareAndSwap(3, 2))); }
@Override public TestCounter getCounter(EmbeddedCacheManager manager, String counterName) { CounterManager counterManager = asCounterManager(manager); counterManager.defineCounter(counterName, CounterConfiguration.builder(CounterType.BOUNDED_STRONG).upperBound(Long.MAX_VALUE) .lowerBound(Long.MIN_VALUE) .build()); return new StrongTestCounter(counterManager.getStrongCounter(counterName)); } },
@Override protected StrongTestCounter createCounter(CounterManager counterManager, String counterName, long initialValue) { counterManager.defineCounter(counterName, CounterConfiguration.builder(CounterType.BOUNDED_STRONG).lowerBound(Long.MIN_VALUE) .upperBound(Long.MAX_VALUE).initialValue(initialValue).build()); return new StrongTestCounter(counterManager.getStrongCounter(counterName)); }
public void testSimpleThreshold(Method method) { CounterManager counterManager = counterManager(0); counterManager.defineCounter(method.getName(), CounterConfiguration.builder(CounterType.BOUNDED_STRONG).lowerBound(-1).upperBound(1).build()); StrongTestCounter counter = new StrongTestCounter(counterManager.getStrongCounter(method.getName())); addAndAssertResult(counter, 1, 1); assertOutOfBoundsAdd(counter, 1, 1); addAndAssertResult(counter, -1, 0); addAndAssertResult(counter, -1, -1); assertOutOfBoundsAdd(counter, -1, -1); counter.reset(); assertOutOfBoundsAdd(counter, 2, 1); assertOutOfBoundsAdd(counter, -3, -1); }