Search in sources :

Example 11 with TestCase

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

the class TestContainer_TimeStep_StartNanosTest method testWithMetronome.

@Test
public void testWithMetronome() throws Exception {
    long intervalUs = 50;
    StartNanosTest testInstance = new StartNanosTest();
    TestCase testCase = new TestCase("test").setProperty("iterations", 10).setProperty("interval", intervalUs + "us").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());
    long firstNanos = startNanosList.get(0);
    for (int k = 1; k < startNanosList.size(); k++) {
        long startNanos = startNanosList.get(k);
        assertEquals(firstNanos + k * TimeUnit.MICROSECONDS.toNanos(intervalUs), startNanos);
    }
}
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 12 with TestCase

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

the class TestContainer_TimeStep_ThrottlingLoggerTest method test.

@Test
public void test() throws Exception {
    ThrottlingLoggerTest testInstance = new ThrottlingLoggerTest();
    TestCase testCase = new TestCase("exceptionTest").setProperty("logRateMs", 1000).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);
    for (TestPhase phase : TestPhase.values()) {
        container.invoke(phase);
    }
}
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 13 with TestCase

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

the class TimeStepModel_IllegalTest method test_threadState_illegalArgumentCountInConstructor.

@Test(expected = IllegalTestException.class)
public void test_threadState_illegalArgumentCountInConstructor() {
    TestCase testCase = new TestCase("id");
    PropertyBinding binding = new PropertyBinding(testCase);
    new TimeStepModel(TestWithContextWithIllegalArgumentCountConstructor.class, binding);
}
Also used : TestCase(com.hazelcast.simulator.common.TestCase) Test(org.junit.Test)

Example 14 with TestCase

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

the class TimeStepModel_IllegalTest method assertBroken.

private static void assertBroken(String source) {
    String header = "import java.util.*;\n" + " import com.hazelcast.simulator.test.*;\n" + "import com.hazelcast.simulator.test.annotations.*;\n" + "import com.hazelcast.simulator.test.annotations.*;\n";
    source = header + source;
    String className = "CLAZZ" + UUID.randomUUID().toString().replace("-", "");
    source = source.replace("CLAZZ", className);
    Class clazz;
    try {
        clazz = InMemoryJavaCompiler.compile(className, source);
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
    TestCase testCase = new TestCase("foo").setProperty("class", clazz.getName());
    try {
        new TimeStepModel(clazz, new PropertyBinding(testCase));
        fail("Expected IllegalTestException in TimeStepModel constructor");
    } catch (IllegalTestException e) {
        e.printStackTrace();
    }
}
Also used : TestCase(com.hazelcast.simulator.common.TestCase)

Example 15 with TestCase

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

the class TimeStepRunStrategyIntegrationTest method testWithThreadContext.

@Test
public void testWithThreadContext() throws Exception {
    int threadCount = 2;
    TestWithThreadState testInstance = new TestWithThreadState();
    TestCase testCase = new TestCase("someid").setProperty("threadCount", threadCount).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 runFuture = spawn(new Callable() {

        @Override
        public Object call() throws Exception {
            container.invoke(RUN);
            return null;
        }
    });
    Thread.sleep(5000);
    testContext.stop();
    runFuture.get();
    container.invoke(TestPhase.LOCAL_TEARDOWN);
    assertEquals(threadCount, testInstance.map.size());
    // each context should be unique
    Set<BaseThreadState> contexts = new HashSet<BaseThreadState>(testInstance.map.values());
    assertEquals(threadCount, contexts.size());
}
Also used : Server(com.hazelcast.simulator.protocol.Server) Callable(java.util.concurrent.Callable) BaseThreadState(com.hazelcast.simulator.test.BaseThreadState) TestCase(com.hazelcast.simulator.common.TestCase) Future(java.util.concurrent.Future) HashSet(java.util.HashSet) 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