Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Setup circleci ADC #573

Merged
merged 2 commits into from
Mar 22, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# java-docs-samples

[![Build Status](https://travis-ci.org/GoogleCloudPlatform/java-docs-samples.svg?branch=master)](https://travis-ci.org/GoogleCloudPlatform/java-docs-samples)
[![Travis Build Status](https://travis-ci.org/GoogleCloudPlatform/java-docs-samples.svg?branch=master)](https://travis-ci.org/GoogleCloudPlatform/java-docs-samples)
[![Circle-CI Build Status](https://circleci.com/gh/GoogleCloudPlatform/java-docs-samples.svg?style=shield&circle-token=117b41ead030b212fc7d519519ee9262c4f3480b)](https://circleci.com/gh/GoogleCloudPlatform/java-docs-samples)
[![ghit.me](https://ghit.me/badge.svg?repo=GoogleCloudPlatform/java-docs-samples)](https://ghit.me/repo/GoogleCloudPlatform/java-docs-samples)
[![Coverage Status](https://codecov.io/gh/GoogleCloudPlatform/java-docs-samples/branch/master/graph/badge.svg)](https://codecov.io/gh/GoogleCloudPlatform/java-docs-samples)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,13 @@
package com.google.cloud.bigquery.samples.test;

public class Constants {
public static final String PROJECT_ID = "cloud-samples-tests";
public static final String PROJECT_ID = System.getenv("GOOGLE_CLOUD_PROJECT");
public static final String BUCKET = PROJECT_ID;
public static final String DATASET_ID = "test_dataset_java";
public static final String CURRENT_TABLE_ID = "test_table_java";
public static final String NEW_TABLE_ID = "test_table_java_2";
public static final String CLOUD_STORAGE_INPUT_URI = "gs://cloud-samples-tests/data.csv";
public static final String CLOUD_STORAGE_OUTPUT_URI = "gs://cloud-samples-tests/output.csv";
public static final String CLOUD_STORAGE_INPUT_URI = "gs://" + BUCKET + "/data.csv";
public static final String CLOUD_STORAGE_OUTPUT_URI = "gs://" + BUCKET + "/output.csv";
public static final String QUERY =
"SELECT corpus FROM publicdata:samples.shakespeare GROUP BY corpus;";
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
*/
@RunWith(JUnit4.class)
public class ListDatasetsProjectsTest {
private static final String PROJECT_ID = System.getenv("GOOGLE_CLOUD_PROJECT");
private static final PrintStream REAL_OUT = System.out;
private static final PrintStream REAL_ERR = System.err;

Expand Down Expand Up @@ -72,6 +73,6 @@ public void testMain() throws Exception {

assertThat(out).named("stdout").contains("Listing all the Projects");
assertThat(out).named("stdout").contains("Project list:");
assertThat(out).named("stdout").containsMatch("Bigquery Samples|cloud-samples-tests");
assertThat(out).named("stdout").containsMatch("Bigquery Samples|" + PROJECT_ID);
}
}
17 changes: 17 additions & 0 deletions circle.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
machine:
java:
version: oraclejdk8
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

openjdk8 ??

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, for some reason I thought we were using oracle. Are we using openjdk?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hm.. doesn't look like circle has openjdk8, so if we want java 8, we have to go with oracle.

environment:
chromedriver_path: /usr/local/bin/chromedriver
dependencies:
pre:
- sudo mkdir /opt/webdriver/
- curl -LO https://github.com/mozilla/geckodriver/releases/download/v0.15.0/geckodriver-v0.15.0-linux64.tar.gz
&& sudo tar -zxf geckodriver-*.tar.gz -C /opt/webdriver/
- sudo apt-add-repository "deb http://archive.ubuntu.com/ubuntu trusty-backports main restricted universe"
- sudo apt-get update
- sudo apt-get install -t trusty-backports shellcheck
- sudo apt-get install expect
test:
override:
- bash ./travis.sh
2 changes: 1 addition & 1 deletion kms/src/test/java/com/example/SnippetsIT.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
@SuppressWarnings("checkstyle:abbreviationaswordinname")
public class SnippetsIT {

static final String PROJECT_ID = "java-docs-samples-tests";
static final String PROJECT_ID = System.getenv("GOOGLE_CLOUD_PROJECT");
static final String KEY_RING_ID = "test-snippets-key-ring";
static final String CRYPTO_KEY_ID = "test-snippets-crypto-key";
static final String TEST_USER = "serviceAccount:"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@
@RunWith(JUnit4.class)
@SuppressWarnings("checkstyle:abbreviationaswordinname")
public class AnalyzeIT {
private static final String PROJECT_ID = System.getenv("GOOGLE_CLOUD_PROJECT");
private static final String BUCKET = PROJECT_ID;

private Analyze analyzeApp;

Expand All @@ -62,7 +64,7 @@ public class AnalyzeIT {
@Test public void analyzeEntities_withEntitiesFile_containsGod() throws Exception {
// Act
List<Entity> entities =
analyzeApp.analyzeEntitiesFile("gs://cloud-samples-tests/natural-language/gettysburg.txt");
analyzeApp.analyzeEntitiesFile("gs://" + BUCKET + "/natural-language/gettysburg.txt");
List<String> got = entities.stream().map(e -> e.getName()).collect(Collectors.toList());

// Assert
Expand All @@ -83,7 +85,7 @@ public class AnalyzeIT {
@Test public void analyzeSentimentFile_returnPositiveFile() throws Exception {
// Act
Sentiment sentiment =
analyzeApp.analyzeSentimentFile("gs://cloud-samples-tests/natural-language/"
analyzeApp.analyzeSentimentFile("gs://" + BUCKET + "/natural-language/"
+ "sentiment/bladerunner-pos.txt");

// Assert
Expand All @@ -105,7 +107,7 @@ public class AnalyzeIT {
@Test public void analyzeSentiment_returnNegativeFile() throws Exception {
// Act
Sentiment sentiment =
analyzeApp.analyzeSentimentFile("gs://cloud-samples-tests/natural-language/"
analyzeApp.analyzeSentimentFile("gs://" + BUCKET + "/natural-language/"
+ "sentiment/bladerunner-neg.txt");

// Assert
Expand All @@ -116,7 +118,7 @@ public class AnalyzeIT {
@Test public void analyzeSentiment_returnNeutralFile() throws Exception {
// Act
Sentiment sentiment =
analyzeApp.analyzeSentimentFile("gs://cloud-samples-tests/natural-language/"
analyzeApp.analyzeSentimentFile("gs://" + BUCKET + "/natural-language/"
+ "sentiment/bladerunner-neutral.txt");

// Assert
Expand All @@ -141,7 +143,7 @@ public class AnalyzeIT {
@Test public void analyzeSyntax_partOfSpeechFile() throws Exception {
// Act
List<Token> token =
analyzeApp.analyzeSyntaxFile("gs://cloud-samples-tests/natural-language/"
analyzeApp.analyzeSyntaxFile("gs://" + BUCKET + "/natural-language/"
+ "sentiment/bladerunner-neutral.txt");

List<Tag> got = token.stream().map(e -> e.getPartOfSpeech().getTag())
Expand Down
3 changes: 2 additions & 1 deletion logging/src/test/java/ListLogsTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ public class ListLogsTest {
private final ByteArrayOutputStream stderr = new ByteArrayOutputStream();
private static final PrintStream REAL_OUT = System.out;
private static final PrintStream REAL_ERR = System.err;
private static final String PROJECT_ID = System.getenv("GOOGLE_CLOUD_PROJECT");

@Before
public void setUp() {
Expand All @@ -53,7 +54,7 @@ public void testUsage() throws Exception {

@Test
public void testListLogs() throws Exception {
ListLogs.main(new String[] {"cloud-samples-tests"});
ListLogs.main(new String[] {PROJECT_ID});
String out = stdout.toString();
// Don't know what logs the test project will have.
assertThat(out, containsPattern("Done\\."));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ public class CloudMonitoringAuthSampleTest {
new ByteArrayOutputStream();
private static final PrintStream REAL_OUT = System.out;
private static final PrintStream REAL_ERR = System.err;
private static final String PROJECT_ID = System.getenv("GOOGLE_CLOUD_PROJECT");

@Before
public void setUp() {
Expand All @@ -56,7 +57,7 @@ public void testUsage() throws Exception {

@Test
public void testListTimeSeries() throws Exception {
CloudMonitoringAuthSample.main(new String[] { "cloud-samples-tests" });
CloudMonitoringAuthSample.main(new String[] { PROJECT_ID });
String out = stdout.toString();
assertThat(out).named("stdout").contains("Timeseries.list raw response:");
assertThat(out)
Expand Down
2 changes: 1 addition & 1 deletion monitoring/v3/src/test/java/ListResourcesTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public class ListResourcesTest {
/**
* The project ID of the project created for the integration tests.
*/
public static final String TEST_PROJECT_ID = "cloud-samples-tests";
public static final String TEST_PROJECT_ID = System.getenv("GOOGLE_CLOUD_PROJECT");

/**
* Google Cloud Monitoring client to integration test.
Expand Down
3 changes: 3 additions & 0 deletions pubsub/cloud-client/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ the [Google Cloud Client Library for Java][google-cloud-java].
[pubsub]: https://cloud.google.com/pubsub/
[google-cloud-java]: https://github.com/GoogleCloudPlatform/google-cloud-java

For more samples, see the samples in
[google-cloud-java](https://github.com/GoogleCloudPlatform/google-cloud-java/tree/master/google-cloud-examples/src/main/java/com/google/cloud/examples/pubsub).

## Quickstart

#### Setup
Expand Down
3 changes: 2 additions & 1 deletion pubsub/cloud-client/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,14 @@
<maven.compiler.target>1.8</maven.compiler.target>
<maven.compiler.source>1.8</maven.compiler.source>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<pubsub.version>0.9.4-alpha</pubsub.version>
</properties>

<dependencies>
<dependency>
<groupId>com.google.cloud</groupId>
<artifactId>google-cloud-pubsub</artifactId>
<version>0.9.4-alpha</version>
<version>${pubsub.version}</version>
</dependency>

<!-- Test dependencies -->
Expand Down
2 changes: 1 addition & 1 deletion speech/cloud-client/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,5 +34,5 @@ You can then run a given `ClassName` via:
### Transcribe a remote audio file (using the recognize sample)
```
mvn exec:java -Dexec.mainClass=com.example.speech.Recognize \
-Dexec.args="syncrecognize 'gs://cloud-samples-tests/speech/brooklyn.flac'"
-Dexec.args="syncrecognize 'gs://java-docs-samples-tests/speech/brooklyn.flac'"
```
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,15 @@
@RunWith(JUnit4.class)
@SuppressWarnings("checkstyle:abbreviationaswordinname")
public class RecognizeIT {
private static final String PROJECT_ID = System.getenv("GOOGLE_CLOUD_PROJECT");
private static final String BUCKET = PROJECT_ID;

private ByteArrayOutputStream bout;
private PrintStream out;

// The path to the audio file to transcribe
private String fileName = "./resources/audio.raw";
private String gcsPath = "gs://cloud-samples-tests/speech/brooklyn.flac";
private String gcsPath = "gs://" + BUCKET + "/speech/brooklyn.flac";

@Before
public void setUp() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@
*/
@RunWith(JUnit4.class)
public class RecognitionAudioFactoryTest {
private static final String PROJECT_ID = System.getenv("GOOGLE_CLOUD_PROJECT");
private static final String BUCKET = PROJECT_ID;

@Test
public void verifyBytesInSizeFromLocalFile() throws IOException {
Expand All @@ -47,7 +49,7 @@ public void verifyBytesInSizeFromLocalFile() throws IOException {

@Test
public void verifyBytesInSizeFromGoogleStorageFile() throws IOException {
String audioUri = "gs://cloud-samples-tests/speech/audio.raw";
String audioUri = "gs://" + BUCKET + "/speech/audio.raw";

URI uri = URI.create(audioUri);
RecognitionAudio audio = RecognitionAudioFactory.createRecognitionAudio(uri);
Expand Down
5 changes: 3 additions & 2 deletions storage/json-api/src/test/java/StorageSampleTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@
import java.util.stream.Collectors;

public class StorageSampleTest {
private static final String BUCKET = "cloud-samples-test";
private static final String PROJECT_ID = System.getenv("GOOGLE_CLOUD_PROJECT");
private static final String BUCKET = PROJECT_ID;
private static final String TEST_OBJECT = "storage-sample-test-upload.txt";

@Test
Expand All @@ -43,7 +44,7 @@ public void testListBucket() throws Exception {
public void testGetBucket() throws Exception {
Bucket bucket = StorageSample.getBucket(BUCKET);
assertThat(bucket.getName()).named("bucket name").isEqualTo(BUCKET);
assertThat(bucket.getLocation()).named("bucket location").isEqualTo("US-CENTRAL1");
assertThat(bucket.getLocation()).named("bucket location").startsWith("US");
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,17 +30,19 @@
@RunWith(JUnit4.class)
public class AwsRequesterTest {

private static final String PROJECT_ID = System.getenv("GOOGLE_CLOUD_PROJECT");

/**
* Tests whether AwsRequester executes a request to create a TransferJob.
*/
@Test
public void testRun() throws Exception {
ByteArrayOutputStream outBytes = new ByteArrayOutputStream();
PrintStream outStream = new PrintStream(outBytes);
System.setProperty("projectId", "cloud-samples-tests");
System.setProperty("projectId", PROJECT_ID);
System.setProperty("jobDescription", "Sample transfer job from S3 to GCS.");
System.setProperty("awsSourceBucket", "cloud-samples-tests");
System.setProperty("gcsSinkBucket", "cloud-samples-tests-storagetransfer");
System.setProperty("gcsSinkBucket", PROJECT_ID + "-storagetransfer");
System.setProperty("startDate", "2000-01-01");
System.setProperty("startTime", "00:00:00");

Expand All @@ -49,4 +51,4 @@ public void testRun() throws Exception {

assertThat(out).contains("\"description\" : \"Sample transfer job from S3 to GCS.\"");
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@
@RunWith(JUnit4.class)
public class NearlineRequesterTest {

private static final String PROJECT_ID = System.getenv("GOOGLE_CLOUD_PROJECT");

/**
* Tests whether NearlineRequester executes a request to create a TransferJob.
*/
Expand All @@ -38,10 +40,10 @@ public void testRun() throws Exception {

ByteArrayOutputStream outBytes = new ByteArrayOutputStream();
PrintStream outStream = new PrintStream(outBytes);
System.setProperty("projectId", "cloud-samples-tests");
System.setProperty("projectId", PROJECT_ID);
System.setProperty("jobDescription", "Sample transfer job from GCS to GCS Nearline.");
System.setProperty("gcsSourceBucket", "cloud-samples-tests-storagetransfer-source");
System.setProperty("gcsNearlineSinkBucket", "cloud-storage-samples-tests-storagetransfer-sink");
System.setProperty("gcsSourceBucket", PROJECT_ID + "-storagetransfer-source");
System.setProperty("gcsNearlineSinkBucket", PROJECT_ID + "-storagetransfer-sink");
System.setProperty("startDate", "2000-01-01");
System.setProperty("startTime", "00:00:00");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,15 @@
import org.junit.Test;

public class StorageSampleTest {
private static final String PROJECT_ID = System.getenv("GOOGLE_CLOUD_PROJECT");

@Test
public void testListBucket() throws Exception {
String listing = StorageSample.listBucket("cloud-samples-tests");
String listing = StorageSample.listBucket(PROJECT_ID);
assertThat(listing)
.containsMatch(
".*<ListBucketResult.*"
+ "<Name>cloud-samples-tests</Name>.*"
+ "<Name>" + PROJECT_ID + "</Name>.*"
+ "</ListBucketResult>.*");
}
}
Expand Down
18 changes: 14 additions & 4 deletions travis.sh
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,14 @@ set -o pipefail
shopt -s globstar


# Setup GCP application default credentials
if [[ $GCLOUD_SERVICE_KEY ]]; then
echo "$GCLOUD_SERVICE_KEY" | \
base64 --decode --ignore-garbage > "${HOME}/google-cloud-service-key.json"
export GOOGLE_APPLICATION_CREDENTIALS="${HOME}/google-cloud-service-key.json"
fi


SKIP_TESTS=false
if [ -z "$GOOGLE_APPLICATION_CREDENTIALS" ] ; then
SKIP_TESTS=true
Expand All @@ -28,15 +36,16 @@ fi
# Finds the closest parent dir that encompasses all changed files, and has a
# pom.xml
travis_changed_files_parent() {
[ -z "$TRAVIS_PULL_REQUEST" ] && return 0 # If we're not in a PR, forget it
# If we're not in a PR, forget it
[ -z "${TRAVIS_PULL_REQUEST-CI_PULL_REQUEST}" ] && return 0

(
set +e

changed="$(git diff --name-only "$TRAVIS_COMMIT" "$TRAVIS_BRANCH")"
changed="$(git diff --name-only "${TRAVIS_COMMIT-CIRCLE_SHA1}" "${TRAVIS_BRANCH-CIRCLE_BRANCH}")"
if [ $? -ne 0 ]; then
# Fall back to git head
changed="$(git diff --name-only "$(git rev-parse HEAD)" "$TRAVIS_BRANCH")"
changed="$(git diff --name-only "$(git rev-parse HEAD)" "${TRAVIS_BRANCH-CIRCLE_BRANCH}")"
[ $? -ne 0 ] && return 0 # Give up. Just run everything.
fi

Expand Down Expand Up @@ -67,7 +76,8 @@ common_travis_dir="$(travis_changed_files_parent)"

# Give Maven a bit more memory
export MAVEN_OPTS='-XX:+PrintFlagsFinal -Xmx800m -Xms400m'
"${TRAVIS_BUILD_DIR}"/mvnw --batch-mode clean verify -e -DskipTests=$SKIP_TESTS | egrep -v "(^\[INFO\] Download|^\[INFO\].*skipping)"
"${TRAVIS_BUILD_DIR-$HOME/$CIRCLE_PROJECT_REPONAME}"/mvnw --batch-mode clean verify -e -DskipTests=$SKIP_TESTS | \
egrep -v "(^\[INFO\] Download|^\[INFO\].*skipping)"

[ -z "$common_travis_dir" ] || popd

Expand Down
Loading