Search in sources :

Example 1 with TestException

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();
    }
}
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 2 with TestException

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);
}
Also used : TestException(com.hazelcast.simulator.test.TestException) TestCase(com.hazelcast.simulator.common.TestCase) Before(org.junit.Before)

Example 3 with TestException

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();
}
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 4 with TestException

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);
    }
}
Also used : HistogramLogWriter(org.HdrHistogram.HistogramLogWriter) TestException(com.hazelcast.simulator.test.TestException) IOException(java.io.IOException) File(java.io.File)

Aggregations

TestException (com.hazelcast.simulator.test.TestException)4 TimeStep (com.hazelcast.simulator.test.annotations.TimeStep)2 IAtomicLong (com.hazelcast.core.IAtomicLong)1 ILock (com.hazelcast.core.ILock)1 Connection (com.hazelcast.nio.Connection)1 Packet (com.hazelcast.nio.Packet)1 TestCase (com.hazelcast.simulator.common.TestCase)1 File (java.io.File)1 IOException (java.io.IOException)1 HistogramLogWriter (org.HdrHistogram.HistogramLogWriter)1 Before (org.junit.Before)1