Skip to content

Commit

Permalink
Merge 0a3419a into e80aa8b
Browse files Browse the repository at this point in the history
  • Loading branch information
mapingo committed Dec 11, 2018
2 parents e80aa8b + 0a3419a commit 15c3b80
Show file tree
Hide file tree
Showing 15 changed files with 284 additions and 11 deletions.
13 changes: 13 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,19 @@ on [Keep a CHANGELOG](http://keepachangelog.com/). This project adheres to

## [Unreleased]

### Changed
- Update framework-api to 3.1.0-M2
- Update framework to 5.1.0-M3
- Update framework-domain to 1.1.0-M3
- Update event-store to 1.1.0-M1
- Update framework-generators to 1.1.0-M1
- Update test-utils to 1.19.0

### Added
- Liquibase script to add events into event_log before startup
- CakeShopReplayEvents IT to test the replaying of events on startup
- SubscriptionEventInterceptor into Event Listener to update Subscription event number

## [1.0.1] - 2018-12-11

### Changed
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,11 @@
<artifactId>event-subscription-registry</artifactId>
<version>${event-store.version}</version>
</dependency>
<dependency>
<groupId>uk.gov.justice.event-store</groupId>
<artifactId>subscription-event-interceptors</artifactId>
<version>${event-store.version}</version>
</dependency>
<dependency>
<groupId>uk.gov.justice.event-store</groupId>
<artifactId>event-listener-interceptors</artifactId>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package uk.gov.justice.services.example.cakeshop.event.listener.provider;

import uk.gov.justice.services.core.interceptor.InterceptorChainEntry;
import uk.gov.justice.services.core.interceptor.InterceptorChainEntryProvider;
import uk.gov.justice.services.event.source.subscriptions.interceptors.SubscriptionEventInterceptor;

import java.util.ArrayList;
import java.util.List;

public class ExampleEventListenerInterceptorChainProvider implements InterceptorChainEntryProvider {

private final List<InterceptorChainEntry> interceptorChainEntries = new ArrayList<InterceptorChainEntry>();

public ExampleEventListenerInterceptorChainProvider() {
interceptorChainEntries.add(new InterceptorChainEntry(1000, SubscriptionEventInterceptor.class));
}

@Override
public String component() {
return "EVENT_LISTENER";
}

@Override
public List<InterceptorChainEntry> interceptorChainTypes() {
return interceptorChainEntries;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package uk.gov.justice.services.example.cakeshop.event.listener.provider;

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

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

import java.util.List;

import org.junit.Test;

public class ExampleEventListenerInterceptorChainProviderTest {

@Test
public void shouldCreateInterceptorChainEntriesWithSubscriptionEventInterceptor() {

final List<InterceptorChainEntry> interceptorChainEntries = new ExampleEventListenerInterceptorChainProvider().interceptorChainTypes();

assertThat(interceptorChainEntries.size(), is(1));

final InterceptorChainEntry interceptorChainEntry = interceptorChainEntries.get(0);
assertThat(interceptorChainEntry.getInterceptorType().getName(), is("uk.gov.justice.services.event.source.subscriptions.interceptors.SubscriptionEventInterceptor"));
assertThat(interceptorChainEntry.getPriority(), is(1000));
}

@Test
public void shouldReturnComponentName() {
assertThat(new ExampleEventListenerInterceptorChainProvider().component(), is("EVENT_LISTENER"));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<artifactId>example-service</artifactId>
<groupId>uk.gov.justice.services.example</groupId>
<version>1.1.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>

<artifactId>example-initialisation-liquibase</artifactId>

<properties>
<sonar.skip>true</sonar.skip>
</properties>

</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
changeLogFile=liquibase/initialise-event-log-db-changelog.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?xml version="1.0" encoding="UTF-8"?>
<databaseChangeLog xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://www.liquibase.org/xml/ns/dbchangelog"
xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog
http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-3.3.xsd">

<includeAll relativeToChangelogFile="true" path="initialise-event-log-db-changesets"/>

</databaseChangeLog>
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
<?xml version="1.0" encoding="UTF-8"?>
<databaseChangeLog xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://www.liquibase.org/xml/ns/dbchangelog"
xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog
http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-3.3.xsd">
<changeSet id="001-add-initial-events" author="techpod"
logicalFilePath="001-add-initial-events.xml">

<insert tableName="event_log">
<column name="id" value="00b78ee7-5d2c-4b6d-858e-0701d0412515"/>
<column name="stream_id" value="489c5e3b-8c0c-4e26-855f-34592604bd98"/>
<column name="position_in_stream" value="1"/>
<column name="name" value="example.recipe-added"/>
<column name="payload" value="{&quot;recipeId&quot;:&quot;489c5e3b-8c0c-4e26-855f-34592604bd98&quot;,&quot;name&quot;:&quot;Carrot Cake&quot;,&quot;ingredients&quot;:[{&quot;name&quot;:&quot;someIngredient&quot;,&quot;quantity&quot;:1}],&quot;glutenFree&quot;:false}" />
<column name="metadata" value="{&quot;createdAt&quot;:&quot;2018-12-06T16:32:48.725Z&quot;,&quot;id&quot;:&quot;00b78ee7-5d2c-4b6d-858e-0701d0412515&quot;,&quot;name&quot;:&quot;example.recipe-added&quot;,&quot;causation&quot;:[&quot;63bc8905-2705-41f9-892e-946e632b1837&quot;,&quot;ffbf5c08-df37-4203-ad81-f8f12edfed2b&quot;],&quot;stream&quot;:{&quot;id&quot;:&quot;489c5e3b-8c0c-4e26-855f-34592604bd98&quot;,&quot;version&quot;:1},&quot;source&quot;:&quot;event.source&quot;,&quot;event&quot;:{&quot;eventNumber&quot;:1,&quot;previousEventNumber&quot;:0}}"/>
<column name="date_created" value="2018-12-06 16:32:48.725+00"/>
<column name="event_number" value="1"/>
</insert>

<insert tableName="event_log">
<column name="id" value="f05cc199-52ab-40a6-ae88-465f810340f6"/>
<column name="stream_id" value="8440bcc3-a4d6-4bd1-817c-ab89ffd307ae"/>
<column name="position_in_stream" value="1"/>
<column name="name" value="example.recipe-added"/>
<column name="payload" value="{&quot;recipeId&quot;:&quot;8440bcc3-a4d6-4bd1-817c-ab89ffd307ae&quot;,&quot;name&quot;:&quot;Lemon Drizzle Cake&quot;,&quot;ingredients&quot;:[{&quot;name&quot;:&quot;someIngredient&quot;,&quot;quantity&quot;:1}],&quot;glutenFree&quot;:false}" />
<column name="metadata" value="{&quot;createdAt&quot;:&quot;2018-12-07T13:29:54.719Z&quot;,&quot;id&quot;:&quot;f05cc199-52ab-40a6-ae88-465f810340f6&quot;,&quot;name&quot;:&quot;example.recipe-added&quot;,&quot;causation&quot;:[&quot;ed137a6a-551c-4f8e-8ca2-b1a1cafe2e0d&quot;,&quot;c6da75ac-41c2-4994-81b7-1a9705c1550f&quot;],&quot;stream&quot;:{&quot;id&quot;:&quot;8440bcc3-a4d6-4bd1-817c-ab89ffd307ae&quot;,&quot;version&quot;:1},&quot;source&quot;:&quot;event.source&quot;,&quot;event&quot;:{&quot;eventNumber&quot;:2,&quot;previousEventNumber&quot;:1}}"/>
<column name="date_created" value="2018-12-06 16:32:48.725+00"/>
<column name="event_number" value="2"/>
</insert>

<insert tableName="event_log">
<column name="id" value="a4fd2ad1-1bef-47dc-9ba5-7525dee670b0"/>
<column name="stream_id" value="489c5e3b-8c0c-4e26-855f-34592604bd98"/>
<column name="position_in_stream" value="2"/>
<column name="name" value="example.recipe-renamed"/>
<column name="payload" value="{&quot;recipeId&quot;:&quot;489c5e3b-8c0c-4e26-855f-34592604bd98&quot;,&quot;name&quot;:&quot;Turnip Cake&quot;}" />
<column name="metadata" value="{&quot;createdAt&quot;:&quot;2018-12-06T16:32:52.325Z&quot;,&quot;id&quot;:&quot;a4fd2ad1-1bef-47dc-9ba5-7525dee670b0&quot;,&quot;name&quot;:&quot;example.recipe-renamed&quot;,&quot;causation&quot;:[&quot;6d1aa026-85fc-4757-8f67-634d43f74969&quot;,&quot;0868cb11-6fd8-49ac-8f77-69e8ee203ee1&quot;],&quot;stream&quot;:{&quot;id&quot;:&quot;489c5e3b-8c0c-4e26-855f-34592604bd98&quot;,&quot;version&quot;:2},&quot;source&quot;:&quot;event.source&quot;,&quot;event&quot;:{&quot;eventNumber&quot;:3,&quot;previousEventNumber&quot;:2}}"/>
<column name="date_created" value="2018-12-06 16:32:52.325+00"/>
<column name="event_number" value="3"/>
</insert>

<insert tableName="event_log">
<column name="id" value="ceeb2594-3d66-4187-b660-4eae72ab6dac"/>
<column name="stream_id" value="8440bcc3-a4d6-4bd1-817c-ab89ffd307ae"/>
<column name="position_in_stream" value="2"/>
<column name="name" value="example.recipe-renamed"/>
<column name="payload" value="{&quot;recipeId&quot;:&quot;8440bcc3-a4d6-4bd1-817c-ab89ffd307ae&quot;,&quot;name&quot;:&quot;Rock Cake&quot;}" />
<column name="metadata" value="{&quot;createdAt&quot;:&quot;2018-12-07T13:29:57.250Z&quot;,&quot;id&quot;:&quot;ceeb2594-3d66-4187-b660-4eae72ab6dac&quot;,&quot;name&quot;:&quot;example.recipe-renamed&quot;,&quot;causation&quot;:[&quot;e67cbf7c-ede1-4a17-8966-2da413967849&quot;,&quot;5c31a322-f201-4340-939a-8e0cd4c67836&quot;],&quot;stream&quot;:{&quot;id&quot;:&quot;8440bcc3-a4d6-4bd1-817c-ab89ffd307ae&quot;,&quot;version&quot;:2},&quot;source&quot;:&quot;event.source&quot;,&quot;event&quot;:{&quot;eventNumber&quot;:4,&quot;previousEventNumber&quot;:3}}"/>
<column name="date_created" value="2018-12-06 16:32:52.325+00"/>
<column name="event_number" value="4"/>
</insert>

</changeSet>
</databaseChangeLog>
38 changes: 36 additions & 2 deletions example-context/example-service/example-it/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,17 @@
<goal>update</goal>
</goals>
</execution>
<execution>
<id>initialise-event-log-liquibase</id>
<configuration>
<changeLogFile>liquibase/initialise-event-log-db-changelog.xml</changeLogFile>
<url>jdbc:postgresql://localhost:5432/frameworkeventstore</url>
</configuration>
<phase>pre-integration-test</phase>
<goals>
<goal>update</goal>
</goals>
</execution>
<execution>
<id>event-buffer-liquibase</id>
<configuration>
Expand All @@ -175,10 +186,23 @@
<goal>update</goal>
</goals>
</execution>
<execution>
<id>subscriptions-liquibase</id>
<configuration>
<changeLogFile>liquibase/subscription-repository-changelog.xml
</changeLogFile>
<url>jdbc:postgresql://localhost:5432/frameworkviewstore</url>
</configuration>
<phase>pre-integration-test</phase>
<goals>
<goal>update</goal>
</goals>
</execution>
<execution>
<id>file-service-liquibase</id>
<configuration>
<changeLogFile>liquibase/file-service-liquibase-db-changelog.xml</changeLogFile>
<changeLogFile>liquibase/file-service-liquibase-db-changelog.xml
</changeLogFile>
<url>jdbc:postgresql://localhost:5432/frameworkfilestore</url>
</configuration>
<phase>pre-integration-test</phase>
Expand Down Expand Up @@ -214,6 +238,16 @@
<artifactId>file-service-liquibase</artifactId>
<version>${file.service.version}</version>
</dependency>
<dependency>
<groupId>uk.gov.justice.event-store</groupId>
<artifactId>subscription-repository-liquibase</artifactId>
<version>${event-store.version}</version>
</dependency>
<dependency>
<groupId>uk.gov.justice.services.example</groupId>
<artifactId>example-initialisation-liquibase</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.postgresql</groupId>
<artifactId>postgresql</artifactId>
Expand Down Expand Up @@ -311,8 +345,8 @@
<jbossHome>${jboss.home}</jbossHome>
<serverConfig>${server.config}</serverConfig>
<timeout>120</timeout>
<javaOpts>-DDEFAULT_PORT=${random-http-port}</javaOpts>
<java-opts>
<javaOpt>-DDEFAULT_PORT=${random-http-port}</javaOpt>
<!--<java-opt>-agentlib:jdwp=transport=dt_socket,server=y,suspend=y,address=8888</java-opt>-->
</java-opts>
<port>${random-management-port}</port>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package uk.gov.justice.services.eventsourcing.jdbc.snapshot;

import static uk.gov.justice.services.test.utils.common.reflection.ReflectionUtils.setField;
import static uk.gov.justice.services.test.utils.core.reflection.ReflectionUtil.setField;

import javax.sql.DataSource;

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
package uk.gov.justice.services.example.cakeshop.it;

import static com.jayway.jsonassert.JsonAssert.with;
import static java.util.UUID.fromString;
import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.is;
import static org.junit.Assert.assertThat;
import static uk.gov.justice.services.example.cakeshop.it.params.CakeShopMediaTypes.CONTEXT_NAME;

import uk.gov.justice.services.event.buffer.core.repository.subscription.Subscription;
import uk.gov.justice.services.example.cakeshop.it.helpers.ApiResponse;
import uk.gov.justice.services.example.cakeshop.it.helpers.CakeShopRepositoryManager;
import uk.gov.justice.services.example.cakeshop.it.helpers.CommandFactory;
import uk.gov.justice.services.example.cakeshop.it.helpers.EventFactory;
import uk.gov.justice.services.example.cakeshop.it.helpers.EventFinder;
import uk.gov.justice.services.example.cakeshop.it.helpers.Querier;
import uk.gov.justice.services.example.cakeshop.it.helpers.RestEasyClientFactory;

import javax.ws.rs.client.Client;

import org.junit.After;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;

public class CakeShopReplayEventsIT {

private static final CakeShopRepositoryManager CAKE_SHOP_REPOSITORY_MANAGER = new CakeShopRepositoryManager();

private final EventFactory eventFactory = new EventFactory();
private final EventFinder eventFinder = new EventFinder(CAKE_SHOP_REPOSITORY_MANAGER);
private final CommandFactory commandFactory = new CommandFactory();

private Client client;
private Querier querier;

@BeforeClass
public static void beforeClass() throws Exception {
CAKE_SHOP_REPOSITORY_MANAGER.initialise();
}

@Before
public void before() {
client = new RestEasyClientFactory().createResteasyClient();
querier = new Querier(client);
}

@After
public void cleanup() {
client.close();
}

@Test
public void shouldFindReplayedRecipesInViewStore() {

final String recipeId_1 = "489c5e3b-8c0c-4e26-855f-34592604bd98";
final String recipeId_2 = "8440bcc3-a4d6-4bd1-817c-ab89ffd307ae";

final ApiResponse response_1 = querier.queryForRecipe(recipeId_1);
final ApiResponse response_2 = querier.queryForRecipe(recipeId_2);

with(response_1.body())
.assertThat("$.id", equalTo(recipeId_1))
.assertThat("$.name", equalTo("Turnip Cake"));

with(response_2.body())
.assertThat("$.id", equalTo(recipeId_2))
.assertThat("$.name", equalTo("Rock Cake"));

assertThat(subscription(recipeId_1).getPosition(), is(2L));
assertThat(subscription(recipeId_2).getPosition(), is(2L));
}

@SuppressWarnings("OptionalGetWithoutIsPresent")
private Subscription subscription(final String recipeId) {
return CAKE_SHOP_REPOSITORY_MANAGER
.getSubscriptionJdbcRepository()
.findByStreamIdAndSource(fromString(recipeId), CONTEXT_NAME)
.get();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import static com.jayway.jsonassert.JsonAssert.with;
import static java.util.UUID.randomUUID;
import static org.hamcrest.core.IsCollectionContaining.hasItem;
import static uk.gov.justice.services.test.utils.common.reflection.ReflectionUtils.setField;
import static uk.gov.justice.services.test.utils.core.reflection.ReflectionUtil.setField;

import uk.gov.justice.domain.snapshot.AggregateSnapshot;
import uk.gov.justice.domain.snapshot.DefaultObjectInputStreamStrategy;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package uk.gov.justice.services.example.cakeshop.it.helpers;

import static uk.gov.justice.services.test.utils.common.reflection.ReflectionUtils.setField;
import static uk.gov.justice.services.test.utils.core.reflection.ReflectionUtil.setField;

import uk.gov.justice.services.event.buffer.core.repository.subscription.SubscriptionJdbcRepository;
import uk.gov.justice.services.jdbc.persistence.JdbcRepositoryHelper;
Expand Down
1 change: 1 addition & 0 deletions example-context/example-service/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
<module>example-it</module>
<module>example-liquibase</module>
<module>example-single</module>
<module>example-initialisation-liquibase</module>
</modules>

<build>
Expand Down
12 changes: 6 additions & 6 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -31,19 +31,19 @@
<properties>
<cpp.repo.name>cake-shop</cpp.repo.name>
<common-bom.version>1.28.0</common-bom.version>
<framework.version>5.0.4</framework.version>
<framework.version>5.1.0-M3</framework.version>
<embedded-artemis.version>1.2.0</embedded-artemis.version>
<event-store.version>1.0.4</event-store.version>
<framework-domain.version>1.0.3</framework-domain.version>
<framework-generators.version>1.0.2</framework-generators.version>
<event-store.version>1.1.0-M1</event-store.version>
<framework-domain.version>1.1.0-M3</framework-domain.version>
<framework-generators.version>1.1.0-M1</framework-generators.version>
<file.service.version>1.17.1</file.service.version>
<framework-api.version>3.0.1</framework-api.version>
<framework-api.version>3.1.0-M2</framework-api.version>
<generator-maven-plugin.version>2.6.1</generator-maven-plugin.version>
<json-schema-catalog.version>1.4.2</json-schema-catalog.version>
<jboss-ejb3-ext-api.version>2.2.0.Final</jboss-ejb3-ext-api.version>
<jboss-vfs.version>3.2.12.Final</jboss-vfs.version>
<raml-maven-plugin.version>1.6.3</raml-maven-plugin.version>
<test-utils.version>1.18.1</test-utils.version>
<test-utils.version>1.19.0</test-utils.version>
<utilities.version>1.16.1</utilities.version>
</properties>

Expand Down

0 comments on commit 15c3b80

Please sign in to comment.