use of com.hazelcast.simulator.test.annotations.TimeStep in project hazelcast-simulator by hazelcast.
the class TryLockTimeOutTest method timeStep.
@SuppressWarnings("checkstyle:nestedtrydepth")
@TimeStep
public void timeStep(ThreadState state) {
int key1 = state.randomInt(maxAccounts);
int key2 = state.randomInt(maxAccounts);
ILock outerLock = targetInstance.getLock(name + key1);
try {
if (outerLock.tryLock(tryLockTimeOutMs, TimeUnit.MILLISECONDS)) {
try {
ILock innerLock = targetInstance.getLock(name + key2);
try {
if (innerLock.tryLock(tryLockTimeOutMs, TimeUnit.MILLISECONDS)) {
try {
IList<Long> accounts = targetInstance.getList(name);
int delta = state.random.nextInt(100);
if (accounts.get(key1) >= delta) {
accounts.set(key1, accounts.get(key1) - delta);
accounts.set(key2, accounts.get(key2) + delta);
state.counter.transfers++;
}
} finally {
innerLock.unlock();
}
}
} catch (InterruptedException e) {
logger.fatal("innerLock " + e.getMessage(), e);
state.counter.interruptedException++;
}
} finally {
outerLock.unlock();
}
}
} catch (InterruptedException e) {
logger.fatal("outerLock " + e.getMessage(), e);
state.counter.interruptedException++;
}
}
use of com.hazelcast.simulator.test.annotations.TimeStep in project hazelcast-simulator by hazelcast.
the class CreateDestroyICacheTest method closeCache.
@TimeStep(prob = 0.2)
public void closeCache(ThreadState state) {
try {
Cache cache = cacheManager.getCache(name);
if (cache != null) {
cache.close();
state.counter.close++;
}
} catch (IllegalStateException e) {
state.counter.closeException++;
}
}
use of com.hazelcast.simulator.test.annotations.TimeStep in project hazelcast-simulator by hazelcast.
the class CacheLoaderTest method timeStep.
@TimeStep
public void timeStep() throws ExecutionException, InterruptedException {
CompletionListenerFuture loaded = new CompletionListenerFuture();
cache.loadAll(keySet, true, loaded);
if (waitForLoadAllFutureCompletion) {
loaded.get();
}
}
use of com.hazelcast.simulator.test.annotations.TimeStep in project hazelcast-simulator by hazelcast.
the class ListenerICacheTest method putExpiryAsync.
@TimeStep(prob = 0)
public void putExpiryAsync(ThreadState state) {
int expiryDuration = state.randomInt(maxExpiryDurationMs);
ExpiryPolicy expiryPolicy = new CreatedExpiryPolicy(new Duration(MILLISECONDS, expiryDuration));
int key = state.randomInt(keyCount);
cache.putAsync(key, state.randomLong(), expiryPolicy);
state.putAsyncExpiry++;
}
use of com.hazelcast.simulator.test.annotations.TimeStep in project hazelcast-simulator by hazelcast.
the class MapTransactionContextTest method timestep.
@TimeStep
public void timestep(ThreadState state) {
int key = state.nextRandom(0, range / 2);
TransactionOptions transactionOptions = new TransactionOptions().setTransactionType(transactionType).setDurability(durability);
TransactionContext transactionContext = targetInstance.newTransactionContext(transactionOptions);
transactionContext.beginTransaction();
TransactionalMap<Object, Object> txMap = transactionContext.getMap("map");
try {
Object val = txMap.getForUpdate(key);
if (val != null) {
key = state.nextRandom(range / 2, range);
}
txMap.put(key, (long) key);
transactionContext.commitTransaction();
} catch (Exception e) {
logger.fatal("----------------------tx exception -------------------------", e);
if (failOnException) {
throw rethrow(e);
}
transactionContext.rollbackTransaction();
}
}
Aggregations