@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 CounterConfiguration readObject(ObjectInput input) throws IOException, ClassNotFoundException { byte flags = input.readByte(); CounterType type = decodeType(flags); Builder builder = builder(type); builder.storage(decodeStorage(flags)); builder.initialValue(input.readLong()); switch (type) { case BOUNDED_STRONG: builder.lowerBound(input.readLong()); builder.upperBound(input.readLong()); break; case WEAK: builder.concurrencyLevel(readUnsignedInt(input)); break; default: } return builder.build(); } }
hr2x_counterConfiguration.concurrencyLevel(hr2x_vInt);
/** * Decodes a {@link CounterConfiguration} encoded by {@link #encodeConfiguration(CounterConfiguration, Consumer, * LongConsumer, IntConsumer)}. * * @return the decoded {@link CounterConfiguration}. * @see #encodeConfiguration(CounterConfiguration, Consumer, LongConsumer, IntConsumer) */ public static CounterConfiguration decodeConfiguration(Supplier<Byte> byteSupplier, LongSupplier longSupplier, IntSupplier intSupplier) { byte flags = byteSupplier.get(); CounterType type = decodeType(flags); CounterConfiguration.Builder builder = CounterConfiguration.builder(type); builder.storage(decodeStorage(flags)); switch (type) { case WEAK: builder.concurrencyLevel(intSupplier.getAsInt()); break; case BOUNDED_STRONG: builder.lowerBound(longSupplier.getAsLong()); builder.upperBound(longSupplier.getAsLong()); break; case UNBOUNDED_STRONG: default: break; } builder.initialValue(longSupplier.getAsLong()); return builder.build(); }
@Override List<CounterConfiguration> configurationsToTest() { return singletonList(builder(WEAK).initialValue(1).concurrencyLevel(2).build()); }
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()); }
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 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)); } }
protected TestCounter createCounter(CounterManager counterManager, String counterName) { counterManager.defineCounter(counterName, CounterConfiguration.builder(CounterType.WEAK).concurrencyLevel(4).build()); return new WeakTestCounter(counterManager.getWeakCounter(counterName)); } }
@Override protected List<CounterConfiguration> configurationToTest() { return Arrays.asList( CounterConfiguration.builder(CounterType.WEAK).initialValue(10).concurrencyLevel(10).build(), CounterConfiguration.builder(CounterType.WEAK).initialValue(20).concurrencyLevel(20).build(), CounterConfiguration.builder(CounterType.WEAK).build() ); }
@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); }
/** * Implementation of abstract method processModelNode * */ @Override void processModelNode(OperationContext context, ModelNode counter, CounterConfiguration.Builder builder) throws OperationFailedException { super.processModelNode(context, counter, builder); Integer concurrency = WeakCounterResource.CONCURRENCY_LEVEL.resolveModelAttribute(context, counter).asInt(); builder.concurrencyLevel(concurrency); } }
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()); }