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));
}
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();
}
}
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();
}
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));
}
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));
}
Aggregations