diff --git a/tessera-data/src/main/java/com/quorum/tessera/data/EncryptedRawTransaction.java b/tessera-data/src/main/java/com/quorum/tessera/data/EncryptedRawTransaction.java index 08f9c838bd..83449337df 100644 --- a/tessera-data/src/main/java/com/quorum/tessera/data/EncryptedRawTransaction.java +++ b/tessera-data/src/main/java/com/quorum/tessera/data/EncryptedRawTransaction.java @@ -14,7 +14,7 @@ query = "delete from EncryptedRawTransaction where hash.hashBytes = :hash"), @NamedQuery( name = "EncryptedRawTransaction.Upcheck", - query = "select count(c) from EncryptedRawTransaction c"), + query = "select count(c.timestamp) from EncryptedRawTransaction c"), @NamedQuery( name = "EncryptedRawTransaction.FindAll", query = "select ert from EncryptedRawTransaction ert order by ert.timestamp, ert.hash"), diff --git a/tessera-data/src/main/java/com/quorum/tessera/data/EncryptedTransaction.java b/tessera-data/src/main/java/com/quorum/tessera/data/EncryptedTransaction.java index 71c17d0e67..b4e596788e 100644 --- a/tessera-data/src/main/java/com/quorum/tessera/data/EncryptedTransaction.java +++ b/tessera-data/src/main/java/com/quorum/tessera/data/EncryptedTransaction.java @@ -19,7 +19,7 @@ query = "select et from EncryptedTransaction et order by et.timestamp,et.hash"), @NamedQuery( name = "EncryptedTransaction.Upcheck", - query = "select count(c) from EncryptedTransaction c") + query = "select count(c.timestamp) from EncryptedTransaction c") }) @Entity @Table(name = "ENCRYPTED_TRANSACTION") diff --git a/tessera-dist/src/main/java/com/quorum/tessera/launcher/Main.java b/tessera-dist/src/main/java/com/quorum/tessera/launcher/Main.java index be4fd13fc0..dbede04586 100644 --- a/tessera-dist/src/main/java/com/quorum/tessera/launcher/Main.java +++ b/tessera-dist/src/main/java/com/quorum/tessera/launcher/Main.java @@ -102,9 +102,16 @@ public static void main(final String... args) throws Exception { LOGGER.debug("Created BatchResendManager"); LOGGER.debug("Creating txn manager"); - TransactionManager.create(); + TransactionManager transactionManager = TransactionManager.create(); LOGGER.debug("Created txn manager"); + LOGGER.debug("Validating if transaction table exists"); + if (!transactionManager.upcheck()) { + throw new RuntimeException( + "The database has not been setup correctly. Please ensure transaction tables " + + "are present and correct"); + } + LOGGER.debug("Creating ScheduledServiceFactory"); ScheduledServiceFactory scheduledServiceFactory = ScheduledServiceFactory.fromConfig(config); scheduledServiceFactory.build(); diff --git a/tessera-jaxrs/common-jaxrs/src/main/java/com/quorum/tessera/api/common/UpCheckResource.java b/tessera-jaxrs/common-jaxrs/src/main/java/com/quorum/tessera/api/common/UpCheckResource.java index 0f445dbabe..280c222f98 100644 --- a/tessera-jaxrs/common-jaxrs/src/main/java/com/quorum/tessera/api/common/UpCheckResource.java +++ b/tessera-jaxrs/common-jaxrs/src/main/java/com/quorum/tessera/api/common/UpCheckResource.java @@ -1,6 +1,5 @@ package com.quorum.tessera.api.common; -import com.quorum.tessera.transaction.TransactionManager; import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.media.Content; import io.swagger.v3.oas.annotations.media.ExampleObject; @@ -8,7 +7,6 @@ import io.swagger.v3.oas.annotations.responses.ApiResponse; import io.swagger.v3.oas.annotations.tags.Tag; import io.swagger.v3.oas.annotations.tags.Tags; -import java.util.Objects; import javax.ws.rs.GET; import javax.ws.rs.Path; import javax.ws.rs.Produces; @@ -25,13 +23,6 @@ public class UpCheckResource { private static final Logger LOGGER = LoggerFactory.getLogger(UpCheckResource.class); private static final String UPCHECK_RESPONSE_IS_UP = "I'm up!"; - private static final String UPCHECK_RESPONSE_DB = "Database unavailable"; - - private final TransactionManager transactionManager; - - public UpCheckResource(final TransactionManager transactionManager) { - this.transactionManager = Objects.requireNonNull(transactionManager); - } /** * Called to check if the application is running and responsive. Gives no details about the health @@ -51,18 +42,12 @@ public UpCheckResource(final TransactionManager transactionManager) { mediaType = MediaType.TEXT_PLAIN, schema = @Schema(type = "string"), examples = { - @ExampleObject(name = UPCHECK_RESPONSE_IS_UP, value = UPCHECK_RESPONSE_IS_UP), - @ExampleObject(name = UPCHECK_RESPONSE_DB, value = UPCHECK_RESPONSE_DB) + @ExampleObject(name = UPCHECK_RESPONSE_IS_UP, value = UPCHECK_RESPONSE_IS_UP) })) @GET @Produces(MediaType.TEXT_PLAIN) public Response upCheck() { LOGGER.info("GET upcheck"); - - if (!transactionManager.upcheck()) { - return Response.ok(UPCHECK_RESPONSE_DB).build(); - } - return Response.ok(UPCHECK_RESPONSE_IS_UP).build(); } } diff --git a/tessera-jaxrs/common-jaxrs/src/test/java/com/quorum/tessera/api/common/UpCheckResourceTest.java b/tessera-jaxrs/common-jaxrs/src/test/java/com/quorum/tessera/api/common/UpCheckResourceTest.java index a333b997e1..fc43c11b73 100644 --- a/tessera-jaxrs/common-jaxrs/src/test/java/com/quorum/tessera/api/common/UpCheckResourceTest.java +++ b/tessera-jaxrs/common-jaxrs/src/test/java/com/quorum/tessera/api/common/UpCheckResourceTest.java @@ -3,49 +3,17 @@ import static org.assertj.core.api.Assertions.assertThat; import static org.mockito.Mockito.*; -import com.quorum.tessera.transaction.TransactionManager; import javax.ws.rs.core.Response; -import org.junit.After; -import org.junit.Before; import org.junit.Test; public class UpCheckResourceTest { - private UpCheckResource resource; - - private TransactionManager transactionManager; - - @Before - public void onSetup() { - this.transactionManager = mock(TransactionManager.class); - - this.resource = new UpCheckResource(transactionManager); - } - - @After - public void onTearDown() { - verifyNoMoreInteractions(transactionManager); - } + private UpCheckResource resource = new UpCheckResource(); @Test - public void upcheck() { - when(transactionManager.upcheck()).thenReturn(true); - + public void upCheck() { final Response response = resource.upCheck(); assertThat(response.getStatus()).isEqualTo(200); assertThat(response.getEntity()).isEqualTo("I'm up!"); - - verify(transactionManager).upcheck(); - } - - @Test - public void upcheckWhenDBNotReady() { - when(transactionManager.upcheck()).thenReturn(false); - - final Response response = resource.upCheck(); - assertThat(response.getStatus()).isEqualTo(200); - assertThat(response.getEntity()).isEqualTo("Database unavailable"); - - verify(transactionManager).upcheck(); } } diff --git a/tessera-jaxrs/sync-jaxrs/src/main/java/com/quorum/tessera/p2p/P2PRestApp.java b/tessera-jaxrs/sync-jaxrs/src/main/java/com/quorum/tessera/p2p/P2PRestApp.java index 0e2ef949db..b2de1d48e9 100644 --- a/tessera-jaxrs/sync-jaxrs/src/main/java/com/quorum/tessera/p2p/P2PRestApp.java +++ b/tessera-jaxrs/sync-jaxrs/src/main/java/com/quorum/tessera/p2p/P2PRestApp.java @@ -114,7 +114,7 @@ public Set getSingletons() { new TransactionResource( transactionManager, batchResendManager, payloadEncoder, legacyResendManager); - final UpCheckResource upCheckResource = new UpCheckResource(transactionManager); + final UpCheckResource upCheckResource = new UpCheckResource(); final PrivacyGroupResource privacyGroupResource = new PrivacyGroupResource(privacyGroupManager); diff --git a/tessera-jaxrs/thirdparty-jaxrs/src/main/java/com/quorum/tessera/thirdparty/ThirdPartyRestApp.java b/tessera-jaxrs/thirdparty-jaxrs/src/main/java/com/quorum/tessera/thirdparty/ThirdPartyRestApp.java index 2132f5b946..16210026d7 100644 --- a/tessera-jaxrs/thirdparty-jaxrs/src/main/java/com/quorum/tessera/thirdparty/ThirdPartyRestApp.java +++ b/tessera-jaxrs/thirdparty-jaxrs/src/main/java/com/quorum/tessera/thirdparty/ThirdPartyRestApp.java @@ -37,7 +37,7 @@ public Set getSingletons() { new RawTransactionResource(transactionManager); final PartyInfoResource partyInfoResource = new PartyInfoResource(discovery); final KeyResource keyResource = new KeyResource(); - final UpCheckResource upCheckResource = new UpCheckResource(transactionManager); + final UpCheckResource upCheckResource = new UpCheckResource(); return Set.of(rawTransactionResource, partyInfoResource, keyResource, upCheckResource); } diff --git a/tessera-jaxrs/transaction-jaxrs/src/main/java/com/quorum/tessera/q2t/Q2TRestApp.java b/tessera-jaxrs/transaction-jaxrs/src/main/java/com/quorum/tessera/q2t/Q2TRestApp.java index d2363ab470..d13d7001c8 100644 --- a/tessera-jaxrs/transaction-jaxrs/src/main/java/com/quorum/tessera/q2t/Q2TRestApp.java +++ b/tessera-jaxrs/transaction-jaxrs/src/main/java/com/quorum/tessera/q2t/Q2TRestApp.java @@ -56,7 +56,7 @@ public Set getSingletons() { RawTransactionResource rawTransactionResource = new RawTransactionResource(transactionManager); EncodedPayloadResource encodedPayloadResource = new EncodedPayloadResource(encodedPayloadManager, transactionManager); - final UpCheckResource upCheckResource = new UpCheckResource(transactionManager); + final UpCheckResource upCheckResource = new UpCheckResource(); final PrivacyGroupResource privacyGroupResource = new PrivacyGroupResource(privacyGroupManager); diff --git a/tests/acceptance-test/src/test/java/com/quorum/tessera/test/rest/ThirdPartyIT.java b/tests/acceptance-test/src/test/java/com/quorum/tessera/test/rest/ThirdPartyIT.java index 713f659b75..b1e0fef7ff 100644 --- a/tests/acceptance-test/src/test/java/com/quorum/tessera/test/rest/ThirdPartyIT.java +++ b/tests/acceptance-test/src/test/java/com/quorum/tessera/test/rest/ThirdPartyIT.java @@ -110,6 +110,7 @@ static Config createNode(NodeAlias nodeAlias) { setUsername("junit"); setPassword("junit"); setUrl("jdbc:h2:mem:thirdpty".concat(nodeAlias.name())); + setAutoCreateTables(true); } });