Search in sources :

Example 1 with ForTestRouteId

use of org.webpieces.compiler.impl.test.ForTestRouteId in project webpieces by deanhiller.

the class AnonymousByteCacheTest method testByteCodeExistsAtCorrectTime.

@SuppressWarnings({ "rawtypes", "unchecked" })
@Test
public void testByteCodeExistsAtCorrectTime() throws Exception {
    Assert.assertFalse(byteCodeControllerFile.exists());
    Assert.assertFalse(byteCodeEnumFile.exists());
    //DO NOT CALL Classname.getClass().getName() so that we don't pre-load it from the default classloader and
    //instead just tediously form the String ourselves...
    String controller = getPackageFilter() + ".AnonymousController";
    log.info("loading class " + controller);
    Class c = compiler.loadClass(controller);
    Assert.assertTrue(byteCodeControllerFile.exists());
    //The enum is not compiled yet...it is on-demand compiled later...
    Assert.assertFalse(byteCodeEnumFile.exists());
    log.info("loaded");
    Callable<ForTestRouteId> callable = (Callable<ForTestRouteId>) invokeMethod(c, "getRunnable");
    ForTestRouteId value = callable.call();
    log.info("test route id=" + value);
    CompileConfig config = createCompileConfig();
    //now create a new compileOnDemand which will use the bytecode cache...
    compiler = CompileOnDemandFactory.createCompileOnDemand(config);
    compiler.loadClass(controller, true);
    Assert.assertTrue(byteCodeControllerFile.exists());
    Assert.assertTrue(byteCodeEnumFile.exists());
}
Also used : ForTestRouteId(org.webpieces.compiler.impl.test.ForTestRouteId) CompileConfig(org.webpieces.compiler.api.CompileConfig) Callable(java.util.concurrent.Callable) Test(org.junit.Test)

Aggregations

Callable (java.util.concurrent.Callable)1 Test (org.junit.Test)1 CompileConfig (org.webpieces.compiler.api.CompileConfig)1 ForTestRouteId (org.webpieces.compiler.impl.test.ForTestRouteId)1