Skip to content

Commit

Permalink
Remove trigger from event_log table
Browse files Browse the repository at this point in the history
  • Loading branch information
allanmckenzie committed Oct 7, 2021
1 parent 7182b39 commit 429550e
Show file tree
Hide file tree
Showing 53 changed files with 80 additions and 58 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ on [Keep a CHANGELOG](http://keepachangelog.com/). This project adheres to
## [Unreleased]
### Changed
- Created branch for version 8.x.x of the framework
- Included fix for out of memory error in catchup for large datasets
- Publishing of events no longer use a trigger on the event_log table

## [7.0.0] - 2021-09-27
### Changed
Expand Down
2 changes: 1 addition & 1 deletion example-context/example-domain/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<artifactId>example-context</artifactId>
<groupId>uk.gov.justice.services.example</groupId>
<version>8.0.0</version>
<version>8.0.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>

Expand Down
2 changes: 1 addition & 1 deletion example-context/example-persistence/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<artifactId>example-context</artifactId>
<groupId>uk.gov.justice.services.example</groupId>
<version>8.0.0</version>
<version>8.0.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import static java.util.UUID.randomUUID;
import static org.hamcrest.Matchers.hasSize;
import static org.hamcrest.Matchers.is;
import static org.junit.Assert.assertThat;
import static org.hamcrest.MatcherAssert.assertThat;

import uk.gov.justice.services.example.cakeshop.persistence.entity.Cake;
import uk.gov.justice.services.test.utils.persistence.BaseTransactionalTest;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<artifactId>example-command</artifactId>
<groupId>uk.gov.justice.services.example</groupId>
<version>8.0.0</version>
<version>8.0.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.Matchers.equalTo;
import static org.junit.Assert.assertThat;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.mockito.Mockito.verify;
import static uk.gov.justice.services.core.annotation.Component.COMMAND_API;
import static uk.gov.justice.services.test.utils.core.matchers.HandlerClassMatcher.isHandlerClass;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@


import static org.hamcrest.CoreMatchers.is;
import static org.junit.Assert.assertThat;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.mockito.Mockito.verify;
import static uk.gov.justice.services.core.annotation.Component.COMMAND_API;
import static uk.gov.justice.services.test.utils.core.matchers.HandlerClassMatcher.isHandlerClass;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

import static org.hamcrest.CoreMatchers.hasItem;
import static org.hamcrest.CoreMatchers.is;
import static org.junit.Assert.assertThat;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;
import static uk.gov.justice.services.core.annotation.Component.COMMAND_API;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<artifactId>example-command</artifactId>
<groupId>uk.gov.justice.services.example</groupId>
<version>8.0.0</version>
<version>8.0.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package uk.gov.justice.services.example.cakeshop.command.handler;

import static org.hamcrest.Matchers.is;
import static org.junit.Assert.assertThat;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.mockito.Mockito.when;
import static uk.gov.justice.services.test.utils.core.messaging.JsonEnvelopeBuilder.envelope;
import static uk.gov.justice.services.test.utils.core.messaging.MetadataBuilderFactory.metadataWithDefaults;
Expand Down
2 changes: 1 addition & 1 deletion example-context/example-service/example-command/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<artifactId>example-service</artifactId>
<groupId>uk.gov.justice.services.example</groupId>
<version>8.0.0</version>
<version>8.0.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<artifactId>example-custom</artifactId>
<groupId>uk.gov.justice.services.example</groupId>
<version>8.0.0</version>
<version>8.0.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import static java.util.UUID.randomUUID;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.CoreMatchers.notNullValue;
import static org.junit.Assert.assertThat;
import static org.hamcrest.MatcherAssert.assertThat;
import static uk.gov.justice.services.test.utils.core.matchers.HandlerClassMatcher.isCustomHandlerClass;
import static uk.gov.justice.services.test.utils.core.matchers.HandlerMethodMatcher.method;
import static uk.gov.justice.services.test.utils.core.messaging.JsonEnvelopeBuilder.envelope;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package uk.gov.justice.services.example.cakeshop.custom.api.response;

import static org.hamcrest.core.Is.is;
import static org.junit.Assert.assertThat;
import static org.hamcrest.MatcherAssert.assertThat;

import java.util.UUID;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package uk.gov.justice.services.example.cakeshop.custom.api.response;

import static org.hamcrest.core.Is.is;
import static org.junit.Assert.assertThat;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.mockito.Mockito.mock;

import java.util.List;
Expand Down
2 changes: 1 addition & 1 deletion example-context/example-service/example-custom/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<artifactId>example-service</artifactId>
<groupId>uk.gov.justice.services.example</groupId>
<version>8.0.0</version>
<version>8.0.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<artifactId>example-service</artifactId>
<groupId>uk.gov.justice.services.example</groupId>
<version>8.0.0</version>
<version>8.0.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<artifactId>example-event</artifactId>
<groupId>uk.gov.justice.services.example</groupId>
<version>8.0.0</version>
<version>8.0.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<artifactId>example-event</artifactId>
<groupId>uk.gov.justice.services.example</groupId>
<version>8.0.0</version>
<version>8.0.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package uk.gov.justice.services.example.cakeshop.event.listener.converter;

import static org.hamcrest.CoreMatchers.equalTo;
import static org.junit.Assert.assertThat;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.mockito.Mockito.when;

import uk.gov.justice.services.example.cakeshop.domain.event.RecipeAdded;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package uk.gov.justice.services.example.cakeshop.event.listener.converter;

import static org.hamcrest.CoreMatchers.equalTo;
import static org.junit.Assert.assertThat;
import static org.hamcrest.MatcherAssert.assertThat;

import uk.gov.justice.services.example.cakeshop.domain.Ingredient;
import uk.gov.justice.services.example.cakeshop.domain.event.RecipeAdded;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package uk.gov.justice.services.example.cakeshop.event.listener.provider;

import static org.hamcrest.CoreMatchers.is;
import static org.junit.Assert.assertThat;
import static org.hamcrest.MatcherAssert.assertThat;

import uk.gov.justice.services.core.interceptor.InterceptorChainEntry;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<artifactId>example-event</artifactId>
<groupId>uk.gov.justice.services.example</groupId>
<version>8.0.0</version>
<version>8.0.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>example-event-processor</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<artifactId>example-event</artifactId>
<groupId>uk.gov.justice.services.example</groupId>
<version>8.0.0</version>
<version>8.0.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>

Expand Down
2 changes: 1 addition & 1 deletion example-context/example-service/example-event/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<groupId>uk.gov.justice.services.example</groupId>
<artifactId>example-service</artifactId>
<version>8.0.0</version>
<version>8.0.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<artifactId>example-service</artifactId>
<groupId>uk.gov.justice.services.example</groupId>
<version>8.0.0</version>
<version>8.0.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>

Expand Down
2 changes: 1 addition & 1 deletion example-context/example-service/example-it/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<groupId>uk.gov.justice.services.example</groupId>
<artifactId>example-service</artifactId>
<version>8.0.0</version>
<version>8.0.0-SNAPSHOT</version>
</parent>
<artifactId>example-it</artifactId>
<properties>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import static java.util.UUID.randomUUID;
import static javax.ws.rs.client.Entity.entity;
import static org.hamcrest.core.Is.is;
import static org.junit.Assert.assertThat;
import static org.hamcrest.MatcherAssert.assertThat;
import static uk.gov.justice.services.example.cakeshop.it.params.CakeShopMediaTypes.ADD_RECIPE_MEDIA_TYPE;
import static uk.gov.justice.services.example.cakeshop.it.params.CakeShopMediaTypes.CONTEXT_NAME;
import static uk.gov.justice.services.example.cakeshop.it.params.CakeShopUris.RECIPES_RESOURCE_URI;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import static java.util.Optional.empty;
import static java.util.Optional.of;
import static org.hamcrest.CoreMatchers.is;
import static org.junit.Assert.assertThat;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.junit.Assert.fail;
import static uk.gov.justice.services.eventstore.management.commands.EventCatchupCommand.CATCHUP;
import static uk.gov.justice.services.jmx.system.command.client.connection.JmxParametersBuilder.jmxParameters;
Expand Down Expand Up @@ -157,6 +157,7 @@ private void addEventsToEventLog(final int numberOfStreams, final int numberOfEv

batchEventInserter.updateEventStreamTable(streamIds);
batchEventInserter.updateEventLogTable(events);
batchEventInserter.updatePublishQueueTableWithEvents(events);

}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import static javax.ws.rs.client.Entity.entity;
import static javax.ws.rs.core.Response.Status.ACCEPTED;
import static org.hamcrest.CoreMatchers.is;
import static org.junit.Assert.assertThat;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.junit.Assert.fail;
import static uk.gov.justice.services.eventstore.management.commands.EventCatchupCommand.CATCHUP;
import static uk.gov.justice.services.example.cakeshop.it.params.CakeShopMediaTypes.ADD_RECIPE_MEDIA_TYPE;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import static java.util.Optional.of;
import static javax.json.Json.createObjectBuilder;
import static org.hamcrest.CoreMatchers.is;
import static org.junit.Assert.assertThat;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.junit.Assert.fail;
import static uk.gov.justice.services.jmx.api.domain.CommandState.COMMAND_COMPLETE;
import static uk.gov.justice.services.jmx.api.domain.CommandState.COMMAND_FAILED;
Expand Down Expand Up @@ -186,6 +186,7 @@ private void addEventsToEventLog(final int numberOfStreams, final int numberOfEv

batchEventInserter.updateEventStreamTable(streamIds);
batchEventInserter.updateEventLogTable(events);
batchEventInserter.updatePublishQueueTableWithEvents(events);
}

private void setPayloadsOfEventsInvalid() throws Exception {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,12 @@
import static java.util.stream.Collectors.toMap;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.CoreMatchers.notNullValue;
import static org.junit.Assert.assertThat;
import static uk.gov.justice.services.eventstore.management.commands.AddTriggerCommand.ADD_TRIGGER;
import static org.hamcrest.MatcherAssert.assertThat;
import static uk.gov.justice.services.eventstore.management.commands.DisablePublishingCommand.DISABLE_PUBLISHING;
import static uk.gov.justice.services.eventstore.management.commands.EnablePublishingCommand.ENABLE_PUBLISHING;
import static uk.gov.justice.services.eventstore.management.commands.EventCatchupCommand.CATCHUP;
import static uk.gov.justice.services.eventstore.management.commands.IndexerCatchupCommand.INDEXER_CATCHUP;
import static uk.gov.justice.services.eventstore.management.commands.RebuildCommand.REBUILD;
import static uk.gov.justice.services.eventstore.management.commands.RemoveTriggerCommand.REMOVE_TRIGGER;
import static uk.gov.justice.services.eventstore.management.commands.ValidatePublishedEventsCommand.VALIDATE_EVENTS;
import static uk.gov.justice.services.eventstore.management.commands.VerifyCatchupCommand.VERIFY_CATCHUP;
import static uk.gov.justice.services.eventstore.management.commands.VerifyRebuildCommand.VERIFY_REBUILD;
Expand All @@ -27,7 +25,6 @@
import uk.gov.justice.services.jmx.system.command.client.SystemCommanderClient;
import uk.gov.justice.services.jmx.system.command.client.TestSystemCommanderClientFactory;
import uk.gov.justice.services.jmx.system.command.client.connection.JmxParameters;
import uk.gov.justice.services.management.suspension.commands.RefreshFeatureControlCacheCommand;

import java.util.List;
import java.util.Map;
Expand Down Expand Up @@ -56,21 +53,19 @@ public void shouldListAllSystemCommands() throws Exception {
.getRemote(CONTEXT_NAME)
.listCommands();

assertThat(systemCommandDetailsList.size(), is(14));
assertThat(systemCommandDetailsList.size(), is(12));

final Map<String, SystemCommandDetails> systemCommandDetailsMap = systemCommandDetailsList
.stream()
.collect(toMap(SystemCommandDetails::getName, systemCommandDetails -> systemCommandDetails));

assertThat(systemCommandDetailsMap.get(ADD_TRIGGER), is(notNullValue()));
assertThat(systemCommandDetailsMap.get(DISABLE_PUBLISHING), is(notNullValue()));
assertThat(systemCommandDetailsMap.get(ENABLE_PUBLISHING), is(notNullValue()));
assertThat(systemCommandDetailsMap.get(CATCHUP), is(notNullValue()));
assertThat(systemCommandDetailsMap.get(INDEXER_CATCHUP), is(notNullValue()));
assertThat(systemCommandDetailsMap.get(PING), is(notNullValue()));
assertThat(systemCommandDetailsMap.get(REBUILD), is(notNullValue()));
assertThat(systemCommandDetailsMap.get(REFRESH_FEATURE_CACHE), is(notNullValue()));
assertThat(systemCommandDetailsMap.get(REMOVE_TRIGGER), is(notNullValue()));
assertThat(systemCommandDetailsMap.get(SUSPEND), is(notNullValue()));
assertThat(systemCommandDetailsMap.get(UNSUSPEND), is(notNullValue()));
assertThat(systemCommandDetailsMap.get(VALIDATE_EVENTS), is(notNullValue()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import static java.util.stream.Collectors.toList;
import static org.hamcrest.CoreMatchers.hasItem;
import static org.hamcrest.CoreMatchers.is;
import static org.junit.Assert.assertThat;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.junit.Assert.fail;
import static uk.gov.justice.services.eventstore.management.commands.RebuildCommand.REBUILD;
import static uk.gov.justice.services.jmx.system.command.client.connection.JmxParametersBuilder.jmxParameters;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ public class BatchEventInserter {
private static final String SQL_INSERT_STREAM = "INSERT INTO event_stream " +
"(stream_id, date_created, active) values (?, ?, ?)";

private static final String SQL_INSERT_EVENT_INTO_PUBLISH_QUEUE = "INSERT INTO pre_publish_queue " +
"(event_log_id, date_queued) values (?, ?)";

private final DataSource eventStoreDataSource;
private final int batchSize;

Expand Down Expand Up @@ -80,4 +83,24 @@ public void updateEventStreamTable(final List<UUID> streamIds) throws Exception
preparedStatement.executeBatch();
}
}

public void updatePublishQueueTableWithEvents(final List<Event> events) throws Exception {

try (final Connection connection = eventStoreDataSource.getConnection();
final PreparedStatement preparedStatement = connection.prepareStatement(SQL_INSERT_EVENT_INTO_PUBLISH_QUEUE)) {
for (int i = 0; i < events.size(); i++) {
final UUID eventId = events.get(i).getId();
preparedStatement.setObject(1, eventId);
preparedStatement.setTimestamp(2, toSqlTimestamp(clock.now()));

preparedStatement.addBatch();

if (i % batchSize == 0) {
preparedStatement.executeBatch();
}
}

preparedStatement.executeBatch();
}
}
}
2 changes: 1 addition & 1 deletion example-context/example-service/example-liquibase/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<groupId>uk.gov.justice.services.example</groupId>
<artifactId>example-service</artifactId>
<version>8.0.0</version>
<version>8.0.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>

Expand Down
Loading

0 comments on commit 429550e

Please sign in to comment.