apex-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tweise <...@git.apache.org>
Subject [GitHub] incubator-apex-core pull request: APEXCORE-304 Added support for l...
Date Mon, 25 Apr 2016 23:35:55 GMT
Github user tweise commented on a diff in the pull request:

    https://github.com/apache/incubator-apex-core/pull/311#discussion_r61008300
  
    --- Diff: engine/src/test/java/com/datatorrent/stram/StramLocalClusterTest.java ---
    @@ -274,4 +287,113 @@ public WindowGenerator setupWindowGenerator()
         localCluster.shutdown();
       }
     
    +  @Test
    +  public void testDynamicLoading() throws Exception
    +  {
    +    String generatedJar = generatejar("POJO");
    +    URLClassLoader uCl = URLClassLoader.newInstance(new URL[] {new File(generatedJar).toURI().toURL()});
    +    Class<?> pojo = uCl.loadClass("POJO");
    +
    +    DynamicLoaderApp app = new DynamicLoaderApp();
    +    app.generatedJar = generatedJar;
    +    app.pojo = pojo;
    +
    +    LocalMode lma = LocalMode.newInstance();
    +    lma.prepareDAG(app, new Configuration());
    +    LocalMode.Controller lc = lma.getController();
    +    lc.runAsync();
    +    DynamicLoaderApp.latch.await();
    +    Assert.assertTrue(DynamicLoaderApp.passed);
    +    lc.shutdown();
    +  }
    +
    +  static class DynamicLoaderApp implements StreamingApplication
    +  {
    +    static boolean passed = false;
    +    static CountDownLatch latch = new CountDownLatch(2);
    +
    +    DynamicLoader test;
    +    String generatedJar;
    +    Class<?> pojo;
    +
    +    @Override
    +    public void populateDAG(DAG dag, Configuration conf)
    +    {
    +      TestGeneratorInputOperator input = dag.addOperator("Input", new TestGeneratorInputOperator());
    +      test = dag.addOperator("Test", new DynamicLoader());
    +
    +      dag.addStream("S1", input.outport, test.input);
    +      dag.setAttribute(Context.DAGContext.LIBRARY_JARS, generatedJar);
    +      dag.setInputPortAttribute(test.input, Context.PortContext.TUPLE_CLASS, pojo);
    +    }
    +  }
    +
    +  static class DynamicLoader extends BaseOperator
    +  {
    +    public final transient DefaultInputPort input = new DefaultInputPort()
    +    {
    +      @Override
    +      public void setup(Context.PortContext context)
    +      {
    +        Class<?> value = context.getValue(Context.PortContext.TUPLE_CLASS);
    +        if (value.getName().equals("POJO")) {
    +          DynamicLoaderApp.passed = true;
    +        } else {
    +          DynamicLoaderApp.passed = false;
    +        }
    +        DynamicLoaderApp.latch.countDown();
    +      }
    +
    +      @Override
    +      public void process(Object tuple)
    +      {
    +      }
    +    };
    +
    +    @Override
    +    public void setup(Context.OperatorContext context)
    +    {
    +      ClassLoader cl = Thread.currentThread().getContextClassLoader();
    +      try {
    +        cl.loadClass("POJO");
    +      } catch (ClassNotFoundException e) {
    +        DynamicLoaderApp.passed = false;
    +        DynamicLoaderApp.latch.countDown();
    +        throw new RuntimeException(e);
    +      }
    +
    +      try {
    +        Class.forName("POJO", true, Thread.currentThread().getContextClassLoader());
    +      } catch (ClassNotFoundException e) {
    +        DynamicLoaderApp.passed = false;
    +        DynamicLoaderApp.latch.countDown();
    +        throw new RuntimeException(e);
    +      }
    +
    +      DynamicLoaderApp.passed = true;
    +      DynamicLoaderApp.latch.countDown();
    +    }
    +  }
    +
    +  private String generatejar(String pojoClassName) throws IOException, InterruptedException
    +  {
    +    String sourceDir = "src/test/resources/dynamicJar/";
    +    String destDir = "target/";
    --- End diff --
    
    use StramTestSupport.TestMeta


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

Mime
View raw message