public void init() { latch = new CountDownLatch(numThreads); for (int i = 0; i < numThreads; ++i) { new Thread( () -> { strategy.beforeThread(); while (!stopped || !taskQueue.isEmpty()) { Runnable task; try { task = taskQueue.poll(100, TimeUnit.MILLISECONDS); } catch (InterruptedException e) { break; } if (task != null) { task.run(); } } strategy.afterThread(); latch.countDown(); }) .start(); } }
private void runImpl(TestRun run) { try { String result = strategy.runTest(run); if (result == null) { run.getCallback().complete(); return; } ObjectMapper mapper = new ObjectMapper(); ObjectNode resultObject = (ObjectNode) mapper.readTree(result); String status = resultObject.get("status").asText(); switch (status) { case "ok": if (!run.getExpectedExceptions().isEmpty()) { run.getCallback().error(new AssertionError("Expected exception was not thrown")); } else { run.getCallback().complete(); } break; case "exception": { String stack = resultObject.get("stack").asText(); String exception = resultObject.has("exception") ? resultObject.get("exception").asText() : null; Class<?> exceptionClass; if (exception != null) { try { exceptionClass = Class.forName(exception, false, TestRunner.class.getClassLoader()); } catch (ClassNotFoundException e) { exceptionClass = null; } } else { exceptionClass = null; } if (exceptionClass != null) { Class<?> caught = exceptionClass; if (run.getExpectedExceptions().stream().anyMatch(e -> e.isAssignableFrom(caught))) { run.getCallback().complete(); break; } } run.getCallback().error(new AssertionError(exception + "\n" + stack)); break; } } } catch (Exception e) { run.getCallback().error(e); } }