Search in sources :

Example 11 with TimeStep

use of com.hazelcast.simulator.test.annotations.TimeStep in project hazelcast-simulator by hazelcast.

the class ListenerICacheTest method getExpiryAsync.

@TimeStep(prob = 0)
public void getExpiryAsync(ThreadState state) throws ExecutionException, InterruptedException {
    int expiryDuration = state.randomInt(maxExpiryDurationMs);
    ExpiryPolicy expiryPolicy = new CreatedExpiryPolicy(new Duration(MILLISECONDS, expiryDuration));
    int key = state.randomInt(keyCount);
    Future<Long> future = cache.getAsync(key, expiryPolicy);
    future.get();
    state.getAsyncExpiry++;
}
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 12 with TimeStep

use of com.hazelcast.simulator.test.annotations.TimeStep in project hazelcast-simulator by hazelcast.

the class ListenerICacheTest method getExpiry.

@TimeStep(prob = 0)
public void getExpiry(ThreadState state) {
    int expiryDuration = state.randomInt(maxExpiryDurationMs);
    ExpiryPolicy expiryPolicy = new CreatedExpiryPolicy(new Duration(MILLISECONDS, expiryDuration));
    int key = state.randomInt(keyCount);
    cache.get(key, expiryPolicy);
    state.getExpiry++;
}
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 13 with TimeStep

use of com.hazelcast.simulator.test.annotations.TimeStep in project hazelcast-simulator by hazelcast.

the class LeaseLockTest method timeStep.

@TimeStep
public void timeStep(BaseThreadState state) {
    int lockIndex = state.randomInt(lockCount);
    ILock lock = targetInstance.getLock(name + lockIndex);
    int leaseTime = 1 + state.randomInt(maxLeaseTimeMillis);
    int tryTime = 1 + state.randomInt(maxTryTimeMillis);
    if (state.randomBoolean()) {
        lock.lock(leaseTime, MILLISECONDS);
    } else {
        try {
            lock.tryLock(tryTime, MILLISECONDS, leaseTime, MILLISECONDS);
        } catch (InterruptedException e) {
            logger.info("tryLock() got exception: " + e.getMessage());
        }
    }
}
Also used : ILock(com.hazelcast.core.ILock) TimeStep(com.hazelcast.simulator.test.annotations.TimeStep)

Example 14 with TimeStep

use of com.hazelcast.simulator.test.annotations.TimeStep in project hazelcast-simulator by hazelcast.

the class SimpleLockTest method timeStep.

@TimeStep
public void timeStep(BaseThreadState state) {
    int key1 = state.randomInt(maxAccounts);
    int key2;
    do {
        key2 = state.randomInt(maxAccounts);
    } while (key1 == key2);
    ILock lock1 = targetInstance.getLock(name + key1);
    if (lock1.tryLock()) {
        try {
            ILock lock2 = targetInstance.getLock(name + key2);
            if (lock2.tryLock()) {
                try {
                    IAtomicLong account1 = targetInstance.getAtomicLong(name + key1);
                    IAtomicLong account2 = targetInstance.getAtomicLong(name + key2);
                    int delta = state.randomInt(100);
                    if (account1.get() >= delta) {
                        account1.set(account1.get() - delta);
                        account2.set(account2.get() + delta);
                    }
                } finally {
                    lock2.unlock();
                }
            }
        } finally {
            lock1.unlock();
        }
    }
}
Also used : ILock(com.hazelcast.core.ILock) IAtomicLong(com.hazelcast.core.IAtomicLong) TimeStep(com.hazelcast.simulator.test.annotations.TimeStep)

Example 15 with TimeStep

use of com.hazelcast.simulator.test.annotations.TimeStep in project hazelcast-simulator by hazelcast.

the class ExecutorTest method timeStep.

@TimeStep
public void timeStep(ThreadState state) throws Exception {
    int index = state.randomInt(executors.length);
    IExecutorService executorService = executors[index];
    state.futureList.clear();
    for (int i = 0; i < submitCount; i++) {
        Future future = executorService.submit(new Task(testContext.getTestId()));
        state.futureList.add(future);
        state.iteration++;
    }
    for (Future future : state.futureList) {
        future.get();
    }
}
Also used : Future(java.util.concurrent.Future) IExecutorService(com.hazelcast.core.IExecutorService) 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