beam-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dhalp...@apache.org
Subject [3/4] beam git commit: LocalResourceId: make toString end in '/' for directories
Date Wed, 26 Apr 2017 19:37:41 GMT
LocalResourceId: make toString end in '/' for directories


Project: http://git-wip-us.apache.org/repos/asf/beam/repo
Commit: http://git-wip-us.apache.org/repos/asf/beam/commit/e07ba68e
Tree: http://git-wip-us.apache.org/repos/asf/beam/tree/e07ba68e
Diff: http://git-wip-us.apache.org/repos/asf/beam/diff/e07ba68e

Branch: refs/heads/master
Commit: e07ba68ea380064ecb8bb9c838e712e2457214c6
Parents: 85aaa62
Author: Dan Halperin <dhalperi@google.com>
Authored: Tue Apr 25 20:48:52 2017 -0700
Committer: Dan Halperin <dhalperi@google.com>
Committed: Wed Apr 26 12:27:42 2017 -0700

----------------------------------------------------------------------
 .../org/apache/beam/sdk/io/LocalResourceId.java |  4 +++-
 .../apache/beam/sdk/io/LocalResourceIdTest.java | 23 ++++++++++++++++++++
 2 files changed, 26 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/beam/blob/e07ba68e/sdks/java/core/src/main/java/org/apache/beam/sdk/io/LocalResourceId.java
----------------------------------------------------------------------
diff --git a/sdks/java/core/src/main/java/org/apache/beam/sdk/io/LocalResourceId.java b/sdks/java/core/src/main/java/org/apache/beam/sdk/io/LocalResourceId.java
index 091e955..9aa765b 100644
--- a/sdks/java/core/src/main/java/org/apache/beam/sdk/io/LocalResourceId.java
+++ b/sdks/java/core/src/main/java/org/apache/beam/sdk/io/LocalResourceId.java
@@ -21,6 +21,7 @@ import static com.google.common.base.Preconditions.checkArgument;
 import static com.google.common.base.Preconditions.checkNotNull;
 import static com.google.common.base.Preconditions.checkState;
 
+import java.io.File;
 import java.nio.file.Path;
 import java.nio.file.Paths;
 import java.util.Objects;
@@ -45,7 +46,8 @@ class LocalResourceId implements ResourceId {
   }
 
   private LocalResourceId(Path path, boolean isDirectory) {
-    this.pathString = path.normalize().toString();
+    this.pathString = path.toAbsolutePath().normalize().toString()
+        + (isDirectory ? File.separatorChar : "");
     this.isDirectory = isDirectory;
   }
 

http://git-wip-us.apache.org/repos/asf/beam/blob/e07ba68e/sdks/java/core/src/test/java/org/apache/beam/sdk/io/LocalResourceIdTest.java
----------------------------------------------------------------------
diff --git a/sdks/java/core/src/test/java/org/apache/beam/sdk/io/LocalResourceIdTest.java
b/sdks/java/core/src/test/java/org/apache/beam/sdk/io/LocalResourceIdTest.java
index 37bd303..7a5f0be 100644
--- a/sdks/java/core/src/test/java/org/apache/beam/sdk/io/LocalResourceIdTest.java
+++ b/sdks/java/core/src/test/java/org/apache/beam/sdk/io/LocalResourceIdTest.java
@@ -17,9 +17,15 @@
  */
 package org.apache.beam.sdk.io;
 
+import static org.hamcrest.Matchers.containsString;
+import static org.hamcrest.Matchers.endsWith;
+import static org.hamcrest.Matchers.not;
+import static org.hamcrest.Matchers.startsWith;
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertNotEquals;
+import static org.junit.Assert.assertThat;
 
+import java.io.File;
 import java.nio.file.Paths;
 import org.apache.beam.sdk.io.fs.ResolveOptions.StandardResolveOptions;
 import org.apache.beam.sdk.io.fs.ResourceId;
@@ -27,6 +33,7 @@ import org.apache.commons.lang3.SystemUtils;
 import org.junit.Rule;
 import org.junit.Test;
 import org.junit.rules.ExpectedException;
+import org.junit.rules.TemporaryFolder;
 import org.junit.runner.RunWith;
 import org.junit.runners.JUnit4;
 
@@ -40,6 +47,8 @@ public class LocalResourceIdTest {
 
   @Rule
   public ExpectedException thrown = ExpectedException.none();
+  @Rule
+  public TemporaryFolder tmpFolder = new TemporaryFolder();
 
   @Test
   public void testResolveInUnix() throws Exception {
@@ -214,6 +223,20 @@ public class LocalResourceIdTest {
         toResourceIdentifier("/root/tmp/"));
   }
 
+  @Test
+  public void testToString() throws Exception {
+    File someFile = tmpFolder.newFile("somefile");
+    LocalResourceId fileResource = LocalResourceId.fromPath(someFile.toPath(), false);
+    assertThat(fileResource.toString(), not(endsWith(File.separator)));
+    assertThat(fileResource.toString(), containsString("somefile"));
+    assertThat(fileResource.toString(), startsWith(tmpFolder.getRoot().getAbsolutePath()));
+
+    LocalResourceId dirResource = LocalResourceId.fromPath(someFile.toPath(), true);
+    assertThat(dirResource.toString(), endsWith(File.separator));
+    assertThat(dirResource.toString(), containsString("somefile"));
+    assertThat(dirResource.toString(), startsWith(tmpFolder.getRoot().getAbsolutePath()));
+  }
+
   private LocalResourceId toResourceIdentifier(String str) throws Exception {
     boolean isDirectory;
     if (SystemUtils.IS_OS_WINDOWS) {


Mime
View raw message