From 4b0725741243013ffcca4fedf08336ff722b8da5 Mon Sep 17 00:00:00 2001 From: Ryan Roberts Date: Fri, 8 Oct 2021 16:55:53 +0100 Subject: [PATCH] fix: Test dependencies etc Signed-off-by: Ryan Roberts --- .../daml/stores/layers/SplitStoreTest.java | 3 - .../PostgresStoreIntegrationTest.java | 132 ------------------ .../PostgresTxLogIntegrationTest.java | 89 ------------ .../stores/resilience/RetryingStoreTest.java | 65 ++++----- .../RetryingTransactionLogTest.java | 71 +++++----- postgres/pom.xml | 4 + .../daml/postgres/ExtraConfig.scala | 2 +- .../com/blockchaintp/daml/postgres/Main.scala | 2 +- qldb/pom.xml | 6 +- .../com/blockchaintp/daml/qldb/Main.scala | 6 +- .../java/store/QldbStoreIntegrationTest.java | 2 +- .../QldbTransactionLogIntegrationTest.java | 2 +- .../java/store/S3StoreIntegrationTest.java | 2 +- 13 files changed, 79 insertions(+), 307 deletions(-) delete mode 100644 core/src/test/java/com/blockchaintp/daml/stores/postgres/PostgresStoreIntegrationTest.java delete mode 100644 core/src/test/java/com/blockchaintp/daml/stores/postgres/PostgresTxLogIntegrationTest.java diff --git a/core/src/test/java/com/blockchaintp/daml/stores/layers/SplitStoreTest.java b/core/src/test/java/com/blockchaintp/daml/stores/layers/SplitStoreTest.java index e3a7b6ef..d9e0728f 100644 --- a/core/src/test/java/com/blockchaintp/daml/stores/layers/SplitStoreTest.java +++ b/core/src/test/java/com/blockchaintp/daml/stores/layers/SplitStoreTest.java @@ -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; @@ -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; @@ -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(); var blobStore = new com.blockchaintp.daml.stores.StubStore(); diff --git a/core/src/test/java/com/blockchaintp/daml/stores/postgres/PostgresStoreIntegrationTest.java b/core/src/test/java/com/blockchaintp/daml/stores/postgres/PostgresStoreIntegrationTest.java deleted file mode 100644 index badc3b92..00000000 --- a/core/src/test/java/com/blockchaintp/daml/stores/postgres/PostgresStoreIntegrationTest.java +++ /dev/null @@ -1,132 +0,0 @@ -/* - * Copyright 2021 Blockchain Technology Partners - * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except - * in compliance with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed under the License - * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express - * or implied. See the License for the specific language governing permissions and limitations under - * the License. - */ -package com.blockchaintp.daml.stores.postgres; - -import com.blockchaintp.daml.stores.exception.StoreReadException; -import com.blockchaintp.daml.stores.exception.StoreWriteException; -import com.blockchaintp.daml.stores.service.Key; -import com.blockchaintp.daml.stores.service.Opaque; -import com.blockchaintp.daml.stores.service.Store; -import com.blockchaintp.daml.stores.service.Value; -import com.google.protobuf.ByteString; -import kr.pe.kwonnam.slf4jlambda.LambdaLoggerFactory; -import org.flywaydb.core.Flyway; -import org.junit.jupiter.api.Assertions; -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.Test; - -import io.zonky.test.db.postgres.embedded.EmbeddedPostgres; - -import java.io.PrintWriter; -import java.sql.DriverManager; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Comparator; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.Optional; -import java.util.Random; -import java.util.stream.Collectors; - -class PostgresStoreIntegrationTest { - - private static final int ITERATIONS = 40; - private Store store; - - @BeforeEach - void createStore() throws Exception { - var pg = EmbeddedPostgres.builder().start(); - pg.getPostgresDatabase().setLogWriter(new PrintWriter(System.out, true)); - var connection = pg.getPostgresDatabase().getConnection(); - Flyway.configure().locations("classpath:migrations/store").dataSource(pg.getPostgresDatabase()).load().migrate(); - - store = new PostgresStore(connection); - } - - @Test - void get_non_existent_items_returns_none() throws StoreReadException { - Assertions.assertEquals(Optional.empty(), store.get(Key.of(ByteString.copyFromUtf8("nothere")))); - - var keys = new ArrayList>(); - keys.add(Key.of(ByteString.copyFromUtf8("nothere"))); - Assertions.assertEquals(Map.of(), store.get(keys)); - } - - @Test - void single_item_put_and_get_are_symmetric() throws StoreWriteException, StoreReadException { - byte[] array = new byte[512]; - new Random().nextBytes(array); - - final var k = Key.of(ByteString.copyFrom(array)); - final var v = Value.of(ByteString.copyFromUtf8("data")); - - // Insert - store.put(k, v); - - var getValue = store.get(k).get(); - Assertions.assertArrayEquals(getValue.toNative().toByteArray(), v.toNative().toByteArray()); - - final var v2 = Value.of(ByteString.copyFromUtf8("data")); - - // Update - store.put(k, v2); - Optional> justPut = store.get(k); - Assertions.assertArrayEquals(v2.toNative().toByteArray(), justPut.get().toNative().toByteArray()); - } - - @Test - void multiple_item_put_and_get_are_symmetric() throws StoreWriteException, StoreReadException { - var map = new HashMap, Value>(); - - for (int i = 0; i != ITERATIONS; i++) { - final var k = Key.of(ByteString.copyFromUtf8(String.format("id%d", i))); - final var v = Value.of(ByteString.copyFromUtf8("data")); - - map.put(k, v); - } - - var sortedkeys = map.keySet().stream() - .sorted(Comparator.comparing(Opaque::toNative, (l, r) -> Arrays.compare(l.toByteArray(), r.toByteArray()))) - .collect(Collectors.toList()); - - // Put our initial list of values, will issue insert - store.put(new ArrayList<>(map.entrySet())); - var rx = store.get(sortedkeys); - - compareUpserted(map, sortedkeys, rx); - - for (var kv : map.entrySet()) { - kv.setValue(Value.of(ByteString.copyFromUtf8("data2"))); - } - - // Put it again - store.put(new ArrayList<>(map.entrySet())); - var rx2 = store.get(sortedkeys); - - compareUpserted(map, sortedkeys, rx2); - } - - final void compareUpserted(final HashMap, Value> map, - final List> sortedkeys, final Map, Value> rx) { - var left = sortedkeys.stream().map(map::get).map(Opaque::toNative).collect(Collectors.toList()); - - var right = sortedkeys.stream().map(rx::get).map(Opaque::toNative).collect(Collectors.toList()); - - for (int i = 0; i != left.size(); i++) { - Assertions.assertArrayEquals(left.get(i).toByteArray(), right.get(i).toByteArray()); - } - } - -} diff --git a/core/src/test/java/com/blockchaintp/daml/stores/postgres/PostgresTxLogIntegrationTest.java b/core/src/test/java/com/blockchaintp/daml/stores/postgres/PostgresTxLogIntegrationTest.java deleted file mode 100644 index 679a2c2b..00000000 --- a/core/src/test/java/com/blockchaintp/daml/stores/postgres/PostgresTxLogIntegrationTest.java +++ /dev/null @@ -1,89 +0,0 @@ -/* - * Copyright 2021 Blockchain Technology Partners - * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except - * in compliance with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed under the License - * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express - * or implied. See the License for the specific language governing permissions and limitations under - * the License. - */ -package com.blockchaintp.daml.stores.postgres; - -import com.blockchaintp.daml.stores.exception.StoreReadException; -import com.blockchaintp.daml.stores.exception.StoreWriteException; -import com.blockchaintp.daml.stores.service.Store; -import com.google.protobuf.ByteString; -import io.zonky.test.db.postgres.embedded.EmbeddedPostgres; -import org.flywaydb.core.Flyway; -import org.junit.jupiter.api.Assertions; -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.Disabled; -import org.junit.jupiter.api.Test; - -import java.io.IOException; -import java.io.PrintWriter; -import java.sql.SQLException; -import java.util.ArrayList; -import java.util.Optional; -import java.util.UUID; -import java.util.concurrent.Executors; -import java.util.concurrent.Future; -import java.util.stream.Collectors; - -@Disabled -class PostgresTxLogIntegrationTest { - private static final int ITERATIONS = 40; - private Store store; - private PostgresTransactionLog txLog; - - @BeforeEach - final void establishStore() throws SQLException, IOException { - var pg = EmbeddedPostgres.builder().start(); - pg.getPostgresDatabase().setLogWriter(new PrintWriter(System.out, true)); - var connection = pg.getPostgresDatabase().getConnection(); - Flyway.configure().locations("classpath:migrations/txlog").dataSource(pg.getPostgresDatabase()).load().migrate(); - - txLog = new PostgresTransactionLog(connection); - } - - @Test - final void committed_transactions_are_read_in_commit_order() - throws StoreWriteException, StoreReadException, InterruptedException { - var ids = new ArrayList(); - - for (var i = 0; i != 3000; i++) { - var id = txLog.begin(Optional.of(UUID.randomUUID())); - ids.add(id._1); - } - var futures = new ArrayList>(); - - var executor = Executors.newFixedThreadPool(30); - ids.stream().forEach(id -> { - futures.add(executor.submit(() -> { - try { - Thread.sleep((long) (Math.random() % 30)); - txLog.sendEvent(id, ByteString.copyFromUtf8("testdata")); - txLog.commit(id); - } catch (StoreWriteException | InterruptedException theE) { - theE.printStackTrace(); - } - })); - }); - - Thread.sleep(10000); - - var aborted = txLog.begin(Optional.empty()); - txLog.sendEvent(aborted._1, ByteString.copyFromUtf8("aborted")); - txLog.abort(aborted._1); - - var stream = txLog.from(-1L, Optional.empty()); - - var page = stream.limit(3000).collect(Collectors.toList()); - - Assertions.assertIterableEquals(ids, page.stream().map(x -> x._2).collect(Collectors.toList())); - } -} diff --git a/core/src/test/java/com/blockchaintp/daml/stores/resilience/RetryingStoreTest.java b/core/src/test/java/com/blockchaintp/daml/stores/resilience/RetryingStoreTest.java index 6a2f9ac5..b64e0ce8 100644 --- a/core/src/test/java/com/blockchaintp/daml/stores/resilience/RetryingStoreTest.java +++ b/core/src/test/java/com/blockchaintp/daml/stores/resilience/RetryingStoreTest.java @@ -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; @@ -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(""))); @@ -59,26 +63,24 @@ 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 @@ -86,12 +88,11 @@ void put_retries_configured_number_of_store_write_exceptions() throws StoreWrite 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(""))); @@ -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(""))); @@ -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()); } } diff --git a/core/src/test/java/com/blockchaintp/daml/stores/resilience/RetryingTransactionLogTest.java b/core/src/test/java/com/blockchaintp/daml/stores/resilience/RetryingTransactionLogTest.java index fa980b44..1c13ea06 100644 --- a/core/src/test/java/com/blockchaintp/daml/stores/resilience/RetryingTransactionLogTest.java +++ b/core/src/test/java/com/blockchaintp/daml/stores/resilience/RetryingTransactionLogTest.java @@ -14,13 +14,11 @@ package com.blockchaintp.daml.stores.resilience; import com.blockchaintp.daml.stores.exception.StoreWriteException; -import com.blockchaintp.daml.stores.layers.RetryingConfig; import com.blockchaintp.daml.stores.layers.RetryingTransactionLog; import com.blockchaintp.daml.stores.service.TransactionLog; import io.vavr.Tuple; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; -import software.amazon.awssdk.services.s3.model.S3Exception; import java.util.Optional; import java.util.UUID; @@ -29,24 +27,26 @@ import static org.mockito.Mockito.*; class RetryingTransactionLogTest { + + class InnerException extends Exception { + } + @Test void transaction_log_operations_are_retried() throws StoreWriteException { var log = mock(TransactionLog.class); var retrying = new RetryingTransactionLog(3, log); - when(log.begin(Optional.empty())).thenThrow(new StoreWriteException(S3Exception.builder().build())) - .thenThrow(new StoreWriteException(S3Exception.builder().build())).thenReturn(Tuple.of(UUID.randomUUID(), 0)); + when(log.begin(Optional.empty())).thenThrow(new StoreWriteException(new InnerException())) + .thenThrow(new StoreWriteException(new InnerException())).thenReturn(Tuple.of(UUID.randomUUID(), 0)); - doThrow(new StoreWriteException(S3Exception.builder().build())) - .doThrow(new StoreWriteException(S3Exception.builder().build())).doNothing().when(log) - .sendEvent(any(UUID.class), any(String.class)); + doThrow(new StoreWriteException(new InnerException())).doThrow(new StoreWriteException(new InnerException())) + .doNothing().when(log).sendEvent(any(UUID.class), any(String.class)); - doThrow(new StoreWriteException(S3Exception.builder().build())) - .doThrow(new StoreWriteException(S3Exception.builder().build())).doReturn(Long.valueOf(0L)).when(log) - .commit(any(UUID.class)); + doThrow(new StoreWriteException(new InnerException())).doThrow(new StoreWriteException(new InnerException())) + .doReturn(Long.valueOf(0L)).when(log).commit(any(UUID.class)); - doThrow(new StoreWriteException(S3Exception.builder().build())) - .doThrow(new StoreWriteException(S3Exception.builder().build())).doNothing().when(log).abort(any(UUID.class)); + doThrow(new StoreWriteException(new InnerException())).doThrow(new StoreWriteException(new InnerException())) + .doNothing().when(log).abort(any(UUID.class)); Assertions.assertDoesNotThrow(() -> retrying.begin(Optional.empty())); Assertions.assertDoesNotThrow(() -> retrying.commit(UUID.randomUUID())); @@ -61,38 +61,33 @@ void transaction_log_write_operations_eventually_fail() throws StoreWriteExcepti var log = mock(TransactionLog.class); var retrying = new RetryingTransactionLog(3, log); - when(log.begin(Optional.empty())).thenThrow(new StoreWriteException(S3Exception.builder().build())) - .thenThrow(new StoreWriteException(S3Exception.builder().build())) - .thenThrow(new StoreWriteException(S3Exception.builder().build())) - .thenThrow(new StoreWriteException(S3Exception.builder().build())).thenReturn(Tuple.of(UUID.randomUUID(), 0)); - - 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(log) - .sendEvent(any(UUID.class), any(String.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())).doReturn(Long.valueOf(0L)).when(log) - .commit(any(UUID.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())).doNothing().when(log).abort(any(UUID.class)); - - Assertions.assertInstanceOf(S3Exception.class, + when(log.begin(Optional.empty())).thenThrow(new StoreWriteException(new InnerException())) + .thenThrow(new StoreWriteException(new InnerException())) + .thenThrow(new StoreWriteException(new InnerException())) + .thenThrow(new StoreWriteException(new InnerException())).thenReturn(Tuple.of(UUID.randomUUID(), 0)); + + doThrow(new StoreWriteException(new InnerException())).doThrow(new StoreWriteException(new InnerException())) + .doThrow(new StoreWriteException(new InnerException())).doThrow(new StoreWriteException(new InnerException())) + .doNothing().when(log).sendEvent(any(UUID.class), any(String.class)); + + doThrow(new StoreWriteException(new InnerException())).doThrow(new StoreWriteException(new InnerException())) + .doThrow(new StoreWriteException(new InnerException())).doThrow(new StoreWriteException(new InnerException())) + .doReturn(Long.valueOf(0L)).when(log).commit(any(UUID.class)); + + doThrow(new StoreWriteException(new InnerException())).doThrow(new StoreWriteException(new InnerException())) + .doThrow(new StoreWriteException(new InnerException())).doThrow(new StoreWriteException(new InnerException())) + .doNothing().when(log).abort(any(UUID.class)); + + Assertions.assertInstanceOf(InnerException.class, Assertions.assertThrows(StoreWriteException.class, () -> retrying.begin(Optional.empty())).getCause()); - Assertions.assertInstanceOf(S3Exception.class, + Assertions.assertInstanceOf(InnerException.class, Assertions.assertThrows(StoreWriteException.class, () -> retrying.commit(UUID.randomUUID())).getCause()); - Assertions.assertInstanceOf(S3Exception.class, + Assertions.assertInstanceOf(InnerException.class, Assertions.assertThrows(StoreWriteException.class, () -> retrying.sendEvent(UUID.randomUUID(), "")).getCause()); - Assertions.assertInstanceOf(S3Exception.class, + Assertions.assertInstanceOf(InnerException.class, Assertions.assertThrows(StoreWriteException.class, () -> retrying.abort(UUID.randomUUID())).getCause()); } diff --git a/postgres/pom.xml b/postgres/pom.xml index 59c0a9dd..2c1ea4cd 100644 --- a/postgres/pom.xml +++ b/postgres/pom.xml @@ -54,6 +54,10 @@ org.slf4j slf4j-api + + io.zonky.test + embedded-postgres + software.amazon.awssdk @@ -155,7 +157,7 @@ true lib/ - com.blockchaintp.daml.store.Main + com.blockchaintp.daml.qldb.Main diff --git a/qldb/src/main/scala/com/blockchaintp/daml/qldb/Main.scala b/qldb/src/main/scala/com/blockchaintp/daml/qldb/Main.scala index b5915c8f..df791ee2 100644 --- a/qldb/src/main/scala/com/blockchaintp/daml/qldb/Main.scala +++ b/qldb/src/main/scala/com/blockchaintp/daml/qldb/Main.scala @@ -18,6 +18,7 @@ import com.blockchaintp.daml.address.QldbAddress import com.blockchaintp.daml.address.QldbIdentifier import com.blockchaintp.daml.participant.InProcLedgerSubmitter import com.blockchaintp.daml.participant.ParticipantBuilder +import com.blockchaintp.daml.resources.QldbResources import com.blockchaintp.daml.runtime.BuilderLedgerFactory import com.blockchaintp.daml.stores.layers.CoercingStore import com.blockchaintp.daml.stores.layers.SplitStore @@ -26,6 +27,7 @@ import com.blockchaintp.daml.stores.qldb.QldbStore import com.blockchaintp.daml.stores.qldb.QldbTransactionLog import com.blockchaintp.daml.stores.s3.S3Store import com.blockchaintp.utility.Aws +import com.blockshaintp.daml.stores.postgres.PostgresStore import com.daml.jwt.JwksVerifier import com.daml.jwt.RSA256Verifier import com.daml.ledger.api.auth.AuthService @@ -39,18 +41,14 @@ import com.daml.ledger.validator.DefaultStateKeySerializationStrategy import com.daml.resources.ProgramResource import scopt.OptionParser import software.amazon.awssdk.auth.credentials.DefaultCredentialsProvider -import software.amazon.awssdk.http.async.SdkAsyncHttpClient -import software.amazon.awssdk.http.nio.netty.NettyNioAsyncHttpClient import software.amazon.awssdk.regions.Region import software.amazon.awssdk.services.qldb.QldbClient import software.amazon.awssdk.services.qldbsession.QldbSessionClient -import software.amazon.awssdk.services.s3.S3AsyncClient import software.amazon.qldb.QldbDriver import software.amazon.qldb.RetryPolicy import scala.jdk.CollectionConverters._ import java.nio.file.Paths -import java.time.Duration import scala.jdk.FunctionConverters.enrichAsJavaFunction import scala.util.Try diff --git a/qldb/src/test/java/store/QldbStoreIntegrationTest.java b/qldb/src/test/java/store/QldbStoreIntegrationTest.java index d63f2083..a4c3c627 100644 --- a/qldb/src/test/java/store/QldbStoreIntegrationTest.java +++ b/qldb/src/test/java/store/QldbStoreIntegrationTest.java @@ -15,10 +15,10 @@ import com.amazon.ion.IonSystem; import com.amazon.ion.system.IonSystemBuilder; +import com.blockchaintp.daml.resources.QldbResources; import com.blockchaintp.daml.stores.exception.StoreReadException; import com.blockchaintp.daml.stores.exception.StoreWriteException; import com.blockchaintp.daml.stores.qldb.QldbStore; -import com.blockchaintp.daml.stores.resources.QldbResources; import com.blockchaintp.daml.stores.service.Key; import com.blockchaintp.daml.stores.service.Opaque; import com.blockchaintp.daml.stores.service.Store; diff --git a/qldb/src/test/java/store/QldbTransactionLogIntegrationTest.java b/qldb/src/test/java/store/QldbTransactionLogIntegrationTest.java index c0d51b03..ba527c96 100644 --- a/qldb/src/test/java/store/QldbTransactionLogIntegrationTest.java +++ b/qldb/src/test/java/store/QldbTransactionLogIntegrationTest.java @@ -15,10 +15,10 @@ import com.amazon.ion.IonSystem; import com.amazon.ion.system.IonSystemBuilder; +import com.blockchaintp.daml.resources.QldbResources; import com.blockchaintp.daml.stores.exception.StoreReadException; import com.blockchaintp.daml.stores.exception.StoreWriteException; import com.blockchaintp.daml.stores.qldb.QldbTransactionLog; -import com.blockchaintp.daml.stores.resources.QldbResources; import com.blockchaintp.utility.Aws; import com.google.protobuf.ByteString; import org.junit.jupiter.api.AfterEach; diff --git a/qldb/src/test/java/store/S3StoreIntegrationTest.java b/qldb/src/test/java/store/S3StoreIntegrationTest.java index ec7aca27..ac474dc4 100644 --- a/qldb/src/test/java/store/S3StoreIntegrationTest.java +++ b/qldb/src/test/java/store/S3StoreIntegrationTest.java @@ -13,9 +13,9 @@ */ package store; +import com.blockchaintp.daml.resources.S3StoreResources; import com.blockchaintp.daml.stores.exception.StoreReadException; import com.blockchaintp.daml.stores.exception.StoreWriteException; -import com.blockchaintp.daml.stores.resources.S3StoreResources; import com.blockchaintp.daml.stores.s3.S3Store; import com.blockchaintp.daml.stores.service.Key; import com.blockchaintp.daml.stores.service.Opaque;