diff --git a/gcloud-java-contrib/gcloud-java-nio/src/main/java/com/google/cloud/storage/contrib/nio/CloudStorageFileSystem.java b/gcloud-java-contrib/gcloud-java-nio/src/main/java/com/google/cloud/storage/contrib/nio/CloudStorageFileSystem.java index 80004792d2f8..13fdb18864b8 100644 --- a/gcloud-java-contrib/gcloud-java-nio/src/main/java/com/google/cloud/storage/contrib/nio/CloudStorageFileSystem.java +++ b/gcloud-java-contrib/gcloud-java-nio/src/main/java/com/google/cloud/storage/contrib/nio/CloudStorageFileSystem.java @@ -145,10 +145,12 @@ public CloudStoragePath getPath(String first, String... more) { * Does nothing. */ @Override - public void close() {} + public void close() throws IOException { + // TODO(#809): Synchronously close all channels associated with this FileSystem instance. + } /** - * Returns {@code true}. + * Returns {@code true}, even if you previously called the {@link #close()} method. */ @Override public boolean isOpen() { diff --git a/gcloud-java-contrib/gcloud-java-nio/src/test/java/com/google/cloud/storage/contrib/nio/CloudStorageFileSystemProviderTest.java b/gcloud-java-contrib/gcloud-java-nio/src/test/java/com/google/cloud/storage/contrib/nio/CloudStorageFileSystemProviderTest.java index e2ade4a1adb1..79e3bc82dfa3 100644 --- a/gcloud-java-contrib/gcloud-java-nio/src/test/java/com/google/cloud/storage/contrib/nio/CloudStorageFileSystemProviderTest.java +++ b/gcloud-java-contrib/gcloud-java-nio/src/test/java/com/google/cloud/storage/contrib/nio/CloudStorageFileSystemProviderTest.java @@ -391,7 +391,7 @@ public void testExists_trailingSlash() { } @Test - public void testExists_trailingSlash_disablePseudoDirectories() { + public void testExists_trailingSlash_disablePseudoDirectories() throws IOException { try (CloudStorageFileSystem fs = forBucket("military", usePseudoDirectories(false))) { assertThat(Files.exists(fs.getPath("fashion/"))).isFalse(); } @@ -547,7 +547,7 @@ public void testIsDirectory_trailingSlash_alwaysTrue() { } @Test - public void testIsDirectory_trailingSlash_pseudoDirectoriesDisabled_false() { + public void testIsDirectory_trailingSlash_pseudoDirectoriesDisabled_false() throws IOException { try (CloudStorageFileSystem fs = forBucket("doodle", usePseudoDirectories(false))) { assertThat(Files.isDirectory(fs.getPath("fundir/"))).isFalse(); } diff --git a/gcloud-java-contrib/gcloud-java-nio/src/test/java/com/google/cloud/storage/contrib/nio/CloudStoragePathTest.java b/gcloud-java-contrib/gcloud-java-nio/src/test/java/com/google/cloud/storage/contrib/nio/CloudStoragePathTest.java index 4a1c40c9b28d..173a8047340a 100644 --- a/gcloud-java-contrib/gcloud-java-nio/src/test/java/com/google/cloud/storage/contrib/nio/CloudStoragePathTest.java +++ b/gcloud-java-contrib/gcloud-java-nio/src/test/java/com/google/cloud/storage/contrib/nio/CloudStoragePathTest.java @@ -52,7 +52,7 @@ public void before() { } @Test - public void testCreate_neverRemoveExtraSlashes() { + public void testCreate_neverRemoveExtraSlashes() throws IOException { try (CloudStorageFileSystem fs = CloudStorageFileSystem.forBucket("doodle")) { assertThat(fs.getPath("lol//cat").toString()).isEqualTo("lol//cat"); assertThat((Object) fs.getPath("lol//cat")).isEqualTo(fs.getPath("lol//cat")); @@ -60,7 +60,7 @@ public void testCreate_neverRemoveExtraSlashes() { } @Test - public void testCreate_preservesTrailingSlash() { + public void testCreate_preservesTrailingSlash() throws IOException { try (CloudStorageFileSystem fs = CloudStorageFileSystem.forBucket("doodle")) { assertThat(fs.getPath("lol/cat/").toString()).isEqualTo("lol/cat/"); assertThat((Object) fs.getPath("lol/cat/")).isEqualTo(fs.getPath("lol/cat/")); @@ -68,7 +68,7 @@ public void testCreate_preservesTrailingSlash() { } @Test - public void testGetGcsFilename_empty_notAllowed() { + public void testGetGcsFilename_empty_notAllowed() throws IOException { try (CloudStorageFileSystem fs = CloudStorageFileSystem.forBucket("doodle")) { thrown.expect(IllegalArgumentException.class); fs.getPath("").getBlobId(); @@ -76,21 +76,21 @@ public void testGetGcsFilename_empty_notAllowed() { } @Test - public void testGetGcsFilename_stripsPrefixSlash() { + public void testGetGcsFilename_stripsPrefixSlash() throws IOException { try (CloudStorageFileSystem fs = CloudStorageFileSystem.forBucket("doodle")) { assertThat(fs.getPath("/hi").getBlobId().name()).isEqualTo("hi"); } } @Test - public void testGetGcsFilename_overrideStripPrefixSlash_doesntStripPrefixSlash() { + public void testGetGcsFilename_overrideStripPrefixSlash_doesntStripPrefixSlash() throws IOException { try (CloudStorageFileSystem fs = CloudStorageFileSystem.forBucket("doodle", stripPrefixSlash(false))) { assertThat(fs.getPath("/hi").getBlobId().name()).isEqualTo("/hi"); } } @Test - public void testGetGcsFilename_extraSlashes_throwsIae() { + public void testGetGcsFilename_extraSlashes_throwsIae() throws IOException { try (CloudStorageFileSystem fs = CloudStorageFileSystem.forBucket("doodle")) { thrown.expect(IllegalArgumentException.class); fs.getPath("a//b").getBlobId().name(); @@ -98,14 +98,14 @@ public void testGetGcsFilename_extraSlashes_throwsIae() { } @Test - public void testGetGcsFilename_overridepermitEmptyPathComponents() { + public void testGetGcsFilename_overridepermitEmptyPathComponents() throws IOException { try (CloudStorageFileSystem fs = CloudStorageFileSystem.forBucket("doodle", permitEmptyPathComponents(true))) { assertThat(fs.getPath("a//b").getBlobId().name()).isEqualTo("a//b"); } } @Test - public void testGetGcsFilename_freaksOutOnExtraSlashesAndDotDirs() { + public void testGetGcsFilename_freaksOutOnExtraSlashesAndDotDirs() throws IOException { try (CloudStorageFileSystem fs = CloudStorageFileSystem.forBucket("doodle")) { thrown.expect(IllegalArgumentException.class); fs.getPath("a//b/..").getBlobId().name(); @@ -113,7 +113,7 @@ public void testGetGcsFilename_freaksOutOnExtraSlashesAndDotDirs() { } @Test - public void testNameCount() { + public void testNameCount() throws IOException { try (CloudStorageFileSystem fs = CloudStorageFileSystem.forBucket("doodle")) { assertThat(fs.getPath("").getNameCount()).isEqualTo(1); assertThat(fs.getPath("/").getNameCount()).isEqualTo(0); @@ -124,7 +124,7 @@ public void testNameCount() { } @Test - public void testGetName() { + public void testGetName() throws IOException { try (CloudStorageFileSystem fs = CloudStorageFileSystem.forBucket("doodle")) { assertThat(fs.getPath("").getName(0).toString()).isEqualTo(""); assertThat(fs.getPath("/hi").getName(0).toString()).isEqualTo("hi"); @@ -133,7 +133,7 @@ public void testGetName() { } @Test - public void testGetName_negative_throwsIae() { + public void testGetName_negative_throwsIae() throws IOException { try (CloudStorageFileSystem fs = CloudStorageFileSystem.forBucket("doodle")) { thrown.expect(IllegalArgumentException.class); fs.getPath("angel").getName(-1); @@ -141,7 +141,7 @@ public void testGetName_negative_throwsIae() { } @Test - public void testGetName_overflow_throwsIae() { + public void testGetName_overflow_throwsIae() throws IOException { try (CloudStorageFileSystem fs = CloudStorageFileSystem.forBucket("doodle")) { thrown.expect(IllegalArgumentException.class); fs.getPath("angel").getName(1); @@ -149,7 +149,7 @@ public void testGetName_overflow_throwsIae() { } @Test - public void testIterator() { + public void testIterator() throws IOException { try (CloudStorageFileSystem fs = CloudStorageFileSystem.forBucket("doodle")) { assertThat(Iterables.get(fs.getPath("/dog/mog"), 0).toString()).isEqualTo("dog"); assertThat(Iterables.get(fs.getPath("/dog/mog"), 1).toString()).isEqualTo("mog"); @@ -160,7 +160,7 @@ public void testIterator() { } @Test - public void testNormalize() { + public void testNormalize() throws IOException { try (CloudStorageFileSystem fs = CloudStorageFileSystem.forBucket("doodle")) { assertThat(fs.getPath("/").normalize().toString()).isEqualTo("/"); assertThat(fs.getPath("a/x/../b/x/..").normalize().toString()).isEqualTo("a/b/"); @@ -170,7 +170,7 @@ public void testNormalize() { } @Test - public void testNormalize_dot_becomesBlank() { + public void testNormalize_dot_becomesBlank() throws IOException { try (CloudStorageFileSystem fs = CloudStorageFileSystem.forBucket("doodle")) { assertThat(fs.getPath("").normalize().toString()).isEqualTo(""); assertThat(fs.getPath(".").normalize().toString()).isEqualTo(""); @@ -178,14 +178,14 @@ public void testNormalize_dot_becomesBlank() { } @Test - public void testNormalize_trailingSlash_isPreserved() { + public void testNormalize_trailingSlash_isPreserved() throws IOException { try (CloudStorageFileSystem fs = CloudStorageFileSystem.forBucket("doodle")) { assertThat(fs.getPath("o/").normalize().toString()).isEqualTo("o/"); } } @Test - public void testNormalize_doubleDot_becomesBlank() { + public void testNormalize_doubleDot_becomesBlank() throws IOException { try (CloudStorageFileSystem fs = CloudStorageFileSystem.forBucket("doodle")) { assertThat(fs.getPath("..").normalize().toString()).isEqualTo(""); assertThat(fs.getPath("../..").normalize().toString()).isEqualTo(""); @@ -193,14 +193,14 @@ public void testNormalize_doubleDot_becomesBlank() { } @Test - public void testNormalize_extraSlashes_getRemoved() { + public void testNormalize_extraSlashes_getRemoved() throws IOException { try (CloudStorageFileSystem fs = CloudStorageFileSystem.forBucket("doodle")) { assertThat(fs.getPath("//life///b/good//").normalize().toString()).isEqualTo("/life/b/good/"); } } @Test - public void testToRealPath_hasDotDir_throwsIae() { + public void testToRealPath_hasDotDir_throwsIae() throws IOException { try (CloudStorageFileSystem fs = CloudStorageFileSystem.forBucket("doodle")) { fs.getPath("a/hi./b").toRealPath(); fs.getPath("a/.hi/b").toRealPath(); @@ -211,7 +211,7 @@ public void testToRealPath_hasDotDir_throwsIae() { } @Test - public void testToRealPath_hasDotDotDir_throwsIae() { + public void testToRealPath_hasDotDotDir_throwsIae() throws IOException { try (CloudStorageFileSystem fs = CloudStorageFileSystem.forBucket("doodle")) { fs.getPath("a/hi../b").toRealPath(); fs.getPath("a/..hi/b").toRealPath(); @@ -222,7 +222,7 @@ public void testToRealPath_hasDotDotDir_throwsIae() { } @Test - public void testToRealPath_extraSlashes_throwsIae() { + public void testToRealPath_extraSlashes_throwsIae() throws IOException { try (CloudStorageFileSystem fs = CloudStorageFileSystem.forBucket("doodle")) { thrown.expect(IllegalArgumentException.class); thrown.expectMessage("extra slashes"); @@ -231,7 +231,7 @@ public void testToRealPath_extraSlashes_throwsIae() { } @Test - public void testToRealPath_overridePermitEmptyPathComponents_extraSlashes_slashesRemain() { + public void testToRealPath_overridePermitEmptyPathComponents_extraSlashes_slashesRemain() throws IOException { try (CloudStorageFileSystem fs = CloudStorageFileSystem.forBucket("doodle", permitEmptyPathComponents(true))) { assertThat(fs.getPath("/life///b/./good/").toRealPath().toString()) .isEqualTo("life///b/./good/"); @@ -239,7 +239,7 @@ public void testToRealPath_overridePermitEmptyPathComponents_extraSlashes_slashe } @Test - public void testToRealPath_permitEmptyPathComponents_doesNotNormalize() { + public void testToRealPath_permitEmptyPathComponents_doesNotNormalize() throws IOException { try (CloudStorageFileSystem fs = CloudStorageFileSystem.forBucket("doodle", permitEmptyPathComponents(true))) { assertThat(fs.getPath("a").toRealPath().toString()).isEqualTo("a"); assertThat(fs.getPath("a//b").toRealPath().toString()).isEqualTo("a//b"); @@ -248,14 +248,14 @@ public void testToRealPath_permitEmptyPathComponents_doesNotNormalize() { } @Test - public void testToRealPath_withWorkingDirectory_makesAbsolute() { + public void testToRealPath_withWorkingDirectory_makesAbsolute() throws IOException { try (CloudStorageFileSystem fs = CloudStorageFileSystem.forBucket("doodle", workingDirectory("/lol"))) { assertThat(fs.getPath("a").toRealPath().toString()).isEqualTo("lol/a"); } } @Test - public void testToRealPath_disableStripPrefixSlash_makesPathAbsolute() { + public void testToRealPath_disableStripPrefixSlash_makesPathAbsolute() throws IOException { try (CloudStorageFileSystem fs = CloudStorageFileSystem.forBucket("doodle", stripPrefixSlash(false))) { assertThat(fs.getPath("a").toRealPath().toString()).isEqualTo("/a"); assertThat(fs.getPath("/a").toRealPath().toString()).isEqualTo("/a"); @@ -263,21 +263,21 @@ public void testToRealPath_disableStripPrefixSlash_makesPathAbsolute() { } @Test - public void testToRealPath_trailingSlash_getsPreserved() { + public void testToRealPath_trailingSlash_getsPreserved() throws IOException { try (CloudStorageFileSystem fs = CloudStorageFileSystem.forBucket("doodle")) { assertThat(fs.getPath("a/b/").toRealPath().toString()).isEqualTo("a/b/"); } } @Test - public void testNormalize_empty_returnsEmpty() { + public void testNormalize_empty_returnsEmpty() throws IOException { try (CloudStorageFileSystem fs = CloudStorageFileSystem.forBucket("doodle")) { assertThat(fs.getPath("").normalize().toString()).isEqualTo(""); } } @Test - public void testNormalize_preserveTrailingSlash() { + public void testNormalize_preserveTrailingSlash() throws IOException { try (CloudStorageFileSystem fs = CloudStorageFileSystem.forBucket("doodle")) { assertThat(fs.getPath("a/b/../c/").normalize().toString()).isEqualTo("a/c/"); assertThat(fs.getPath("a/b/./c/").normalize().toString()).isEqualTo("a/b/c/"); @@ -285,7 +285,7 @@ public void testNormalize_preserveTrailingSlash() { } @Test - public void testGetParent_preserveTrailingSlash() { + public void testGetParent_preserveTrailingSlash() throws IOException { try (CloudStorageFileSystem fs = CloudStorageFileSystem.forBucket("doodle")) { assertThat(fs.getPath("a/b/c").getParent().toString()).isEqualTo("a/b/"); assertThat(fs.getPath("a/b/c/").getParent().toString()).isEqualTo("a/b/"); @@ -297,7 +297,7 @@ public void testGetParent_preserveTrailingSlash() { } @Test - public void testGetRoot() { + public void testGetRoot() throws IOException { try (CloudStorageFileSystem fs = CloudStorageFileSystem.forBucket("doodle")) { assertThat(fs.getPath("/hello").getRoot().toString()).isEqualTo("/"); assertThat((Object) fs.getPath("hello").getRoot()).isNull(); @@ -305,7 +305,7 @@ public void testGetRoot() { } @Test - public void testRelativize() { + public void testRelativize() throws IOException { try (CloudStorageFileSystem fs = CloudStorageFileSystem.forBucket("doodle")) { assertThat( fs.getPath("/foo/bar/lol/cat").relativize(fs.getPath("/foo/a/b/../../c")).toString()) @@ -314,7 +314,7 @@ public void testRelativize() { } @Test - public void testRelativize_providerMismatch() { + public void testRelativize_providerMismatch() throws IOException { try (CloudStorageFileSystem gcs = CloudStorageFileSystem.forBucket("doodle")) { thrown.expect(ProviderMismatchException.class); gcs.getPath("/etc").relativize(FileSystems.getDefault().getPath("/dog")); @@ -323,7 +323,7 @@ public void testRelativize_providerMismatch() { @Test @SuppressWarnings("ReturnValueIgnored") // testing that an Exception is thrown - public void testRelativize_providerMismatch2() { + public void testRelativize_providerMismatch2() throws IOException { try (CloudStorageFileSystem gcs = CloudStorageFileSystem.forBucket("doodle")) { thrown.expect(ProviderMismatchException.class); gcs.getPath("/dog").relativize(FileSystems.getDefault().getPath("/etc")); @@ -331,7 +331,7 @@ public void testRelativize_providerMismatch2() { } @Test - public void testResolve() { + public void testResolve() throws IOException { try (CloudStorageFileSystem fs = CloudStorageFileSystem.forBucket("doodle")) { assertThat(fs.getPath("/hi").resolve("there").toString()).isEqualTo("/hi/there"); assertThat(fs.getPath("hi").resolve("there").toString()).isEqualTo("hi/there"); @@ -339,7 +339,7 @@ public void testResolve() { } @Test - public void testResolve_providerMismatch() { + public void testResolve_providerMismatch() throws IOException { try (CloudStorageFileSystem gcs = CloudStorageFileSystem.forBucket("doodle")) { thrown.expect(ProviderMismatchException.class); gcs.getPath("etc").resolve(FileSystems.getDefault().getPath("/dog")); @@ -347,7 +347,7 @@ public void testResolve_providerMismatch() { } @Test - public void testIsAbsolute() { + public void testIsAbsolute() throws IOException { try (CloudStorageFileSystem fs = CloudStorageFileSystem.forBucket("doodle")) { assertThat(fs.getPath("/hi").isAbsolute()).isTrue(); assertThat(fs.getPath("hi").isAbsolute()).isFalse(); @@ -355,7 +355,7 @@ public void testIsAbsolute() { } @Test - public void testToAbsolutePath() { + public void testToAbsolutePath() throws IOException { try (CloudStorageFileSystem fs = CloudStorageFileSystem.forBucket("doodle")) { assertThat((Object) fs.getPath("/hi").toAbsolutePath()).isEqualTo(fs.getPath("/hi")); assertThat((Object) fs.getPath("hi").toAbsolutePath()).isEqualTo(fs.getPath("/hi")); @@ -363,14 +363,14 @@ public void testToAbsolutePath() { } @Test - public void testToAbsolutePath_withWorkingDirectory() { + public void testToAbsolutePath_withWorkingDirectory() throws IOException { try (CloudStorageFileSystem fs = CloudStorageFileSystem.forBucket("doodle", workingDirectory("/lol"))) { assertThat(fs.getPath("a").toAbsolutePath().toString()).isEqualTo("/lol/a"); } } @Test - public void testGetFileName() { + public void testGetFileName() throws IOException { try (CloudStorageFileSystem fs = CloudStorageFileSystem.forBucket("doodle")) { assertThat(fs.getPath("/hi/there").getFileName().toString()).isEqualTo("there"); assertThat(fs.getPath("military/fashion/show").getFileName().toString()).isEqualTo("show"); @@ -378,7 +378,7 @@ public void testGetFileName() { } @Test - public void testCompareTo() { + public void testCompareTo() throws IOException { try (CloudStorageFileSystem fs = CloudStorageFileSystem.forBucket("doodle")) { assertThat(fs.getPath("/hi/there").compareTo(fs.getPath("/hi/there"))).isEqualTo(0); assertThat(fs.getPath("/hi/there").compareTo(fs.getPath("/hi/therf"))).isEqualTo(-1); @@ -387,7 +387,7 @@ public void testCompareTo() { } @Test - public void testStartsWith() { + public void testStartsWith() throws IOException { try (CloudStorageFileSystem fs = CloudStorageFileSystem.forBucket("doodle")) { assertThat(fs.getPath("/hi/there").startsWith(fs.getPath("/hi/there"))).isTrue(); assertThat(fs.getPath("/hi/there").startsWith(fs.getPath("/hi/therf"))).isFalse(); @@ -400,7 +400,7 @@ public void testStartsWith() { } @Test - public void testEndsWith() { + public void testEndsWith() throws IOException { try (CloudStorageFileSystem fs = CloudStorageFileSystem.forBucket("doodle")) { assertThat(fs.getPath("/hi/there").endsWith(fs.getPath("there"))).isTrue(); assertThat(fs.getPath("/hi/there").endsWith(fs.getPath("therf"))).isFalse(); @@ -441,7 +441,7 @@ public void testRelativize_willWorkWithRecursiveCopy() throws IOException { } @Test - public void testToFile_unsupported() { + public void testToFile_unsupported() throws IOException { try (CloudStorageFileSystem fs = CloudStorageFileSystem.forBucket("doodle")) { Path path = fs.getPath("/lol"); thrown.expect(UnsupportedOperationException.class); @@ -450,7 +450,7 @@ public void testToFile_unsupported() { } @Test - public void testEquals() { + public void testEquals() throws IOException { try (CloudStorageFileSystem fs = CloudStorageFileSystem.forBucket("doodle")) { new EqualsTester() // These are obviously equal. @@ -466,7 +466,7 @@ public void testEquals() { } @Test - public void testEquals_currentDirectoryIsTakenIntoConsideration() { + public void testEquals_currentDirectoryIsTakenIntoConsideration() throws IOException { try (CloudStorageFileSystem fs = CloudStorageFileSystem.forBucket("doodle", workingDirectory("/hello"))) { new EqualsTester() .addEqualityGroup(fs.getPath("cat"), fs.getPath("/hello/cat")) @@ -476,7 +476,7 @@ public void testEquals_currentDirectoryIsTakenIntoConsideration() { } @Test - public void testNullness() throws NoSuchMethodException, SecurityException { + public void testNullness() throws IOException, NoSuchMethodException, SecurityException { try (CloudStorageFileSystem fs = CloudStorageFileSystem.forBucket("doodle")) { NullPointerTester tester = new NullPointerTester(); tester.ignore(CloudStoragePath.class.getMethod("equals", Object.class));