@Test public void canDetectBqProject() { environmentVariables.set("GOOGLE_CLOUD_PROJECT", "gcp-project"); environmentVariables.set("BIG_QUERY_DEFAULT_PROJECT", "bq-project"); Env env = new Env(ImmutableSet.of("BIG_QUERY_DEFAULT_PROJECT")); assertEquals("gcp-project", BigQueryOptions.getDefaultInstance().getProjectId()); assertEquals("bq-project", SinkConfig.getBigQueryService(env).getOptions().getProjectId()); }
@VisibleForTesting static com.google.cloud.bigquery.BigQuery getBigQueryService(Env env) { BigQueryOptions.Builder builder = BigQueryOptions.getDefaultInstance().toBuilder(); env.optString(BIG_QUERY_DEFAULT_PROJECT).ifPresent(builder::setProjectId); return builder.build().getService(); }
SinkConfig { @VisibleForTesting static com.google.cloud.bigquery.BigQuery getBigQueryService(Env env) { BigQueryOptions.Builder builder = BigQueryOptions.getDefaultInstance().toBuilder(); env.optString(BIG_QUERY_DEFAULT_PROJECT).ifPresent(builder::setProjectId); return builder.build().getService(); } }
SinkConfig { @VisibleForTesting static com.google.cloud.bigquery.BigQuery getBigQueryService(Env env) { BigQueryOptions.Builder builder = BigQueryOptions.getDefaultInstance().toBuilder(); env.optString(BIG_QUERY_DEFAULT_PROJECT).ifPresent(builder::setProjectId); return builder.build().getService(); } private  SinkConfig(); }
SinkConfig { @VisibleForTesting static com.google.cloud.bigquery.BigQuery getBigQueryService(Env env) { BigQueryOptions.Builder builder = BigQueryOptions.getDefaultInstance().toBuilder(); env.optString(BIG_QUERY_DEFAULT_PROJECT).ifPresent(builder::setProjectId); return builder.build().getService(); } private  SinkConfig(); static Output getOutput(); static Input getInput(Output output); }
SinkConfig { @VisibleForTesting static com.google.cloud.bigquery.BigQuery getBigQueryService(Env env) { BigQueryOptions.Builder builder = BigQueryOptions.getDefaultInstance().toBuilder(); env.optString(BIG_QUERY_DEFAULT_PROJECT).ifPresent(builder::setProjectId); return builder.build().getService(); } private  SinkConfig(); static Output getOutput(); static Input getInput(Output output); static final String OUTPUT_TABLE; }