@Override public void testWeakCounter(Method method) { final Random random = generateRandom(); final String counterName = method.getName(); CounterConfiguration config = builder(CounterType.WEAK) .initialValue(random.nextInt()) .storage(random.nextBoolean() ? Storage.VOLATILE : Storage.PERSISTENT) .concurrencyLevel(abs(random.nextInt())) .build(); doCreationTest(counterName, config); }
private void doCreationTest(String name, CounterConfiguration config) { List<CounterManager> remoteCounterManagers = allRemoteCounterManagerSupplier.get(); assertTrue(remoteCounterManagers.get(0).defineCounter(name, config)); remoteCounterManagers.forEach(cm -> assertFalse(cm.defineCounter(name, builder(CounterType.WEAK).build()))); remoteCounterManagers.forEach(cm -> assertTrue(cm.isDefined(name))); remoteCounterManagers.forEach(cm -> assertEquals(config, cm.getConfiguration(name))); //test single embedded counter manager to check if everything is correctly stored EmbeddedCacheManager cacheManager = cacheManagerSupplier.get(); CounterManager counterManager = EmbeddedCounterManagerFactory.asCounterManager(cacheManager); assertTrue(counterManager.isDefined(name)); assertEquals(config, counterManager.getConfiguration(name)); }
@Override public void testLowerBoundedStrongCounter(Method method) { final Random random = generateRandom(); final String counterName = method.getName(); CounterConfiguration config = builder(CounterType.BOUNDED_STRONG) .initialValue(15) .lowerBound(5) .storage(random.nextBoolean() ? Storage.VOLATILE : Storage.PERSISTENT) .build(); doCreationTest(counterName, config); }
@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)); }
@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)); }
public void testRemove() { checkRemove("A", builder(CounterType.WEAK).initialValue(10).build(), 121, 20, s -> addToWeakCounter(s, 111), s -> addToWeakCounter(s, 10), this::getWeakCounterValue); checkRemove("B", builder(CounterType.UNBOUNDED_STRONG).initialValue(-10).build(), -11, -9, s -> addToStrongCounter(s, -1, false), s -> addToStrongCounter(s, 1, false), this::getStrongCounterValue); }
private static WeakCounterImpl getCounter(EmbeddedCacheManager manager, String counterName) { CounterManager counterManager = asCounterManager(manager); counterManager .defineCounter(counterName, CounterConfiguration.builder(CounterType.WEAK).concurrencyLevel(128).build()); return (WeakCounterImpl) counterManager.getWeakCounter(counterName); }
@Override public void testBoundedStrongCounter(Method method) { final Random random = generateRandom(); final String counterName = method.getName(); CounterConfiguration config = builder(CounterType.BOUNDED_STRONG) .initialValue(15) .lowerBound(5) .upperBound(20) .storage(random.nextBoolean() ? Storage.VOLATILE : Storage.PERSISTENT) .build(); doCreationTest(counterName, config); }
@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)); } },
public void testLazyStart() { for (EmbeddedCacheManager manager : cacheManagers) { assertFalse(manager.isRunning(CounterModuleLifecycle.COUNTER_CACHE_NAME)); } counterManager(0).defineCounter("some-counter", CounterConfiguration.builder(CounterType.WEAK).build()); for (EmbeddedCacheManager manager : cacheManagers) { eventually(() -> "counter cache didn't start in " + manager.getTransport().getAddress(), () -> manager.isRunning(CounterModuleLifecycle.COUNTER_CACHE_NAME), 30, TimeUnit.SECONDS); } }
@Override void define(CounterManager manager, String name) { manager.defineCounter(name, builder(CounterType.BOUNDED_STRONG).initialValue(10).lowerBound(0).upperBound(20).build()); }
public void testDefinedCounters() { final Collection<String> list = new ArrayList<>(3); assertJmxResult(list, this::executeCountersOperation, CounterJmxTest::assertCollection); addCounterAndCheckList(list, "A", builder(CounterType.WEAK).build()); addCounterAndCheckList(list, "B", builder(CounterType.BOUNDED_STRONG).build()); addCounterAndCheckList(list, "C", builder(CounterType.UNBOUNDED_STRONG).build()); }
public void testSingleConcurrencyLevel() throws ExecutionException, InterruptedException { final CounterManager counterManager = EmbeddedCounterManagerFactory.asCounterManager(manager(0)); final String counterName = "c1-counter"; counterManager.defineCounter(counterName, CounterConfiguration.builder(CounterType.WEAK).concurrencyLevel(1).build()); WeakCounter wc = counterManager.getWeakCounter(counterName); wc.add(2).get(); assertEquals(2, wc.getValue()); }
private void defineCounter(CounterManager counterManager, String counterName, int initialValue) { counterManager.defineCounter( counterName, CounterConfiguration.builder( CounterType.UNBOUNDED_STRONG ) .initialValue( initialValue ) .storage( Storage.PERSISTENT ) .build() ); } }
@Override public TestCounter getCounter(EmbeddedCacheManager manager, String counterName) { CounterManager counterManager = asCounterManager(manager); counterManager.defineCounter(counterName, CounterConfiguration.builder(CounterType.WEAK).build()); return new WeakTestCounter(asCounterManager(manager).getWeakCounter(counterName)); } };
@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)); } },
public void testGetValueAndReset() { checkValueAndReset("A", builder(CounterType.WEAK).initialValue(10).build(), 20, s -> addToWeakCounter(s, 10), this::resetWeakCounter); checkValueAndReset("B", builder(CounterType.UNBOUNDED_STRONG).initialValue(-10).build(), 5, s -> addToStrongCounter(s, 15, false), this::resetStrongCounter); checkValueAndReset("C", builder(CounterType.BOUNDED_STRONG).initialValue(1).lowerBound(0).upperBound(2).build(), 2, s -> addToStrongCounter(s, 3, true), this::resetStrongCounter); }
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 void testUpperBoundedStrongCounter(Method method) { final Random random = generateRandom(); final String counterName = method.getName(); CounterConfiguration config = builder(CounterType.BOUNDED_STRONG) .initialValue(5) .upperBound(15) .storage(random.nextBoolean() ? Storage.VOLATILE : Storage.PERSISTENT) .build(); doCreationTest(counterName, config); }