Skip to content

Commit

Permalink
Move JMX client classes to framework
Browse files Browse the repository at this point in the history
  • Loading branch information
amckenzie committed Jun 11, 2019
1 parent 1f5d8fe commit 909e93c
Show file tree
Hide file tree
Showing 13 changed files with 89 additions and 192 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,6 @@
<artifactId>core</artifactId>
<version>${framework.version}</version>
</dependency>
<dependency>
<groupId>uk.gov.justice.services</groupId>
<artifactId>shuttering-core</artifactId>
<version>${framework.version}</version>
</dependency>
<dependency>
<groupId>uk.gov.justice.framework-generators</groupId>
<artifactId>rest-adapter-file-service</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,6 @@
<groupId>uk.gov.justice.services</groupId>
<artifactId>core</artifactId>
</dependency>
<dependency>
<groupId>uk.gov.justice.services</groupId>
<artifactId>shuttering-core</artifactId>
<version>${framework.version}</version>
</dependency>
<dependency>
<groupId>uk.gov.justice.event-store</groupId>
<artifactId>aggregate-snapshot-service</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,6 @@
<artifactId>core</artifactId>
<version>${framework.version}</version>
</dependency>
<dependency>
<groupId>uk.gov.justice.services</groupId>
<artifactId>shuttering-core</artifactId>
<version>${framework.version}</version>
</dependency>
<dependency>
<groupId>uk.gov.justice.framework-generators</groupId>
<artifactId>messaging-adapter-core</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,6 @@
<artifactId>core</artifactId>
<version>${framework.version}</version>
</dependency>
<dependency>
<groupId>uk.gov.justice.services</groupId>
<artifactId>shuttering-core</artifactId>
<version>${framework.version}</version>
</dependency>
<dependency>
<groupId>uk.gov.justice.framework-generators</groupId>
<artifactId>messaging-adapter-core</artifactId>
Expand Down
14 changes: 10 additions & 4 deletions example-context/example-service/example-it/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@
</dependency>
<dependency>
<groupId>uk.gov.justice.services</groupId>
<artifactId>jmx</artifactId>
<artifactId>jmx-command-handling</artifactId>
<scope>test</scope>
</dependency>
<dependency>
Expand Down Expand Up @@ -224,6 +224,12 @@
<version>${framework.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>uk.gov.justice.services</groupId>
<artifactId>jmx-command-client</artifactId>
<version>${framework.version}</version>
<scope>test</scope>
</dependency>
</dependencies>

<build>
Expand Down Expand Up @@ -297,9 +303,9 @@
</goals>
</execution>
<execution>
<id>shuttering-liquibase</id>
<id>framework-system-liquibase</id>
<configuration>
<changeLogFile>liquibase/shuttering-changelog.xml
<changeLogFile>liquibase/framework-system-changelog.xml
</changeLogFile>
<url>jdbc:postgresql://localhost:5432/frameworkviewstore</url>
</configuration>
Expand Down Expand Up @@ -350,7 +356,7 @@
</dependency>
<dependency>
<groupId>uk.gov.justice.services</groupId>
<artifactId>shuttering-liquibase</artifactId>
<artifactId>framework-system-liquibase</artifactId>
<version>${framework.version}</version>
</dependency>
<dependency>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
package uk.gov.justice.services.example.cakeshop.it;

import static java.lang.Integer.valueOf;
import static java.lang.System.getProperty;
import static java.util.Optional.empty;
import static java.util.Optional.of;
import static org.hamcrest.CoreMatchers.is;
import static org.junit.Assert.assertThat;
import static org.junit.Assert.fail;
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.eventsourcing.repository.jdbc.event.EventJdbcRepository;
Expand All @@ -18,8 +21,9 @@
import uk.gov.justice.services.example.cakeshop.it.helpers.PositionInStreamIterator;
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.SystemCommandMBeanClient;
import uk.gov.justice.services.example.cakeshop.persistence.entity.Recipe;
import uk.gov.justice.services.jmx.system.command.client.SystemCommanderClient;
import uk.gov.justice.services.jmx.system.command.client.SystemCommanderClientFactory;
import uk.gov.justice.services.test.utils.core.messaging.Poller;
import uk.gov.justice.services.test.utils.persistence.DatabaseCleaner;

Expand All @@ -45,11 +49,14 @@ public class CakeShopReplayEventsIT {
private final EventStreamJdbcRepository eventStreamJdbcRepository = eventStreamJdbcRepositoryFactory.getEventStreamJdbcRepository(eventStoreDataSource);

private final RecipeTableInspector recipeTableInspector = new RecipeTableInspector(viewStoreDataSource);
private final DatabaseCleaner databaseCleaner = new DatabaseCleaner();

private final Poller poller = new Poller(60, 1000L);

private final SystemCommandMBeanClient systemCommandMBeanClient = new SystemCommandMBeanClient();
private final DatabaseCleaner databaseCleaner = new DatabaseCleaner();
private static final String HOST = getHost();
private static final int PORT = valueOf(getProperty("random.management.port"));

private final SystemCommanderClientFactory systemCommanderClientFactory = new SystemCommanderClientFactory();

private Client client;

Expand All @@ -69,7 +76,6 @@ public void before() {
@After
public void cleanup() {
client.close();
systemCommandMBeanClient.close();
}

@Test
Expand All @@ -92,7 +98,10 @@ public void shouldReplayAndFindRecipesInViewStore() throws Exception {

cleanViewstoreTables();

systemCommandMBeanClient.getMbeanProxy().runCommand(new CatchupCommand());
try (final SystemCommanderClient systemCommanderClient = systemCommanderClientFactory.create(HOST, PORT)) {
systemCommanderClient.getRemote().call(new CatchupCommand());

}

final Optional<Integer> numberOfReplayedRecipesOptional = checkExpectedNumberOfRecipes(numberOfStreams);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
package uk.gov.justice.services.example.cakeshop.it;

import static java.lang.Integer.valueOf;
import static java.lang.System.getProperty;
import static java.util.Optional.empty;
import static java.util.Optional.of;
import static org.junit.Assert.fail;
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.eventsourcing.repository.jdbc.event.EventJdbcRepository;
import uk.gov.justice.services.eventsourcing.repository.jdbc.event.EventRepositoryFactory;
import uk.gov.justice.services.eventsourcing.repository.jdbc.event.EventStreamJdbsRepositoryFactory;
import uk.gov.justice.services.eventsourcing.repository.jdbc.event.PublishedEventTableTruncator;
import uk.gov.justice.services.eventsourcing.repository.jdbc.eventstream.EventStreamJdbcRepository;
import uk.gov.justice.services.eventsourcing.repository.jdbc.exception.InvalidPositionException;
import uk.gov.justice.services.eventstore.management.catchup.commands.CatchupCommand;
Expand All @@ -18,7 +20,8 @@
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.SystemCommandMBeanClient;
import uk.gov.justice.services.jmx.system.command.client.SystemCommanderClient;
import uk.gov.justice.services.jmx.system.command.client.SystemCommanderClientFactory;
import uk.gov.justice.services.test.utils.core.messaging.Poller;
import uk.gov.justice.services.test.utils.persistence.DatabaseCleaner;

Expand All @@ -39,15 +42,18 @@ public class CatchupPerformanceIT {
private final DataSource eventStoreDataSource = new DatabaseManager().initEventStoreDb();
private final DataSource viewStoreDataSource = new DatabaseManager().initViewStoreDb();
private final EventJdbcRepository eventJdbcRepository = new EventRepositoryFactory().getEventJdbcRepository(eventStoreDataSource);
private final PublishedEventTableTruncator publishedEventTableTruncator = new PublishedEventTableTruncator(eventStoreDataSource);

private final EventStreamJdbsRepositoryFactory eventStreamJdbcRepositoryFactory = new EventStreamJdbsRepositoryFactory();
private final EventStreamJdbcRepository eventStreamJdbcRepository = eventStreamJdbcRepositoryFactory.getEventStreamJdbcRepository(eventStoreDataSource);

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

private final SystemCommandMBeanClient systemCommandMBeanClient = new SystemCommandMBeanClient();
private static final String HOST = getHost();
private static final int PORT = valueOf(getProperty("random.management.port"));


private final SystemCommanderClientFactory systemCommanderClientFactory = new SystemCommanderClientFactory();
private final DatabaseCleaner databaseCleaner = new DatabaseCleaner();

private final Poller longPoller = new Poller(1200, 1000L);
Expand All @@ -67,7 +73,6 @@ public void before() {
@After
public void cleanup() {
client.close();
systemCommandMBeanClient.close();
}

@Test
Expand Down Expand Up @@ -169,8 +174,10 @@ private List<UUID> addEventsToEventLog(final int numberOfStreams, final int numb

private void runCatchup() throws Exception {

systemCommandMBeanClient.getMbeanProxy().runCommand(new CatchupCommand());
try (final SystemCommanderClient systemCommanderClient = systemCommanderClientFactory.create(HOST, PORT)) {

systemCommanderClient.getRemote().call(new CatchupCommand());
}
}

private Optional<Integer> checkExpectedNumberOfRecipes(final int numberOfStreams) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package uk.gov.justice.services.example.cakeshop.it;

import static java.lang.Integer.valueOf;
import static java.lang.System.getProperty;
import static java.util.Optional.empty;
import static java.util.Optional.of;
import static java.util.UUID.randomUUID;
Expand All @@ -8,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.test.utils.common.host.TestHostProvider.getHost;

import uk.gov.justice.services.eventsourcing.repository.jdbc.event.Event;
import uk.gov.justice.services.eventsourcing.repository.jdbc.event.PublishedEvent;
Expand All @@ -16,7 +19,8 @@
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.example.cakeshop.it.helpers.SystemCommandMBeanClient;
import uk.gov.justice.services.jmx.system.command.client.SystemCommanderClient;
import uk.gov.justice.services.jmx.system.command.client.SystemCommanderClientFactory;
import uk.gov.justice.services.test.utils.core.messaging.Poller;
import uk.gov.justice.services.test.utils.events.TestEventInserter;
import uk.gov.justice.services.test.utils.persistence.DatabaseCleaner;
Expand Down Expand Up @@ -46,7 +50,10 @@ public class RebuildIT {

private final Poller poller = new Poller();

private final SystemCommandMBeanClient systemCommandMBeanClient = new SystemCommandMBeanClient();
private static final String HOST = getHost();
private static final int PORT = valueOf(getProperty("random.management.port"));

private final SystemCommanderClientFactory systemCommanderClientFactory = new SystemCommanderClientFactory();

@Before
public void before() throws Exception {
Expand Down Expand Up @@ -97,7 +104,10 @@ public void shouldRenumberTheEventLogTableAndRebuldPublishedEvents() throws Exce
}

private void invokeRebuild() throws Exception {
systemCommandMBeanClient.getMbeanProxy().runCommand(new RebuildCommand());

try(final SystemCommanderClient systemCommanderClient = systemCommanderClientFactory.create(HOST, PORT)) {
systemCommanderClient.getRemote().call(new RebuildCommand());
}
}

private List<PublishedEvent> getPublishedEvents() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@

import static com.jayway.awaitility.Awaitility.await;
import static com.jayway.jsonassert.JsonAssert.with;
import static java.lang.Integer.valueOf;
import static java.lang.String.format;
import static java.lang.System.getProperty;
import static java.util.Optional.empty;
import static java.util.Optional.of;
import static java.util.UUID.randomUUID;
Expand All @@ -11,25 +13,22 @@
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.core.IsCollectionContaining.hasItem;
import static org.slf4j.LoggerFactory.getLogger;
import static uk.gov.justice.services.test.utils.common.host.TestHostProvider.getHost;
import static uk.gov.justice.services.test.utils.core.matchers.HttpStatusCodeMatcher.isStatus;

import uk.gov.justice.services.example.cakeshop.it.helpers.ApiResponse;
import uk.gov.justice.services.example.cakeshop.it.helpers.CommandSender;
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.example.cakeshop.it.helpers.SystemCommandMBeanClient;
import uk.gov.justice.services.jmx.command.SystemCommanderMBean;
import uk.gov.justice.services.jmx.system.command.client.SystemCommanderClient;
import uk.gov.justice.services.jmx.system.command.client.SystemCommanderClientFactory;
import uk.gov.justice.services.management.shuttering.command.ShutterSystemCommand;
import uk.gov.justice.services.management.shuttering.command.UnshutterSystemCommand;

import java.io.IOException;
import java.util.Optional;

import javax.management.InstanceNotFoundException;
import javax.management.IntrospectionException;
import javax.management.MalformedObjectNameException;
import javax.management.ReflectionException;
import javax.ws.rs.client.Client;
import javax.ws.rs.core.Response.Status;

Expand All @@ -50,7 +49,10 @@ public class ShutteringIT {
private Querier querier;
private CommandSender commandSender;

private final SystemCommandMBeanClient systemCommandMBeanClient = new SystemCommandMBeanClient();
private static final String HOST = getHost();
private static final int PORT = valueOf(getProperty("random.management.port"));

private final SystemCommanderClientFactory systemCommanderClientFactory = new SystemCommanderClientFactory();

@Before
public void before() {
Expand All @@ -60,23 +62,25 @@ public void before() {
}

@After
public void cleanup() throws MalformedObjectNameException, IntrospectionException, ReflectionException, InstanceNotFoundException, IOException {
public void cleanup() throws Exception {
client.close();

final SystemCommanderMBean systemCommanderMBean = systemCommandMBeanClient.getMbeanProxy();
//invoke unshuttering - Always ensure unshutter is invoked as we cannot guarantee order of execution for other Cakeshop IT's
try (final SystemCommanderClient systemCommanderClient = systemCommanderClientFactory.create(HOST, PORT)) {

//invoke unshuttering - Always ensure unshutter is invoked as we cannot guarantee order of execution for other Cakeeshop IT's
systemCommanderMBean.runCommand(new UnshutterSystemCommand());
systemCommandMBeanClient.close();
systemCommanderClient
.getRemote()
.call(new UnshutterSystemCommand());
}
}

@Test
public void shouldNotReturnRecipesAfterShuttering() throws Exception {

final SystemCommanderMBean systemCommanderMBean = systemCommandMBeanClient.getMbeanProxy();

//invoke shuttering
systemCommanderMBean.runCommand(new ShutterSystemCommand());
try (final SystemCommanderClient systemCommanderClient = systemCommanderClientFactory.create(HOST, PORT)) {
systemCommanderClient.getRemote().call(new ShutterSystemCommand());
}

//add 2 recipes
final String recipeId = addRecipe(MARBLE_CAKE);
Expand All @@ -91,25 +95,28 @@ public void shouldNotReturnRecipesAfterShuttering() throws Exception {
@Test
public void shouldQueryForRecipesAfterUnShuttering() throws Exception {

final SystemCommanderMBean systemCommanderMBean = systemCommandMBeanClient.getMbeanProxy();
try (final SystemCommanderClient systemCommanderClient = systemCommanderClientFactory.create(HOST, PORT)) {

//invoke shuttering
systemCommanderMBean.runCommand(new ShutterSystemCommand());
final SystemCommanderMBean systemCommander = systemCommanderClient.getRemote();

//add more recipes
final String recipeId = addRecipe(MARBLE_CAKE);
final String recipeId2 = addRecipe(CARROT_CAKE);
//invoke shuttering
systemCommander.call(new ShutterSystemCommand());

Thread.sleep(5000L);
//add more recipes
final String recipeId = addRecipe(MARBLE_CAKE);
final String recipeId2 = addRecipe(CARROT_CAKE);

//check recipes have not been added due to shuttering
verifyRecipeAdded(recipeId, recipeId2, null, null, false, NOT_FOUND);
Thread.sleep(5000L);

//check recipes have not been added due to shuttering
verifyRecipeAdded(recipeId, recipeId2, null, null, false, NOT_FOUND);

//invoke unshuttering
systemCommanderMBean.runCommand(new UnshutterSystemCommand());
//invoke unshuttering
systemCommander.call(new UnshutterSystemCommand());

////check new recipes have been added successfully after unshuttering
verifyRecipeAdded(recipeId, recipeId2, MARBLE_CAKE, CARROT_CAKE, true, OK);
//check new recipes have been added successfully after unshuttering
verifyRecipeAdded(recipeId, recipeId2, MARBLE_CAKE, CARROT_CAKE, true, OK);
}
}

private void verifyRecipeAdded(final String recipeId,
Expand Down
Loading

0 comments on commit 909e93c

Please sign in to comment.