Search in sources :

Example 6 with TestCase

use of com.hazelcast.simulator.common.TestCase in project hazelcast-simulator by hazelcast.

the class TestSuite method load.

@SuppressFBWarnings("DM_DEFAULT_ENCODING")
private void load(String testContent) {
    Properties properties = new Properties();
    try {
        properties.load(new StringReader(testContent));
    } catch (UnsupportedEncodingException e) {
        throw rethrow(e);
    } catch (IOException e) {
        throw rethrow(e);
    }
    Map<String, TestCase> testCases = createTestCases(properties);
    if (testCases.isEmpty()) {
        throw new BindException("No tests are defined.");
    }
    if (testCases.size() == 1) {
        // use classname instead of empty desc in single test scenarios
        TestCase testCase = testCases.values().iterator().next();
        String className = testCase.getClassname();
        if (testCase.getId().isEmpty() && className != null) {
            String desc = className.substring(className.lastIndexOf('.') + 1);
            testCases = singletonMap(desc, new TestCase(desc, testCase.getProperties()));
        }
    }
    for (String testCaseId : getTestCaseIds(testCases)) {
        TestCase testCase = testCases.get(testCaseId);
        if (testCase.getClassname() == null) {
            String msg;
            if (testCaseId.isEmpty()) {
                msg = "There is no class set. Add class=YourTestClass";
            } else {
                msg = format("There is no class set for test [%s]. Add %s.class=YourTestClass", testCaseId, testCaseId);
            }
            throw new BindException(msg);
        }
        addTest(testCase);
    }
}
Also used : TestCase(com.hazelcast.simulator.common.TestCase) StringReader(java.io.StringReader) UnsupportedEncodingException(java.io.UnsupportedEncodingException) BindException(com.hazelcast.simulator.utils.BindException) IOException(java.io.IOException) Properties(java.util.Properties) SuppressFBWarnings(edu.umd.cs.findbugs.annotations.SuppressFBWarnings)

Example 7 with TestCase

use of com.hazelcast.simulator.common.TestCase in project hazelcast-simulator by hazelcast.

the class TestSuite method getOrCreateTestCase.

private static TestCase getOrCreateTestCase(Map<String, TestCase> testCases, String testCaseId) {
    TestCase testCase = testCases.get(testCaseId);
    if (testCase == null) {
        if (!testCaseId.isEmpty() && !isValidFileName(testCaseId)) {
            throw new IllegalArgumentException(format("Can't create TestCase: testId [%s] is an invalid filename for performance log", testCaseId));
        }
        testCase = new TestCase(testCaseId);
        testCases.put(testCaseId, testCase);
    }
    return testCase;
}
Also used : TestCase(com.hazelcast.simulator.common.TestCase)

Example 8 with TestCase

use of com.hazelcast.simulator.common.TestCase in project hazelcast-simulator by hazelcast.

the class TestContainer_TimeStep_MaxIterationsTest method test.

@Test
public void test() throws Exception {
    MaxIterationTest testInstance = new MaxIterationTest();
    TestCase testCase = new TestCase("stopRun").setProperty("threadCount", 1).setProperty("iterations", 100).setProperty("class", testInstance.getClass());
    TestContextImpl testContext = new TestContextImpl(testCase.getId(), "localhost", mock(Server.class));
    final TestContainer container = new TestContainer(testContext, testInstance, testCase);
    container.invoke(SETUP);
    for (TestPhase phase : TestPhase.values()) {
        container.invoke(phase);
    }
    assertNoExceptions();
    assertEquals(100, testInstance.runCount.get());
}
Also used : Server(com.hazelcast.simulator.protocol.Server) TestCase(com.hazelcast.simulator.common.TestCase) TestPhase(com.hazelcast.simulator.common.TestPhase) Test(org.junit.Test)

Example 9 with TestCase

use of com.hazelcast.simulator.common.TestCase in project hazelcast-simulator by hazelcast.

the class TestContainer_TimeStep_OrderTest method test.

@Test
public void test() throws Exception {
    TestInstance testInstance = new TestInstance();
    TestCase testCase = new TestCase("exceptionTest").setProperty("threadCount", 1).setProperty("class", testInstance.getClass());
    TestContextImpl testContext = new TestContextImpl(testCase.getId(), "localhost", mock(Server.class));
    final TestContainer container = new TestContainer(testContext, testInstance, testCase);
    container.invoke(SETUP);
    Future f = spawn(new Callable() {

        @Override
        public Object call() throws Exception {
            container.invoke(RUN);
            return null;
        }
    });
    assertCompletesEventually(f);
    assertNoExceptions();
    assertEquals(asList("beforeRun", "timeStep", "afterRun"), testInstance.calls);
}
Also used : Server(com.hazelcast.simulator.protocol.Server) TestCase(com.hazelcast.simulator.common.TestCase) Future(java.util.concurrent.Future) Callable(java.util.concurrent.Callable) StopException(com.hazelcast.simulator.test.StopException) Test(org.junit.Test)

Example 10 with TestCase

use of com.hazelcast.simulator.common.TestCase in project hazelcast-simulator by hazelcast.

the class TestContainer_TimeStep_StartNanosTest method testWithoutMetronome.

@Test
public void testWithoutMetronome() throws Exception {
    StartNanosTest testInstance = new StartNanosTest();
    TestCase testCase = new TestCase("test").setProperty("iterations", 10).setProperty("threadCount", 1).setProperty("class", testInstance.getClass());
    TestContextImpl testContext = new TestContextImpl(testCase.getId(), "localhost", mock(Server.class));
    TestContainer container = new TestContainer(testContext, testInstance, testCase);
    for (TestPhase phase : TestPhase.values()) {
        container.invoke(phase);
    }
    List<Long> startNanosList = testInstance.startNanosList;
    assertEquals(10, startNanosList.size());
}
Also used : Server(com.hazelcast.simulator.protocol.Server) TestCase(com.hazelcast.simulator.common.TestCase) TestPhase(com.hazelcast.simulator.common.TestPhase) Test(org.junit.Test)

Aggregations

TestCase (com.hazelcast.simulator.common.TestCase)74 Test (org.junit.Test)61 Server (com.hazelcast.simulator.protocol.Server)18 SuccessTest (com.hazelcast.simulator.tests.SuccessTest)13 Callable (java.util.concurrent.Callable)11 Future (java.util.concurrent.Future)11 FailingTest (com.hazelcast.simulator.tests.FailingTest)10 CreateTestOperation (com.hazelcast.simulator.worker.operations.CreateTestOperation)9 StoppingTest (com.hazelcast.simulator.tests.StoppingTest)8 TestPhase (com.hazelcast.simulator.common.TestPhase)7 StubPromise (com.hazelcast.simulator.protocol.StubPromise)6 StartPhaseOperation (com.hazelcast.simulator.worker.operations.StartPhaseOperation)6 StopException (com.hazelcast.simulator.test.StopException)5 TestSuite (com.hazelcast.simulator.coordinator.TestSuite)4 BusySpinningMetronome (com.hazelcast.simulator.worker.metronome.BusySpinningMetronome)4 EmptyMetronome (com.hazelcast.simulator.worker.metronome.EmptyMetronome)4 Metronome (com.hazelcast.simulator.worker.metronome.Metronome)4 SleepingMetronome (com.hazelcast.simulator.worker.metronome.SleepingMetronome)4 BaseThreadState (com.hazelcast.simulator.test.BaseThreadState)2 HashMap (java.util.HashMap)2