Skip to content

Commit

Permalink
Merge pull request #38 from CJSCommonPlatform/add-component-to-integr…
Browse files Browse the repository at this point in the history
…ation-tests

Add component to integration tests
  • Loading branch information
MartinYSpasov committed May 30, 2019
2 parents 0102482 + 2345b1c commit 05d8d1c
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
import uk.gov.justice.services.example.cakeshop.it.helpers.PublishedEventCounter;
import uk.gov.justice.services.example.cakeshop.it.helpers.RecipeTableInspector;
import uk.gov.justice.services.example.cakeshop.it.helpers.RestEasyClientFactory;
import uk.gov.justice.services.example.cakeshop.it.helpers.StandaloneStreamStatusJdbcRepositoryFactory;
import uk.gov.justice.services.jmx.Catchup;
import uk.gov.justice.services.jmx.CatchupMBean;
import uk.gov.justice.services.test.utils.core.messaging.Poller;
Expand Down Expand Up @@ -51,8 +50,6 @@ public class CatchupPerformanceIT {
private final EventStreamJdbsRepositoryFactory eventStreamJdbcRepositoryFactory = new EventStreamJdbsRepositoryFactory();
private final EventStreamJdbcRepository eventStreamJdbcRepository = eventStreamJdbcRepositoryFactory.getEventStreamJdbcRepository(eventStoreDataSource);

private final StandaloneStreamStatusJdbcRepositoryFactory standaloneStreamStatusJdbcRepositoryFactory = new StandaloneStreamStatusJdbcRepositoryFactory();

private final RecipeTableInspector recipeTableInspector = new RecipeTableInspector(viewStoreDataSource);
private final PublishedEventCounter publishedEventCounter = new PublishedEventCounter(eventStoreDataSource);

Expand All @@ -78,6 +75,7 @@ public void shouldReplayAndFindRecipesInViewStore() throws Exception {
final int numberOfStreams = 10;
final int numberOfEventsPerStream = 100;
final int totalEvents = numberOfStreams * numberOfEventsPerStream;
final String componentName = "EVENT_LISTENER";

truncateEventLog();
recipeTableInspector.truncateViewstoreTables();
Expand All @@ -102,7 +100,7 @@ public void shouldReplayAndFindRecipesInViewStore() throws Exception {
for (final UUID streamId : streamIds) {

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

final Optional<Long> eventCount = longPoller.pollUntilFound(() -> {
final long eventsPerStream = recipeTableInspector.countEventsPerStream(streamId);
final long eventsPerStream = recipeTableInspector.countEventsPerStream(streamId, componentName);
if (eventsPerStream == numberOfEventsPerStream) {
return of(eventsPerStream);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package uk.gov.justice.services.example.cakeshop.it.helpers;


import static java.lang.String.format;

import uk.gov.justice.services.example.cakeshop.persistence.entity.Recipe;

import java.sql.Connection;
Expand Down Expand Up @@ -91,18 +93,22 @@ public List<Recipe> getAllRecipes() {
}
}

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

final String sql = "SELECT position FROM stream_status WHERE stream_id = ?";
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);

try(final ResultSet resultSet = preparedStatement.executeQuery()) {
resultSet.next();
return resultSet.getLong(1);
if(resultSet.next()) {
return resultSet.getLong(1);
} else {
throw new RuntimeException(format("No results returned from query '%s'", sql));
}
}

} catch (final SQLException e) {
Expand Down

0 comments on commit 05d8d1c

Please sign in to comment.