Quantcast
Channel: Active questions tagged retry-logic - Stack Overflow
Viewing all articles
Browse latest Browse all 950

How to test whether Retry Configuration is Working or not in Google Cloud Storage in GCP in Spring boot

$
0
0

I have Configured Retry Configuration for google cloud storage operations

@Beanpublic Storage getGCSClient() {        logger.debug("Creating GCSClient for Project {}", gcsProjectId);        RetrySettings retrySettings = StorageOptions.getDefaultRetrySettings().toBuilder().setMaxAttempts(maxAttempts)                .setRetryDelayMultiplier(delayMultiplier).setTotalTimeout(Duration.ofMinutes(totalTimeout)).build();        return StorageOptions.newBuilder()                .setStorageRetryStrategy(StorageRetryStrategy.getDefaultStorageRetryStrategy())                .setRetrySettings(retrySettings).setProjectId(gcsProjectId).build().getService();    }

How to test whether Retrying is working or not. Do we need to add exception handling for gcs operations. Could some one help me with this.

public void copyObject(String inputBucket, String sourceKey, String destinatonKey) throws ProcessingException {        try {            Storage storage = gcsConfig.getGCSClient();            BlobId source = BlobId.of(inputBucket, sourceKey);            BlobId target = BlobId.of(inputBucket, destinatonKey);            Storage.BlobTargetOption precondition;            if (storage.get(inputBucket, destinatonKey) == null) {                precondition = Storage.BlobTargetOption.doesNotExist();            } else {                precondition = Storage.BlobTargetOption                        .generationMatch(storage.get(inputBucket, destinatonKey).getGeneration());            }            storage.copy(Storage.CopyRequest.newBuilder().setSource(source).setTarget(target, precondition).build());        } catch (StorageException ex) {            throw new ProcessingException(ex.getMessage() +"while copying:" + sourceKey);        } catch (Exception ex) {            throw new ProcessingException("Exception occured for gcp copyObject while copying : " + sourceKey + ex.getMessage());        }    }

I here want to test this copyObject method, if there is an internal server error which i was getting in production,
going through the documentation, got to understand that retrying might resolve the problem.
here i want to test this code. how can i replicate internal server 500, so that i understand that code is working


Viewing all articles
Browse latest Browse all 950

Trending Articles