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 Wed, 20 Apr 2016 22:25:06 GMT
Github user tweise commented on a diff in the pull request:

    https://github.com/apache/incubator-apex-core/pull/311#discussion_r60498409
  
    --- Diff: engine/src/test/java/com/datatorrent/stram/StramLocalClusterTest.java ---
    @@ -274,4 +286,103 @@ public WindowGenerator setupWindowGenerator()
         localCluster.shutdown();
       }
     
    +  @Test
    +  public void testDynamicLoading() throws IOException, ClassNotFoundException
    +  {
    +    final String generatedJar = generatejar();
    +    File file = new File(generatedJar);
    +    final Class<?> pojo = URLClassLoader.newInstance(new URL[]{file.toURI().toURL()}).loadClass("POJO");
    +
    +    StreamingApplication app = new StreamingApplication()
    +    {
    +      @Override
    +      public void populateDAG(DAG dag, Configuration conf)
    +      {
    +        TestGeneratorInputOperator genNode = dag.addOperator("genNode", TestGeneratorInputOperator.class);
    +        genNode.setMaxTuples(2);
    +
    +        DynamicLoader dynamicLoader = dag.addOperator("DynamicLoader", new DynamicLoader());
    +        dynamicLoader.setClass("POJO");
    +
    +        dag.addStream("fromNode1", genNode.outport, dynamicLoader.in);
    +
    +        dag.setInputPortAttribute(dynamicLoader.in, Context.PortContext.TUPLE_CLASS,
pojo);
    +        conf.set(LIBJARS_CONF_KEY_NAME, generatedJar);
    +      }
    +    };
    +
    +    LocalMode.runApp(app, 10000);
    +
    +    FileUtils.forceDelete(new File("src/test/resources/dynamicJar/POJO.class"));
    +    FileUtils.forceDelete(new File("src/test/resources/dynamicJar/testPOJO.jar"));
    +  }
    +
    +  public static class DynamicLoader extends BaseOperator
    +  {
    +    private String classToLoad;
    +
    +    public final transient DefaultInputPort in = new DefaultInputPort()
    +    {
    +      @Override
    +      public void setup(Context.PortContext context)
    +      {
    +        Class<?> value = context.getValue(Context.PortContext.TUPLE_CLASS);
    +
    +        if (!value.getName().equals("POJO")) {
    +          throw new RuntimeException("Class name not matching. Name is " + value.getName());
    +        }
    +      }
    +
    +      @Override
    +      public void process(Object tuple)
    +      {
    +
    +      }
    +    };
    +
    +    @Override
    +    public void setup(Context.OperatorContext context)
    +    {
    +      try {
    +        Thread.currentThread().getContextClassLoader().loadClass(classToLoad);
    +        Assert.assertTrue(true);
    +      } catch (ClassNotFoundException e) {
    +        Assert.fail(e.getMessage());
    --- End diff --
    
    propagate exception


---
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