Search in sources :

Example 56 with TestCase

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

the class TimeStepModel_probabilityTest method loadModel.

private TimeStepModel loadModel(String code, Map<String, Double> probs) {
    String header = "import java.util.*;\n" + "import com.hazelcast.simulator.test.annotations.*;\n" + "import com.hazelcast.simulator.test.annotations.*;\n";
    code = header + code;
    String className = "CLAZZ" + UUID.randomUUID().toString().replace("-", "");
    code = code.replace("CLAZZ", className);
    Class clazz;
    try {
        clazz = InMemoryJavaCompiler.compile(className, code);
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
    TestCase testCase = new TestCase("foo").setProperty("class", clazz);
    for (Map.Entry<String, Double> entry : probs.entrySet()) {
        testCase.setProperty(entry.getKey(), entry.getValue());
    }
    return new TimeStepModel(clazz, new PropertyBinding(testCase));
}
Also used : TestCase(com.hazelcast.simulator.common.TestCase) Map(java.util.Map) HashMap(java.util.HashMap)

Example 57 with TestCase

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

the class TestContainer_NestedPropertyBindingTest method testNestProperties.

@Test
public void testNestProperties() {
    TestCase testCase = new TestCase("id").setProperty("nested.intField", 10).setProperty("nested.booleanField", true).setProperty("nested.stringField", "somestring");
    DummyTest test = new DummyTest();
    testContainer = createTestContainer(test, testCase);
    assertNotNull(test.nested);
    assertEquals(10, test.nested.intField);
    assertEquals(true, test.nested.booleanField);
    assertEquals("somestring", test.nested.stringField);
}
Also used : TestCase(com.hazelcast.simulator.common.TestCase) Test(org.junit.Test)

Example 58 with TestCase

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

the class TestContainer_NestedPropertyBindingTest method testNestedPropertyNotFound.

@Test(expected = BindException.class)
public void testNestedPropertyNotFound() {
    TestCase testCase = new TestCase("id").setProperty("nested.notexist", 10);
    DummyTest test = new DummyTest();
    createTestContainer(test, testCase);
}
Also used : TestCase(com.hazelcast.simulator.common.TestCase) Test(org.junit.Test)

Example 59 with TestCase

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

the class TestContainer_TimeStep_AsyncSupportTest method createContainerAndRunTestInstance.

private TestContainer createContainerAndRunTestInstance(Object testInstance, int totalIterationCount) throws Exception {
    TestCase testCase = new TestCase("test").setProperty("iterations", totalIterationCount).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);
    }
    return container;
}
Also used : Server(com.hazelcast.simulator.protocol.Server) TestCase(com.hazelcast.simulator.common.TestCase) TestPhase(com.hazelcast.simulator.common.TestPhase)

Example 60 with TestCase

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

the class TestContainer_TimeStep_MultipleExecutionGroupsTest method test.

@Test
public void test() throws Exception {
    MultipleExecutionGroupsTest testInstance = new MultipleExecutionGroupsTest();
    TestCase testCase = new TestCase("multipleExecutionGroupsTest").setProperty("group1ThreadCount", 2).setProperty("group2ThreadCount", 3).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(2, testInstance.group1Threads.size());
    assertEquals(3, testInstance.group2Threads.size());
    assertTrue(disjoint(testInstance.group1Threads, testInstance.group2Threads));
}
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)

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