Skip to content

Commit

Permalink
Merge c18163f into 9635829
Browse files Browse the repository at this point in the history
  • Loading branch information
allanmckenzie committed Nov 8, 2019
2 parents 9635829 + c18163f commit 116a79c
Show file tree
Hide file tree
Showing 10 changed files with 81 additions and 58 deletions.
6 changes: 6 additions & 0 deletions example-context/example-service/example-it/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,12 @@
<version>${event-store.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>uk.gov.justice.event-store</groupId>
<artifactId>event-store-management-commands</artifactId>
<version>${event-store.version}</version>
<scope>test</scope>
</dependency>
</dependencies>

<build>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import static org.hamcrest.CoreMatchers.is;
import static org.junit.Assert.assertThat;
import static org.junit.Assert.fail;
import static uk.gov.justice.services.eventstore.management.commands.EventCatchupCommand.CATCHUP;
import static uk.gov.justice.services.jmx.system.command.client.connection.JmxParametersBuilder.jmxParameters;
import static uk.gov.justice.services.test.utils.common.host.TestHostProvider.getHost;

Expand All @@ -18,7 +19,6 @@
import uk.gov.justice.services.example.cakeshop.it.helpers.PositionInStreamIterator;
import uk.gov.justice.services.example.cakeshop.it.helpers.ProcessedEventCounter;
import uk.gov.justice.services.example.cakeshop.it.helpers.RestEasyClientFactory;
import uk.gov.justice.services.jmx.api.command.EventCatchupCommand;
import uk.gov.justice.services.jmx.system.command.client.SystemCommanderClient;
import uk.gov.justice.services.jmx.system.command.client.TestSystemCommanderClientFactory;
import uk.gov.justice.services.jmx.system.command.client.connection.JmxParameters;
Expand Down Expand Up @@ -96,28 +96,20 @@ public void shouldReplayAndFindRecipesInViewStore() throws Exception {

System.out.println("Inserted " + totalEvents + " events into event_log");
System.out.println("Waiting for events to publish...");
cleanViewstoreTables();

longPoller.pollUntilFound(() -> {
final Optional<Integer> processedEventCount = longPoller.pollUntilFound(() -> {
final int eventCount = processedEventCounter.countProcessedEvents();
if (eventCount == 0) {
if (eventCount == totalEvents) {
return of(eventCount);
}

return empty();
});

try (final Connection connection = eventStoreDataSource.getConnection();
final PreparedStatement preparedStatement = connection.prepareStatement("SELECT COUNT (*) FROM publish_queue");
final ResultSet resultSet = preparedStatement.executeQuery()) {
assertThat(processedEventCount, is(of(totalEvents)));

int eventCount = -1;
if (resultSet.next()) {
eventCount = resultSet.getInt(1);
}

assertThat(eventCount, is(0));
}
cleanViewstoreTables();

System.out.println("Running catchup...");
runCatchup();
Expand Down Expand Up @@ -180,7 +172,7 @@ private void runCatchup() throws Exception {

try (final SystemCommanderClient systemCommanderClient = systemCommanderClientFactory.create(jmxParameters)) {

systemCommanderClient.getRemote(CONTEXT_NAME).call(new EventCatchupCommand());
systemCommanderClient.getRemote(CONTEXT_NAME).call(CATCHUP);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import static org.hamcrest.CoreMatchers.is;
import static org.junit.Assert.assertThat;
import static org.junit.Assert.fail;
import static uk.gov.justice.services.eventstore.management.commands.EventCatchupCommand.CATCHUP;
import static uk.gov.justice.services.example.cakeshop.it.params.CakeShopMediaTypes.ADD_RECIPE_MEDIA_TYPE;
import static uk.gov.justice.services.example.cakeshop.it.params.CakeShopUris.RECIPES_RESOURCE_URI;
import static uk.gov.justice.services.jmx.system.command.client.connection.JmxParametersBuilder.jmxParameters;
Expand All @@ -24,7 +25,6 @@
import uk.gov.justice.services.example.cakeshop.it.helpers.DatabaseManager;
import uk.gov.justice.services.example.cakeshop.it.helpers.ProcessedEventCounter;
import uk.gov.justice.services.example.cakeshop.it.helpers.RestEasyClientFactory;
import uk.gov.justice.services.jmx.api.command.EventCatchupCommand;
import uk.gov.justice.services.jmx.system.command.client.SystemCommanderClient;
import uk.gov.justice.services.jmx.system.command.client.TestSystemCommanderClientFactory;
import uk.gov.justice.services.jmx.system.command.client.connection.JmxParameters;
Expand Down Expand Up @@ -176,7 +176,7 @@ private void runCatchup() throws Exception {

try (final SystemCommanderClient systemCommanderClient = systemCommanderClientFactory.create(jmxParameters)) {

systemCommanderClient.getRemote(CONTEXT_NAME).call(new EventCatchupCommand());
systemCommanderClient.getRemote(CONTEXT_NAME).call(CATCHUP);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@
import static uk.gov.justice.services.test.utils.common.host.TestHostProvider.getHost;

import uk.gov.justice.services.eventsourcing.repository.jdbc.event.Event;
import uk.gov.justice.services.eventstore.management.commands.ValidatePublishedEventsCommand;
import uk.gov.justice.services.example.cakeshop.it.helpers.BatchEventInserter;
import uk.gov.justice.services.example.cakeshop.it.helpers.CakeshopEventGenerator;
import uk.gov.justice.services.example.cakeshop.it.helpers.DatabaseManager;
import uk.gov.justice.services.example.cakeshop.it.helpers.PositionInStreamIterator;
import uk.gov.justice.services.example.cakeshop.it.helpers.PublishedEventCounter;
import uk.gov.justice.services.jmx.api.command.SystemCommand;
import uk.gov.justice.services.jmx.api.command.ValidatePublishedEventsCommand;
import uk.gov.justice.services.jmx.api.domain.CommandState;
import uk.gov.justice.services.jmx.api.domain.SystemCommandStatus;
import uk.gov.justice.services.jmx.api.mbean.SystemCommanderMBean;
Expand Down Expand Up @@ -151,7 +151,7 @@ private Optional<SystemCommandStatus> runCommand(final JmxParameters jmxParamete

final SystemCommanderMBean systemCommanderMBean = systemCommanderClient.getRemote(CONTEXT_NAME);
final UUID commandId = systemCommanderMBean
.call(systemCommand);
.call(systemCommand.getName());

return poller.pollUntilFound(() -> commandNoLongerInProgress(systemCommanderMBean, commandId));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,30 +2,45 @@

import static java.lang.Integer.parseInt;
import static java.lang.System.getProperty;
import static java.util.stream.Collectors.toMap;
import static org.hamcrest.CoreMatchers.hasItem;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.CoreMatchers.notNullValue;
import static org.junit.Assert.assertThat;
import static uk.gov.justice.services.eventstore.management.commands.AddTriggerCommand.ADD_TRIGGER;
import static uk.gov.justice.services.eventstore.management.commands.DisablePublishingCommand.DISABLE_PUBLISHING;
import static uk.gov.justice.services.eventstore.management.commands.EnablePublishingCommand.ENABLE_PUBLISHING;
import static uk.gov.justice.services.eventstore.management.commands.EventCatchupCommand.CATCHUP;
import static uk.gov.justice.services.eventstore.management.commands.IndexerCatchupCommand.INDEXER_CATCHUP;
import static uk.gov.justice.services.eventstore.management.commands.RebuildCommand.REBUILD;
import static uk.gov.justice.services.eventstore.management.commands.RemoveTriggerCommand.REMOVE_TRIGGER;
import static uk.gov.justice.services.eventstore.management.commands.ValidatePublishedEventsCommand.VALIDATE_EVENTS;
import static uk.gov.justice.services.eventstore.management.commands.VerifyCatchupCommand.VERIFY_CATCHUP;
import static uk.gov.justice.services.jmx.system.command.client.connection.JmxParametersBuilder.jmxParameters;
import static uk.gov.justice.services.management.ping.commands.PingCommand.PING;
import static uk.gov.justice.services.management.shuttering.commands.ShutterCommand.SHUTTER;
import static uk.gov.justice.services.management.shuttering.commands.UnshutterCommand.UNSHUTTER;
import static uk.gov.justice.services.test.utils.common.host.TestHostProvider.getHost;

import uk.gov.justice.services.jmx.api.command.AddTriggerCommand;
import uk.gov.justice.services.jmx.api.command.DisablePublishingCommand;
import uk.gov.justice.services.jmx.api.command.EnablePublishingCommand;
import uk.gov.justice.services.jmx.api.command.EventCatchupCommand;
import uk.gov.justice.services.jmx.api.command.IndexerCatchupCommand;
import uk.gov.justice.services.jmx.api.command.PingCommand;
import uk.gov.justice.services.jmx.api.command.RebuildCommand;
import uk.gov.justice.services.jmx.api.command.RemoveTriggerCommand;
import uk.gov.justice.services.jmx.api.command.ShutterCommand;
import uk.gov.justice.services.jmx.api.command.SystemCommand;
import uk.gov.justice.services.jmx.api.command.UnshutterCommand;
import uk.gov.justice.services.jmx.api.command.ValidatePublishedEventsCommand;
import uk.gov.justice.services.jmx.api.command.VerifyCatchupCommand;
import uk.gov.justice.services.eventstore.management.commands.AddTriggerCommand;
import uk.gov.justice.services.eventstore.management.commands.DisablePublishingCommand;
import uk.gov.justice.services.eventstore.management.commands.EnablePublishingCommand;
import uk.gov.justice.services.eventstore.management.commands.EventCatchupCommand;
import uk.gov.justice.services.eventstore.management.commands.IndexerCatchupCommand;
import uk.gov.justice.services.eventstore.management.commands.RebuildCommand;
import uk.gov.justice.services.eventstore.management.commands.RemoveTriggerCommand;
import uk.gov.justice.services.eventstore.management.commands.ValidatePublishedEventsCommand;
import uk.gov.justice.services.eventstore.management.commands.VerifyCatchupCommand;
import uk.gov.justice.services.jmx.api.command.SystemCommandDetails;
import uk.gov.justice.services.jmx.system.command.client.SystemCommanderClient;
import uk.gov.justice.services.jmx.system.command.client.TestSystemCommanderClientFactory;
import uk.gov.justice.services.jmx.system.command.client.connection.JmxParameters;
import uk.gov.justice.services.management.ping.commands.PingCommand;
import uk.gov.justice.services.management.shuttering.commands.ShutterCommand;
import uk.gov.justice.services.management.shuttering.commands.UnshutterCommand;

import java.util.List;
import java.util.Map;

import org.junit.Test;

Expand All @@ -47,21 +62,28 @@ public void shouldListAllSystemCommands() throws Exception {

try (final SystemCommanderClient systemCommanderClient = testSystemCommanderClientFactory.create(jmxParameters)) {

final List<SystemCommand> systemCommands = systemCommanderClient.getRemote(CONTEXT_NAME).listCommands();
final List<SystemCommandDetails> systemCommandDetailsList = systemCommanderClient
.getRemote(CONTEXT_NAME)
.listCommands();

assertThat(systemCommands.size(), is(12));
assertThat(systemCommands, hasItem(new AddTriggerCommand()));
assertThat(systemCommands, hasItem(new DisablePublishingCommand()));
assertThat(systemCommands, hasItem(new EnablePublishingCommand()));
assertThat(systemCommands, hasItem(new EventCatchupCommand()));
assertThat(systemCommands, hasItem(new IndexerCatchupCommand()));
assertThat(systemCommands, hasItem(new PingCommand()));
assertThat(systemCommands, hasItem(new RebuildCommand()));
assertThat(systemCommands, hasItem(new RemoveTriggerCommand()));
assertThat(systemCommands, hasItem(new ShutterCommand()));
assertThat(systemCommands, hasItem(new UnshutterCommand()));
assertThat(systemCommands, hasItem(new ValidatePublishedEventsCommand()));
assertThat(systemCommands, hasItem(new VerifyCatchupCommand()));
assertThat(systemCommandDetailsList.size(), is(12));

final Map<String, SystemCommandDetails> systemCommandDetailsMap = systemCommandDetailsList
.stream()
.collect(toMap(SystemCommandDetails::getName, systemCommandDetails -> systemCommandDetails));

assertThat(systemCommandDetailsMap.get(ADD_TRIGGER), is(notNullValue()));
assertThat(systemCommandDetailsMap.get(DISABLE_PUBLISHING), is(notNullValue()));
assertThat(systemCommandDetailsMap.get(ENABLE_PUBLISHING), is(notNullValue()));
assertThat(systemCommandDetailsMap.get(CATCHUP), is(notNullValue()));
assertThat(systemCommandDetailsMap.get(INDEXER_CATCHUP), is(notNullValue()));
assertThat(systemCommandDetailsMap.get(PING), is(notNullValue()));
assertThat(systemCommandDetailsMap.get(REBUILD), is(notNullValue()));
assertThat(systemCommandDetailsMap.get(REMOVE_TRIGGER), is(notNullValue()));
assertThat(systemCommandDetailsMap.get(SHUTTER), is(notNullValue()));
assertThat(systemCommandDetailsMap.get(UNSHUTTER), is(notNullValue()));
assertThat(systemCommandDetailsMap.get(VALIDATE_EVENTS), is(notNullValue()));
assertThat(systemCommandDetailsMap.get(VERIFY_CATCHUP), is(notNullValue()));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import static org.hamcrest.CoreMatchers.is;
import static org.junit.Assert.assertThat;
import static org.junit.Assert.fail;
import static uk.gov.justice.services.eventstore.management.commands.RebuildCommand.REBUILD;
import static uk.gov.justice.services.jmx.system.command.client.connection.JmxParametersBuilder.jmxParameters;
import static uk.gov.justice.services.test.utils.common.host.TestHostProvider.getHost;

Expand All @@ -19,7 +20,6 @@
import uk.gov.justice.services.example.cakeshop.it.helpers.DatabaseManager;
import uk.gov.justice.services.example.cakeshop.it.helpers.EventFactory;
import uk.gov.justice.services.example.cakeshop.it.helpers.RestEasyClientFactory;
import uk.gov.justice.services.jmx.api.command.RebuildCommand;
import uk.gov.justice.services.jmx.system.command.client.SystemCommanderClient;
import uk.gov.justice.services.jmx.system.command.client.TestSystemCommanderClientFactory;
import uk.gov.justice.services.jmx.system.command.client.connection.JmxParameters;
Expand Down Expand Up @@ -114,7 +114,7 @@ private void invokeRebuild() throws Exception {
.build();

try(final SystemCommanderClient systemCommanderClient = testSystemCommanderClientFactory.create(jmxParameters)) {
systemCommanderClient.getRemote(CONTEXT_NAME).call(new RebuildCommand());
systemCommanderClient.getRemote(CONTEXT_NAME).call(REBUILD);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
import static org.slf4j.LoggerFactory.getLogger;
import static uk.gov.justice.services.jmx.api.domain.CommandState.COMMAND_COMPLETE;
import static uk.gov.justice.services.jmx.system.command.client.connection.JmxParametersBuilder.jmxParameters;
import static uk.gov.justice.services.management.shuttering.commands.ShutterCommand.SHUTTER;
import static uk.gov.justice.services.management.shuttering.commands.UnshutterCommand.UNSHUTTER;
import static uk.gov.justice.services.test.utils.common.host.TestHostProvider.getHost;
import static uk.gov.justice.services.test.utils.core.matchers.HttpStatusCodeMatcher.isStatus;

Expand All @@ -24,8 +26,6 @@
import uk.gov.justice.services.example.cakeshop.it.helpers.EventFactory;
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.jmx.api.command.ShutterCommand;
import uk.gov.justice.services.jmx.api.command.UnshutterCommand;
import uk.gov.justice.services.jmx.api.domain.SystemCommandStatus;
import uk.gov.justice.services.jmx.api.mbean.SystemCommanderMBean;
import uk.gov.justice.services.jmx.system.command.client.SystemCommanderClient;
Expand Down Expand Up @@ -90,7 +90,7 @@ public void cleanup() throws Exception {

final SystemCommanderMBean systemCommanderMBean = systemCommanderClient.getRemote(CONTEXT_NAME);

final UUID commandId = systemCommanderMBean.call(new UnshutterCommand());
final UUID commandId = systemCommanderMBean.call(UNSHUTTER);

final Optional<SystemCommandStatus> unshutterStatus = poller.pollUntilFound(() -> {
final SystemCommandStatus commandStatus = systemCommanderMBean.getCommandStatus(commandId);
Expand All @@ -117,7 +117,7 @@ public void shouldNotReturnRecipesAfterShuttering() throws Exception {
.build();
try (final SystemCommanderClient systemCommanderClient = testSystemCommanderClientFactory.create(jmxParameters)) {
final SystemCommanderMBean systemCommanderMBean = systemCommanderClient.getRemote(CONTEXT_NAME);
final UUID commandId = systemCommanderMBean.call(new ShutterCommand());
final UUID commandId = systemCommanderMBean.call(SHUTTER);

final Optional<SystemCommandStatus> shutterStatus = poller.pollUntilFound(() -> {
final SystemCommandStatus commandStatus = systemCommanderMBean.getCommandStatus(commandId);
Expand Down Expand Up @@ -156,7 +156,7 @@ public void shouldQueryForRecipesAfterUnShuttering() throws Exception {
final SystemCommanderMBean systemCommanderMBean = systemCommanderClient.getRemote(CONTEXT_NAME);

//invoke shuttering
final UUID shutterCommandId = systemCommanderMBean.call(new ShutterCommand());
final UUID shutterCommandId = systemCommanderMBean.call(SHUTTER);

final Optional<SystemCommandStatus> shutterStatus = poller.pollUntilFound(() -> {
final SystemCommandStatus commandStatus = systemCommanderMBean.getCommandStatus(shutterCommandId);
Expand All @@ -182,7 +182,7 @@ public void shouldQueryForRecipesAfterUnShuttering() throws Exception {
verifyRecipeAdded(recipeId, recipeId2, null, null, false, NOT_FOUND);

//invoke unshuttering
final UUID unshutterCommandId = systemCommanderMBean.call(new UnshutterCommand());
final UUID unshutterCommandId = systemCommanderMBean.call(UNSHUTTER);

final Optional<SystemCommandStatus> unshutterStatus = poller.pollUntilFound(() -> {
final SystemCommandStatus commandStatus = systemCommanderMBean.getCommandStatus(unshutterCommandId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,6 @@ public void shouldIndexData() {

final ApiResponse queryResponse = querier.queryForIndex(recipeId.toString());

System.out.println(queryResponse.body());

with(queryResponse.body())
.assertThat("$.indexId", equalTo(recipeId.toString()))
.assertThat("$.deliveryDate", equalTo("2016-01-21T16:42:03.522Z"));
Expand Down
5 changes: 5 additions & 0 deletions example-context/example-service/example-single/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,11 @@
<artifactId>jmx-api</artifactId>
<version>${framework.version}</version>
</dependency>
<dependency>
<groupId>uk.gov.justice.event-store</groupId>
<artifactId>event-store-management-commands</artifactId>
<version>${event-store.version}</version>
</dependency>

<!-- Test Dependencies -->
<dependency>
Expand Down
6 changes: 3 additions & 3 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,9 @@
<cpp.repo.name>cake-shop</cpp.repo.name>

<framework-api.version>4.1.0</framework-api.version>
<framework.version>6.2.5</framework.version>
<event-store.version>2.2.7</event-store.version>
<framework-generators.version>2.2.3</framework-generators.version>
<framework.version>6.3.0</framework.version>
<event-store.version>2.3.0</event-store.version>
<framework-generators.version>2.3.0</framework-generators.version>
<file.service.version>1.17.12</file.service.version>

<common-bom.version>2.4.0</common-bom.version>
Expand Down

0 comments on commit 116a79c

Please sign in to comment.