Skip to content

Commit

Permalink
fix: Test dependencies etc
Browse files Browse the repository at this point in the history
Signed-off-by: Ryan Roberts <[email protected]>
  • Loading branch information
ryan-s-roberts committed Oct 11, 2021
1 parent 7d2504d commit 4b07257
Show file tree
Hide file tree
Showing 13 changed files with 79 additions and 307 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
*/
package com.blockchaintp.daml.stores.layers;

import com.amazon.ion.system.IonSystemBuilder;
import com.blockchaintp.daml.stores.exception.StoreReadException;
import com.blockchaintp.daml.stores.exception.StoreWriteException;
import com.blockchaintp.daml.stores.service.Key;
Expand All @@ -25,7 +24,6 @@
import org.junit.jupiter.api.Test;

import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets;
import java.util.Arrays;
import java.util.Map;
import java.util.Optional;
Expand Down Expand Up @@ -57,7 +55,6 @@ void unindexed_put_enters_hash_into_txlog_after_storing_in_blobstore()
@Test
void indexed_put_enters_hash_into_txlog_after_storing_in_blobStore_and_also_stores_index()
throws StoreWriteException, StoreReadException {
var ion = IonSystemBuilder.standard().build();
var txLog = new com.blockchaintp.daml.stores.StubStore<ByteString, ByteString>();
var blobStore = new com.blockchaintp.daml.stores.StubStore<ByteString, ByteString>();

Expand Down

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
import com.blockchaintp.daml.stores.service.Value;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import software.amazon.awssdk.services.s3.model.S3Exception;

import java.util.Arrays;
import java.util.HashMap;
Expand All @@ -34,18 +33,23 @@

@SuppressWarnings({ "unchecked", "rawtypes" })
class RetryingStoreTest {

protected class InnerException extends Exception {

}

@Test
void get_retries_configured_number_of_store_read_exceptions() throws StoreReadException {
var store = mock(Store.class);
var retrying = new RetryingStore(new RetryingConfig(), store);

when(store.get(any(Key.class))).thenThrow(new StoreReadException(S3Exception.builder().build()))
.thenThrow(new StoreReadException(S3Exception.builder().build())).thenReturn(Optional.of(Value.of("stuff")));
when(store.get(any(Key.class))).thenThrow(new StoreReadException(new InnerException()))
.thenThrow(new StoreReadException(new InnerException())).thenReturn(Optional.of(Value.of("stuff")));

var retMap = new HashMap<>();
retMap.put(Key.of("stuff"), Value.of("stuff"));
when(store.get(any(List.class))).thenThrow(new StoreReadException(S3Exception.builder().build()))
.thenThrow(new StoreReadException(S3Exception.builder().build())).thenReturn(retMap);
when(store.get(any(List.class))).thenThrow(new StoreReadException(new InnerException()))
.thenThrow(new StoreReadException(new InnerException())).thenReturn(retMap);

/// Scalar get
Assertions.assertEquals(Optional.of(Value.of("stuff")), retrying.get(Key.of("")));
Expand All @@ -59,39 +63,36 @@ void get_eventually_fails_with_a_store_read_exception() throws StoreReadExceptio
var store = mock(Store.class);
var retrying = new RetryingStore(new RetryingConfig(), store);

when(store.get(any(Key.class))).thenThrow(new StoreReadException(S3Exception.builder().build()))
.thenThrow(new StoreReadException(S3Exception.builder().build()))
.thenThrow(new StoreReadException(S3Exception.builder().build()))
.thenThrow(new StoreReadException(S3Exception.builder().build()))
.thenThrow(new StoreReadException(S3Exception.builder().build())).thenReturn(Optional.of(Value.of("stuff")));
when(store.get(any(Key.class))).thenThrow(new StoreReadException(new InnerException()))
.thenThrow(new StoreReadException(new InnerException())).thenThrow(new StoreReadException(new InnerException()))
.thenThrow(new StoreReadException(new InnerException())).thenThrow(new StoreReadException(new InnerException()))
.thenReturn(Optional.of(Value.of("stuff")));

when(store.get(any(List.class))).thenThrow(new StoreReadException(S3Exception.builder().build()))
.thenThrow(new StoreReadException(S3Exception.builder().build()))
.thenThrow(new StoreReadException(S3Exception.builder().build()))
.thenThrow(new StoreReadException(S3Exception.builder().build()))
.thenThrow(new StoreReadException(S3Exception.builder().build())).thenReturn(new HashMap<>());
when(store.get(any(List.class))).thenThrow(new StoreReadException(new InnerException()))
.thenThrow(new StoreReadException(new InnerException())).thenThrow(new StoreReadException(new InnerException()))
.thenThrow(new StoreReadException(new InnerException())).thenThrow(new StoreReadException(new InnerException()))
.thenReturn(new HashMap<>());

var getEx = Assertions.assertThrows(StoreReadException.class, () -> retrying.get(Key.of("")));

var getMultipleEx = Assertions.assertThrows(StoreReadException.class, () -> retrying.get(Arrays.asList()));

/// Check we did not double wrap
Assertions.assertInstanceOf(S3Exception.class, getEx.getCause());
Assertions.assertInstanceOf(InnerException.class, getEx.getCause());

Assertions.assertInstanceOf(S3Exception.class, getMultipleEx.getCause());
Assertions.assertInstanceOf(InnerException.class, getMultipleEx.getCause());
}

@Test
void put_retries_configured_number_of_store_write_exceptions() throws StoreWriteException {
var store = mock(Store.class);
var retrying = new RetryingStore(new RetryingConfig(), store);

doThrow(new StoreWriteException(S3Exception.builder().build()))
.doThrow(new StoreWriteException(S3Exception.builder().build())).doNothing().when(store)
.put(any(Key.class), any(Value.class));
doThrow(new StoreWriteException(new InnerException())).doThrow(new StoreWriteException(new InnerException()))
.doNothing().when(store).put(any(Key.class), any(Value.class));

doThrow(new StoreWriteException(S3Exception.builder().build()))
.doThrow(new StoreWriteException(S3Exception.builder().build())).doNothing().when(store).put(any(List.class));
doThrow(new StoreWriteException(new InnerException())).doThrow(new StoreWriteException(new InnerException()))
.doNothing().when(store).put(any(List.class));

/// Scalar put
Assertions.assertDoesNotThrow(() -> retrying.put(Key.of(""), Value.of("")));
Expand All @@ -105,18 +106,14 @@ void put_eventually_fails_with_a_store_write_exceptions() throws StoreWriteExcep
var store = mock(Store.class);
var retrying = new RetryingStore(new RetryingConfig(), store);

doThrow(new StoreWriteException(S3Exception.builder().build()))
.doThrow(new StoreWriteException(S3Exception.builder().build()))
.doThrow(new StoreWriteException(S3Exception.builder().build()))
.doThrow(new StoreWriteException(S3Exception.builder().build()))
.doThrow(new StoreWriteException(S3Exception.builder().build())).doNothing().when(store)
doThrow(new StoreWriteException(new InnerException())).doThrow(new StoreWriteException(new InnerException()))
.doThrow(new StoreWriteException(new InnerException())).doThrow(new StoreWriteException(new InnerException()))
.doThrow(new StoreWriteException(new InnerException())).doNothing().when(store)
.put(any(Key.class), any(Value.class));

doThrow(new StoreWriteException(S3Exception.builder().build()))
.doThrow(new StoreWriteException(S3Exception.builder().build()))
.doThrow(new StoreWriteException(S3Exception.builder().build()))
.doThrow(new StoreWriteException(S3Exception.builder().build()))
.doThrow(new StoreWriteException(S3Exception.builder().build())).doNothing().when(store).put(any(List.class));
doThrow(new StoreWriteException(new InnerException())).doThrow(new StoreWriteException(new InnerException()))
.doThrow(new StoreWriteException(new InnerException())).doThrow(new StoreWriteException(new InnerException()))
.doThrow(new StoreWriteException(new InnerException())).doNothing().when(store).put(any(List.class));

/// Scalar put
var putEx = Assertions.assertThrows(StoreWriteException.class, () -> retrying.put(Key.of(""), Value.of("")));
Expand All @@ -125,9 +122,9 @@ void put_eventually_fails_with_a_store_write_exceptions() throws StoreWriteExcep
var putMultipleEx = Assertions.assertThrows(StoreWriteException.class, () -> retrying.put(Arrays.asList()));

/// Check we did not double wrap
Assertions.assertInstanceOf(S3Exception.class, putEx.getCause());
Assertions.assertInstanceOf(InnerException.class, putEx.getCause());

Assertions.assertInstanceOf(S3Exception.class, putMultipleEx.getCause());
Assertions.assertInstanceOf(InnerException.class, putMultipleEx.getCause());

}
}
Loading

0 comments on commit 4b07257

Please sign in to comment.