use of com.hazelcast.simulator.test.TestException 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.TestException in project hazelcast-simulator by hazelcast.
the class FailureOperationTest method before.
@Before
public void before() {
testCase = new TestCase(TEST_ID);
cause = new TestException("expected exception");
operation = new FailureOperation("FailureOperationTest", WORKER_EXCEPTION, workerAddress, null, cause);
fullOperation = new FailureOperation("FailureOperationTest", WORKER_EXCEPTION, workerAddress, null, "A1_W1-member", TEST_ID, null).setTestCase(testCase);
}
use of com.hazelcast.simulator.test.TestException 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.TestException in project hazelcast-simulator by hazelcast.
the class TestPerformanceTracker method createHistogramLogWriter.
HistogramLogWriter createHistogramLogWriter(String probeName) {
String testId = testContainer.getTestCase().getId();
try {
File latencyFile = getLatencyFile(testId, probeName);
HistogramLogWriter histogramLogWriter = new HistogramLogWriter(latencyFile);
histogramLogWriter.setBaseTime(startMeasuringTime());
histogramLogWriter.outputStartTime(startMeasuringTime());
histogramLogWriter.outputComment("[Latency histograms for " + testId + '.' + probeName + ']');
histogramLogWriter.outputLogFormatVersion();
histogramLogWriter.outputLegend();
return histogramLogWriter;
} catch (IOException e) {
throw new TestException("Could not initialize HistogramLogWriter for test " + testId, e);
}
}
Aggregations