diff --git a/example-context/example-service/example-it/src/test/java/uk/gov/justice/services/eventsourcing/repository/jdbc/event/LinkedEventRepositoryTruncator.java b/example-context/example-service/example-it/src/test/java/uk/gov/justice/services/eventsourcing/repository/jdbc/event/LinkedEventRepositoryTruncator.java deleted file mode 100644 index f822e856..00000000 --- a/example-context/example-service/example-it/src/test/java/uk/gov/justice/services/eventsourcing/repository/jdbc/event/LinkedEventRepositoryTruncator.java +++ /dev/null @@ -1,22 +0,0 @@ -package uk.gov.justice.services.eventsourcing.repository.jdbc.event; - -import uk.gov.justice.services.eventsourcing.publishedevent.PublishedEventInserter; - -import java.sql.SQLException; - -import javax.sql.DataSource; - -public class LinkedEventRepositoryTruncator { - - private final DataSource datasource; - private final PublishedEventInserter publishedEventInserter; - - public LinkedEventRepositoryTruncator(final DataSource datasource) { - this.datasource = datasource; - this.publishedEventInserter = new PublishedEventInserter(); - } - - public void truncate() throws SQLException { - publishedEventInserter.truncate(datasource.getConnection()); - } -} diff --git a/example-context/example-service/example-it/src/test/java/uk/gov/justice/services/eventsourcing/repository/jdbc/event/PublishedEventTableTruncator.java b/example-context/example-service/example-it/src/test/java/uk/gov/justice/services/eventsourcing/repository/jdbc/event/PublishedEventTableTruncator.java new file mode 100644 index 00000000..15b4313e --- /dev/null +++ b/example-context/example-service/example-it/src/test/java/uk/gov/justice/services/eventsourcing/repository/jdbc/event/PublishedEventTableTruncator.java @@ -0,0 +1,22 @@ +package uk.gov.justice.services.eventsourcing.repository.jdbc.event; + +import uk.gov.justice.services.eventsourcing.publishedevent.jdbc.DatabaseTableTruncator; + +import java.sql.SQLException; + +import javax.sql.DataSource; + +public class PublishedEventTableTruncator { + + private final DataSource datasource; + private final DatabaseTableTruncator databaseTableTruncator; + + public PublishedEventTableTruncator(final DataSource datasource) { + this.datasource = datasource; + this.databaseTableTruncator = new DatabaseTableTruncator(); + } + + public void truncate() throws SQLException { + databaseTableTruncator.truncate("published_event", datasource); + } +} diff --git a/example-context/example-service/example-it/src/test/java/uk/gov/justice/services/example/cakeshop/it/CakeShopReplayEventsIT.java b/example-context/example-service/example-it/src/test/java/uk/gov/justice/services/example/cakeshop/it/CakeShopReplayEventsIT.java index 900a56ff..574d9672 100644 --- a/example-context/example-service/example-it/src/test/java/uk/gov/justice/services/example/cakeshop/it/CakeShopReplayEventsIT.java +++ b/example-context/example-service/example-it/src/test/java/uk/gov/justice/services/example/cakeshop/it/CakeShopReplayEventsIT.java @@ -11,7 +11,7 @@ import uk.gov.justice.services.eventsourcing.repository.jdbc.event.EventJdbcRepository; import uk.gov.justice.services.eventsourcing.repository.jdbc.event.EventRepositoryFactory; import uk.gov.justice.services.eventsourcing.repository.jdbc.event.EventStreamJdbsRepositoryFactory; -import uk.gov.justice.services.eventsourcing.repository.jdbc.event.LinkedEventRepositoryTruncator; +import uk.gov.justice.services.eventsourcing.repository.jdbc.event.PublishedEventTableTruncator; import uk.gov.justice.services.eventsourcing.repository.jdbc.eventstream.EventStreamJdbcRepository; import uk.gov.justice.services.eventsourcing.repository.jdbc.exception.InvalidPositionException; import uk.gov.justice.services.example.cakeshop.it.helpers.CakeshopEventGenerator; @@ -49,7 +49,7 @@ public class CakeShopReplayEventsIT { private final DataSource eventStoreDataSource = new DatabaseManager().initEventStoreDb(); private final DataSource viewStoreDataSource = new DatabaseManager().initViewStoreDb(); private final EventJdbcRepository eventJdbcRepository = new EventRepositoryFactory().getEventJdbcRepository(eventStoreDataSource); - private final LinkedEventRepositoryTruncator linkedEventRepositoryTruncator = new LinkedEventRepositoryTruncator(eventStoreDataSource); + private final PublishedEventTableTruncator publishedEventTableTruncator = new PublishedEventTableTruncator(eventStoreDataSource); private final EventStreamJdbsRepositoryFactory eventStreamJdbcRepositoryFactory = new EventStreamJdbsRepositoryFactory(); private final EventStreamJdbcRepository eventStreamJdbcRepository = eventStreamJdbcRepositoryFactory.getEventStreamJdbcRepository(eventStoreDataSource); @@ -148,7 +148,7 @@ private void truncateEventLog() throws SQLException { final Stream eventStream = eventJdbcRepository.findAll(); eventStream.forEach(event -> eventJdbcRepository.clear(event.getStreamId())); - linkedEventRepositoryTruncator.truncate(); + publishedEventTableTruncator.truncate(); } private void runCatchup() throws Exception { diff --git a/example-context/example-service/example-it/src/test/java/uk/gov/justice/services/example/cakeshop/it/CatchupPerformanceIT.java b/example-context/example-service/example-it/src/test/java/uk/gov/justice/services/example/cakeshop/it/CatchupPerformanceIT.java index 19e4bb1b..bb85e3d6 100644 --- a/example-context/example-service/example-it/src/test/java/uk/gov/justice/services/example/cakeshop/it/CatchupPerformanceIT.java +++ b/example-context/example-service/example-it/src/test/java/uk/gov/justice/services/example/cakeshop/it/CatchupPerformanceIT.java @@ -9,7 +9,7 @@ import uk.gov.justice.services.eventsourcing.repository.jdbc.event.EventJdbcRepository; import uk.gov.justice.services.eventsourcing.repository.jdbc.event.EventRepositoryFactory; import uk.gov.justice.services.eventsourcing.repository.jdbc.event.EventStreamJdbsRepositoryFactory; -import uk.gov.justice.services.eventsourcing.repository.jdbc.event.LinkedEventRepositoryTruncator; +import uk.gov.justice.services.eventsourcing.repository.jdbc.event.PublishedEventTableTruncator; import uk.gov.justice.services.eventsourcing.repository.jdbc.eventstream.EventStreamJdbcRepository; import uk.gov.justice.services.eventsourcing.repository.jdbc.exception.InvalidPositionException; import uk.gov.justice.services.example.cakeshop.it.helpers.CakeshopEventGenerator; @@ -22,8 +22,6 @@ import uk.gov.justice.services.example.cakeshop.it.helpers.StandaloneStreamStatusJdbcRepositoryFactory; import uk.gov.justice.services.jmx.Catchup; import uk.gov.justice.services.jmx.CatchupMBean; -import uk.gov.justice.services.jmx.Shuttering; -import uk.gov.justice.services.jmx.ShutteringMBean; import uk.gov.justice.services.test.utils.core.messaging.Poller; import java.sql.SQLException; @@ -48,7 +46,7 @@ public class CatchupPerformanceIT { private final DataSource eventStoreDataSource = new DatabaseManager().initEventStoreDb(); private final DataSource viewStoreDataSource = new DatabaseManager().initViewStoreDb(); private final EventJdbcRepository eventJdbcRepository = new EventRepositoryFactory().getEventJdbcRepository(eventStoreDataSource); - private final LinkedEventRepositoryTruncator linkedEventRepositoryTruncator = new LinkedEventRepositoryTruncator(eventStoreDataSource); + private final PublishedEventTableTruncator publishedEventTableTruncator = new PublishedEventTableTruncator(eventStoreDataSource); private final EventStreamJdbsRepositoryFactory eventStreamJdbcRepositoryFactory = new EventStreamJdbsRepositoryFactory(); private final EventStreamJdbcRepository eventStreamJdbcRepository = eventStreamJdbcRepositoryFactory.getEventStreamJdbcRepository(eventStoreDataSource); @@ -74,18 +72,6 @@ public void cleanup() { client.close(); } - @After - public void unShutter() throws Exception { - - try (final JMXConnector jmxConnector = mBeanHelper.getJMXConnector()) { - final MBeanServerConnection connection = jmxConnector.getMBeanServerConnection(); - - final ObjectName objectName = new ObjectName("shuttering", "type", Shuttering.class.getSimpleName()); - - mBeanHelper.getMbeanProxy(connection, objectName, ShutteringMBean.class).doUnshutteringRequested(); - } - } - @Test public void shouldReplayAndFindRecipesInViewStore() throws Exception { @@ -93,8 +79,6 @@ public void shouldReplayAndFindRecipesInViewStore() throws Exception { final int numberOfEventsPerStream = 100; final int totalEvents = numberOfStreams * numberOfEventsPerStream; - shutter(); - truncateEventLog(); recipeTableInspector.truncateViewstoreTables(); @@ -111,10 +95,25 @@ public void shouldReplayAndFindRecipesInViewStore() throws Exception { if (numberOfEvents.isPresent()) { System.out.println("Inserted " + numberOfEvents.get() + " events"); - } else { + } else { fail("Failed to insert " + totalEvents + " events"); } + for (final UUID streamId : streamIds) { + + final Optional eventCount = longPoller.pollUntilFound(() -> { + final long eventsPerStream = recipeTableInspector.countEventsPerStream(streamId); + if (eventsPerStream == numberOfEventsPerStream) { + return of(eventsPerStream); + } + + return empty(); + }); + + if (!eventCount.isPresent()) { + fail(); + } + } recipeTableInspector.truncateViewstoreTables(); @@ -127,7 +126,7 @@ public void shouldReplayAndFindRecipesInViewStore() throws Exception { } - for(final UUID streamId: streamIds) { + for (final UUID streamId : streamIds) { final Optional eventCount = longPoller.pollUntilFound(() -> { final long eventsPerStream = recipeTableInspector.countEventsPerStream(streamId); @@ -138,7 +137,7 @@ public void shouldReplayAndFindRecipesInViewStore() throws Exception { return empty(); }); - if (! eventCount.isPresent()) { + if (!eventCount.isPresent()) { fail(); } } @@ -177,18 +176,7 @@ private void truncateEventLog() throws SQLException { final Stream eventStream = eventJdbcRepository.findAll(); eventStream.forEach(event -> eventJdbcRepository.clear(event.getStreamId())); - linkedEventRepositoryTruncator.truncate(); - } - - private void shutter() throws Exception { - - try (final JMXConnector jmxConnector = mBeanHelper.getJMXConnector()) { - final MBeanServerConnection connection = jmxConnector.getMBeanServerConnection(); - - final ObjectName objectName = new ObjectName("shuttering", "type", Shuttering.class.getSimpleName()); - - mBeanHelper.getMbeanProxy(connection, objectName, ShutteringMBean.class).doShutteringRequested(); - } + publishedEventTableTruncator.truncate(); } private void runCatchup() throws Exception { diff --git a/example-context/example-service/example-it/src/test/java/uk/gov/justice/services/example/cakeshop/it/ShutteringIT.java b/example-context/example-service/example-it/src/test/java/uk/gov/justice/services/example/cakeshop/it/ShutteringIT.java index 28b57aa5..9ef0838d 100644 --- a/example-context/example-service/example-it/src/test/java/uk/gov/justice/services/example/cakeshop/it/ShutteringIT.java +++ b/example-context/example-service/example-it/src/test/java/uk/gov/justice/services/example/cakeshop/it/ShutteringIT.java @@ -71,7 +71,7 @@ public void cleanup() throws MalformedObjectNameException, IntrospectionExceptio } @Test - public void shouldNotReturnRecipesAfterShuttering() throws MalformedObjectNameException, IntrospectionException, ReflectionException, InstanceNotFoundException, IOException { + public void shouldNotReturnRecipesAfterShuttering() throws Exception { //invoke shuttering invokeShuttering(true); @@ -79,12 +79,14 @@ public void shouldNotReturnRecipesAfterShuttering() throws MalformedObjectNameEx final String recipeId = addRecipe(MARBLE_CAKE); final String recipeId2 = addRecipe(CARROT_CAKE); + Thread.sleep(5000L); + //check recipes have not been added due to shuttering verifyRecipeAdded(recipeId, recipeId2, null, null, false, NOT_FOUND); } @Test - public void shouldQueryForRecipesAfterUnShuttering() throws MalformedObjectNameException, IntrospectionException, ReflectionException, InstanceNotFoundException, IOException { + public void shouldQueryForRecipesAfterUnShuttering() throws Exception { //invoke shuttering invokeShuttering(true); @@ -92,6 +94,8 @@ public void shouldQueryForRecipesAfterUnShuttering() throws MalformedObjectNameE final String recipeId = addRecipe(MARBLE_CAKE); final String recipeId2 = addRecipe(CARROT_CAKE); + Thread.sleep(5000L); + //check recipes have not been added due to shuttering verifyRecipeAdded(recipeId, recipeId2, null, null, false, NOT_FOUND); diff --git a/example-context/example-service/example-it/src/test/resources/wildfly-config/standalone-single.xml b/example-context/example-service/example-it/src/test/resources/wildfly-config/standalone-single.xml index 2d17b029..81d1735e 100644 --- a/example-context/example-service/example-it/src/test/resources/wildfly-config/standalone-single.xml +++ b/example-context/example-service/example-it/src/test/resources/wildfly-config/standalone-single.xml @@ -107,9 +107,6 @@ - - - @@ -443,6 +440,8 @@ + + diff --git a/pom.xml b/pom.xml index 9b9a9ca4..b1c94af3 100644 --- a/pom.xml +++ b/pom.xml @@ -31,12 +31,12 @@ cake-shop 2.0.2 - 6.0.0-M24 + 6.0.0-M26 1.2.0 - 2.0.0-M25 - 2.0.0-M18 + 2.0.0-M27 + 2.0.0-M20 1.17.7 - 4.0.0-M20 + 4.0.0-M21 2.7.0 1.7.0 2.2.0.Final