Search in sources :

Example 66 with TestCase

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

the class TimeStepRunStrategyIntegrationTest method testWithAllRunPhases.

@Test
public void testWithAllRunPhases() throws Exception {
    int threadCount = 2;
    TestWithAllRunPhases testInstance = new TestWithAllRunPhases();
    TestCase testCase = new TestCase(TEST_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;
        }
    });
    sleepSeconds(5);
    testContext.stop();
    runFuture.get();
    container.invoke(TestPhase.LOCAL_TEARDOWN);
    System.out.println("done");
    assertEquals(threadCount, testInstance.beforeRunCount.get());
    assertEquals(threadCount, testInstance.afterRunCount.get());
    System.out.println(testInstance.timeStepCount);
}
Also used : Server(com.hazelcast.simulator.protocol.Server) TestCase(com.hazelcast.simulator.common.TestCase) Future(java.util.concurrent.Future) Callable(java.util.concurrent.Callable) Test(org.junit.Test)

Example 67 with TestCase

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

the class RunTestSuiteTask method run0.

private boolean run0(List<TestData> tests, List<WorkerData> targets) {
    int testCount = testSuite.size();
    boolean parallel = testSuite.isParallel() && testCount > 1;
    Map<TestPhase, CountDownLatch> testPhaseSyncMap = getTestPhaseSyncMap(testCount, parallel, coordinatorParameters.getLastTestPhaseToSync());
    LOGGER.info("Starting TestSuite");
    echoTestSuiteDuration(parallel);
    for (TestData test : tests) {
        int testIndex = test.getTestIndex();
        TestCase testCase = test.getTestCase();
        LOGGER.info(format("Configuration for %s (T%d):%n%s", testCase.getId(), testIndex, testCase));
        TestCaseRunner runner = new TestCaseRunner(test, coordinatorParameters, targets, client, testPhaseSyncMap, failureCollector, registry, performanceStatsCollector);
        runners.add(runner);
    }
    echoTestSuiteStart(testCount, parallel);
    long started = System.nanoTime();
    boolean success = parallel ? runParallel() : runSequential();
    echoTestSuiteEnd(testCount, started);
    return success;
}
Also used : TestData(com.hazelcast.simulator.coordinator.registry.TestData) TestCase(com.hazelcast.simulator.common.TestCase) TestPhase(com.hazelcast.simulator.common.TestPhase) TestCaseRunner(com.hazelcast.simulator.coordinator.TestCaseRunner) CountDownLatch(java.util.concurrent.CountDownLatch)

Example 68 with TestCase

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

the class CoordinatorCli method loadTestSuite.

private TestSuite loadTestSuite() {
    TestSuite testSuite = loadRawTestSuite();
    if (testSuite == null) {
        return null;
    }
    WorkerQuery workerQuery = new WorkerQuery().setTargetType(options.valueOf(targetTypeSpec));
    int targetCount = options.valueOf(targetCountSpec);
    if (targetCount > 0) {
        workerQuery.setMaxCount(targetCount);
    }
    int durationSeconds = getDurationSeconds(options, durationSpec);
    testSuite.setDurationSeconds(durationSeconds).setFailFast(options.valueOf(failFastSpec)).setVerifyEnabled(options.valueOf(verifyEnabledSpec)).setParallel(options.has(parallelSpec)).setWorkerQuery(workerQuery);
    // if the coordinator is not monitoring performance, we don't care for measuring latencies
    if (coordinatorParameters.getSimulatorProperties().getInt("WORKER_PERFORMANCE_MONITOR_INTERVAL_SECONDS") == 0) {
        for (TestCase testCase : testSuite.getTestCaseList()) {
            testCase.setProperty("measureLatency", "false");
        }
    }
    return testSuite;
}
Also used : TestCase(com.hazelcast.simulator.common.TestCase) WorkerQuery(com.hazelcast.simulator.coordinator.registry.WorkerQuery)

Example 69 with TestCase

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

the class TestSuite method createTestCases.

private static Map<String, TestCase> createTestCases(Properties properties) {
    Map<String, TestCase> testCases = new HashMap<String, TestCase>();
    for (String property : properties.stringPropertyNames()) {
        String value = (String) properties.get(property);
        int indexOfAt = property.indexOf('@');
        String testId = "";
        String field = property;
        if (indexOfAt > -1) {
            testId = property.substring(0, indexOfAt);
            field = property.substring(indexOfAt + 1);
        }
        if (!testId.isEmpty() && !isValidTestId(testId)) {
            throw new IllegalArgumentException(format("TestId [%s] is not a valid id", testId));
        }
        if (value.isEmpty()) {
            throw new IllegalArgumentException(format("Value of property %s in testId [%s] is empty!", property, testId));
        }
        TestCase testCase = getOrCreateTestCase(testCases, testId);
        testCase.setProperty(field, value);
    }
    return testCases;
}
Also used : TestCase(com.hazelcast.simulator.common.TestCase) HashMap(java.util.HashMap)

Example 70 with TestCase

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

the class TestManager method createTest.

public void createTest(CreateTestOperation operation) {
    TestCase testCase = operation.getTestCase();
    String testId = testCase.getId();
    TestContainer testContainer = tests.get(testId);
    if (testContainer != null) {
        throw new IllegalStateException(format("Can't init TestCase: %s, another test with testId %s already exists", operation, testId));
    }
    LOGGER.info(format("%s Initializing test %s %s%n%s", DASHES, testId, DASHES, testCase));
    TestContextImpl testContext = new TestContextImpl(testId, null, server);
    testContainer = new TestContainer(testContext, testCase, vendorDriver.getVendorInstance());
    tests.put(testId, testContainer);
}
Also used : TestCase(com.hazelcast.simulator.common.TestCase)

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