Skip to content

Commit

Permalink
Merge fee4a69 into 36c58b4
Browse files Browse the repository at this point in the history
  • Loading branch information
allanmckenzie committed Jun 10, 2019
2 parents 36c58b4 + fee4a69 commit 9a53627
Show file tree
Hide file tree
Showing 8 changed files with 57 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import uk.gov.justice.services.example.cakeshop.it.helpers.EventFinder;
import uk.gov.justice.services.example.cakeshop.it.helpers.RestEasyClientFactory;
import uk.gov.justice.services.test.utils.core.http.HttpResponsePoller;
import uk.gov.justice.services.test.utils.persistence.DatabaseCleaner;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
Expand All @@ -42,12 +43,18 @@ public class CakeShopConcurrencyIT {

private final HttpResponsePoller httpResponsePoller = new HttpResponsePoller();
private final EventFinder eventFinder = new EventFinder(eventJdbcRepository);
private final DatabaseCleaner databaseCleaner = new DatabaseCleaner();

private Client client;

@Before
public void before() throws Exception {
client = new RestEasyClientFactory().createResteasyClient();

final String contextName = "framework";

databaseCleaner.cleanEventStoreTables(contextName);
cleanViewstoreTables();
}

@After
Expand Down Expand Up @@ -115,4 +122,21 @@ public void shouldRegisterRecipeRemovedEvent() {
final String notFoundResponse = httpResponsePoller.pollUntilNotFound(RECIPES_RESOURCE_QUERY_URI + recipeId, QUERY_RECIPE_MEDIA_TYPE);
assertThat(notFoundResponse, notNullValue());
}

private void cleanViewstoreTables() {

final String contextName = "framework";

databaseCleaner.cleanViewStoreTables(contextName,
"ingredient",
"recipe",
"cake",
"cake_order",
"processed_event",
"shuttered_command_store"
);

databaseCleaner.cleanStreamBufferTable(contextName);
databaseCleaner.cleanStreamStatusTable(contextName);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@

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

public class CakeShopReplayEventsIT {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package uk.gov.justice.services.example.cakeshop.it;

import static com.jayway.awaitility.Awaitility.await;
import static com.jayway.awaitility.Duration.*;
import static com.jayway.jsonassert.JsonAssert.with;
import static java.time.temporal.ChronoUnit.SECONDS;
import static java.util.UUID.randomUUID;
Expand Down Expand Up @@ -34,12 +33,10 @@
import javax.ws.rs.client.Client;
import javax.ws.rs.core.Response;

import com.jayway.awaitility.Duration;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;


public class CakeShopTimeStampIT {

private final DataSource eventStoreDataSource = new DatabaseManager().initEventStoreDb();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,6 @@ public void shouldReplayAndFindRecipesInViewStore() throws Exception {
final int numberOfStreams = 10;
final int numberOfEventsPerStream = 100;
final int totalEvents = numberOfStreams * numberOfEventsPerStream;
final String componentName = "EVENT_LISTENER";

final List<UUID> streamIds = addEventsToEventLog(numberOfStreams, numberOfEventsPerStream);

Expand All @@ -98,7 +97,7 @@ public void shouldReplayAndFindRecipesInViewStore() throws Exception {
for (final UUID streamId : streamIds) {

final Optional<Long> eventCount = longPoller.pollUntilFound(() -> {
final long eventsPerStream = recipeTableInspector.countEventsPerStream(streamId, componentName);
final long eventsPerStream = recipeTableInspector.countEventsPerStream(streamId);
if (eventsPerStream == numberOfEventsPerStream) {
return of(eventsPerStream);
}
Expand All @@ -107,7 +106,7 @@ public void shouldReplayAndFindRecipesInViewStore() throws Exception {
});

if (!eventCount.isPresent()) {
fail("Expected " + numberOfEventsPerStream + " events but found " + recipeTableInspector.countEventsPerStream(streamId, componentName) + " in stream " + streamId);
fail("Expected " + numberOfEventsPerStream + " events but found " + recipeTableInspector.countEventsPerStream(streamId) + " in stream " + streamId);
}
}

Expand All @@ -125,7 +124,7 @@ public void shouldReplayAndFindRecipesInViewStore() throws Exception {
for (final UUID streamId : streamIds) {

final Optional<Long> eventCount = longPoller.pollUntilFound(() -> {
final long eventsPerStream = recipeTableInspector.countEventsPerStream(streamId, componentName);
final long eventsPerStream = recipeTableInspector.countEventsPerStream(streamId);
if (eventsPerStream == numberOfEventsPerStream) {
return of(eventsPerStream);
}
Expand Down Expand Up @@ -202,5 +201,4 @@ private void cleanViewstoreTables() {
databaseCleaner.cleanStreamBufferTable(contextName);
databaseCleaner.cleanStreamStatusTable(contextName);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@
import javax.ws.rs.client.Client;

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

public class RebuildIT {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import uk.gov.justice.services.example.cakeshop.it.helpers.ApiResponse;
import uk.gov.justice.services.example.cakeshop.it.helpers.Querier;
import uk.gov.justice.services.example.cakeshop.it.helpers.RestEasyClientFactory;
import uk.gov.justice.services.test.utils.persistence.DatabaseCleaner;

import java.util.UUID;

Expand All @@ -26,16 +27,20 @@
import org.junit.Before;
import org.junit.Test;


public class UnifiedSearchIndexerIT {

private Client client;
private Querier querier;
private final Client client = new RestEasyClientFactory().createResteasyClient();
private final Querier querier = new Querier(client);

private final DatabaseCleaner databaseCleaner = new DatabaseCleaner();

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

final String contextName = "framework";

databaseCleaner.cleanEventStoreTables(contextName);
cleanViewstoreTables();
}

@After
Expand Down Expand Up @@ -69,4 +74,21 @@ public void shouldIndexData() {
.assertThat("$.indexId", equalTo(recipeId.toString()))
.assertThat("$.deliveryDate", equalTo("2016-01-21T16:42:03.522Z"));
}

private void cleanViewstoreTables() {

final String contextName = "framework";

databaseCleaner.cleanViewStoreTables(contextName,
"ingredient",
"recipe",
"cake",
"cake_order",
"processed_event",
"shuttered_command_store"
);

databaseCleaner.cleanStreamBufferTable(contextName);
databaseCleaner.cleanStreamStatusTable(contextName);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -63,15 +63,15 @@ public List<Recipe> getAllRecipes() {
}
}

public long countEventsPerStream(final UUID streamId, final String componentName) {
public long countEventsPerStream(final UUID streamId) {

final String sql = "SELECT position FROM stream_status WHERE stream_id = ? AND component = ?";

try(final Connection connection = viewStoreDataSource.getConnection();
final PreparedStatement preparedStatement = connection.prepareStatement(sql)) {

preparedStatement.setObject(1, streamId);
preparedStatement.setString(2, componentName);
preparedStatement.setString(2, "EVENT_LISTENER");

try(final ResultSet resultSet = preparedStatement.executeQuery()) {
if(resultSet.next()) {
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
<common-bom.version>2.0.2</common-bom.version>
<framework.version>6.0.0-M28</framework.version>
<embedded-artemis.version>1.2.0</embedded-artemis.version>
<event-store.version>2.0.0-M33</event-store.version>
<event-store.version>2.0.0-M34</event-store.version>
<framework-generators.version>2.0.0-M22</framework-generators.version>
<file.service.version>1.17.7</file.service.version>
<framework-api.version>4.0.0-M22</framework-api.version>
Expand Down

0 comments on commit 9a53627

Please sign in to comment.