Skip to content

Commit

Permalink
Making requested pull review changes.
Browse files Browse the repository at this point in the history
  • Loading branch information
antillean committed Sep 25, 2017
1 parent 5983ac5 commit ba11c43
Show file tree
Hide file tree
Showing 3 changed files with 85 additions and 52 deletions.
14 changes: 8 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,15 @@ buildscript {

### Configuration

The AWS S3 build cache implementation requires two configuration options:
The AWS S3 build cache implementation has a few configuration options:

| Configuration Key | Description |
| ----------------- | ----------- |
| region | The AWS region the S3 bucket is located in. |
| bucket | The name of the AWS S3 bucket where cache objects should be stored. |
| reducedRedundancy | Whether or not to use [reduced redundancy](https://aws.amazon.com/s3/reduced-redundancy/). Enabled by default. |
| Configuration Key | Description | Default Value |
| ----------------- | ----------- | ----------- |
| region | The AWS region the S3 bucket is located in. | |
| bucket | The name of the AWS S3 bucket where cache objects should be stored. | |
| reducedRedundancy | Whether or not to use [reduced redundancy](https://aws.amazon.com/s3/reduced-redundancy/). | true |

(Options without a default value are mandatory.)


The `buildCache` configuration block might look like this:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,19 @@
/*
* Copyright 2017 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package ch.myniva.gradle.caching.s3.internal;

import static org.junit.Assert.assertNotNull;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,24 @@
/*
* Copyright 2017 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package ch.myniva.gradle.caching.s3.internal;

import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.*;

import com.amazonaws.services.s3.AmazonS3;
import com.amazonaws.services.s3.model.ObjectMetadata;
import com.amazonaws.services.s3.model.PutObjectRequest;
Expand All @@ -10,64 +29,60 @@
import org.junit.Test;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;

import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;

import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.*;

public class AwsS3BuildCacheServiceTest {
@Mock
AmazonS3 s3;
@Mock
BuildCacheKey key;
@Mock
BuildCacheEntryWriter writer;
@Mock
PutObjectRequest putObjectRequest = mock(PutObjectRequest.class);
@Mock
AmazonS3 s3;
@Mock
BuildCacheKey key;
@Mock
BuildCacheEntryWriter writer;
@Mock
PutObjectRequest putObjectRequest = mock(PutObjectRequest.class);

AwsS3BuildCacheService buildCacheService;
AwsS3BuildCacheService buildCacheService;

@Before
public void setup() {
MockitoAnnotations.initMocks(this);
}
@Before
public void setup() {
MockitoAnnotations.initMocks(this);
}

@Test
public void storePutsObjectAndUsesReducedRedundancyWhenConfigured() throws IOException {
/** Setup **/
buildCacheService = spy(new AwsS3BuildCacheService(s3, "bucketName", true));
doReturn(putObjectRequest).when(buildCacheService).getPutObjectRequest(any(BuildCacheKey.class),
any(ObjectMetadata.class), any(InputStream.class));
@Test
public void storePutsObjectAndUsesReducedRedundancyWhenConfigured() throws IOException {
/** Setup **/
buildCacheService = spy(new AwsS3BuildCacheService(s3, "bucketName", true));
doReturn(putObjectRequest).when(buildCacheService).getPutObjectRequest(any(BuildCacheKey.class),
any(ObjectMetadata.class), any(InputStream.class));

/** Run **/
buildCacheService.store(key, writer);
/** Run **/
buildCacheService.store(key, writer);

/** Check **/
verifyThatStoreStores();
verify(putObjectRequest).withStorageClass(eq(StorageClass.ReducedRedundancy));
}
/** Check **/
verifyThatStoreStores();
verify(putObjectRequest).withStorageClass(eq(StorageClass.ReducedRedundancy));
}

@Test
public void storePutsObjectAndDoesNotUseReducedRedundancyWhenConfigured() throws IOException {
/** Setup **/
buildCacheService = spy(new AwsS3BuildCacheService(s3, "bucketName", false));
doReturn(putObjectRequest).when(buildCacheService).getPutObjectRequest(any(BuildCacheKey.class),
any(ObjectMetadata.class), any(InputStream.class));
@Test
public void storePutsObjectAndDoesNotUseReducedRedundancyWhenConfigured() throws IOException {
/** Setup **/
buildCacheService = spy(new AwsS3BuildCacheService(s3, "bucketName", false));
doReturn(putObjectRequest).when(buildCacheService).getPutObjectRequest(any(BuildCacheKey.class),
any(ObjectMetadata.class), any(InputStream.class));

/** Run **/
buildCacheService.store(key, writer);
/** Run **/
buildCacheService.store(key, writer);

/** Check **/
verifyThatStoreStores();
verify(putObjectRequest, never()).withStorageClass(eq(StorageClass.ReducedRedundancy));
}
/** Check **/
verifyThatStoreStores();
verify(putObjectRequest, never()).withStorageClass(eq(StorageClass.ReducedRedundancy));
}

private void verifyThatStoreStores() throws IOException {
verify(writer).writeTo(any(ByteArrayOutputStream.class));
verify(buildCacheService).getPutObjectRequest(eq(key), any(ObjectMetadata.class), any(InputStream.class));
verify(s3).putObject(eq(putObjectRequest));
}
private void verifyThatStoreStores() throws IOException {
verify(writer).writeTo(any(ByteArrayOutputStream.class));
verify(buildCacheService).getPutObjectRequest(eq(key), any(ObjectMetadata.class), any(InputStream.class));
verify(s3).putObject(eq(putObjectRequest));
}
}

0 comments on commit ba11c43

Please sign in to comment.