@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); }
@Override public void testUnboundedStrongCounter(Method method) { final Random random = generateRandom(); final String counterName = method.getName(); CounterConfiguration config = builder(CounterType.UNBOUNDED_STRONG) .initialValue(random.nextInt()) .storage(random.nextBoolean() ? Storage.VOLATILE : Storage.PERSISTENT) .build(); doCreationTest(counterName, config); }
void processModelNode(OperationContext context, ModelNode counter, CounterConfiguration.Builder builder) throws OperationFailedException { long initialValue = CounterResource.INITIAL_VALUE.resolveModelAttribute(context, counter).asLong(); String storageType = CounterResource.STORAGE.resolveModelAttribute(context, counter).asString(); builder.initialValue(initialValue); builder.storage(Storage.valueOf(storageType)); }
@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); }
@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 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 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 void define(CounterManager manager, String name) { manager.defineCounter(name, builder(CounterType.WEAK).initialValue(10).build()); }
@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 testGetConfiguration() { assertConfiguration("A", createWeakCounterProperties(), builder(CounterType.WEAK).initialValue(10).concurrencyLevel(1).build()); assertConfiguration("B", createUnboundedCounterProperties(), builder(CounterType.UNBOUNDED_STRONG).initialValue(5).build()); assertConfiguration("C", createBoundedCounterProperties(), builder(CounterType.BOUNDED_STRONG).initialValue(5).lowerBound(0).upperBound(10).build()); }
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); }
@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 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 void define(CounterManager manager, String name) { manager.defineCounter(name, builder(CounterType.BOUNDED_STRONG).initialValue(10).lowerBound(0).upperBound(20).build()); }
@Override List<CounterConfiguration> configurationsToTest() { return asList( builder(UNBOUNDED_STRONG).initialValue(5).build(), builder(BOUNDED_STRONG).initialValue(0).lowerBound(-1).upperBound(1).build() ); }
@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 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); }
private void defineCounter(CounterManager counterManager, String counterName, int initialValue) { counterManager.defineCounter( counterName, CounterConfiguration.builder( CounterType.UNBOUNDED_STRONG ) .initialValue( initialValue ) .storage( Storage.PERSISTENT ) .build() ); } }
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); }