Skip to content

Commit 335a4d4

Browse files
jean-philippe-martinmziccard
authored andcommitted
---
yaml --- r: 7415 b: refs/heads/tswast-patch-1 c: 3b55bfb h: refs/heads/master i: 7413: fd502f3 7411: 4fbedda 7407: aa20248
1 parent d9bd475 commit 335a4d4

6 files changed

Lines changed: 61 additions & 39 deletions

File tree

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,5 +57,5 @@ refs/tags/v0.18.0: 9d193c4c4b9d1c6f21515dd8e50836b9194ec9bb
5757
refs/tags/v0.19.0: e67b56e4d8dad5f9a7b38c9b2107c23c828f2ed5
5858
refs/tags/v0.20.0: 839f7fb7156535146aa1cb2c5aadd8d375d854e8
5959
refs/tags/v0.20.1: 370471f437f1f4f68a11e068df5cd6bf39edb1fa
60-
refs/heads/tswast-patch-1: 5917ae7e96edd45dc9cdd67cd646de1f0b374dac
60+
refs/heads/tswast-patch-1: 3b55bfbd56293367c25f7fc83b17f2d527572aae
6161
refs/heads/pubsub-streaming-pull: 19262b752ee874eb2ca3b950eb2aef44d5a5267b

branches/tswast-patch-1/gcloud-java-contrib/gcloud-java-nio/src/main/java/com/google/cloud/storage/contrib/nio/CloudStorageConfiguration.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -82,8 +82,9 @@ public static final class Builder {
8282
private int blockSize = CloudStorageFileSystem.BLOCK_SIZE_DEFAULT;
8383

8484
/**
85-
* Changes current working directory for new filesystem. This cannot be changed once it's
86-
* been set. You'll need to create another {@link CloudStorageFileSystem} object.
85+
* Changes current working directory for new filesystem. This defaults to the root directory.
86+
* The working directory cannot be changed once it's been set. You'll need to create another
87+
* {@link CloudStorageFileSystem} object.
8788
*
8889
* @throws IllegalArgumentException if {@code path} is not absolute.
8990
*/
@@ -95,7 +96,7 @@ public Builder workingDirectory(String path) {
9596

9697
/**
9798
* Configures whether or not we should throw an exception when encountering object names
98-
* containing superfluous slashes, e.g. {@code a//b}
99+
* containing superfluous slashes, e.g. {@code a//b}.
99100
*/
100101
public Builder permitEmptyPathComponents(boolean value) {
101102
permitEmptyPathComponents = value;

branches/tswast-patch-1/gcloud-java-contrib/gcloud-java-nio/src/main/java/com/google/cloud/storage/contrib/nio/CloudStorageFileSystem.java

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@
3838
import javax.annotation.CheckReturnValue;
3939
import javax.annotation.Nullable;
4040
import javax.annotation.concurrent.Immutable;
41+
import javax.annotation.CheckReturnValue;
42+
import javax.annotation.concurrent.ThreadSafe;
4143

4244
/**
4345
* Google Cloud Storage {@link FileSystem} implementation.
@@ -47,7 +49,7 @@
4749
* @see <a href="https://developers.google.com/storage/docs/bucketnaming">
4850
* Bucket and Object Naming Guidelines</a>
4951
*/
50-
@Immutable
52+
@ThreadSafe
5153
public final class CloudStorageFileSystem extends FileSystem {
5254

5355
/**
@@ -65,6 +67,7 @@ public final class CloudStorageFileSystem extends FileSystem {
6567
* @see #forBucket(String, CloudStorageConfiguration)
6668
* @see java.nio.file.FileSystems#getFileSystem(java.net.URI)
6769
*/
70+
@CheckReturnValue
6871
public static CloudStorageFileSystem forBucket(String bucket) {
6972
return forBucket(bucket, CloudStorageConfiguration.DEFAULT);
7073
}
@@ -74,6 +77,7 @@ public static CloudStorageFileSystem forBucket(String bucket) {
7477
*
7578
* @see #forBucket(String)
7679
*/
80+
@CheckReturnValue
7781
public static CloudStorageFileSystem forBucket(String bucket, CloudStorageConfiguration config) {
7882
checkArgument(
7983
!bucket.startsWith(URI_SCHEME + ":"), "Bucket name must not have schema: %s", bucket);
@@ -155,7 +159,9 @@ public CloudStoragePath getPath(String first, String... more) {
155159
}
156160

157161
/**
158-
* Does nothing.
162+
* Does nothing currently. This method <i>might</i> be updated in the future to close all channels
163+
* associated with this file system object. However it's unlikely that even then, calling this
164+
* method will become mandatory.
159165
*/
160166
@Override
161167
public void close() throws IOException {
@@ -191,6 +197,9 @@ public Iterable<Path> getRootDirectories() {
191197
return ImmutableSet.<Path>of(CloudStoragePath.getPath(this, UnixPath.ROOT));
192198
}
193199

200+
/**
201+
* Returns nothing because GCS doesn't have disk partitions of limited size, or anything similar.
202+
*/
194203
@Override
195204
public Iterable<FileStore> getFileStores() {
196205
return ImmutableSet.of();
@@ -206,7 +215,7 @@ public Set<String> supportedFileAttributeViews() {
206215
*/
207216
@Override
208217
public PathMatcher getPathMatcher(String syntaxAndPattern) {
209-
// TODO: Implement me.
218+
// TODO(#813): Implement me.
210219
throw new UnsupportedOperationException();
211220
}
212221

branches/tswast-patch-1/gcloud-java-contrib/gcloud-java-nio/src/main/java/com/google/cloud/storage/contrib/nio/CloudStorageFileSystemProvider.java

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -70,10 +70,16 @@
7070

7171
import javax.annotation.Nullable;
7272
import javax.annotation.concurrent.ThreadSafe;
73+
import javax.inject.Singleton;
7374

7475
/**
7576
* Google Cloud Storage {@link FileSystemProvider} implementation.
77+
*
78+
* <p><b>Note:</b> This class should never be used directly. This class is instantiated by the
79+
* service loader and called through a standardized API, e.g. {@link java.nio.file.Files}. However
80+
* the javadocs in this class serve as useful documentation for the behavior of the GCS NIO library.
7681
*/
82+
@Singleton
7783
@ThreadSafe
7884
@AutoService(FileSystemProvider.class)
7985
public final class CloudStorageFileSystemProvider extends FileSystemProvider {
@@ -152,6 +158,13 @@ public CloudStorageFileSystem getFileSystem(URI uri) {
152158

153159
/**
154160
* Returns Cloud Storage file system, provided a URI with no path, e.g. {@code gs://bucket}.
161+
*
162+
* @param uri bucket and current working directory, e.g. {@code gs://bucket}
163+
* @param env map of configuration options, whose keys correspond to the method names of
164+
* {@link CloudStorageConfiguration.Builder}. However you are not allowed to set the working
165+
* directory, as that should be provided in the {@code uri}
166+
* @throws IllegalArgumentException if {@code uri} specifies a user, query, fragment, or scheme is
167+
* not {@value CloudStorageFileSystem#URI_SCHEME}
155168
*/
156169
@Override
157170
public CloudStorageFileSystem newFileSystem(URI uri, Map<String, ?> env) {
@@ -527,9 +540,9 @@ public <A extends BasicFileAttributes> A readAttributes(
527540

528541
@Override
529542
public Map<String, Object> readAttributes(Path path, String attributes, LinkOption... options) {
530-
// Java 7 NIO defines at least eleven string attributes we'd want to support
531-
// (eg. BasicFileAttributeView and PosixFileAttributeView), so rather than a partial
532-
// implementation we rely on the other overload for now.
543+
// TODO(#811): Java 7 NIO defines at least eleven string attributes we'd want to support
544+
// (eg. BasicFileAttributeView and PosixFileAttributeView), so rather than a partial
545+
// implementation we rely on the other overload for now.
533546
throw new UnsupportedOperationException();
534547
}
535548

@@ -611,13 +624,13 @@ public String toString() {
611624
}
612625

613626
private IOException asIOException(StorageException oops) {
627+
// RPC API can only throw StorageException, but CloudStorageFileSystemProvider
628+
// can only throw IOException. Square peg, round hole.
629+
// TODO(#810): Research if other codes should be translated similarly.
614630
if (oops.code() == 404) {
615631
return new NoSuchFileException(oops.reason());
616632
}
617-
// TODO: research if other codes should be translated to IOException.
618633

619-
// RPC API can only throw StorageException, but CloudStorageFileSystemProvider
620-
// can only throw IOException. Square peg, round hole.
621634
Throwable cause = oops.getCause();
622635
try {
623636
if (cause instanceof FileAlreadyExistsException) {

branches/tswast-patch-1/gcloud-java-contrib/gcloud-java-nio/src/test/java/com/google/cloud/storage/contrib/nio/it/ITGcsNio.java

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -58,17 +58,16 @@
5858
import java.util.logging.Logger;
5959

6060
/**
61-
* Integration test for gcloud-nio. This test actually talks to GCS (you need an account).
62-
* Tests both reading and writing.
61+
* Integration test for gcloud-nio.
6362
*
64-
* You *must* set the GOOGLE_APPLICATION_CREDENTIALS environment variable
65-
* for this test to work. It must contain the name of a local file that contains
66-
* your Service Account JSON Key.
63+
* <p>This test actually talks to GCS (you need an account) and tests both reading and writing. You
64+
* *must* set the {@code GOOGLE_APPLICATION_CREDENTIALS} environment variable for this test to work.
65+
* It must contain the name of a local file that contains your Service Account JSON Key.
6766
*
68-
* The instructions for how to get the Service Account JSON Key are
67+
* <p>The instructions for how to get the Service Account JSON Key are
6968
* at https://cloud.google.com/storage/docs/authentication?hl=en#service_accounts
7069
*
71-
* The short version is this: go to cloud.google.com/console,
70+
* <p>The short version is this: go to cloud.google.com/console,
7271
* select your project, search for "API manager", click "Credentials",
7372
* click "create credentials/service account key", new service account,
7473
* JSON. The contents of the file that's sent to your browsers is your
@@ -78,19 +77,18 @@
7877
@RunWith(JUnit4.class)
7978
public class ITGcsNio {
8079

81-
private static final List<String> FILE_CONTENTS = ImmutableList.of(
82-
"Tous les êtres humains naissent libres et égaux en dignité et en droits.",
83-
"Ils sont doués de raison et de conscience et doivent agir ",
84-
"les uns envers les autres dans un esprit de fraternité.");
80+
private static final List<String> FILE_CONTENTS =
81+
ImmutableList.of(
82+
"Tous les êtres humains naissent libres et égaux en dignité et en droits.",
83+
"Ils sont doués de raison et de conscience et doivent agir ",
84+
"les uns envers les autres dans un esprit de fraternité.");
8585

8686
private static final Logger log = Logger.getLogger(ITGcsNio.class.getName());
8787
private static final String BUCKET = RemoteStorageHelper.generateBucketName();
8888
private static final String SML_FILE = "tmp-test-small-file.txt";
8989
private static final int SML_SIZE = 100;
90-
// it's big, relatively speaking.
91-
private static final String BIG_FILE = "tmp-test-big-file.txt";
92-
// arbitrary size that's not too round.
93-
private static final int BIG_SIZE = 2 * 1024 * 1024 - 50;
90+
private static final String BIG_FILE = "tmp-test-big-file.txt"; // it's big, relatively speaking.
91+
private static final int BIG_SIZE = 2 * 1024 * 1024 - 50; // arbitrary size that's not too round.
9492
private static final String PREFIX = "tmp-test-file";
9593
private static Storage storage;
9694
private static StorageOptions storageOptions;

branches/tswast-patch-1/gcloud-java-storage/src/main/java/com/google/cloud/storage/testing/FakeStorageRpc.java

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -58,14 +58,15 @@
5858
* <li>patch
5959
* <li>continueRewrite
6060
* <li>createBatch
61+
* <li>checksums, etags
6162
* </ul>
6263
* </ul>
6364
*/
6465
@NotThreadSafe
6566
public class FakeStorageRpc implements StorageRpc {
6667

6768
// fullname -> metadata
68-
Map<String, StorageObject> stuff = new HashMap<>();
69+
Map<String, StorageObject> metadata = new HashMap<>();
6970
// fullname -> contents
7071
Map<String, byte[]> contents = new HashMap<>();
7172
// fullname -> future contents that will be visible on close.
@@ -74,15 +75,15 @@ public class FakeStorageRpc implements StorageRpc {
7475
private final boolean throwIfOption;
7576

7677
/**
77-
* @param throwIfOption if true, we throw when given any option.
78+
* @param throwIfOption if true, we throw when given any option
7879
*/
7980
public FakeStorageRpc(boolean throwIfOption) {
8081
this.throwIfOption = throwIfOption;
8182
}
8283

8384
// remove all files
8485
void reset() {
85-
stuff = new HashMap<>();
86+
metadata = new HashMap<>();
8687
contents = new HashMap<>();
8788
}
8889

@@ -96,7 +97,7 @@ public StorageObject create(StorageObject object, InputStream content, Map<Optio
9697
throws StorageException {
9798
potentiallyThrow(options);
9899
String key = fullname(object);
99-
stuff.put(key, object);
100+
metadata.put(key, object);
100101
try {
101102
contents.put(key, com.google.common.io.ByteStreams.toByteArray(content));
102103
} catch (IOException e) {
@@ -138,7 +139,7 @@ public Tuple<String, Iterable<StorageObject>> list(String bucket, Map<Option, ?>
138139

139140
List<StorageObject> values = new ArrayList<>();
140141
Map<String, StorageObject> folders = new HashMap<>();
141-
for (StorageObject so : stuff.values()) {
142+
for (StorageObject so : metadata.values()) {
142143
if (!so.getName().startsWith(prefix)) {
143144
continue;
144145
}
@@ -175,8 +176,8 @@ public StorageObject get(StorageObject object, Map<Option, ?> options) throws St
175176
}
176177

177178
String key = fullname(object);
178-
if (stuff.containsKey(key)) {
179-
StorageObject ret = stuff.get(key);
179+
if (metadata.containsKey(key)) {
180+
StorageObject ret = metadata.get(key);
180181
if (contents.containsKey(key)) {
181182
ret.setSize(BigInteger.valueOf(contents.get(key).length));
182183
}
@@ -208,7 +209,7 @@ public boolean delete(Bucket bucket, Map<Option, ?> options) throws StorageExcep
208209
public boolean delete(StorageObject object, Map<Option, ?> options) throws StorageException {
209210
String key = fullname(object);
210211
contents.remove(key);
211-
return null != stuff.remove(key);
212+
return null != metadata.remove(key);
212213
}
213214

214215
@Override
@@ -272,10 +273,10 @@ public String open(StorageObject object, Map<Option, ?> options) throws StorageE
272273
}
273274
}
274275
}
275-
if (mustNotExist && stuff.containsKey(key)) {
276+
if (mustNotExist && metadata.containsKey(key)) {
276277
throw new StorageException(new FileAlreadyExistsException(key));
277278
}
278-
stuff.put(key, object);
279+
metadata.put(key, object);
279280

280281
return fullname(object);
281282
}
@@ -327,7 +328,7 @@ public RewriteResponse openRewrite(RewriteRequest rewriteRequest) throws Storage
327328
throw new StorageException(new FileAlreadyExistsException(destKey));
328329
}
329330

330-
stuff.put(destKey, rewriteRequest.target);
331+
metadata.put(destKey, rewriteRequest.target);
331332

332333
byte[] data = contents.get(sourceKey);
333334
contents.put(destKey, Arrays.copyOf(data, data.length));

0 commit comments

Comments
 (0)