Search in sources :

Example 16 with TimeStep

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

the class BucketReadWriteTest method put.

@TimeStep(prob = 0.1)
public JsonDocument put(ThreadState state) {
    int key = state.randomInt(keyDomain);
    JsonObject content = JsonObject.create().put("x", values[state.randomInt(valueCount)]);
    return bucket.upsert(JsonDocument.create("" + key, content));
}
Also used : JsonObject(com.couchbase.client.java.document.json.JsonObject) TimeStep(com.hazelcast.simulator.test.annotations.TimeStep)

Example 17 with TimeStep

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

the class LockTest method timeStep.

@TimeStep
public void timeStep(ThreadState state) {
    long key1 = state.getRandomAccountKey();
    long key2 = state.getRandomAccountKey();
    int randomAmount = state.randomInt(amount);
    ILock lock1 = targetInstance.getLock(getLockId(key1));
    ILock lock2 = targetInstance.getLock(getLockId(key2));
    IAtomicLong account1 = targetInstance.getAtomicLong(getAccountId(key1));
    IAtomicLong account2 = targetInstance.getAtomicLong(getAccountId(key2));
    if (!lock1.tryLock()) {
        return;
    }
    try {
        if (!lock2.tryLock()) {
            return;
        }
        try {
            if (account1.get() < 0 || account2.get() < 0) {
                throw new TestException("Amount on account can't be smaller than 0");
            }
            if (account1.get() < randomAmount) {
                return;
            }
            account1.set(account1.get() - randomAmount);
            account2.set(account2.get() + randomAmount);
        } finally {
            lock2.unlock();
        }
    } finally {
        lock1.unlock();
    }
}
Also used : TestException(com.hazelcast.simulator.test.TestException) ILock(com.hazelcast.core.ILock) IAtomicLong(com.hazelcast.core.IAtomicLong) TimeStep(com.hazelcast.simulator.test.annotations.TimeStep)

Example 18 with TimeStep

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

the class NetworkTest method timeStep.

@TimeStep
public void timeStep(ThreadState state) throws Exception {
    if (state.responseFuture.thread == null) {
        state.responseFuture.thread = Thread.currentThread();
    }
    Connection connection = state.nextConnection();
    byte[] payload = makePayload(payloadSize);
    Packet requestPacket = new Packet(payload, state.workerId);
    if (!connection.write(requestPacket)) {
        throw new TestException("Failed to write packet to connection %s", connection);
    }
    try {
        state.responseFuture.get(requestTimeout, requestTimeUnit);
    } catch (Exception e) {
        throw new TestException("Failed to receive request from connection %s within timeout %d %s", connection, requestTimeout, requestTimeUnit, e);
    }
    state.responseFuture.reset();
}
Also used : Packet(com.hazelcast.nio.Packet) TestException(com.hazelcast.simulator.test.TestException) Connection(com.hazelcast.nio.Connection) TestException(com.hazelcast.simulator.test.TestException) TimeStep(com.hazelcast.simulator.test.annotations.TimeStep)

Example 19 with TimeStep

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

the class AsyncAtomicLongTest method write.

@TimeStep
public void write(ThreadState state, Probe probe, @StartNanos long startNanos) {
    AsyncAtomicLong counter = state.getRandomCounter();
    state.increments++;
    ICompletableFuture<Long> future = counter.asyncIncrementAndGet();
    state.add(future);
    future.andThen(new LongExecutionCallback(probe, startNanos));
}
Also used : AsyncAtomicLong(com.hazelcast.core.AsyncAtomicLong) AsyncAtomicLong(com.hazelcast.core.AsyncAtomicLong) IAtomicLong(com.hazelcast.core.IAtomicLong) TimeStep(com.hazelcast.simulator.test.annotations.TimeStep)

Example 20 with TimeStep

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

the class AsyncAtomicLongTest method get.

@TimeStep(prob = -1)
public void get(ThreadState state, Probe probe, @StartNanos long startNanos) {
    AsyncAtomicLong counter = state.getRandomCounter();
    ICompletableFuture<Long> future = counter.asyncGet();
    state.add(future);
    future.andThen(new LongExecutionCallback(probe, startNanos));
}
Also used : AsyncAtomicLong(com.hazelcast.core.AsyncAtomicLong) AsyncAtomicLong(com.hazelcast.core.AsyncAtomicLong) IAtomicLong(com.hazelcast.core.IAtomicLong) 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