Search in sources :

Example 1 with BaseThreadState

use of com.hazelcast.simulator.test.BaseThreadState 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)

Example 2 with BaseThreadState

use of com.hazelcast.simulator.test.BaseThreadState in project hazelcast-simulator by hazelcast.

the class TestContainer_TimeStepTest method testWithThreadState.

@Test
public void testWithThreadState() throws Exception {
    int threadCount = 2;
    TestWithThreadState testInstance = new TestWithThreadState();
    TestCase testCase = new TestCase("id").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> threadStates = new HashSet<BaseThreadState>(testInstance.map.values());
    assertEquals(threadCount, threadStates.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)2 Server (com.hazelcast.simulator.protocol.Server)2 BaseThreadState (com.hazelcast.simulator.test.BaseThreadState)2 HashSet (java.util.HashSet)2 Callable (java.util.concurrent.Callable)2 Future (java.util.concurrent.Future)2 Test (org.junit.Test)2