diff --git a/.github/release-please.yml b/.github/release-please.yml index 8274468280..dce2c84509 100644 --- a/.github/release-please.yml +++ b/.github/release-please.yml @@ -1 +1,2 @@ releaseType: java-yoshi +bumpMinorPreMajor: true \ No newline at end of file diff --git a/.kokoro/build.sh b/.kokoro/build.sh index fa132f410d..dc2936ef76 100755 --- a/.kokoro/build.sh +++ b/.kokoro/build.sh @@ -27,6 +27,7 @@ echo ${JOB_TYPE} mvn install -B -V \ -DskipTests=true \ -Dclirr.skip=true \ + -Denforcer.skip=true \ -Dmaven.javadoc.skip=true \ -Dgcloud.download.skip=true \ -T 1C @@ -38,7 +39,7 @@ fi case ${JOB_TYPE} in test) - mvn test -B -Dclirr.skip=true + mvn test -B -Dclirr.skip=true -Denforcer.skip=true bash ${KOKORO_GFILE_DIR}/codecov.sh bash .kokoro/coerce_logs.sh ;; @@ -49,12 +50,17 @@ javadoc) mvn javadoc:javadoc javadoc:test-javadoc ;; integration) - mvn -B ${INTEGRATION_TEST_ARGS} -DtrimStackTrace=false -Dclirr.skip=true -fae verify + mvn -B ${INTEGRATION_TEST_ARGS} \ + -DtrimStackTrace=false \ + -Dclirr.skip=true \ + -Denforcer.skip=true \ + -fae \ + verify bash .kokoro/coerce_logs.sh ;; clirr) - mvn -B clirr:check + mvn -B -Denforcer.skip=true clirr:check ;; *) ;; -esac \ No newline at end of file +esac diff --git a/.kokoro/dependencies.sh b/.kokoro/dependencies.sh index 51e976d441..3fc816b94c 100755 --- a/.kokoro/dependencies.sh +++ b/.kokoro/dependencies.sh @@ -23,5 +23,9 @@ echo $JOB_TYPE export MAVEN_OPTS="-Xmx1024m -XX:MaxPermSize=128m" -mvn install -DskipTests=true -B -V +# this should run maven enforcer +mvn install -B -V \ + -DskipTests=true \ + -Dclirr.skip=true + mvn -B dependency:analyze -DfailOnWarning=true diff --git a/.kokoro/release/drop.cfg b/.kokoro/release/drop.cfg index 211c014c2a..6590b0c133 100644 --- a/.kokoro/release/drop.cfg +++ b/.kokoro/release/drop.cfg @@ -4,6 +4,3 @@ env_vars: { key: "TRAMPOLINE_BUILD_FILE" value: "github/java-core/.kokoro/release/drop.sh" } - -# Download staging properties file. -gfile_resources: "/bigstore/cloud-devrel-kokoro-resources/java/releases/java-core" \ No newline at end of file diff --git a/.kokoro/release/promote.cfg b/.kokoro/release/promote.cfg index b3fc2015d6..800f0884e6 100644 --- a/.kokoro/release/promote.cfg +++ b/.kokoro/release/promote.cfg @@ -4,7 +4,3 @@ env_vars: { key: "TRAMPOLINE_BUILD_FILE" value: "github/java-core/.kokoro/release/promote.sh" } - -# Download staging properties file. -gfile_resources: "/bigstore/cloud-devrel-kokoro-resources/java/releases/java-core" - diff --git a/.repo-metadata.json b/.repo-metadata.json index e3e884930d..6f416a3b18 100644 --- a/.repo-metadata.json +++ b/.repo-metadata.json @@ -5,5 +5,5 @@ "language": "java", "repo": "googleapis/java-core", "repo_short": "java-core", - "distribution_name": "google-cloud-java" + "distribution_name": "com.google.cloud:google-cloud-core" } diff --git a/CHANGELOG.md b/CHANGELOG.md index 4eb8233eb0..05107ed47e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,24 @@ # Changelog +## [1.92.0](https://www.github.com/googleapis/java-core/compare/v1.91.3...v1.92.0) (2019-12-13) + + +### Features + +* increase DEFAULT_CHUNK_SIZE to reduce transfer overhead ([#87](https://www.github.com/googleapis/java-core/issues/87)) ([09b327d](https://www.github.com/googleapis/java-core/commit/09b327daf764403b7800180cab79ae3e38815075)) +* support setting ServiceOption for quota project ([#92](https://www.github.com/googleapis/java-core/issues/92)) ([6aa4476](https://www.github.com/googleapis/java-core/commit/6aa4476441fd7636dd116516d3bf4b738cf8a8a9)) + + +### Dependencies + +* update dependency com.google.api-client:google-api-client-bom to v1.30.5 ([#68](https://www.github.com/googleapis/java-core/issues/68)) ([e1a4047](https://www.github.com/googleapis/java-core/commit/e1a4047fb470ea4f80459ca0bb399f4ab2c7decf)) +* update dependency com.google.api:gax-bom to v1.50.1 ([#73](https://www.github.com/googleapis/java-core/issues/73)) ([f493b5b](https://www.github.com/googleapis/java-core/commit/f493b5bbe5945202af6a94fe01407f795014b4a1)) +* update dependency com.google.api:gax-bom to v1.51.0 ([#85](https://www.github.com/googleapis/java-core/issues/85)) ([71d0de7](https://www.github.com/googleapis/java-core/commit/71d0de782432814971facb7cbb67acdec5e45f00)) +* update dependency com.google.auth:google-auth-library-bom to v0.19.0 ([#93](https://www.github.com/googleapis/java-core/issues/93)) ([b465630](https://www.github.com/googleapis/java-core/commit/b465630023dc87537a02a34fb957be340aeb6078)) +* update dependency com.google.http-client:google-http-client-bom to v1.33.0 ([#71](https://www.github.com/googleapis/java-core/issues/71)) ([8f1e690](https://www.github.com/googleapis/java-core/commit/8f1e690611e98855d0eed26d7ef75120bccc862e)) +* update dependency io.grpc:grpc-bom to v1.25.0 ([#72](https://www.github.com/googleapis/java-core/issues/72)) ([3a09fc7](https://www.github.com/googleapis/java-core/commit/3a09fc7c4ce73a3c4f144d0cd4da6d29a1664b75)) +* update to threetenbp 1.4.0 ([#89](https://www.github.com/googleapis/java-core/issues/89)) ([5128bd4](https://www.github.com/googleapis/java-core/commit/5128bd45bae8cbb8540eccd683f5bba52783feef)) + ### [1.91.3](https://www.github.com/googleapis/java-core/compare/v1.91.2...v1.91.3) (2019-10-23) diff --git a/google-cloud-core-bom/pom.xml b/google-cloud-core-bom/pom.xml index fc33e94245..f9ce77ee26 100644 --- a/google-cloud-core-bom/pom.xml +++ b/google-cloud-core-bom/pom.xml @@ -3,12 +3,12 @@ 4.0.0 com.google.cloud google-cloud-core-bom - 1.91.3 + 1.92.0 pom com.google.cloud google-cloud-shared-config - 0.2.1 + 0.3.0 Google Cloud Core @@ -63,17 +63,17 @@ com.google.cloud google-cloud-core - 1.91.3 + 1.92.0 com.google.cloud google-cloud-core-grpc - 1.91.3 + 1.92.0 com.google.cloud google-cloud-core-http - 1.91.3 + 1.92.0 diff --git a/google-cloud-core-grpc/pom.xml b/google-cloud-core-grpc/pom.xml index f95e757971..431f8b0b36 100644 --- a/google-cloud-core-grpc/pom.xml +++ b/google-cloud-core-grpc/pom.xml @@ -3,7 +3,7 @@ 4.0.0 com.google.cloud google-cloud-core-grpc - 1.91.3 + 1.92.0 jar Google Cloud Core gRPC https://github.com/googleapis/google-cloud-java/tree/master/google-cloud-clients/google-cloud-core-grpc @@ -13,7 +13,7 @@ com.google.cloud google-cloud-core-parent - 1.91.3 + 1.92.0 google-cloud-core-grpc diff --git a/google-cloud-core-http/pom.xml b/google-cloud-core-http/pom.xml index f9df33bf3c..3162fe68a4 100644 --- a/google-cloud-core-http/pom.xml +++ b/google-cloud-core-http/pom.xml @@ -3,7 +3,7 @@ 4.0.0 com.google.cloud google-cloud-core-http - 1.91.3 + 1.92.0 jar Google Cloud Core HTTP https://github.com/googleapis/google-cloud-java/tree/master/google-cloud-clients/google-cloud-core-http @@ -13,7 +13,7 @@ com.google.cloud google-cloud-core-parent - 1.91.3 + 1.92.0 google-cloud-core-http diff --git a/google-cloud-core-http/src/main/java/com/google/cloud/http/HttpTransportOptions.java b/google-cloud-core-http/src/main/java/com/google/cloud/http/HttpTransportOptions.java index 2dbcb018f8..4bdfee3cca 100644 --- a/google-cloud-core-http/src/main/java/com/google/cloud/http/HttpTransportOptions.java +++ b/google-cloud-core-http/src/main/java/com/google/cloud/http/HttpTransportOptions.java @@ -176,6 +176,7 @@ ApiClientHeaderProvider.Builder getInternalHeaderProviderBuilder( builder.setClientLibToken( ServiceOptions.getGoogApiClientLibName(), GaxProperties.getLibraryVersion(serviceOptions.getClass())); + builder.setQuotaProjectIdToken(serviceOptions.getQuotaProjectId()); return builder; } diff --git a/google-cloud-core/pom.xml b/google-cloud-core/pom.xml index d0e53e22e1..d3f2f690a8 100644 --- a/google-cloud-core/pom.xml +++ b/google-cloud-core/pom.xml @@ -3,7 +3,7 @@ 4.0.0 com.google.cloud google-cloud-core - 1.91.3 + 1.92.0 jar Google Cloud Core https://github.com/googleapis/google-cloud-java/tree/master/google-cloud-clients/google-cloud-core @@ -13,7 +13,7 @@ com.google.cloud google-cloud-core-parent - 1.91.3 + 1.92.0 google-cloud-core diff --git a/google-cloud-core/src/main/java/com/google/cloud/BaseWriteChannel.java b/google-cloud-core/src/main/java/com/google/cloud/BaseWriteChannel.java index 865af88959..e45a5aead1 100644 --- a/google-cloud-core/src/main/java/com/google/cloud/BaseWriteChannel.java +++ b/google-cloud-core/src/main/java/com/google/cloud/BaseWriteChannel.java @@ -36,8 +36,8 @@ public abstract class BaseWriteChannel< ServiceOptionsT extends ServiceOptions, EntityT extends Serializable> implements WriteChannel { - private static final int MIN_CHUNK_SIZE = 256 * 1024; - private static final int DEFAULT_CHUNK_SIZE = 8 * MIN_CHUNK_SIZE; + private static final int MIN_CHUNK_SIZE = 256 * 1024; // 256 KiB + private static final int DEFAULT_CHUNK_SIZE = 60 * MIN_CHUNK_SIZE; // 15MiB private final ServiceOptionsT options; private final EntityT entity; diff --git a/google-cloud-core/src/main/java/com/google/cloud/ServiceOptions.java b/google-cloud-core/src/main/java/com/google/cloud/ServiceOptions.java index 56f2d19595..792609f4b4 100644 --- a/google-cloud-core/src/main/java/com/google/cloud/ServiceOptions.java +++ b/google-cloud-core/src/main/java/com/google/cloud/ServiceOptions.java @@ -43,6 +43,7 @@ import com.google.api.gax.rpc.NoHeaderProvider; import com.google.auth.Credentials; import com.google.auth.oauth2.GoogleCredentials; +import com.google.auth.oauth2.QuotaProjectIdProvider; import com.google.auth.oauth2.ServiceAccountCredentials; import com.google.cloud.spi.ServiceRpcFactory; import com.google.common.base.Preconditions; @@ -102,6 +103,7 @@ public abstract class ServiceOptions< protected Credentials credentials; private final TransportOptions transportOptions; private final HeaderProvider headerProvider; + private final String quotaProjectId; private transient ServiceRpcFactory serviceRpcFactory; private transient ServiceFactory serviceFactory; @@ -132,6 +134,7 @@ public abstract static class Builder< private TransportOptions transportOptions; private HeaderProvider headerProvider; private String clientLibToken = ServiceOptions.getGoogApiClientLibName(); + private String quotaProjectId; @InternalApi("This class should only be extended within google-cloud-java") protected Builder() {} @@ -147,6 +150,7 @@ protected Builder(ServiceOptions options) { clock = options.clock; transportOptions = options.transportOptions; clientLibToken = options.clientLibToken; + quotaProjectId = options.quotaProjectId; } protected abstract ServiceOptions build(); @@ -212,6 +216,10 @@ public B setCredentials(Credentials credentials) { if (this.projectId == null && credentials instanceof ServiceAccountCredentials) { this.projectId = ((ServiceAccountCredentials) credentials).getProjectId(); } + + if (this.quotaProjectId == null && credentials instanceof QuotaProjectIdProvider) { + this.quotaProjectId = ((ServiceAccountCredentials) credentials).getQuotaProjectId(); + } return self(); } @@ -269,6 +277,17 @@ public B setClientLibToken(String clientLibToken) { return self(); } + /** + * Sets the quotaProjectId that specifies the project used for quota and billing purposes. + * + * @see See system parameter + * $userProject + */ + public B setQuotaProjectId(String quotaProjectId) { + this.quotaProjectId = quotaProjectId; + return self(); + } + protected Set getAllowedClientLibTokens() { return allowedClientLibTokens; } @@ -305,6 +324,10 @@ protected ServiceOptions( firstNonNull(builder.transportOptions, serviceDefaults.getDefaultTransportOptions()); headerProvider = firstNonNull(builder.headerProvider, new NoHeaderProvider()); clientLibToken = builder.clientLibToken; + quotaProjectId = + builder.quotaProjectId != null + ? builder.quotaProjectId + : getValueFromCredentialsFile(System.getenv(CREDENTIAL_ENV_NAME), "quota_project_id"); } /** @@ -488,24 +511,24 @@ static boolean headerContainsMetadataFlavor(HttpResponse response) { } protected static String getServiceAccountProjectId() { - return getServiceAccountProjectId(System.getenv(CREDENTIAL_ENV_NAME)); + return getValueFromCredentialsFile(System.getenv(CREDENTIAL_ENV_NAME), "project_id"); } @InternalApi("Visible for testing") - static String getServiceAccountProjectId(String credentialsPath) { - String project = null; + static String getValueFromCredentialsFile(String credentialsPath, String key) { + String value = null; if (credentialsPath != null) { try (InputStream credentialsStream = new FileInputStream(credentialsPath)) { JsonFactory jsonFactory = JacksonFactory.getDefaultInstance(); JsonObjectParser parser = new JsonObjectParser(jsonFactory); GenericJson fileContents = parser.parseAndClose(credentialsStream, Charsets.UTF_8, GenericJson.class); - project = (String) fileContents.get("project_id"); + value = (String) fileContents.get(key); } catch (IOException e) { // ignore } } - return project; + return value; } /** @@ -664,7 +687,8 @@ protected int baseHashCode() { retrySettings, serviceFactoryClassName, serviceRpcFactoryClassName, - clock); + clock, + quotaProjectId); } protected boolean baseEquals(ServiceOptions other) { @@ -674,7 +698,8 @@ protected boolean baseEquals(ServiceOptions other) { && Objects.equals(retrySettings, other.retrySettings) && Objects.equals(serviceFactoryClassName, other.serviceFactoryClassName) && Objects.equals(serviceRpcFactoryClassName, other.serviceRpcFactoryClassName) - && Objects.equals(clock, clock); + && Objects.equals(clock, clock) + && Objects.equals(quotaProjectId, other.quotaProjectId); } private void readObject(ObjectInputStream input) throws IOException, ClassNotFoundException { @@ -734,4 +759,9 @@ public static T getFromServiceLoader(Class clazz, T defaultInst public String getClientLibToken() { return clientLibToken; } + + /** Returns the quotaProjectId that specifies the project used for quota and billing purposes. */ + public String getQuotaProjectId() { + return quotaProjectId; + } } diff --git a/google-cloud-core/src/test/java/com/google/cloud/BaseWriteChannelTest.java b/google-cloud-core/src/test/java/com/google/cloud/BaseWriteChannelTest.java index b5e5273420..3f539e5f64 100644 --- a/google-cloud-core/src/test/java/com/google/cloud/BaseWriteChannelTest.java +++ b/google-cloud-core/src/test/java/com/google/cloud/BaseWriteChannelTest.java @@ -55,8 +55,8 @@ protected CustomServiceOptions( private static final Serializable ENTITY = 42L; private static final String UPLOAD_ID = "uploadId"; private static final byte[] CONTENT = {0xD, 0xE, 0xA, 0xD}; - private static final int MIN_CHUNK_SIZE = 256 * 1024; - private static final int DEFAULT_CHUNK_SIZE = 8 * MIN_CHUNK_SIZE; + private static final int MIN_CHUNK_SIZE = 256 * 1024; // 256 KiB + private static final int DEFAULT_CHUNK_SIZE = 60 * MIN_CHUNK_SIZE; // 15MiB private static final Random RANDOM = new Random(); private static BaseWriteChannel channel; diff --git a/google-cloud-core/src/test/java/com/google/cloud/ServiceOptionsTest.java b/google-cloud-core/src/test/java/com/google/cloud/ServiceOptionsTest.java index 3ce9ffd543..8f8cab08b3 100644 --- a/google-cloud-core/src/test/java/com/google/cloud/ServiceOptionsTest.java +++ b/google-cloud-core/src/test/java/com/google/cloud/ServiceOptionsTest.java @@ -53,6 +53,10 @@ import org.junit.rules.ExpectedException; public class ServiceOptionsTest { + private static GoogleCredentials credentials; + private static GoogleCredentials credentialsWithProjectId; + private static GoogleCredentials credentialsWithQuotaProject; + private static final String JSON_KEY = "{\n" + " \"private_key_id\": \"somekeyid\",\n" @@ -80,16 +84,6 @@ public class ServiceOptionsTest { + " \"client_id\": \"someclientid.apps.googleusercontent.com\",\n" + " \"type\": \"service_account\"\n" + "}"; - private static GoogleCredentials credentials; - - static { - try { - InputStream keyStream = new ByteArrayInputStream(JSON_KEY.getBytes()); - credentials = GoogleCredentials.fromStream(keyStream); - } catch (IOException e) { - fail("Couldn't create fake JSON credentials."); - } - } private static final String JSON_KEY_PROJECT_ID = "{\n" @@ -119,15 +113,51 @@ public class ServiceOptionsTest { + " \"client_id\": \"someclientid.apps.googleusercontent.com\",\n" + " \"type\": \"service_account\"\n" + "}"; - private static GoogleCredentials credentialsWithProjectId; + + private static final String JSON_KEY_QUOTA_PROJECT_ID = + "{\n" + + " \"private_key_id\": \"somekeyid\",\n" + + " \"private_key\": \"-----BEGIN PRIVATE KEY-----\\nMIIEvgIBADANBgkqhkiG9w0BAQEFAASCBKgwggS" + + "kAgEAAoIBAQC+K2hSuFpAdrJI\\nnCgcDz2M7t7bjdlsadsasad+fvRSW6TjNQZ3p5LLQY1kSZRqBqylRkzteMOyHg" + + "aR\\n0Pmxh3ILCND5men43j3h4eDbrhQBuxfEMalkG92sL+PNQSETY2tnvXryOvmBRwa/\\nQP/9dJfIkIDJ9Fw9N4" + + "Bhhhp6mCcRpdQjV38H7JsyJ7lih/oNjECgYAt\\nknddadwkwewcVxHFhcZJO+XWf6ofLUXpRwiTZakGMn8EE1uVa2" + + "LgczOjwWHGi99MFjxSer5m9\\n1tCa3/KEGKiS/YL71JvjwX3mb+cewlkcmweBKZHM2JPTk0ZednFSpVZMtycjkbLa" + + "\\ndYOS8V85AgMBewECggEBAKksaldajfDZDV6nGqbFjMiizAKJolr/M3OQw16K6o3/\\n0S31xIe3sSlgW0+UbYlF" + + "4U8KifhManD1apVSC3csafaspP4RZUHFhtBywLO9pR5c\\nr6S5aLp+gPWFyIp1pfXbWGvc5VY/v9x7ya1VEa6rXvL" + + "sKupSeWAW4tMj3eo/64ge\\nsdaceaLYw52KeBYiT6+vpsnYrEkAHO1fF/LavbLLOFJmFTMxmsNaG0tuiJHgjshB\\" + + "n82DpMCbXG9YcCgI/DbzuIjsdj2JC1cascSP//3PmefWysucBQe7Jryb6NQtASmnv\\nCdDw/0jmZTEjpe4S1lxfHp" + + "lAhHFtdgYTvyYtaLZiVVkCgYEA8eVpof2rceecw/I6\\n5ng1q3Hl2usdWV/4mZMvR0fOemacLLfocX6IYxT1zA1FF" + + "JlbXSRsJMf/Qq39mOR2\\nSpW+hr4jCoHeRVYLgsbggtrevGmILAlNoqCMpGZ6vDmJpq6ECV9olliDvpPgWOP+\\nm" + + "YPDreFBGxWvQrADNbRt2dmGsrsCgYEAyUHqB2wvJHFqdmeBsaacewzV8x9WgmeX\\ngUIi9REwXlGDW0Mz50dxpxcK" + + "CAYn65+7TCnY5O/jmL0VRxU1J2mSWyWTo1C+17L0\\n3fUqjxL1pkefwecxwecvC+gFFYdJ4CQ/MHHXU81Lwl1iWdF" + + "Cd2UoGddYaOF+KNeM\\nHC7cmqra+JsCgYEAlUNywzq8nUg7282E+uICfCB0LfwejuymR93CtsFgb7cRd6ak\\nECR" + + "8FGfCpH8ruWJINllbQfcHVCX47ndLZwqv3oVFKh6pAS/vVI4dpOepP8++7y1u\\ncoOvtreXCX6XqfrWDtKIvv0vjl" + + "HBhhhp6mCcRpdQjV38H7JsyJ7lih/oNjECgYAt\\nkndj5uNl5SiuVxHFhcZJO+XWf6ofLUregtevZakGMn8EE1uVa" + + "2AY7eafmoU/nZPT\\n00YB0TBATdCbn/nBSuKDESkhSg9s2GEKQZG5hBmL5uCMfo09z3SfxZIhJdlerreP\\nJ7gSi" + + "dI12N+EZxYd4xIJh/HFDgp7RRO87f+WJkofMQKBgGTnClK1VMaCRbJZPriw\\nEfeFCoOX75MxKwXs6xgrw4W//AYG" + + "GUjDt83lD6AZP6tws7gJ2IwY/qP7+lyhjEqN\\nHtfPZRGFkGZsdaksdlaksd323423d+15/UvrlRSFPNj1tWQmNKk" + + "XyRDW4IG1Oa2p\\nrALStNBx5Y9t0/LQnFI4w3aG\\n-----END PRIVATE KEY-----\\n\",\n" + + " \"project_id\": \"someprojectid\",\n" + + " \"client_email\": \"someclientid@developer.gserviceaccount.com\",\n" + + " \"client_id\": \"someclientid.apps.googleusercontent.com\",\n" + + " \"type\": \"service_account\",\n" + + " \"quota_project_id\": \"some-quota-project-id\"\n" + + "}"; static { + credentials = loadCredentials(JSON_KEY); + credentialsWithProjectId = loadCredentials(JSON_KEY_PROJECT_ID); + credentialsWithQuotaProject = loadCredentials(JSON_KEY_QUOTA_PROJECT_ID); + } + + static GoogleCredentials loadCredentials(String credentialFile) { try { - InputStream keyStream = new ByteArrayInputStream(JSON_KEY_PROJECT_ID.getBytes()); - credentialsWithProjectId = GoogleCredentials.fromStream(keyStream); + InputStream keyStream = new ByteArrayInputStream(credentialFile.getBytes()); + return GoogleCredentials.fromStream(keyStream); } catch (IOException e) { fail("Couldn't create fake JSON credentials."); } + return null; } private static final ApiClock TEST_CLOCK = new TestClock(); @@ -138,6 +168,7 @@ public class ServiceOptionsTest { .setHost("host") .setProjectId("project-id") .setRetrySettings(ServiceOptions.getNoRetrySettings()) + .setQuotaProjectId("quota-project-id") .build(); private static final TestServiceOptions OPTIONS_NO_CREDENTIALS = TestServiceOptions.newBuilder() @@ -146,6 +177,7 @@ public class ServiceOptionsTest { .setHost("host") .setProjectId("project-id") .setRetrySettings(ServiceOptions.getNoRetrySettings()) + .setQuotaProjectId("quota-project-id") .build(); private static final TestServiceOptions DEFAULT_OPTIONS = TestServiceOptions.newBuilder().setProjectId("project-id").build(); @@ -283,6 +315,39 @@ public void testBuilder() { assertSame(ServiceOptions.getDefaultRetrySettings(), DEFAULT_OPTIONS.getRetrySettings()); } + @Test + public void testBuilder_quotaProjectServiceOptionTakesPrecedence() { + TestServiceOptions noCredsWithQuotaProject = + TestServiceOptions.newBuilder() + .setCredentials(NoCredentials.getInstance()) + .setProjectId("project-id") + .setQuotaProjectId("quota-project-id") + .build(); + TestServiceOptions quotaProjectCredsWithQuotaProject = + TestServiceOptions.newBuilder() + .setQuotaProjectId("quota-project-id") + .setCredentials(credentialsWithQuotaProject) + .build(); + TestServiceOptions quotaProjectCredsWithQuotaProject2 = + TestServiceOptions.newBuilder() + .setCredentials(credentialsWithQuotaProject) + .setQuotaProjectId("quota-project-id") + .build(); + TestServiceOptions quotaProjectCreds = + TestServiceOptions.newBuilder().setCredentials(credentialsWithQuotaProject).build(); + TestServiceOptions none = + TestServiceOptions.newBuilder() + .setCredentials(NoCredentials.getInstance()) + .setProjectId("project-id") + .build(); + + assertEquals("quota-project-id", noCredsWithQuotaProject.getQuotaProjectId()); + assertEquals("quota-project-id", quotaProjectCredsWithQuotaProject.getQuotaProjectId()); + assertEquals("quota-project-id", quotaProjectCredsWithQuotaProject2.getQuotaProjectId()); + assertEquals("some-quota-project-id", quotaProjectCreds.getQuotaProjectId()); + assertEquals(null, none.getQuotaProjectId()); + } + @Test public void testBuilderNoCredentials() { assertEquals(NoCredentials.getInstance(), OPTIONS_NO_CREDENTIALS.getCredentials()); @@ -293,6 +358,7 @@ public void testBuilderNoCredentials() { assertEquals("host", OPTIONS_NO_CREDENTIALS.getHost()); assertEquals("project-id", OPTIONS_NO_CREDENTIALS.getProjectId()); assertSame(ServiceOptions.getNoRetrySettings(), OPTIONS_NO_CREDENTIALS.getRetrySettings()); + assertEquals("quota-project-id", OPTIONS.getQuotaProjectId()); } @Test @@ -372,7 +438,8 @@ public void testGetServiceAccountProjectId() throws Exception { Files.write("{\"project_id\":\"my-project-id\"}".getBytes(), credentialsFile); assertEquals( - "my-project-id", ServiceOptions.getServiceAccountProjectId(credentialsFile.getPath())); + "my-project-id", + ServiceOptions.getValueFromCredentialsFile(credentialsFile.getPath(), "project_id")); } @Test @@ -381,14 +448,14 @@ public void testGetServiceAccountProjectId_badJson() throws Exception { credentialsFile.deleteOnExit(); Files.write("asdfghj".getBytes(), credentialsFile); - assertNull(ServiceOptions.getServiceAccountProjectId(credentialsFile.getPath())); + assertNull(ServiceOptions.getValueFromCredentialsFile(credentialsFile.getPath(), "project_id")); } @Test public void testGetServiceAccountProjectId_nonExistentFile() throws Exception { File credentialsFile = new File("/doesnotexist"); - assertNull(ServiceOptions.getServiceAccountProjectId(credentialsFile.getPath())); + assertNull(ServiceOptions.getValueFromCredentialsFile(credentialsFile.getPath(), "project_id")); } @Test diff --git a/pom.xml b/pom.xml index 1b025878cc..2718decfb9 100644 --- a/pom.xml +++ b/pom.xml @@ -4,7 +4,7 @@ com.google.cloud google-cloud-core-parent pom - 1.91.3 + 1.92.0 Google Cloud Core Parent https://github.com/googleapis/java-core @@ -14,7 +14,7 @@ com.google.cloud google-cloud-shared-config - 0.2.1 + 0.3.0 @@ -152,14 +152,14 @@ github google-cloud-core-parent - 1.49.1 + 1.52.0 1.8.1 1.17.0 0.13.0 - 0.18.0 - 1.30.4 - 1.32.1 - 1.24.1 + 0.19.0 + 1.30.6 + 1.33.0 + 1.25.0 3.10.0 0.24.0 1.3.2 @@ -168,7 +168,7 @@ 1.0 3.6 3.0.2 - 1.3.3 + 1.4.0 2.6 2.3.3 2.8.6 diff --git a/synth.metadata b/synth.metadata index 3841938ac0..6822849bef 100644 --- a/synth.metadata +++ b/synth.metadata @@ -1,5 +1,5 @@ { - "updateTime": "2019-10-19T07:59:22.603125Z", + "updateTime": "2019-11-19T20:08:48.618165Z", "sources": [ { "template": { diff --git a/versions.txt b/versions.txt index eaac9cb3af..b6b09bca2f 100644 --- a/versions.txt +++ b/versions.txt @@ -1,4 +1,4 @@ # Format: # module:released-version:current-version -google-cloud-core:1.91.3:1.91.3 \ No newline at end of file +google-cloud-core:1.92.0:1.92.0 \ No newline at end of file