Skip to content

Commit

Permalink
Merge 19c209a into 956a3d4
Browse files Browse the repository at this point in the history
  • Loading branch information
Allan Mckenzie committed Jun 22, 2018
2 parents 956a3d4 + 19c209a commit 5268c91
Show file tree
Hide file tree
Showing 19 changed files with 239 additions and 191 deletions.
9 changes: 9 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,15 @@ git:
cache:
directories:
- "$HOME/.m2"
services:
- postgresql
before_script:
- psql -c 'create database frameworkeventstore;' -U postgres
- psql -c 'create database frameworkviewstore;' -U postgres
- psql -c 'create database frameworkfilestore;' -U postgres
- psql -c "CREATE USER framework WITH PASSWORD 'framework';" -U postgres
addons:
postgresql: "9.5"
sonarcloud:
organization: cjscommonplatform
token:
Expand All @@ -25,3 +33,4 @@ env:
global:
- secure: BRSJ5hIFNiXtOwq8qQfxFCoi+DghyCF4YoKK+xZz3BIHF+VN9LK5i99Be9e/eYsmo3b055UgaFJyrjMfjilj9Phu53VKeRd0BR9s8C06z8xxxjR5F5bxi2GzOYQDFauijYDhef4nt+rEGkA3sZ5qyHgKZYleD6RIbX40u+YfU7Wa12vjBBzoMF/guRg1Z/PZpKrGB/WiBhkmE3aF7tcWvgiBtMU74Vdf/Izv/FKFzP9wUEoambW+9E6XaP4MsqbLWhUg2W7ZJONudNqbqUaM600400IZis1sdeD/8lEsoEWPmhz1zjbRrKQXRpHyR86xtNnhvKmtzxAhiKrlOj/5AakttinoLSDay7VesYVCpHyYSRX2xlgds36clypqmlX2LvkmGFzIFasSBiSUyK+cSwsNV1dHFxDazHLrMt/DRuYn3FnyEd4E7Vza/OtOXHyP/IVm0UXFidpPAn3y3zvu96GDwFjz9b5q11Y3qrxyCj21G5FLN6qInKQYBu1ChcNBAPDZtGyVlpxVhyqgO3b9dTTsIMD6mxMvOweJYG4wfrKOuctRSqxr5YKpfk6TQwzDvIEw/iMmT38fRQzg0fgd20XKiMrLSXhG3GpHS0NPecjXqZZq/hknck4fqgg1CwY9sW8mg3jhEDkBhik14QL7Jqy52ufKL+EVzDxScl0dmXM=
- secure: PN6h2UE/x/VRUzaYiMSyoTNAlC03c+GUXpP/oRojoqVe/UxQ+NWbffDDu251jKSjZ3PVtRvUolVao8s5GMH81K0csv8M+HxxVeUrRDgCW2TOrggFJtex4ww8dUVXsKBtIlojTcLBW2qEwF5Qpky7jwRFy8oke5lhM2tPx2NNYWzoee+IDAn12yDDW676Apmvofj2UO/htyZrNhJNc1jSbcaemCA4rcTBemkojd2o9TsiUNlb8Ve6JfU9iKjgsqg+EFwME4zdVqXRF7DiFW2pMd9HmdFVVA9RM02pdr77HIPatCvDmmqkA99cIyn4iMNe5L0QI0eUhpMKpjFJwSpsgIBr9gE0gzYJIbbldNuvXr87K1Snte/nxPIFs6iu86ebdcENX/h10s9hAgDuoIbW7FWkzLTeeWh/+Yk/eGD/DFPZ1GpZEAi/mxSUzaT1pa+jMrmf3MIq/5Vcojm7H7wRAlkDBlZs5KT9OUZI8on1pC3xksML9WiEEkfemQ+5Ij1e0k7Pj6UpF2lKR0keZ5GS5JoDxQPegs/IL2X2riPtW6xW5JKxPwS0qZtfUKGfO1y5KEIb6OyWq9s20HkB/NG3z+zwaCRvWQ/oRpgsybkkZPQ626AhR9JMCsLxIAKubEXlt3YpnLpu6Wh4ZAXN/hEwdYGPVTrF5hn6ML353+3i6Jc=
- PGPORT=5432
28 changes: 28 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,31 @@ Tools for working with services using the microservice framework.

# Replay Tool
For instruction on how to use the replay tool, please see the [replay tool page](https://github.com/CJSCommonPlatform/framework-tools/tree/master/framework-tools-replay)

## Integration Tests
The Integraion Tests expect a running [Postgres](https://www.postgresql.org/) database,
with the correct users and databases configured. The integration tests can be skipped if no local Postgres database is installed

To run with the Integration Tests then your postgress should be configured so, with the folowing user:

| Parameter | Vaule |
|-----------|---------------|
| host | **localhost** |
| port | **5432** |
| username | **framework** |
| password | **framework** |

You will then need to create three databases owned by the new **framework** user:

* __frameworkeventstore__
* __frameworkviewstore__
* __frameworkfilestore__

### Skipping Integration Tests
If you do not have access to a local posgres database then the Integration Tests can be skipped.
To skip, set the following property when running Maven:

```
mvn clean install -Drun.it=false
```

9 changes: 0 additions & 9 deletions framework-tools-replay/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -67,11 +67,6 @@
<groupId>org.wildfly.swarm</groupId>
<artifactId>jpa</artifactId>
</dependency>
<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
<version>${com.h2database.version}</version>
</dependency>
<dependency>
<groupId>org.wildfly.swarm</groupId>
<artifactId>datasources</artifactId>
Expand Down Expand Up @@ -163,10 +158,6 @@
<groupId>org.jboss.logging</groupId>
<artifactId>jboss-logging</artifactId>
</exclusion>
<exclusion>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
</exclusion>
</exclusions>
</dependency>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
import javax.ejb.TransactionAttribute;
import javax.inject.Inject;

import org.slf4j.Logger;

@Stateless
public class AsyncStreamDispatcher {

Expand Down Expand Up @@ -42,6 +44,9 @@ public class AsyncStreamDispatcher {
@Inject
private LoggingMdc loggingMdc;

@Inject
private Logger logger;

@TransactionAttribute(NOT_SUPPORTED)
public UUID dispatch(final UUID streamId) {

Expand All @@ -66,6 +71,7 @@ public UUID dispatch(final UUID streamId) {
}

private void replayAllEventsOf(final UUID streamId) {

final long lastPosition = jsonEnvelopeJdbcRepository.getCurrentVersion(streamId);

for (long position = FIRST_POSITION; position <= lastPosition; position = position + PAGE_SIZE) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,10 @@ public class JsonEnvelopeJdbcRepository {
@Inject
private EventSource eventSource;

public Stream<JsonEnvelope> pageEventStream(final UUID streamId, final long position, final long pageSize) {
public Stream<JsonEnvelope> pageEventStream(final UUID streamId, final long position, final int pageSize) {
return eventSource
.getStreamById(streamId)
.readFrom(position)
.limit(pageSize);
.readFrom(position, pageSize);
}

public JsonEnvelope getLatestEvent(final UUID streamId) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.runners.MockitoJUnitRunner;
import org.slf4j.Logger;

@RunWith(MockitoJUnitRunner.class)
public class AsyncStreamDispatcherTest {
Expand All @@ -49,6 +50,9 @@ public class AsyncStreamDispatcherTest {
@Mock
private LoggingMdc loggingMdc;

@Mock
private Logger logger;

@InjectMocks
private AsyncStreamDispatcher asyncStreamDispatcher;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
import org.mockito.Mock;
import org.mockito.runners.MockitoJUnitRunner;


@RunWith(MockitoJUnitRunner.class)
public class JsonEnvelopeJdbcRepositoryTest {

Expand All @@ -39,16 +38,15 @@ public void shouldGetAStreamOfEventsAPageAtATime() throws Exception {

final UUID streamId = randomUUID();
final long position = 23L;
final long pageSize = 2L;
final int pageSize = 2;

final EventStream eventStream = mock(EventStream.class);

final JsonEnvelope jsonEnvelope_1 = mock(JsonEnvelope.class);
final JsonEnvelope jsonEnvelope_2 = mock(JsonEnvelope.class);
final JsonEnvelope jsonEnvelope_3 = mock(JsonEnvelope.class);

when(eventSource.getStreamById(streamId)).thenReturn(eventStream);
when(eventStream.readFrom(position)).thenReturn(Stream.of(jsonEnvelope_1, jsonEnvelope_2, jsonEnvelope_3));
when(eventStream.readFrom(position, pageSize)).thenReturn(Stream.of(jsonEnvelope_1, jsonEnvelope_2));

final Stream<JsonEnvelope> envelopeStream = jsonEnvelopeJdbcRepository.pageEventStream(streamId, position, pageSize);

Expand Down
21 changes: 2 additions & 19 deletions framework-tools-replay/standalone-ds.xml
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,8 @@
</handlers>
</root-logger>
<formatter name="PATTERN">
<pattern-formatter pattern="%d{yyyy-MM-dd HH:mm:ss,SSS} %-5p [%c] %X{streamId} %X{eventData} %s%e%n"/>
<pattern-formatter
pattern="%d{yyyy-MM-dd HH:mm:ss,SSS} %-5p [%c] %X{streamId} %X{eventData} %s%e%n"/>
</formatter>
</subsystem>
<subsystem xmlns="urn:jboss:domain:bean-validation:1.0"/>
Expand Down Expand Up @@ -186,25 +187,7 @@
class-name="org.jboss.jca.adapters.jdbc.extensions.postgres.PostgreSQLValidConnectionChecker"/>
</validation>
</xa-datasource>

<xa-datasource jndi-name="java:jboss/datasources/ExampleDS" pool-name="ExampleDS">
<driver>h2</driver>
<xa-datasource-property name="URL">jdbc:h2:mem:test;DB_CLOSE_DELAY=-1;DB_CLOSE_ON_EXIT=FALSE</xa-datasource-property>
<xa-pool>
<min-pool-size>3</min-pool-size>
<max-pool-size>1000</max-pool-size>
<prefill>true</prefill>
</xa-pool>
<security>
<user-name>sa</user-name>
<password>sa</password>
</security>
</xa-datasource>

<drivers>
<driver name="h2" module="com.h2database.h2">
<xa-datasource-class>org.h2.jdbcx.JdbcDataSource</xa-datasource-class>
</driver>
<driver name="postgres" module="org.postgresql">
<driver-class>org.postgresql.Driver</driver-class>
<xa-datasource-class>org.postgresql.xa.PGXADataSource</xa-datasource-class>
Expand Down
37 changes: 26 additions & 11 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<parent>
<groupId>uk.gov.justice</groupId>
<artifactId>maven-framework-parent-pom</artifactId>
<version>1.12.2</version>
<version>1.12.3</version>
</parent>

<artifactId>framework-tools</artifactId>
Expand All @@ -16,18 +16,13 @@

<properties>
<cpp.repo.name>framework-tools</cpp.repo.name>
<common-bom.version>1.26.0</common-bom.version>
<framework-api.version>2.0.3</framework-api.version>
<framework.version>4.1.0</framework.version>
<common-bom.version>1.27.0</common-bom.version>
<framework-api.version>2.1.2</framework-api.version>
<framework.version>4.2.1</framework.version>
<wildfly.swarm.version>2017.11.0</wildfly.swarm.version>
<test.utils.version>1.17.2</test.utils.version>
<schema-service.version>1.2.2</schema-service.version>
<test.utils.version>1.17.3</test.utils.version>
<schema-service.version>1.2.3</schema-service.version>
<version.swarm.fraction-plugin>77</version.swarm.fraction-plugin>
<!--
note h2 version is because swarm has its own version of h2 which we must use
for the integration tests to work as h2 version inter-compatibility is volatile
-->
<com.h2database.version>1.4.187</com.h2database.version>
<slf4j-jboss-logmanager.version>1.0.4.GA</slf4j-jboss-logmanager.version>
<jboss-logmanager.version>2.1.2.Final</jboss-logmanager.version>
</properties>
Expand Down Expand Up @@ -96,4 +91,24 @@
</plugins>
</build>

<profiles>
<profile>
<id>integration-tests</id>
<activation>
<property>
<name>run.it</name>
<value>!false</value>
</property>
</activation>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-failsafe-plugin</artifactId>
</plugin>
</plugins>
</build>
</profile>
</profiles>

</project>
15 changes: 2 additions & 13 deletions replay-tool-test/replay-tool-integration-test/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,22 +13,15 @@

<dependencies>
<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
<groupId>org.postgresql</groupId>
<artifactId>postgresql</artifactId>
<scope>test</scope>
<version>${com.h2database.version}</version>
</dependency>
<dependency>
<groupId>uk.gov.justice.utils</groupId>
<artifactId>test-utils-core</artifactId>
<version>${test.utils.version}</version>
<scope>test</scope>
<exclusions>
<exclusion>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>junit</groupId>
Expand Down Expand Up @@ -81,10 +74,6 @@

<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-failsafe-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package uk.gov.justice.framework.tools.replay;


import static java.util.Arrays.asList;
import static java.util.UUID.randomUUID;
import static org.hamcrest.CoreMatchers.is;
Expand All @@ -12,7 +11,6 @@
import uk.gov.justice.framework.tools.replay.database.LiquibaseRunner;
import uk.gov.justice.framework.tools.replay.events.User;
import uk.gov.justice.framework.tools.replay.events.UserFactory;
import uk.gov.justice.framework.tools.replay.h2.InMemoryDatabaseRunner;
import uk.gov.justice.framework.tools.replay.wildfly.WildflyRunner;
import uk.gov.justice.services.eventsourcing.repository.jdbc.event.Event;

Expand All @@ -21,9 +19,7 @@

import javax.sql.DataSource;

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

public class EventOrderingIT {
Expand All @@ -41,24 +37,13 @@ public class EventOrderingIT {
private final DataSource eventStoreDataSource = datasourceCreator.createEventStoreDataSource();
private final EventInserter eventInserter = new EventInserter(eventStoreDataSource, viewStoreDataSource);
private final UserFactory userFactory = new UserFactory();
private final InMemoryDatabaseRunner inMemoryDatabaseRunner = new InMemoryDatabaseRunner();

@Before
public void startDatabase() {
inMemoryDatabaseRunner.startH2Database();
}

@Before
public void runLiquibase() throws Exception {
liquibaseRunner.createEventStoreSchema(eventStoreDataSource);
liquibaseRunner.createViewStoreSchema(viewStoreDataSource);
}

@After
public void stopDB() throws Exception {
inMemoryDatabaseRunner.stopH2Database();
}

@Test
public void shouldInsertEventsInTheCorrectOrder() throws Exception {

Expand All @@ -67,11 +52,9 @@ public void shouldInsertEventsInTheCorrectOrder() throws Exception {

final UUID userId = randomUUID();


final User user = new User(userId, "Fred", "Bloggs");
final User updatedUser = new User(userId, "Billy", "Bloggs");


final List<Event> someEvents = userFactory.convertToEvents(asList(user, updatedUser), eventName, streamId);

eventInserter.insertEventsIntoVewstore(
Expand Down
Loading

0 comments on commit 5268c91

Please sign in to comment.