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);
}
}
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;
}
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());
}
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);
}
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());
}
Aggregations