Search in sources :

Example 21 with TimeStep

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++;
    }
}
Also used : ILock(com.hazelcast.core.ILock) TimeStep(com.hazelcast.simulator.test.annotations.TimeStep)

Example 22 with TimeStep

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++;
    }
}
Also used : Cache(javax.cache.Cache) TimeStep(com.hazelcast.simulator.test.annotations.TimeStep)

Example 23 with TimeStep

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();
    }
}
Also used : CompletionListenerFuture(javax.cache.integration.CompletionListenerFuture) TimeStep(com.hazelcast.simulator.test.annotations.TimeStep)

Example 24 with TimeStep

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++;
}
Also used : CreatedExpiryPolicy(javax.cache.expiry.CreatedExpiryPolicy) ExpiryPolicy(javax.cache.expiry.ExpiryPolicy) Duration(javax.cache.expiry.Duration) CreatedExpiryPolicy(javax.cache.expiry.CreatedExpiryPolicy) TimeStep(com.hazelcast.simulator.test.annotations.TimeStep)

Example 25 with TimeStep

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();
    }
}
Also used : TransactionOptions(com.hazelcast.transaction.TransactionOptions) TransactionContext(com.hazelcast.transaction.TransactionContext) TimeStep(com.hazelcast.simulator.test.annotations.TimeStep)

Aggregations

TimeStep (com.hazelcast.simulator.test.annotations.TimeStep)32 IAtomicLong (com.hazelcast.core.IAtomicLong)6 Predicate (com.hazelcast.query.Predicate)6 Employee (com.hazelcast.simulator.tests.map.helpers.Employee)6 SqlPredicate (com.hazelcast.query.SqlPredicate)5 ILock (com.hazelcast.core.ILock)4 CreatedExpiryPolicy (javax.cache.expiry.CreatedExpiryPolicy)4 Duration (javax.cache.expiry.Duration)4 ExpiryPolicy (javax.cache.expiry.ExpiryPolicy)4 AsyncAtomicLong (com.hazelcast.core.AsyncAtomicLong)2 EntryObject (com.hazelcast.query.EntryObject)2 PagingPredicate (com.hazelcast.query.PagingPredicate)2 PredicateBuilder (com.hazelcast.query.PredicateBuilder)2 TestException (com.hazelcast.simulator.test.TestException)2 TransactionContext (com.hazelcast.transaction.TransactionContext)2 Cache (javax.cache.Cache)2 JsonObject (com.couchbase.client.java.document.json.JsonObject)1 IExecutorService (com.hazelcast.core.IExecutorService)1 IMap (com.hazelcast.core.IMap)1 JobTracker (com.hazelcast.mapreduce.JobTracker)1