Minor: Changing tests which use resource files to use Class.getResource instead of... master
authorCameron Lee <calee@linkedin.com>
Sat, 23 Jun 2018 01:18:06 +0000 (18:18 -0700)
committerJagadish <jvenkatraman@linkedin.com>
Sat, 23 Jun 2018 01:18:06 +0000 (18:18 -0700)
Author: Cameron Lee <calee@linkedin.com>

Reviewers: Jagadish<jagadish@apache.org>

Closes #562 from cameronlee314/get_resource

samza-core/src/test/java/org/apache/samza/runtime/TestApplicationRunnerMain.java
samza-core/src/test/scala/org/apache/samza/config/factories/TestPropertiesConfigFactory.scala
samza-core/src/test/scala/org/apache/samza/job/TestJobRunner.scala
samza-hdfs/src/test/scala/org/apache/samza/system/hdfs/TestHdfsSystemProducerTestSuite.scala

index eb0ebe9..7e6433c 100644 (file)
  */
 package org.apache.samza.runtime;
 
-import java.io.File;
 import org.apache.samza.application.StreamApplication;
 import org.apache.samza.config.Config;
 import org.apache.samza.job.ApplicationStatus;
 import org.apache.samza.operators.StreamGraph;
 import org.junit.Test;
 
-import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.*;
 
 
 public class TestApplicationRunnerMain {
@@ -37,7 +36,7 @@ public class TestApplicationRunnerMain {
         "--config-factory",
         "org.apache.samza.config.factories.PropertiesConfigFactory",
         "--config-path",
-        String.format("file://%s/src/test/resources/test.properties", new File(".").getCanonicalPath()),
+        getClass().getResource("/test.properties").getPath(),
         "-config", ApplicationRunnerMain.STREAM_APPLICATION_CLASS_CONFIG + "=org.apache.samza.runtime.TestApplicationRunnerMain$TestStreamApplicationDummy",
         "-config", "app.runner.class=org.apache.samza.runtime.TestApplicationRunnerMain$TestApplicationRunnerInvocationCounts"
     });
@@ -52,7 +51,7 @@ public class TestApplicationRunnerMain {
         "--config-factory",
         "org.apache.samza.config.factories.PropertiesConfigFactory",
         "--config-path",
-        String.format("file://%s/src/test/resources/test.properties", new File(".").getCanonicalPath()),
+        getClass().getResource("/test.properties").getPath(),
         "-config", ApplicationRunnerMain.STREAM_APPLICATION_CLASS_CONFIG + "=org.apache.samza.runtime.TestApplicationRunnerMain$TestStreamApplicationDummy",
         "-config", "app.runner.class=org.apache.samza.runtime.TestApplicationRunnerMain$TestApplicationRunnerInvocationCounts",
         "--operation=kill"
@@ -68,7 +67,7 @@ public class TestApplicationRunnerMain {
         "--config-factory",
         "org.apache.samza.config.factories.PropertiesConfigFactory",
         "--config-path",
-        String.format("file://%s/src/test/resources/test.properties", new File(".").getCanonicalPath()),
+        getClass().getResource("/test.properties").getPath(),
         "-config", ApplicationRunnerMain.STREAM_APPLICATION_CLASS_CONFIG + "=org.apache.samza.runtime.TestApplicationRunnerMain$TestStreamApplicationDummy",
         "-config", "app.runner.class=org.apache.samza.runtime.TestApplicationRunnerMain$TestApplicationRunnerInvocationCounts",
         "--operation=status"
index 9688abb..789869c 100644 (file)
@@ -20,7 +20,6 @@
 package org.apache.samza.config.factories
 
 import java.net.URI
-import java.io.File
 
 import org.apache.samza.SamzaException
 import org.junit.Assert._
@@ -31,7 +30,7 @@ class TestPropertiesConfigFactory {
 
   @Test
   def testCanReadPropertiesConfigFiles {
-    val config = factory.getConfig(URI.create("file://%s/src/test/resources/test.properties" format new File(".").getCanonicalPath))
+    val config = factory.getConfig(getClass.getResource("/test.properties").toURI)
     assertEquals("bar", config.get("foo"))
   }
 
index 0a1314e..0853f8e 100644 (file)
 
 package org.apache.samza.job
 
-import java.io.File
-
 import org.apache.samza.config.Config
 import org.apache.samza.coordinator.stream.MockCoordinatorStreamSystemFactory
-import org.junit.After
 import org.junit.Assert._
-import org.junit.Test
+import org.junit.{After, Test}
 
 object TestJobRunner {
   var processCount = 0
@@ -49,7 +46,7 @@ class TestJobRunner {
       "--config-factory",
       "org.apache.samza.config.factories.PropertiesConfigFactory",
       "--config-path",
-      "file://%s/src/test/resources/test.properties" format new File(".").getCanonicalPath))
+      getClass.getResource("/test.properties").getPath))
     assertEquals(1, TestJobRunner.processCount)
   }
 
@@ -62,7 +59,7 @@ class TestJobRunner {
       "--config-factory",
       "org.apache.samza.config.factories.PropertiesConfigFactory",
       "--config-path",
-      "file://%s/src/test/resources/test.properties" format new File(".").getCanonicalPath,
+      getClass.getResource("/test.properties").getPath,
       "--operation=kill"))
     assertEquals(1, TestJobRunner.killCount)
   }
@@ -76,7 +73,7 @@ class TestJobRunner {
       "--config-factory",
       "org.apache.samza.config.factories.PropertiesConfigFactory",
       "--config-path",
-      "file://%s/src/test/resources/test.properties" format new File(".").getCanonicalPath,
+      getClass.getResource("/test.properties").getPath,
       "--operation=status"))
     assertEquals(1, TestJobRunner.getStatusCount)
   }
index 8bea0bc..41fbdd9 100644 (file)
@@ -20,8 +20,6 @@
 package org.apache.samza.system.hdfs
 
 
-import java.io.File
-import java.net.URI
 import java.text.SimpleDateFormat
 import java.util.Date
 
@@ -52,7 +50,6 @@ object TestHdfsSystemProducerTestSuite {
   val AVRO_JOB_NAME = "samza-hdfs-test-job-avro" // write some data as Avro
   val TEXT_BATCH_JOB_NAME = "samza-hdfs-test-batch-job-text" // force a file split, understanding that Text does some compressing
   val AVRO_BATCH_JOB_NAME = "samza-hdfs-test-batch-job-avro" // force a file split, understanding that Avro does some compressing
-  val RESOURCE_PATH_FORMAT = "file://%s/src/test/resources/%s.properties"
   val TEST_DATE = (new SimpleDateFormat("yyyy_MM_dd-HH")).format(new Date)
 
   // Test data
@@ -85,7 +82,7 @@ object TestHdfsSystemProducerTestSuite {
     Some(
       hdfsFactory.getProducer(
         name,
-        propsFactory.getConfig(URI.create(RESOURCE_PATH_FORMAT format (new File(".").getCanonicalPath, name))),
+        propsFactory.getConfig(getClass.getResource(String.format("/%s.properties", name)).toURI),
         new HdfsSystemProducerMetrics(name),
         cluster
       )