diff --git a/service/pom.xml b/service/pom.xml index 879cf92b9..6732c2251 100644 --- a/service/pom.xml +++ b/service/pom.xml @@ -43,10 +43,6 @@ io.dropwizard dropwizard-core - - io.dropwizard - dropwizard-jdbi3 - io.dropwizard dropwizard-auth @@ -118,19 +114,10 @@ logstash-logback-encoder - - org.jdbi - jdbi3-core - - io.dropwizard.metrics metrics-core - - io.dropwizard.metrics - metrics-jdbi3 - io.dropwizard.metrics metrics-healthchecks diff --git a/service/src/main/java/org/whispersystems/textsecuregcm/storage/FaultTolerantDatabase.java b/service/src/main/java/org/whispersystems/textsecuregcm/storage/FaultTolerantDatabase.java deleted file mode 100644 index e06e8749f..000000000 --- a/service/src/main/java/org/whispersystems/textsecuregcm/storage/FaultTolerantDatabase.java +++ /dev/null @@ -1,44 +0,0 @@ -/* - * Copyright 2013-2020 Signal Messenger, LLC - * SPDX-License-Identifier: AGPL-3.0-only - */ - -package org.whispersystems.textsecuregcm.storage; - -import com.codahale.metrics.SharedMetricRegistries; -import org.jdbi.v3.core.Jdbi; -import org.whispersystems.textsecuregcm.configuration.CircuitBreakerConfiguration; -import org.whispersystems.textsecuregcm.util.CircuitBreakerUtil; -import org.whispersystems.textsecuregcm.util.Constants; - -import java.util.function.Consumer; -import java.util.function.Function; - -import io.github.resilience4j.circuitbreaker.CircuitBreaker; - -public class FaultTolerantDatabase { - - private final Jdbi database; - private final CircuitBreaker circuitBreaker; - - public FaultTolerantDatabase(String name, Jdbi database, CircuitBreakerConfiguration circuitBreakerConfiguration) { - this.database = database; - this.circuitBreaker = CircuitBreaker.of(name, circuitBreakerConfiguration.toCircuitBreakerConfig()); - - CircuitBreakerUtil.registerMetrics(SharedMetricRegistries.getOrCreate(Constants.METRICS_NAME), - circuitBreaker, - FaultTolerantDatabase.class); - } - - public void use(Consumer consumer) { - this.circuitBreaker.executeRunnable(() -> consumer.accept(database)); - } - - public T with(Function consumer) { - return this.circuitBreaker.executeSupplier(() -> consumer.apply(database)); - } - - public Jdbi getDatabase() { - return database; - } -} diff --git a/service/src/test/java/org/whispersystems/textsecuregcm/storage/AccountsTest.java b/service/src/test/java/org/whispersystems/textsecuregcm/storage/AccountsTest.java index f1e2a8c83..03ec5b583 100644 --- a/service/src/test/java/org/whispersystems/textsecuregcm/storage/AccountsTest.java +++ b/service/src/test/java/org/whispersystems/textsecuregcm/storage/AccountsTest.java @@ -16,7 +16,6 @@ import static org.mockito.Mockito.when; import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.uuid.UUIDComparator; -import io.github.resilience4j.circuitbreaker.CallNotPermittedException; import java.nio.charset.StandardCharsets; import java.util.ArrayList; import java.util.Arrays; @@ -27,14 +26,11 @@ import java.util.Random; import java.util.UUID; import java.util.concurrent.CompletableFuture; import java.util.concurrent.CompletionException; -import org.jdbi.v3.core.transaction.TransactionException; import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.RegisterExtension; import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.ValueSource; -import org.whispersystems.textsecuregcm.configuration.CircuitBreakerConfiguration; import org.whispersystems.textsecuregcm.configuration.dynamic.DynamicConfiguration; import org.whispersystems.textsecuregcm.tests.util.AccountsHelper; import org.whispersystems.textsecuregcm.tests.util.DevicesHelper; @@ -494,60 +490,6 @@ class AccountsTest { assertThat(retrieved.isPresent()).isFalse(); } - @Test - @Disabled("Need fault tolerant dynamodb") - void testBreaker() throws InterruptedException { - - CircuitBreakerConfiguration configuration = new CircuitBreakerConfiguration(); - configuration.setWaitDurationInOpenStateInSeconds(1); - configuration.setRingBufferSizeInHalfOpenState(1); - configuration.setRingBufferSizeInClosedState(2); - configuration.setFailureRateThreshold(50); - - final DynamoDbClient client = mock(DynamoDbClient.class); - final DynamoDbAsyncClient asyncClient = mock(DynamoDbAsyncClient.class); - - when(client.transactWriteItems(any(TransactWriteItemsRequest.class))) - .thenThrow(RuntimeException.class); - - when(asyncClient.updateItem(any(UpdateItemRequest.class))) - .thenReturn(CompletableFuture.failedFuture(new RuntimeException())); - - Accounts accounts = new Accounts(mockDynamicConfigManager, client, asyncClient, ACCOUNTS_TABLE_NAME, NUMBER_CONSTRAINT_TABLE_NAME, - PNI_CONSTRAINT_TABLE_NAME, USERNAME_CONSTRAINT_TABLE_NAME, SCAN_PAGE_SIZE); - Account account = generateAccount("+14151112222", UUID.randomUUID(), UUID.randomUUID()); - - try { - accounts.update(account); - throw new AssertionError(); - } catch (TransactionException e) { - // good - } - - try { - accounts.update(account); - throw new AssertionError(); - } catch (TransactionException e) { - // good - } - - try { - accounts.update(account); - throw new AssertionError(); - } catch (CallNotPermittedException e) { - // good - } - - Thread.sleep(1100); - - try { - accounts.update(account); - throw new AssertionError(); - } catch (TransactionException e) { - // good - } - } - @Test void testCanonicallyDiscoverableSet() { Device device = generateDevice(1);