private void defineCounter(CounterManager counterManager, String counterName, int initialValue) { counterManager.defineCounter( counterName, CounterConfiguration.builder( CounterType.UNBOUNDED_STRONG ) .initialValue( initialValue ) .storage( Storage.PERSISTENT ) .build() ); } }
@Override protected StrongTestCounter createCounter(CounterManager counterManager, String counterName, CounterConfiguration configuration) { counterManager.defineCounter(counterName, configuration); return new StrongTestCounter(counterManager.getStrongCounter(counterName)); }
@Override protected WeakTestCounter createCounter(CounterManager counterManager, String counterName, CounterConfiguration configuration) { counterManager.defineCounter(counterName, configuration); return new WeakTestCounter(counterManager.getWeakCounter(counterName)); }
@Override void define(CounterManager manager, String name) { manager.defineCounter(name, builder(CounterType.WEAK).initialValue(10).build()); }
private void checkRemove(String name, CounterConfiguration config, long add1Result, long add2Result, Consumer<String> add1, Consumer<String> add2, Function<String, Long> getValue) { assertTrue(counterManager(0).defineCounter(name, config)); add1.accept(name); assertEquals(add1Result, (long) getValue.apply(name)); executeCounterNameArgOperation(0, "remove", name); assertEquals(config.initialValue(), (long) getValue.apply(name)); add2.accept(name); assertEquals(add2Result, (long) getValue.apply(name)); executeCounterNameArgOperation(1, "remove", name); assertEquals(config.initialValue(), (long) getValue.apply(name)); }
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 WeakCounter defineAndCreateCounter(String counterName, long initialValue) { final CounterManager counterManager = counterManagerSupplier.get(); assertTrue(counterManager .defineCounter(counterName, builder(WEAK).initialValue(initialValue).concurrencyLevel(8).build())); return counterManager.getWeakCounter(counterName); }
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 void define(CounterManager manager, String name) { manager.defineCounter(name, builder(CounterType.BOUNDED_STRONG).initialValue(10).lowerBound(0).upperBound(20).build()); }
@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 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 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)); }
private void checkValueAndReset(String name, CounterConfiguration config, long addResult, Consumer<String> add, Consumer<String> reset) { assertTrue(counterManager(0).defineCounter(name, config)); assertJmxResult(config.initialValue(), i -> executeCounterNameArgOperation(i, "value", name), AssertJUnit::assertEquals); add.accept(name); assertJmxResult(addResult, i -> executeCounterNameArgOperation(i, "value", name), AssertJUnit::assertEquals); reset.accept(name); assertJmxResult(config.initialValue(), i -> executeCounterNameArgOperation(i, "value", name), AssertJUnit::assertEquals); }
@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)); } };
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()); }
@Override protected WeakTestCounter createCounter(CounterManager counterManager, String counterName, long initialValue) { counterManager.defineCounter(counterName, CounterConfiguration.builder(CounterType.WEAK).initialValue(initialValue).concurrencyLevel(4).build()); return new WeakTestCounter(counterManager.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)); } },
@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)); }
private void assertConfiguration(String name, Properties props, CounterConfiguration config) { assertTrue(counterManager(0).defineCounter(name, config)); assertJmxResult(props, i -> executeCounterNameArgOperation(i, "configuration", name), AssertJUnit::assertEquals); assertEquals(props, PropertyFormatter.getInstance().format(config)); assertEquals(config, fromProperties(props)); }
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); } }