Repository: samza Updated Branches: refs/heads/master 187ec5f2f -> c8b776ec1
Minor: Changing tests which use resource files to use Class.getResource instead of File to get the path to the resource; without this change, these tests fail when run in the IDE Author: Cameron Lee <ca...@linkedin.com> Reviewers: Jagadish<jagad...@apache.org> Closes #562 from cameronlee314/get_resource Project: http://git-wip-us.apache.org/repos/asf/samza/repo Commit: http://git-wip-us.apache.org/repos/asf/samza/commit/c8b776ec Tree: http://git-wip-us.apache.org/repos/asf/samza/tree/c8b776ec Diff: http://git-wip-us.apache.org/repos/asf/samza/diff/c8b776ec Branch: refs/heads/master Commit: c8b776ec1023599f9dc6c936c483d4eb4227017f Parents: 187ec5f Author: Cameron Lee <ca...@linkedin.com> Authored: Fri Jun 22 18:18:06 2018 -0700 Committer: Jagadish <jvenkatra...@linkedin.com> Committed: Fri Jun 22 18:18:06 2018 -0700 ---------------------------------------------------------------------- .../apache/samza/runtime/TestApplicationRunnerMain.java | 9 ++++----- .../config/factories/TestPropertiesConfigFactory.scala | 3 +-- .../test/scala/org/apache/samza/job/TestJobRunner.scala | 11 ++++------- .../system/hdfs/TestHdfsSystemProducerTestSuite.scala | 5 +---- 4 files changed, 10 insertions(+), 18 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/samza/blob/c8b776ec/samza-core/src/test/java/org/apache/samza/runtime/TestApplicationRunnerMain.java ---------------------------------------------------------------------- diff --git a/samza-core/src/test/java/org/apache/samza/runtime/TestApplicationRunnerMain.java b/samza-core/src/test/java/org/apache/samza/runtime/TestApplicationRunnerMain.java index eb0ebe9..7e6433c 100644 --- a/samza-core/src/test/java/org/apache/samza/runtime/TestApplicationRunnerMain.java +++ b/samza-core/src/test/java/org/apache/samza/runtime/TestApplicationRunnerMain.java @@ -18,14 +18,13 @@ */ 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" http://git-wip-us.apache.org/repos/asf/samza/blob/c8b776ec/samza-core/src/test/scala/org/apache/samza/config/factories/TestPropertiesConfigFactory.scala ---------------------------------------------------------------------- diff --git a/samza-core/src/test/scala/org/apache/samza/config/factories/TestPropertiesConfigFactory.scala b/samza-core/src/test/scala/org/apache/samza/config/factories/TestPropertiesConfigFactory.scala index 9688abb..789869c 100644 --- a/samza-core/src/test/scala/org/apache/samza/config/factories/TestPropertiesConfigFactory.scala +++ b/samza-core/src/test/scala/org/apache/samza/config/factories/TestPropertiesConfigFactory.scala @@ -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")) } http://git-wip-us.apache.org/repos/asf/samza/blob/c8b776ec/samza-core/src/test/scala/org/apache/samza/job/TestJobRunner.scala ---------------------------------------------------------------------- diff --git a/samza-core/src/test/scala/org/apache/samza/job/TestJobRunner.scala b/samza-core/src/test/scala/org/apache/samza/job/TestJobRunner.scala index 0a1314e..0853f8e 100644 --- a/samza-core/src/test/scala/org/apache/samza/job/TestJobRunner.scala +++ b/samza-core/src/test/scala/org/apache/samza/job/TestJobRunner.scala @@ -19,13 +19,10 @@ 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) } http://git-wip-us.apache.org/repos/asf/samza/blob/c8b776ec/samza-hdfs/src/test/scala/org/apache/samza/system/hdfs/TestHdfsSystemProducerTestSuite.scala ---------------------------------------------------------------------- diff --git a/samza-hdfs/src/test/scala/org/apache/samza/system/hdfs/TestHdfsSystemProducerTestSuite.scala b/samza-hdfs/src/test/scala/org/apache/samza/system/hdfs/TestHdfsSystemProducerTestSuite.scala index 8bea0bc..41fbdd9 100644 --- a/samza-hdfs/src/test/scala/org/apache/samza/system/hdfs/TestHdfsSystemProducerTestSuite.scala +++ b/samza-hdfs/src/test/scala/org/apache/samza/system/hdfs/TestHdfsSystemProducerTestSuite.scala @@ -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 )