use of fixture.gcs.FakeOAuth2HttpHandler in project OpenSearch by opensearch-project.
the class GoogleCloudStorageBlobContainerRetriesTests method createBlobContainer.
@Override
protected BlobContainer createBlobContainer(@Nullable final Integer maxRetries, @Nullable final TimeValue readTimeout, @Nullable final Boolean disableChunkedEncoding, @Nullable final ByteSizeValue bufferSize) {
final Settings.Builder clientSettings = Settings.builder();
final String client = randomAlphaOfLength(5).toLowerCase(Locale.ROOT);
clientSettings.put(ENDPOINT_SETTING.getConcreteSettingForNamespace(client).getKey(), httpServerUrl());
clientSettings.put(TOKEN_URI_SETTING.getConcreteSettingForNamespace(client).getKey(), httpServerUrl() + "/token");
if (readTimeout != null) {
clientSettings.put(READ_TIMEOUT_SETTING.getConcreteSettingForNamespace(client).getKey(), readTimeout);
}
final MockSecureSettings secureSettings = new MockSecureSettings();
secureSettings.setFile(CREDENTIALS_FILE_SETTING.getConcreteSettingForNamespace(client).getKey(), createServiceAccount(random()));
clientSettings.setSecureSettings(secureSettings);
final GoogleCloudStorageService service = new GoogleCloudStorageService() {
@Override
StorageOptions createStorageOptions(final GoogleCloudStorageClientSettings clientSettings, final HttpTransportOptions httpTransportOptions) {
StorageOptions options = super.createStorageOptions(clientSettings, httpTransportOptions);
RetrySettings.Builder retrySettingsBuilder = RetrySettings.newBuilder().setTotalTimeout(options.getRetrySettings().getTotalTimeout()).setInitialRetryDelay(Duration.ofMillis(10L)).setRetryDelayMultiplier(1.0d).setMaxRetryDelay(Duration.ofSeconds(1L)).setJittered(false).setInitialRpcTimeout(Duration.ofSeconds(1)).setRpcTimeoutMultiplier(options.getRetrySettings().getRpcTimeoutMultiplier()).setMaxRpcTimeout(Duration.ofSeconds(1));
if (maxRetries != null) {
retrySettingsBuilder.setMaxAttempts(maxRetries + 1);
}
return options.toBuilder().setHost(options.getHost()).setCredentials(options.getCredentials()).setRetrySettings(retrySettingsBuilder.build()).build();
}
};
service.refreshAndClearCache(GoogleCloudStorageClientSettings.load(clientSettings.build()));
httpServer.createContext("/token", new FakeOAuth2HttpHandler());
final GoogleCloudStorageBlobStore blobStore = new GoogleCloudStorageBlobStore("bucket", client, "repo", service, randomIntBetween(1, 8) * 1024);
return new GoogleCloudStorageBlobContainer(BlobPath.cleanPath(), blobStore);
}
use of fixture.gcs.FakeOAuth2HttpHandler in project OpenSearch by opensearch-project.
the class GoogleCloudStorageBlobStoreRepositoryTests method createHttpHandlers.
@Override
protected Map<String, HttpHandler> createHttpHandlers() {
final Map<String, HttpHandler> handlers = new HashMap<>(2);
handlers.put("/", new GoogleCloudStorageStatsCollectorHttpHandler(new GoogleCloudStorageBlobStoreHttpHandler("bucket")));
handlers.put("/token", new FakeOAuth2HttpHandler());
return Collections.unmodifiableMap(handlers);
}
Aggregations