Skip to content

Commit

Permalink
Added Furnace cleanup from ForgeTestMethodExecutor just in case
Browse files Browse the repository at this point in the history
  • Loading branch information
lincolnthree committed Oct 31, 2013
1 parent 4ada7ba commit cb2ebd2
Showing 1 changed file with 114 additions and 107 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
*/
public class ForgeTestMethodExecutor implements ContainerMethodExecutor
{
private Furnace forge;
private Furnace furnace;

public ForgeTestMethodExecutor(ForgeProtocolConfiguration config, final FurnaceHolder holder)
{
Expand All @@ -43,158 +43,165 @@ public ForgeTestMethodExecutor(ForgeProtocolConfiguration config, final FurnaceH
{
throw new IllegalArgumentException("Furnace runtime must be provided");
}
this.forge = holder.getFurnace();
this.furnace = holder.getFurnace();
}

@Override
public TestResult invoke(final TestMethodExecutor testMethodExecutor)
{
if (testMethodExecutor == null)
{
throw new IllegalArgumentException("TestMethodExecutor must be specified");
}

Object testInstance = null;
Class<?> testClass = null;
try
{
final String testClassName = testMethodExecutor.getInstance().getClass().getName();
final AddonRegistry addonRegistry = forge.getAddonRegistry();

waitUntilStable(forge);
System.out.println("Searching for test [" + testClassName + "]");
if (testMethodExecutor == null)
{
throw new IllegalArgumentException("TestMethodExecutor must be specified");
}

for (Addon addon : addonRegistry.getAddons())
Object testInstance = null;
Class<?> testClass = null;
try
{
if (addon.getStatus().isStarted())
{
ServiceRegistry registry = addon.getServiceRegistry();
ExportedInstance<?> exportedInstance = registry.getExportedInstance(testClassName);
final String testClassName = testMethodExecutor.getInstance().getClass().getName();
final AddonRegistry addonRegistry = furnace.getAddonRegistry();

waitUntilStable(furnace);
System.out.println("Searching for test [" + testClassName + "]");

if (exportedInstance != null)
for (Addon addon : addonRegistry.getAddons())
{
if (addon.getStatus().isStarted())
{
if (testInstance == null)
{
testInstance = exportedInstance.get();
testClass = ClassLoaders.loadClass(addon.getClassLoader(), testClassName);
}
else
ServiceRegistry registry = addon.getServiceRegistry();
ExportedInstance<?> exportedInstance = registry.getExportedInstance(testClassName);

if (exportedInstance != null)
{
throw new IllegalStateException(
"Multiple test classes found in deployed addons. " +
"You must have only one @Deployment(testable=true\"); deployment");
if (testInstance == null)
{
testInstance = exportedInstance.get();
testClass = ClassLoaders.loadClass(addon.getClassLoader(), testClassName);
}
else
{
throw new IllegalStateException(
"Multiple test classes found in deployed addons. " +
"You must have only one @Deployment(testable=true\"); deployment");
}
}
}
}
}
}
catch (Exception e)
{
String message = "Error launching test "
+ testMethodExecutor.getInstance().getClass().getName() + "."
+ testMethodExecutor.getMethod().getName() + "()";
System.out.println(message);
throw new IllegalStateException(message, e);
}
catch (Exception e)
{
String message = "Error launching test "
+ testMethodExecutor.getInstance().getClass().getName() + "."
+ testMethodExecutor.getMethod().getName() + "()";
System.out.println(message);
throw new IllegalStateException(message, e);
}

if (testInstance != null)
{
try
if (testInstance != null)
{
TestResult result = null;
try
{
TestResult result = null;
try
{
testInstance = ClassLoaderAdapterCallback.enhance(getClass().getClassLoader(),
testInstance.getClass().getClassLoader(), testInstance, testClass);
testInstance.getClass();
}
catch (Exception e)
{
System.out.println("Could not enhance test class. Falling back to un-proxied invocation.");
}
try
{
testInstance = ClassLoaderAdapterCallback.enhance(getClass().getClassLoader(),
testInstance.getClass().getClassLoader(), testInstance, testClass);
testInstance.getClass();
}
catch (Exception e)
{
System.out.println("Could not enhance test class. Falling back to un-proxied invocation.");
}

Method method = testInstance.getClass().getMethod(testMethodExecutor.getMethod().getName());
Annotation[] annotations = method.getAnnotations();
Method method = testInstance.getClass().getMethod(testMethodExecutor.getMethod().getName());
Annotation[] annotations = method.getAnnotations();

for (Annotation annotation : annotations)
{
if ("org.junit.Ignore".equals(annotation.getClass().getName()))
for (Annotation annotation : annotations)
{
result = new TestResult(Status.SKIPPED);
if ("org.junit.Ignore".equals(annotation.getClass().getName()))
{
result = new TestResult(Status.SKIPPED);
}
}
}

if (result == null)
{
try
if (result == null)
{
System.out.println("Executing test method: "
+ testMethodExecutor.getInstance().getClass().getName() + "."
+ testMethodExecutor.getMethod().getName() + "()");

try
{
invokeBefore(testInstance.getClass(), testInstance);
method.invoke(testInstance);
System.out.println("Executing test method: "
+ testMethodExecutor.getInstance().getClass().getName() + "."
+ testMethodExecutor.getMethod().getName() + "()");

try
{
invokeBefore(testInstance.getClass(), testInstance);
method.invoke(testInstance);
}
catch (Exception e)
{
throw e;
}
finally
{
invokeAfter(testInstance.getClass(), testInstance);
}

result = new TestResult(Status.PASSED);
}
catch (Exception e)
catch (InvocationTargetException e)
{
throw e;
if (e.getCause() != null && e.getCause() instanceof Exception)
throw (Exception) e.getCause();
else
throw e;
}
finally
{
invokeAfter(testInstance.getClass(), testInstance);
}

result = new TestResult(Status.PASSED);
}
catch (InvocationTargetException e)
}
catch (AssertionError e)
{
result = new TestResult(Status.FAILED, e);
}
catch (Exception e)
{
result = new TestResult(Status.FAILED, e);

Throwable cause = e.getCause();
while (cause != null)
{
if (e.getCause() != null && e.getCause() instanceof Exception)
throw (Exception) e.getCause();
else
throw e;
if (cause instanceof AssertionError)
{
result = new TestResult(Status.FAILED, cause);
break;
}
cause = cause.getCause();
}
}
}
catch (AssertionError e)
{
result = new TestResult(Status.FAILED, e);
return result;
}
catch (Exception e)
{
result = new TestResult(Status.FAILED, e);

Throwable cause = e.getCause();
while (cause != null)
{
if (cause instanceof AssertionError)
{
result = new TestResult(Status.FAILED, cause);
break;
}
cause = cause.getCause();
}
String message = "Error launching test "
+ testMethodExecutor.getInstance().getClass().getName() + "."
+ testMethodExecutor.getMethod().getName() + "()";
System.out.println(message);
throw new IllegalStateException(message, e);
}
return result;
}
catch (Exception e)
else
{
String message = "Error launching test "
+ testMethodExecutor.getInstance().getClass().getName() + "."
+ testMethodExecutor.getMethod().getName() + "()";
System.out.println(message);
throw new IllegalStateException(message, e);
throw new IllegalStateException(
"Test runner could not locate test class in any deployment. "
+ "Verify that your test case is deployed in an addon that supports remote " +
"services (Did you forget beans.xml in your deployment?)");
}
}
else
finally
{
throw new IllegalStateException(
"Test runner could not locate test class in any deployment. "
+ "Verify that your test case is deployed in an addon that supports remote " +
"services (Did you forget beans.xml in your deployment?)");
furnace = null;
}
}

Expand Down

0 comments on commit cb2ebd2

Please sign in to comment.