[ 
https://issues.apache.org/jira/browse/APEXCORE-304?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15250843#comment-15250843
 ] 

ASF GitHub Bot commented on APEXCORE-304:
-----------------------------------------

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


> Ability to add jars to classpath in populateDAG
> -----------------------------------------------
>
>                 Key: APEXCORE-304
>                 URL: https://issues.apache.org/jira/browse/APEXCORE-304
>             Project: Apache Apex Core
>          Issue Type: Improvement
>            Reporter: Chinmay Kolhatkar
>            Assignee: Chinmay Kolhatkar
>
> This will have following functionality:
> 1) In populateDAG one would be allowed to add given local jar path to 
> classpath of the application.
> 2) Optionally delete the given jar file after copying to HDFS is done.



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)

Reply via email to