Skip to content

Commit

Permalink
Update to framework version 5.0.4
Browse files Browse the repository at this point in the history
  • Loading branch information
mapingo authored and amckenzie committed Nov 20, 2018
1 parent 42719df commit ed1f90c
Show file tree
Hide file tree
Showing 31 changed files with 483 additions and 224 deletions.
7 changes: 7 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,12 @@ 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 USER framework WITH PASSWORD 'framework';" -U postgres
addons:
sonarcloud:
organization: cjscommonplatform
Expand All @@ -23,5 +29,6 @@ script: "${PWD}/target/travis-settings/java/script-install.sh coveralls:report s
after_success: "${PWD}/target/travis-settings/java/after_success.sh"
env:
global:
- PGPORT=5432
- secure: XwuDzOLJPJ8Sz2/9cN57nVUoRzW6c6lNboDyveD2ec4fQhOgLdb78yYaV4e7yx31WhXyUX1GeQYKghDGgDluH5jDAeCG91/BrK4KVRAT0AC//34pGnujAJq4pNL7/w0CAcRoQXNLUsdet8tIlkmX4XaM6fokCV4RTdXm0nnICCLQegzvVIBi1Pc2pHKAxpz67aebJHXmC7fTxwtdallm+3KlBgTyhoOfXCTrnyboKYdXMs8tzDP7ro1KzOEVCVhhtR5MZfHCCbPotRewbuX+0WHmXicaBoCZrAxovxaAdjRqC5UuU1iqOV1uXUydg49QxoLy0vfzaLrVz/TQk/ac+YIdJYaR7HTjYp23XJX6i/2Tq4BZPo6EoLc7ERFIleKasJHDiHxYBD6FiWCFe+TPmfHjEsi+pTW/hK3GlLYB9jNM0/6taWiA0aP7Q0rXgRqyuHF1hIelBKHmJBpY+pJpv7IXUNGMmzzRjZX+wbLvODF18DjJpzrai2sBd53tkqBpTjYoFMPLOG9rXpEju92aym/h6I7A8fnCVxsM2Q1a+E7Ahan7YxYMFjz6bzwTg3LuPop0ZzHdJ6/yboAmsTSg2BZvZDFDaQYxPxQEH49NpfMGmN+st1EIl5NSHypO7Kmd7NwWLmymtwraPKurd+yfyp96QO6KQbwuNf71ifSSdiA=
- secure: fVz9tjeWQh+1QrA+gMQZiOD/PJz0txejlsg9HFhkiA4NpdXbAIhx8K/FILIAOiiWqo+V2mDYVzULMsPV3ecD4Z0RdeA0iEUZzbzl3w+IXMZpclydML8147AerDOdz2gEM/FybIrATU0ig3VLMYsgU859rKK68TGY8LiA67ad1WNV5ru02Gqc917NSvda/gUoxoZ23qy0kbDFPyElgD8k8oxzCSK1FNNAr03VKInQNGXm4w6YbCSV/VIxKLwsrs05i6zoqHzP1z8wU908KQDsHtjzIA8jEltCm107SfdZIZHRxAW4CpEhOQjMHYtmXrqCBuAkrUdQfzpGaUYtFt8gpsZFKoVwRLHpFSP6iIwQYVJGJdi2Wk015NmnAK+g3hpcypovSDS0OuC/mducMvrxdl5sw9h+FImrgnLAm7UTCfDugeS5vKN5BbJeNapcf8xOPi4oEDXIsdb8Tyq/kJsgoRB5kD90Ig7Mzp559J38YelmSeJSulzPMW2Sp+VAjlcqCLeBMURcg/eH+UTJ9EAk2DV9DJUn0jLNWS1bdY8CpCn10cgcrmNRYWLdUqRIw9cdpVy7jw55kur4KdS2fpEeOvOk3e6UkBYjIwsUacr74cGphswpvJwnYRIYOBbAN2ONceMo/LtU3wdtaIvUvckGvAWYKGzMd0NXraPIK/e0p7c=
4 changes: 4 additions & 0 deletions event-tool/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,10 @@
<artifactId>datasources</artifactId>
</dependency>

<dependency>
<groupId>org.postgresql</groupId>
<artifactId>postgresql</artifactId>
</dependency>
<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
import static org.wildfly.swarm.bootstrap.Main.MAIN_PROCESS_FILE;

import uk.gov.justice.event.tool.task.StreamTransformationTask;
import uk.gov.justice.services.eventsourcing.repository.jdbc.EventRepository;
import uk.gov.justice.services.eventsourcing.repository.jdbc.eventstream.EventStream;
import uk.gov.justice.services.eventsourcing.repository.jdbc.eventstream.EventStreamJdbcRepository;
import uk.gov.justice.tools.eventsourcing.transformation.service.EventStreamTransformationService;

import java.io.File;
Expand Down Expand Up @@ -40,7 +40,7 @@ public class StartTransformation implements ManagedTaskListener {
private ManagedExecutorService executorService;

@Inject
private EventStreamJdbcRepository eventStreamJdbcRepository;
private EventRepository eventRepository;

@Inject
private EventStreamTransformationService eventStreamTransformationService;
Expand All @@ -64,7 +64,8 @@ void go() {
}

private void createTransformationTasks(final int pass) {
final Stream<UUID> activeStreams = eventStreamJdbcRepository.findActive().map(EventStream::getStreamId);

final Stream<UUID> activeStreams = eventRepository.getAllActiveStreamIds();

activeStreams
.forEach(streamId -> {
Expand Down Expand Up @@ -153,4 +154,4 @@ private void checkForMainProcessFile() {
}
}

}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package uk.gov.justice.event.tool;

import static java.util.UUID.randomUUID;
import static org.hamcrest.Matchers.is;
import static org.junit.Assert.assertThat;
import static org.junit.Assert.assertTrue;
Expand All @@ -9,11 +10,13 @@
import static org.mockito.Mockito.when;

import uk.gov.justice.event.tool.task.StreamTransformationTask;
import uk.gov.justice.services.eventsourcing.repository.jdbc.EventRepository;
import uk.gov.justice.services.eventsourcing.repository.jdbc.eventstream.EventStream;
import uk.gov.justice.services.eventsourcing.repository.jdbc.eventstream.EventStreamJdbcRepository;
import uk.gov.justice.tools.eventsourcing.transformation.EventTransformationRegistry;
import uk.gov.justice.tools.eventsourcing.transformation.service.EventStreamTransformationService;

import java.util.UUID;
import java.util.concurrent.Future;
import java.util.stream.Stream;

Expand All @@ -34,7 +37,7 @@ public class StartTransformationTest {
private ManagedExecutorService executorService;

@Mock
private EventStreamJdbcRepository eventStreamJdbcRepository;
private EventRepository eventRepository;

@Mock
private EventStreamTransformationService eventStreamTransformationService;
Expand All @@ -59,13 +62,17 @@ public class StartTransformationTest {

@Before
public void setup() {
when(eventStreamJdbcRepository.findActive()).thenReturn(Stream.of(eventStream, eventStream2));
when(passesDeterminer.getPassValue()).thenReturn(1).thenReturn(2);
when(passesDeterminer.isLastElementInPasses()).thenReturn(true);
}

@Test
public void shouldCreateTasksForEachStream() {

final UUID streamId_1 = randomUUID();
final UUID streamId_2 = randomUUID();

when(eventRepository.getAllActiveStreamIds()).thenReturn(Stream.of(streamId_1, streamId_2));
when(executorService.submit(any(StreamTransformationTask.class))).thenReturn(mock(Future.class));

startTransformation.go();
Expand All @@ -76,7 +83,11 @@ public void shouldCreateTasksForEachStream() {

@Test
public void shouldRemoveFinishedTasks() {
when(eventStreamJdbcRepository.findActive()).thenReturn(Stream.of(eventStream, eventStream2));

final UUID streamId_1 = randomUUID();
final UUID streamId_2 = randomUUID();

when(eventRepository.getAllActiveStreamIds()).thenReturn(Stream.of(streamId_1, streamId_2));
when(passesDeterminer.getPassValue()).thenReturn(1);

final Future future = mock(Future.class);
Expand All @@ -96,7 +107,15 @@ public void shouldRemoveFinishedTasks() {

@Test
public void shouldRemoveFinishedTaskForAllPasses(){
when(eventStreamJdbcRepository.findActive()).thenReturn(Stream.of(eventStream, eventStream2)).thenReturn(Stream.of(eventStream2));

final UUID streamId_1 = randomUUID();
final UUID streamId_2 = randomUUID();
final UUID streamId_3 = randomUUID();

when(eventRepository.getAllActiveStreamIds())
.thenReturn(Stream.of(streamId_1, streamId_2))
.thenReturn(Stream.of(streamId_3));

when(passesDeterminer.getPassValue()).thenReturn(1).thenReturn(2);
when(passesDeterminer.isLastElementInPasses()).thenReturn(false).thenReturn(true);

Expand Down Expand Up @@ -125,4 +144,4 @@ public void shouldRemoveFinishedTaskForAllPasses(){
assertThat(startTransformation.outstandingTasks.size(), is(0));
}

}
}
22 changes: 14 additions & 8 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -19,18 +19,18 @@
<developerConnection>${cpp.scm.developerConnection}</developerConnection>
<url>${cpp.scm.url}</url>
</scm>

<properties>
<cpp.repo.name>stream-transformation-tool</cpp.repo.name>

<framework.version>4.3.2</framework.version>
<common-bom.version>1.22.0</common-bom.version>
<utilities.version>1.11.0</utilities.version>
<test-utils.version>1.16.0</test-utils.version>
<framework.version>5.0.4</framework.version>
<event-store.version>1.0.4</event-store.version>
<common-bom.version>1.28.0</common-bom.version>
<utilities.version>1.16.1</utilities.version>
<test-utils.version>1.18.1</test-utils.version>

<wildfly.swarm.version>2017.11.0</wildfly.swarm.version>
<version.swarm.fraction-plugin>77</version.swarm.fraction-plugin>
<com.h2database.version>1.4.187</com.h2database.version>
<junit-dataprovider.version>1.13.1</junit-dataprovider.version>
</properties>

Expand Down Expand Up @@ -104,9 +104,8 @@
<version>${framework.version}</version>
</dependency>
<dependency>
<groupId>uk.gov.justice.services</groupId>
<groupId>uk.gov.justice.event-store</groupId>
<artifactId>event-repository-jdbc</artifactId>
<version>${framework.version}</version>
</dependency>
<dependency>
<groupId>uk.gov.justice.utils</groupId>
Expand All @@ -120,6 +119,13 @@
<version>${junit-dataprovider.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>uk.gov.justice.event-store</groupId>
<artifactId>event-store-bom</artifactId>
<version>${event-store.version}</version>
<scope>import</scope>
<type>pom</type>
</dependency>
</dependencies>
</dependencyManagement>

Expand Down
40 changes: 6 additions & 34 deletions stream-transformation-test/stream-transformation-it/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,14 @@

<dependencies>
<dependency>
<groupId>uk.gov.justice.services</groupId>
<groupId>uk.gov.justice.event-store</groupId>
<artifactId>event-repository-jdbc</artifactId>
<version>${event-store.version}</version>
</dependency>
<dependency>
<groupId>uk.gov.justice.services</groupId>
<groupId>uk.gov.justice.event-store</groupId>
<artifactId>event-repository-liquibase</artifactId>
<version>${event-store.version}</version>
</dependency>
<dependency>
<groupId>uk.gov.justice.services</groupId>
Expand All @@ -40,8 +42,8 @@
<version>${framework.version}</version>
</dependency>
<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
<groupId>org.postgresql</groupId>
<artifactId>postgresql</artifactId>
</dependency>
<dependency>
<groupId>junit</groupId>
Expand Down Expand Up @@ -69,36 +71,6 @@

<build>
<plugins>
<plugin>
<groupId>com.edugility</groupId>
<artifactId>h2-maven-plugin</artifactId>
<configuration>
<port>8092</port>
</configuration>
<executions>
<execution>
<id>Spawn a new H2 TCP server</id>
<phase>pre-integration-test</phase>
<goals>
<goal>spawn</goal>
</goals>
</execution>
<execution>
<id>Stop a spawned H2 TCP server</id>
<phase>post-integration-test</phase>
<goals>
<goal>stop</goal>
</goals>
</execution>
</executions>
<dependencies>
<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
<version>${com.h2database.version}</version>
</dependency>
</dependencies>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-failsafe-plugin</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import static org.slf4j.LoggerFactory.getLogger;
import static uk.gov.justice.framework.tools.transformation.EventLogBuilder.eventLogFrom;

import uk.gov.justice.services.eventsourcing.repository.jdbc.exception.InvalidSequenceIdException;
import uk.gov.justice.services.eventsourcing.repository.jdbc.exception.InvalidPositionException;

import java.sql.Connection;
import java.sql.PreparedStatement;
Expand Down Expand Up @@ -45,7 +45,7 @@ public void resetDatabase() throws SQLException {
}
}

public void insertEventLogData(final String eventName, final UUID streamId, final long sequenceId) throws InvalidSequenceIdException {
public void insertEventLogData(final String eventName, final UUID streamId, final long sequenceId) throws InvalidPositionException {
eventLogJdbcRepository.insert(eventLogFrom(eventName, sequenceId, streamId));
eventStreamJdbcRepository.insert(streamId);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@ public static Event eventLogFrom(final String eventName, final Long sequenceId,
.with(metadataWithRandomUUID(eventName)
.createdAt(ZonedDateTime.now())
.withVersion(sequenceId)
.withStreamId(streamId))
.withStreamId(streamId)
.withSource("sample")
)
.withPayloadOf("test", "a string")
.build();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,45 +8,36 @@
import liquibase.database.jvm.JdbcConnection;
import liquibase.exception.LiquibaseException;
import liquibase.resource.ClassLoaderResourceAccessor;
import org.apache.commons.dbcp2.BasicDataSource;
import org.postgresql.ds.PGSimpleDataSource;

public class LiquibaseUtil {

private static final TestProperties TEST_PROPERTIES = new TestProperties("test.properties");
private static final String DATABASE_NAME = "frameworkeventstore";

public DataSource initEventStoreDb() throws SQLException, LiquibaseException {
return initDatabase("db.eventstore.url",
"db.eventstore.userName",
"db.eventstore.password",
"liquibase/event-store-db-changelog.xml");
}
private TestProperties testProperties = new TestProperties("test.properties");

private DataSource initDatabase(final String dbUrlPropertyName,
final String dbUserNamePropertyName,
final String dbPasswordPropertyName,
final String... liquibaseChangeLogXmls) throws SQLException, LiquibaseException {
public DataSource initEventStoreDb() throws SQLException, LiquibaseException {

final BasicDataSource dataSource = new BasicDataSource();
final String username = testProperties.value("db.eventstore.userName");
final String password = testProperties.value("db.eventstore.password");
final int portNumber = Integer.parseInt(testProperties.value("db.eventstore.portNumber"));

dataSource.setDriverClassName(TEST_PROPERTIES.value("db.driver"));
final PGSimpleDataSource dataSource = new PGSimpleDataSource();
dataSource.setPortNumber(portNumber);
dataSource.setDatabaseName(DATABASE_NAME);
dataSource.setUser(username);
dataSource.setPassword(password);

dataSource.setUrl(TEST_PROPERTIES.value(dbUrlPropertyName));
dataSource.setUsername(TEST_PROPERTIES.value(dbUserNamePropertyName));
dataSource.setPassword(TEST_PROPERTIES.value(dbPasswordPropertyName));
boolean dropped = false;
final JdbcConnection jdbcConnection = new JdbcConnection(dataSource.getConnection());

for (String liquibaseChangeLogXml : liquibaseChangeLogXmls) {
Liquibase liquibase = new Liquibase(liquibaseChangeLogXml,
new ClassLoaderResourceAccessor(), jdbcConnection);
if (!dropped) {
liquibase.dropAll();
dropped = true;
}
liquibase.update("");
}
return dataSource;
}
final Liquibase liquibase = new Liquibase(
"liquibase/event-store-db-changelog.xml",
new ClassLoaderResourceAccessor(),
jdbcConnection);

liquibase.dropAll();
liquibase.update("");

return dataSource;
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package uk.gov.justice.framework.tools.transformation;


import static uk.gov.justice.services.test.utils.common.reflection.ReflectionUtils.setField;
import static org.slf4j.LoggerFactory.getLogger;

import uk.gov.justice.services.eventsourcing.repository.jdbc.AnsiSQLEventLogInsertionStrategy;
import uk.gov.justice.services.eventsourcing.repository.jdbc.event.EventJdbcRepository;
Expand All @@ -17,10 +17,15 @@ public class TestEventLogJdbcRepository extends EventJdbcRepository {
protected final DataSource dbsource;

public TestEventLogJdbcRepository(final DataSource datasource) {
super(
new AnsiSQLEventLogInsertionStrategy(),
new JdbcRepositoryHelper(),
jndiName -> datasource,
"",
getLogger(EventJdbcRepository.class)
);

this.dbsource = datasource;
setField(this, "eventInsertionStrategy", new AnsiSQLEventLogInsertionStrategy());
setField(this, "dataSource", datasource);
setField(this, "jdbcRepositoryHelper", new JdbcRepositoryHelper());
}

protected DataSource getDataSource() {
Expand Down
Loading

0 comments on commit ed1f90c

Please sign in to comment.