String testMethod = testMethodExecutor.getMethod().getName();
String testCanonicalName = testClass + "." + testMethod;
NotificationListener commandListener = null;
ObjectName objectName = null;
TestResult result = null;
try {
objectName = new ObjectName(JMXTestRunnerMBean.OBJECT_NAME);
commandListener = new CallbackNotificationListener(objectName);
mbeanServer.addNotificationListener(objectName, commandListener, null, null);
JMXTestRunnerMBean testRunner = getMBeanProxy(objectName, JMXTestRunnerMBean.class);
log.debugf("Invoke %s: %s", executionType, testCanonicalName);
if (executionType == ExecutionType.REMOTE) {
result = testRunner.runTestMethodRemote(testClass, testMethod);
} else {
InputStream resultStream = testRunner.runTestMethodEmbedded(testClass, testMethod);
ObjectInputStream ois = new ObjectInputStream(resultStream);
result = (TestResult) ois.readObject();
}
} catch (final Throwable th) {
result = new TestResult(Status.FAILED);
result.setThrowable(th);
} finally {
result.setEnd(System.currentTimeMillis());
if (objectName != null && commandListener != null) {
try {
mbeanServer.removeNotificationListener(objectName, commandListener);
} catch (Throwable th) {
log.errorf(th, "Cannot remove notification listener");
}
}
}
log.debugf("Result: %s", result);
if (result.getStatus() == Status.FAILED)
log.errorf(result.getThrowable(), "Failed: %s", testCanonicalName);
return result;
}