SAMZA-1358: fix the bug in validating task.class empty string when app.class is confi...
authorYi Pan (Data Infrastructure) <nickpan47@gmail.com>
Tue, 11 Jul 2017 17:55:51 +0000 (10:55 -0700)
committerYi Pan (Data Infrastructure) <nickpan47@gmail.com>
Tue, 11 Jul 2017 17:55:51 +0000 (10:55 -0700)
…p.class is configured

Another bug due to scala/java differences.

Author: Yi Pan (Data Infrastructure) <nickpan47@gmail.com>

Reviewers: Jacob Maes <jmaes@linkedin.com>

Closes #242 from nickpan47/SAMZA-1358

samza-core/src/main/java/org/apache/samza/task/TaskFactoryUtil.java
samza-core/src/test/java/org/apache/samza/task/TestTaskFactoryUtil.java

index 6408e6f..1fe9187 100644 (file)
@@ -32,6 +32,8 @@ import java.util.concurrent.ExecutorService;
 
 import scala.runtime.AbstractFunction0;
 
+import static org.apache.samza.util.ScalaToJavaUtils.defaultValue;
+
 /**
  * This class provides utility functions to load task factory classes based on config, and to wrap {@link StreamTaskFactory} in {@link AsyncStreamTaskFactory}
  * when running {@link StreamTask}s in multi-thread mode
@@ -162,7 +164,8 @@ public class TaskFactoryUtil {
     ApplicationConfig appConfig = new ApplicationConfig(config);
     if (appConfig.getAppClass() != null && !appConfig.getAppClass().isEmpty()) {
       TaskConfig taskConfig = new TaskConfig(config);
-      if (taskConfig.getTaskClass() != null && !taskConfig.getTaskClass().isEmpty()) {
+      String taskClassName = taskConfig.getTaskClass().getOrElse(defaultValue(null));
+      if (taskClassName != null && !taskClassName.isEmpty()) {
         throw new ConfigException("High level StreamApplication API cannot be used together with low-level API using task.class.");
       }
 
index e300996..942792f 100644 (file)
@@ -156,6 +156,17 @@ public class TestTaskFactoryUtil {
     } catch (ConfigException ce) {
       // expected
     }
+
+
+    config = new MapConfig(new HashMap<String, String>() {
+      {
+        this.put("task.class", "");
+        this.put(ApplicationConfig.APP_CLASS, "org.apache.samza.testUtils.TestStreamApplication");
+      }
+    });
+    streamApp = TaskFactoryUtil.createStreamApplication(config);
+    assertNotNull(streamApp);
+
   }
 
   @Test