@Setup public void setup() { values = new Object[valueCount]; Random random = new Random(); for (int i = 0; i < valueCount; i++) { if (useStringValue) { values[i] = generateString(valueLength); } else { values[i] = generateByteArray(random, valueLength); } } counters = getCounters(); String[] names = generateStringKeys(name, countersLength, keyLocality, targetInstance); for (int i = 0; i < counters.length; i++) { IAtomicReference<Object> atomicReference = targetInstance.getAtomicReference(names[i]); atomicReference.set(values[random.nextInt(values.length)]); counters[i] = atomicReference; } }
@Teardown public void teardown() { for (IAtomicReference counter : counters) { counter.destroy(); } logger.info(getOperationCountInformation(targetInstance)); }
@Override public <E> IAtomicReference<E> getAtomicReference(String s) { return null; }
@Override public <E> IAtomicReference<E> getAtomicReference(final String name) { return getHazelcastInstance().getAtomicReference(name); }
@SuppressWarnings("unchecked") private IAtomicReference<Object>[] getCounters() { return (IAtomicReference<Object>[]) new IAtomicReference[countersLength]; }
@TimeStep(prob = 1) public void put(ThreadState state) { IAtomicReference<Object> counter = state.getRandomCounter(); Object value = values[state.randomInt(values.length)]; counter.set(value); }
@TimeStep(prob = -1) public void get(ThreadState state) { IAtomicReference<Object> counter = state.getRandomCounter(); counter.get(); }
private IAtomicReference<Object> getRandomCounter() { return counters[randomInt(counters.length)]; }
/** * Returns the atomic reference related with the given name. * * @param referenceName the atomic reference * @return the name of atomic reference * @throws NullPointerException if the given name is {@code null} */ private static <T> IAtomicReference<T> getAtomicReference(final String referenceName) { Objects.requireNonNull(referenceName, "The given atomic reference name must not be null."); return Holder.INSTANCE.getInstance().getAtomicReference(referenceName); }