Skip to content

Commit

Permalink
Merge branch 'master' into fake-storage-rpc-set-update-time
Browse files Browse the repository at this point in the history
# Conflicts:
#	google-cloud-nio/src/main/java/com/google/cloud/storage/contrib/nio/testing/FakeStorageRpc.java
  • Loading branch information
hosainnet committed Aug 4, 2020
2 parents 4a3c707 + 4e7bac1 commit 8ce0ccd
Show file tree
Hide file tree
Showing 11 changed files with 232 additions and 20 deletions.
10 changes: 10 additions & 0 deletions .kokoro/release/publish_javadoc.cfg
Original file line number Diff line number Diff line change
@@ -1,14 +1,24 @@
# Format: //devtools/kokoro/config/proto/build.proto

gfile_resources: "/bigstore/cloud-devrel-kokoro-resources/doc-templates/"

env_vars: {
key: "STAGING_BUCKET"
value: "docs-staging"
}

env_vars: {
key: "STAGING_BUCKET_V2"
value: "docs-staging-v2-staging"
# Production will be at: docs-staging-v2
}

env_vars: {
key: "TRAMPOLINE_BUILD_FILE"
value: "github/java-storage-nio/.kokoro/release/publish_javadoc.sh"
}


before_action {
fetch_keystore {
keystore_resource {
Expand Down
25 changes: 23 additions & 2 deletions .kokoro/release/publish_javadoc.sh
Original file line number Diff line number Diff line change
Expand Up @@ -24,20 +24,25 @@ if [[ -z "${STAGING_BUCKET}" ]]; then
exit 1
fi

if [[ -z "${STAGING_BUCKET_V2}" ]]; then
echo "Need to set STAGING_BUCKET_V2 environment variable"
exit 1
fi

# work from the git root directory
pushd $(dirname "$0")/../../

# install docuploader package
python3 -m pip install gcp-docuploader

# compile all packages
mvn clean install -B -DskipTests=true
mvn clean install -B -q -DskipTests=true

NAME=google-cloud-nio
VERSION=$(grep ${NAME}: versions.txt | cut -d: -f3)

# build the docs
mvn site -B
mvn site -B -q

pushd target/site/apidocs

Expand All @@ -53,3 +58,19 @@ python3 -m docuploader upload . \
--staging-bucket ${STAGING_BUCKET}

popd

# V2
mvn clean site -B -q -Ddevsite.template="${KOKORO_GFILE_DIR}/java/"

pushd target/devsite

# create metadata
python3 -m docuploader create-metadata \
--name ${NAME} \
--version ${VERSION} \
--language java

# upload docs
python3 -m docuploader upload . \
--credentials ${CREDENTIALS} \
--staging-bucket ${STAGING_BUCKET_V2}
6 changes: 3 additions & 3 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
# Changelog

### [0.120.2](https://www.github.com/googleapis/java-storage-nio/compare/v0.120.1...v0.120.2) (2020-06-18)
### [0.121.2](https://www.github.com/googleapis/java-storage-nio/compare/v0.120.1...v0.121.2) (2020-06-18)


### Bug Fixes

* update FakeStorageRpc to extend StorageRpcTestBase [#135](https://www.github.com/googleapis/java-storage-nio/issues/135) ([7614295](https://www.github.com/googleapis/java-storage-nio/commit/761429571eea15b11b2d44b4f5a2c65b4f649484))

### [0.120.1](https://www.github.com/googleapis/java-storage-nio/compare/v0.120.0...v0.120.1) (2020-06-16)
### [0.121.1](https://www.github.com/googleapis/java-storage-nio/compare/v0.120.0...v0.121.1) (2020-06-16)


### Dependencies
Expand All @@ -33,7 +33,7 @@

* update CONTRIBUTING.md to include code formatting ([#534](https://www.github.com/googleapis/java-storage-nio/issues/534)) ([#103](https://www.github.com/googleapis/java-storage-nio/issues/103)) ([c329a58](https://www.github.com/googleapis/java-storage-nio/commit/c329a58086501f77d7c7e0db44eb06cb68eb933b))

## [0.120.0](https://www.github.com/googleapis/java-storage-nio/compare/0.120.0-alpha...v0.120.0) (2020-04-24)
## [0.121.0](https://www.github.com/googleapis/java-storage-nio/compare/0.120.0-alpha...v0.121.0) (2020-04-24)


### Features
Expand Down
2 changes: 1 addition & 1 deletion google-cloud-nio/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
<version>3.3.3</version>
<version>3.4.4</version>
<scope>test</scope>
</dependency><dependency>
<groupId>org.hamcrest</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@
import java.nio.file.attribute.FileTime;
import java.nio.file.attribute.UserPrincipalLookupService;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Objects;
import java.util.Set;
import javax.annotation.CheckReturnValue;
Expand All @@ -61,10 +63,11 @@ public final class CloudStorageFileSystem extends FileSystem {
public static final int BLOCK_SIZE_DEFAULT = 2 * 1024 * 1024;
public static final FileTime FILE_TIME_UNKNOWN = FileTime.fromMillis(0);
public static final Set<String> SUPPORTED_VIEWS = ImmutableSet.of(BASIC_VIEW, GCS_VIEW);

private final CloudStorageFileSystemProvider provider;
private final String bucket;
private final CloudStorageConfiguration config;
private static final Map<CloudStorageConfiguration, Set<CloudStorageFileSystemProvider>>
CONFIG_TO_PROVIDERS_MAP = new HashMap<>();

// Users can change this: then this affects every filesystem object created
// later, including via SPI. This is meant to be done only once, at the beginning
Expand Down Expand Up @@ -145,7 +148,28 @@ public static CloudStorageFileSystem forBucket(String bucket, CloudStorageConfig
!bucket.startsWith(URI_SCHEME + ":"), "Bucket name must not have schema: %s", bucket);
checkNotNull(config);
return new CloudStorageFileSystem(
new CloudStorageFileSystemProvider(config.userProject()), bucket, config);
getCloudStorageFileSystemProvider(config, null), bucket, config);
}

private static CloudStorageFileSystemProvider getCloudStorageFileSystemProvider(
CloudStorageConfiguration config, StorageOptions storageOptions) {
CloudStorageFileSystemProvider newProvider =
(storageOptions == null)
? new CloudStorageFileSystemProvider(config.userProject())
: new CloudStorageFileSystemProvider(config.userProject(), storageOptions);
Set<CloudStorageFileSystemProvider> existingProviders = CONFIG_TO_PROVIDERS_MAP.get(config);
if (existingProviders == null) {
existingProviders = new HashSet<>();
} else {
for (CloudStorageFileSystemProvider existiningProvider : existingProviders) {
if (existiningProvider.equals(newProvider)) {
return existiningProvider;
}
}
}
existingProviders.add(newProvider);
CONFIG_TO_PROVIDERS_MAP.put(config, existingProviders);
return newProvider;
}

/**
Expand All @@ -169,9 +193,7 @@ public static CloudStorageFileSystem forBucket(
checkArgument(
!bucket.startsWith(URI_SCHEME + ":"), "Bucket name must not have schema: %s", bucket);
return new CloudStorageFileSystem(
new CloudStorageFileSystemProvider(config.userProject(), storageOptions),
bucket,
checkNotNull(config));
getCloudStorageFileSystemProvider(config, storageOptions), bucket, checkNotNull(config));
}

CloudStorageFileSystem(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,15 +108,14 @@ private CloudStorageReadChannel(
this.config = config;
// get the generation, enshrine that in our options
fetchSize(gcsStorage, userProject, file);
List options = Lists.newArrayList(blobSourceOptions);
List<BlobSourceOption> options = Lists.newArrayList(blobSourceOptions);
if (null != generation) {
options.add(Storage.BlobSourceOption.generationMatch(generation));
}
if (!Strings.isNullOrEmpty(userProject)) {
options.add(BlobSourceOption.userProject(userProject));
}
this.blobSourceOptions =
(BlobSourceOption[]) options.toArray(new BlobSourceOption[options.size()]);
this.blobSourceOptions = options.toArray(new BlobSourceOption[options.size()]);

// innerOpen checks that it sees the same generation as fetchSize did,
// which ensure the file hasn't changed.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -345,6 +345,17 @@ public String open(String signedURL) {
public void write(
String uploadId, byte[] toWrite, int toWriteOffset, long destOffset, int length, boolean last)
throws StorageException {
writeWithResponse(uploadId, toWrite, toWriteOffset, destOffset, length, last);
}

@Override
public StorageObject writeWithResponse(
String uploadId,
byte[] toWrite,
int toWriteOffset,
long destOffset,
int length,
boolean last) {
// this may have a lot more allocations than ideal, but it'll work.
byte[] bytes;
if (futureContents.containsKey(uploadId)) {
Expand All @@ -359,11 +370,12 @@ public void write(
}
System.arraycopy(toWrite, toWriteOffset, bytes, (int) destOffset, length);
// we want to mimic the GCS behavior that file contents are only visible on close.
StorageObject storageObject = null;
if (last) {
contents.put(uploadId, bytes);
futureContents.remove(uploadId);
if (metadata.containsKey(uploadId)) {
StorageObject storageObject = metadata.get(uploadId);
storageObject = metadata.get(uploadId);
storageObject.setUpdated(now());
Long generation = storageObject.getGeneration();
if (null == generation) {
Expand All @@ -375,6 +387,7 @@ public void write(
} else {
futureContents.put(uploadId, bytes);
}
return storageObject;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@

import static com.google.common.truth.Truth.assertThat;
import static java.nio.charset.StandardCharsets.UTF_8;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotEquals;
import static org.junit.Assert.assertNotSame;
import static org.junit.Assert.assertSame;

import com.google.cloud.storage.StorageOptions;
import com.google.cloud.storage.contrib.nio.testing.LocalStorageHelper;
Expand Down Expand Up @@ -334,6 +338,39 @@ public void testDeleteRecursive() throws IOException {
}
}

@Test
public void testSameProvider() throws IOException {
try (CloudStorageFileSystem sourceFileSystem =
CloudStorageFileSystem.forBucket(
"bucket",
CloudStorageConfiguration.builder().permitEmptyPathComponents(true).build())) {
CloudStorageFileSystem destFileSystem =
CloudStorageFileSystem.forBucket(
"new-bucket",
CloudStorageConfiguration.builder().permitEmptyPathComponents(true).build());
assertSame(sourceFileSystem.provider(), destFileSystem.provider());
assertEquals(sourceFileSystem.config(), destFileSystem.config());
assertEquals("bucket", sourceFileSystem.bucket());
assertEquals("new-bucket", destFileSystem.bucket());
}
}

@Test
public void testDifferentProvider() throws IOException {
try (CloudStorageFileSystem sourceFileSystem =
CloudStorageFileSystem.forBucket(
"bucket",
CloudStorageConfiguration.builder().permitEmptyPathComponents(true).build())) {
CloudStorageFileSystem destFileSystem =
CloudStorageFileSystem.forBucket(
"new-bucket",
CloudStorageConfiguration.builder().permitEmptyPathComponents(false).build());
assertNotSame(sourceFileSystem.provider(), destFileSystem.provider());
assertNotEquals(sourceFileSystem.config(), destFileSystem.config());
assertEquals("bucket", sourceFileSystem.bucket());
assertEquals("new-bucket", destFileSystem.bucket());
}
}
/**
* Delete the given directory and all of its contents if non-empty.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@
import static com.google.common.truth.Truth.assertThat;
import static com.google.common.truth.Truth.assertWithMessage;
import static java.nio.charset.StandardCharsets.UTF_8;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotEquals;
import static org.junit.Assert.assertNotSame;
import static org.junit.Assert.assertSame;

import com.google.api.client.http.HttpResponseException;
import com.google.cloud.storage.BlobInfo;
Expand Down Expand Up @@ -96,6 +100,7 @@ public class ITGcsNio {

private static final Logger log = Logger.getLogger(ITGcsNio.class.getName());
private static final String BUCKET = RemoteStorageHelper.generateBucketName();
private static final String TARGET_BUCKET = RemoteStorageHelper.generateBucketName();
private static final String REQUESTER_PAYS_BUCKET =
RemoteStorageHelper.generateBucketName() + "_rp";
private static final String SML_FILE = "tmp-test-small-file.txt";
Expand All @@ -119,6 +124,7 @@ public static void beforeClass() throws IOException {
storage = storageOptions.getService();
// create and populate test bucket
storage.create(BucketInfo.of(BUCKET));
storage.create(BucketInfo.of(TARGET_BUCKET));
fillFile(storage, BUCKET, SML_FILE, SML_SIZE);
fillFile(storage, BUCKET, BIG_FILE, BIG_SIZE);
BucketInfo requesterPaysBucket =
Expand Down Expand Up @@ -1040,6 +1046,34 @@ public ImmutableList<Path> getPaths() {
}
}

@Test
public void testCopyWithSameProvider() throws IOException {
CloudStorageFileSystem sourceFileSystem = getTestBucket();
CloudStorageFileSystem targetFileSystem =
CloudStorageFileSystem.forBucket(
TARGET_BUCKET, CloudStorageConfiguration.DEFAULT, storageOptions);
Path sourceFileSystemPath = sourceFileSystem.getPath(SML_FILE);
Path targetFileSystemPath = targetFileSystem.getPath(PREFIX + randomSuffix());
Files.copy(sourceFileSystemPath, targetFileSystemPath);
assertSame(sourceFileSystem.provider(), targetFileSystem.provider());
assertEquals(sourceFileSystem.config(), targetFileSystem.config());
}

@Test
public void testCopyWithDifferentProvider() throws IOException {
CloudStorageFileSystem sourceFileSystem = getTestBucket();
CloudStorageFileSystem targetFileSystem =
CloudStorageFileSystem.forBucket(
TARGET_BUCKET,
CloudStorageConfiguration.builder().permitEmptyPathComponents(true).build(),
storageOptions);
Path sourceFileSystemPath = sourceFileSystem.getPath(SML_FILE);
Path targetFileSystemPath = targetFileSystem.getPath(PREFIX + randomSuffix());
Files.copy(sourceFileSystemPath, targetFileSystemPath);
assertNotSame(sourceFileSystem.provider(), targetFileSystem.provider());
assertNotEquals(sourceFileSystem.config(), targetFileSystem.config());
}

private CloudStorageFileSystem getTestBucket() throws IOException {
// in typical usage we use the single-argument version of forBucket
// and rely on the user being logged into their project with the
Expand Down
6 changes: 3 additions & 3 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
<parent>
<groupId>com.google.cloud</groupId>
<artifactId>google-cloud-shared-config</artifactId>
<version>0.8.1</version>
<version>0.9.2</version>
</parent>

<developers>
Expand Down Expand Up @@ -79,15 +79,15 @@
<dependency>
<groupId>com.google.cloud</groupId>
<artifactId>google-cloud-shared-dependencies</artifactId>
<version>0.8.2</version>
<version>0.8.3</version>
<type>pom</type>
<scope>import</scope>
</dependency>

<dependency>
<groupId>com.google.cloud</groupId>
<artifactId>google-cloud-storage</artifactId>
<version>1.110.0</version>
<version>1.111.1</version>
</dependency>
<dependency>
<groupId>com.google.apis</groupId>
Expand Down
Loading

0 comments on commit 8ce0ccd

Please sign in to comment.