Skip to content

Commit

Permalink
Merge pull request #714 from jean-philippe-martin/integration-tests
Browse files Browse the repository at this point in the history
Add integration test and example jar.
  • Loading branch information
jean-philippe-martin committed Mar 25, 2016
2 parents b7f137d + 331d0ec commit b584349
Show file tree
Hide file tree
Showing 10 changed files with 554 additions and 43 deletions.
56 changes: 35 additions & 21 deletions gcloud-java-contrib/gcloud-java-nio/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
<dependencies>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>gcloud-java</artifactId>
<artifactId>gcloud-java-storage</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
Expand Down Expand Up @@ -92,26 +92,40 @@
<compilerArgument>-Xlint:unchecked</compilerArgument>
</configuration>
</plugin>
<plugin>
<artifactId>maven-jar-plugin</artifactId>
<version>2.6</version>
<configuration>
<archive>
<addMavenDescriptor>true</addMavenDescriptor>
<index>true</index>
<manifest>
<addDefaultImplementationEntries>true</addDefaultImplementationEntries>
<addDefaultSpecificationEntries>true</addDefaultSpecificationEntries>
</manifest>
<manifestEntries>
<artifactId>${project.artifactId}</artifactId>
<groupId>${project.groupId}</groupId>
<version>${project.version}</version>
<buildNumber>${buildNumber}</buildNumber>
</manifestEntries>
</archive>
</configuration>
</plugin>
<!-- shade the jar so we can demo adding the NIO jar to add functionality. -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>2.4.3</version>
<configuration>
<shadedArtifactAttached>true</shadedArtifactAttached>
<relocations>
<relocation>
<pattern>com</pattern>
<shadedPattern>shaded.gcloud-nio.com</shadedPattern>
<excludes>
<exclude>com.google.gcloud.**</exclude>
</excludes>
</relocation>
<relocation>
<pattern>org</pattern>
<shadedPattern>shaded.gcloud-nio.org</shadedPattern>
</relocation>
<relocation>
<pattern>google</pattern>
<shadedPattern>shaded.gcloud-nio.google</shadedPattern>
</relocation>
</relocations>
</configuration>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ public CloudStorageConfiguration build() {
Builder() {}
}

static final CloudStorageConfiguration DEFAULT = builder().build();
public static final CloudStorageConfiguration DEFAULT = builder().build();

static CloudStorageConfiguration fromMap(Map<String, ?> env) {
Builder builder = builder();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import static com.google.common.base.Preconditions.checkNotNull;

import com.google.common.collect.ImmutableSet;
import com.google.gcloud.storage.StorageOptions;

import java.io.IOException;
import java.net.URI;
Expand All @@ -34,6 +35,7 @@
import java.util.Objects;
import java.util.Set;

import javax.annotation.Nullable;
import javax.annotation.concurrent.Immutable;

/**
Expand All @@ -60,7 +62,7 @@ public final class CloudStorageFileSystem extends FileSystem {
* provides a simpler alternative.
*
* @see #forBucket(String, CloudStorageConfiguration)
* @see java.nio.file.FileSystems#getFileSystem(java.net.URI)
* @see java.nio.file.FileSystems#getFileSystem(URI)
*/
public static CloudStorageFileSystem forBucket(String bucket) {
return forBucket(bucket, CloudStorageConfiguration.DEFAULT);
Expand All @@ -72,10 +74,21 @@ public static CloudStorageFileSystem forBucket(String bucket) {
* @see #forBucket(String)
*/
public static CloudStorageFileSystem forBucket(String bucket, CloudStorageConfiguration config) {
checkArgument(
!bucket.startsWith(URI_SCHEME + ":"), "Bucket name must not have schema: %s", bucket);
return new CloudStorageFileSystem(
new CloudStorageFileSystemProvider(), bucket, checkNotNull(config));
return forBucket(bucket, config, null);
}

/**
* Creates a new filesystem for a particular bucket, with customizable settings and storage
* options.
*
* @see #forBucket(String)
*/
public static CloudStorageFileSystem forBucket(String bucket, CloudStorageConfiguration config,
@Nullable StorageOptions storageOptions) {
checkArgument(!bucket.startsWith(URI_SCHEME + ":"),
"Bucket name must not have schema: %s", bucket);
return new CloudStorageFileSystem(new CloudStorageFileSystemProvider(storageOptions),
bucket, checkNotNull(config));
}

public static final String URI_SCHEME = "gs";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,14 +82,14 @@ public final class CloudStorageFileSystemProvider extends FileSystemProvider {
private final Storage storage;

// used only when we create a new instance of CloudStorageFileSystemProvider.
private static StorageOptions storageOptions;
private static StorageOptions defaultStorageOptions;

/**
* Sets options that are only used by the constructor.
* Sets default options that are only used by the constructor.
*/
@VisibleForTesting
public static void setGCloudOptions(StorageOptions newStorageOptions) {
storageOptions = newStorageOptions;
defaultStorageOptions = newStorageOptions;
}

/**
Expand All @@ -99,14 +99,19 @@ public static void setGCloudOptions(StorageOptions newStorageOptions) {
* @see CloudStorageFileSystem#forBucket(String)
*/
public CloudStorageFileSystemProvider() {
this(storageOptions);
this(defaultStorageOptions);
}

private CloudStorageFileSystemProvider(@Nullable StorageOptions gcsStorageOptions) {
if (gcsStorageOptions == null) {
this.storage = StorageOptions.defaultInstance().service();
CloudStorageFileSystemProvider(@Nullable StorageOptions explicitOptions) {
// explicit options have priority over default options.
if (explicitOptions == null) {
if (defaultStorageOptions == null) {
this.storage = StorageOptions.defaultInstance().service();
} else {
this.storage = defaultStorageOptions.service();
}
} else {
this.storage = gcsStorageOptions.service();
this.storage = explicitOptions.service();
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@

import com.google.common.testing.EqualsTester;
import com.google.common.testing.NullPointerTester;
import com.google.gcloud.storage.StorageOptions;
import com.google.gcloud.storage.testing.LocalGcsHelper;

import org.junit.Before;
Expand Down Expand Up @@ -127,7 +128,8 @@ public void testNullness() throws IOException, NoSuchMethodException, SecurityEx
NullPointerTester tester =
new NullPointerTester()
.ignore(CloudStorageFileSystem.class.getMethod("equals", Object.class))
.setDefault(CloudStorageConfiguration.class, CloudStorageConfiguration.DEFAULT);
.setDefault(CloudStorageConfiguration.class, CloudStorageConfiguration.DEFAULT)
.setDefault(StorageOptions.class, LocalGcsHelper.options());
tester.testAllPublicStaticMethods(CloudStorageFileSystem.class);
tester.testAllPublicInstanceMethods(fs);
}
Expand Down
Loading

0 comments on commit b584349

Please sign in to comment.