use of com.google.cloud.compute.ComputeOptions in project google-cloud-java by GoogleCloudPlatform.
the class RemoteComputeHelper method create.
/**
* Creates a {@code RemoteComputeHelper} object for the given project id and JSON key input
* stream.
*
* @param projectId id of the project to be used for running the tests
* @param keyStream input stream for a JSON key
* @return A {@code RemoteComputeHelper} object for the provided options
* @throws ComputeHelperException if {@code keyStream} is not a valid JSON key stream
*/
public static RemoteComputeHelper create(String projectId, InputStream keyStream) {
try {
HttpTransportOptions transportOptions = ComputeOptions.getDefaultHttpTransportOptions();
transportOptions = transportOptions.toBuilder().setConnectTimeout(60000).setReadTimeout(60000).build();
ComputeOptions computeOptions = ComputeOptions.newBuilder().setCredentials(ServiceAccountCredentials.fromStream(keyStream)).setProjectId(projectId).setRetrySettings(retrySettings()).setTransportOptions(transportOptions).build();
return new RemoteComputeHelper(computeOptions);
} catch (IOException ex) {
if (log.isLoggable(Level.WARNING)) {
log.log(Level.WARNING, ex.getMessage());
}
throw ComputeHelperException.translate(ex);
}
}
use of com.google.cloud.compute.ComputeOptions in project google-cloud-java by GoogleCloudPlatform.
the class RemoteComputeHelperTest method testCreateFromStream.
@Test
public void testCreateFromStream() {
RemoteComputeHelper helper = RemoteComputeHelper.create(PROJECT_ID, JSON_KEY_STREAM);
ComputeOptions options = helper.getOptions();
assertEquals(PROJECT_ID, options.getProjectId());
assertEquals(60000, ((HttpTransportOptions) options.getTransportOptions()).getConnectTimeout());
assertEquals(60000, ((HttpTransportOptions) options.getTransportOptions()).getReadTimeout());
assertEquals(10, options.getRetrySettings().getMaxAttempts());
assertEquals(Duration.ofMillis(30000), options.getRetrySettings().getMaxRetryDelay());
assertEquals(Duration.ofMillis(120000), options.getRetrySettings().getTotalTimeout());
assertEquals(Duration.ofMillis(250), options.getRetrySettings().getInitialRetryDelay());
}
use of com.google.cloud.compute.ComputeOptions in project google-cloud-java by GoogleCloudPlatform.
the class RemoteComputeHelper method create.
/**
* Creates a {@code RemoteComputeHelper} object using default project id and authentication
* credentials.
*/
public static RemoteComputeHelper create() {
HttpTransportOptions transportOptions = ComputeOptions.getDefaultHttpTransportOptions();
transportOptions = transportOptions.toBuilder().setConnectTimeout(60000).setReadTimeout(60000).build();
ComputeOptions computeOptions = ComputeOptions.newBuilder().setRetrySettings(retrySettings()).setTransportOptions(transportOptions).build();
return new RemoteComputeHelper(computeOptions);
}
Aggregations