Search in sources :

Example 1 with FakeOAuth2HttpHandler

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);
}
Also used : FakeOAuth2HttpHandler(fixture.gcs.FakeOAuth2HttpHandler) Matchers.containsString(org.hamcrest.Matchers.containsString) MockSecureSettings(org.opensearch.common.settings.MockSecureSettings) RetrySettings(com.google.api.gax.retrying.RetrySettings) StorageOptions(com.google.cloud.storage.StorageOptions) HttpTransportOptions(com.google.cloud.http.HttpTransportOptions) MockSecureSettings(org.opensearch.common.settings.MockSecureSettings) Settings(org.opensearch.common.settings.Settings) RetrySettings(com.google.api.gax.retrying.RetrySettings)

Example 2 with FakeOAuth2HttpHandler

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);
}
Also used : GoogleCloudStorageHttpHandler(fixture.gcs.GoogleCloudStorageHttpHandler) FakeOAuth2HttpHandler(fixture.gcs.FakeOAuth2HttpHandler) HttpHandler(com.sun.net.httpserver.HttpHandler) FakeOAuth2HttpHandler(fixture.gcs.FakeOAuth2HttpHandler) HashMap(java.util.HashMap)

Aggregations

FakeOAuth2HttpHandler (fixture.gcs.FakeOAuth2HttpHandler)2 RetrySettings (com.google.api.gax.retrying.RetrySettings)1 HttpTransportOptions (com.google.cloud.http.HttpTransportOptions)1 StorageOptions (com.google.cloud.storage.StorageOptions)1 HttpHandler (com.sun.net.httpserver.HttpHandler)1 GoogleCloudStorageHttpHandler (fixture.gcs.GoogleCloudStorageHttpHandler)1 HashMap (java.util.HashMap)1 Matchers.containsString (org.hamcrest.Matchers.containsString)1 MockSecureSettings (org.opensearch.common.settings.MockSecureSettings)1 Settings (org.opensearch.common.settings.Settings)1