Skip to content

Commit

Permalink
Update to use test JMX client
Browse files Browse the repository at this point in the history
  • Loading branch information
amckenzie committed Jul 18, 2019
1 parent a190fec commit e968235
Show file tree
Hide file tree
Showing 8 changed files with 70 additions and 42 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 @@ -173,6 +173,12 @@
<version>${framework.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>uk.gov.justice.services</groupId>
<artifactId>test-utils-jmx</artifactId>
<version>${framework.version}</version>
<scope>test</scope>
</dependency>
</dependencies>

<build>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@
import uk.gov.justice.services.example.cakeshop.it.helpers.RestEasyClientFactory;
import uk.gov.justice.services.jmx.api.command.CatchupCommand;
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.jmx.system.command.client.TestSystemCommanderClientFactory;
import uk.gov.justice.services.jmx.system.command.client.connection.JmxParameters;
import uk.gov.justice.services.jmx.system.command.client.connection.JmxParametersBuilder;
import uk.gov.justice.services.test.utils.core.messaging.Poller;
import uk.gov.justice.services.test.utils.persistence.DatabaseCleaner;
Expand Down Expand Up @@ -55,8 +56,7 @@ public class CatchupPerformanceIT {
private static final String HOST = getHost();
private static final int PORT = valueOf(getProperty("random.management.port"));


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

private final Poller longPoller = new Poller(1200, 1000L);
Expand Down Expand Up @@ -167,13 +167,15 @@ private void addEventsToEventLog(final int numberOfStreams, final int numberOfEv

private void runCatchup() throws Exception {

final JmxParametersBuilder jmxParameters = jmxParameters()
final String contextName = "example-single";
final JmxParameters jmxParameters = jmxParameters()
.withHost(HOST)
.withPort(PORT);
.withPort(PORT)
.build();

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

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@
import uk.gov.justice.services.example.cakeshop.it.helpers.RestEasyClientFactory;
import uk.gov.justice.services.jmx.api.command.IndexerCatchupCommand;
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.jmx.system.command.client.TestSystemCommanderClientFactory;
import uk.gov.justice.services.jmx.system.command.client.connection.JmxParameters;
import uk.gov.justice.services.jmx.system.command.client.connection.JmxParametersBuilder;
import uk.gov.justice.services.test.utils.core.messaging.Poller;
import uk.gov.justice.services.test.utils.persistence.DatabaseCleaner;
Expand Down Expand Up @@ -58,7 +59,7 @@ public class IndexerCatchUpIT {
private static final String HOST = getHost();
private static final int PORT = valueOf(getProperty("random.management.port"));

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

private final Poller longPoller = new Poller(1200, 1000L);
Expand Down Expand Up @@ -162,13 +163,15 @@ private List<UUID> addEventsToEventLog(final int numberOfStreams) throws Invalid

private void runCatchup() throws Exception {

final JmxParametersBuilder jmxParameters = jmxParameters()
final String contextName = "example-single";
final JmxParameters jmxParameters = jmxParameters()
.withHost(HOST)
.withPort(PORT);
.withPort(PORT)
.build();

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

systemCommanderClient.getRemote().call(new IndexerCatchupCommand());
systemCommanderClient.getRemote(contextName).call(new IndexerCatchupCommand());
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@
import uk.gov.justice.services.jmx.api.command.SystemCommand;
import uk.gov.justice.services.jmx.api.command.UnshutterSystemCommand;
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.jmx.system.command.client.connection.JmxParametersBuilder;
import uk.gov.justice.services.jmx.system.command.client.TestSystemCommanderClientFactory;
import uk.gov.justice.services.jmx.system.command.client.connection.JmxParameters;

import java.util.List;

Expand All @@ -29,18 +29,20 @@ public class ListSystemCommandsIT {
private static final int PORT = valueOf(getProperty("random.management.port"));


private final SystemCommanderClientFactory systemCommanderClientFactory = new SystemCommanderClientFactory();
private final TestSystemCommanderClientFactory testSystemCommanderClientFactory = new TestSystemCommanderClientFactory();

@Test
public void shouldListAllSystemCommands() throws Exception {

final JmxParametersBuilder jmxParameters = jmxParameters()
final String contextName = "example-single";
final JmxParameters jmxParameters = jmxParameters()
.withHost(HOST)
.withPort(PORT);
.withPort(PORT)
.build();

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

final List<SystemCommand> systemCommands = systemCommanderClient.getRemote().listCommands();
final List<SystemCommand> systemCommands = systemCommanderClient.getRemote(contextName).listCommands();

assertThat(systemCommands.size(), is(6));
assertThat(systemCommands, hasItem(new PingSystemCommand()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@
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.SystemCommanderClientFactory;
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.jmx.system.command.client.connection.JmxParametersBuilder;
import uk.gov.justice.services.test.utils.core.messaging.Poller;
import uk.gov.justice.services.test.utils.events.TestEventInserter;
Expand Down Expand Up @@ -55,7 +56,7 @@ public class RebuildIT {
private static final String HOST = getHost();
private static final int PORT = valueOf(getProperty("random.management.port"));

private final SystemCommanderClientFactory systemCommanderClientFactory = new SystemCommanderClientFactory();
private final TestSystemCommanderClientFactory testSystemCommanderClientFactory = new TestSystemCommanderClientFactory();

@Before
public void before() throws Exception {
Expand Down Expand Up @@ -107,12 +108,14 @@ public void shouldRenumberTheEventLogTableAndRebuldPublishedEvents() throws Exce

private void invokeRebuild() throws Exception {

final JmxParametersBuilder jmxParameters = jmxParameters()
final String contextName = "example-single";
final JmxParameters jmxParameters = jmxParameters()
.withHost(HOST)
.withPort(PORT);
.withPort(PORT)
.build();

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@
import uk.gov.justice.services.jmx.api.command.UnshutterSystemCommand;
import uk.gov.justice.services.jmx.api.mbean.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.jmx.system.command.client.TestSystemCommanderClientFactory;
import uk.gov.justice.services.jmx.system.command.client.connection.JmxParameters;
import uk.gov.justice.services.jmx.system.command.client.connection.JmxParametersBuilder;
import uk.gov.justice.services.test.utils.persistence.DatabaseCleaner;

Expand Down Expand Up @@ -55,7 +56,7 @@ public class ShutteringIT {
private static final String HOST = getHost();
private static final int PORT = valueOf(getProperty("random.management.port"));

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

@Before
Expand All @@ -74,13 +75,15 @@ public void cleanup() throws Exception {

//invoke unshuttering - Always ensure unshutter is invoked as we cannot guarantee order of execution for other Cakeshop ITs

final JmxParametersBuilder jmxParameters = jmxParameters()
final String contextName = "example-single";
final JmxParameters jmxParameters = jmxParameters()
.withHost(HOST)
.withPort(PORT);
try (final SystemCommanderClient systemCommanderClient = systemCommanderClientFactory.create(jmxParameters)) {
.withPort(PORT)
.build();
try (final SystemCommanderClient systemCommanderClient = testSystemCommanderClientFactory.create(jmxParameters)) {

systemCommanderClient
.getRemote()
.getRemote(contextName)
.call(new UnshutterSystemCommand());
}
}
Expand All @@ -89,11 +92,13 @@ public void cleanup() throws Exception {
public void shouldNotReturnRecipesAfterShuttering() throws Exception {

//invoke shuttering
final JmxParametersBuilder jmxParameters = jmxParameters()
final String contextName = "example-single";
final JmxParameters jmxParameters = jmxParameters()
.withHost(HOST)
.withPort(PORT);
try (final SystemCommanderClient systemCommanderClient = systemCommanderClientFactory.create(jmxParameters)) {
systemCommanderClient.getRemote().call(new ShutterSystemCommand());
.withPort(PORT)
.build();
try (final SystemCommanderClient systemCommanderClient = testSystemCommanderClientFactory.create(jmxParameters)) {
systemCommanderClient.getRemote(contextName).call(new ShutterSystemCommand());
}

//add 2 recipes
Expand All @@ -109,12 +114,14 @@ public void shouldNotReturnRecipesAfterShuttering() throws Exception {
@Test
public void shouldQueryForRecipesAfterUnShuttering() throws Exception {

final JmxParametersBuilder jmxParameters = jmxParameters()
final String contextName = "example-single";
final JmxParameters jmxParameters = jmxParameters()
.withHost(HOST)
.withPort(PORT);
try (final SystemCommanderClient systemCommanderClient = systemCommanderClientFactory.create(jmxParameters)) {
.withPort(PORT)
.build();
try (final SystemCommanderClient systemCommanderClient = testSystemCommanderClientFactory.create(jmxParameters)) {

final SystemCommanderMBean systemCommander = systemCommanderClient.getRemote();
final SystemCommanderMBean systemCommander = systemCommanderClient.getRemote(contextName);

//invoke shuttering
systemCommander.call(new ShutterSystemCommand());
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 @@ -75,6 +75,11 @@
<classifier>yaml</classifier>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>uk.gov.justice.services</groupId>
<artifactId>jmx-api</artifactId>
<version>${framework.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.0.1</framework-api.version>
<framework.version>6.0.0-RC7</framework.version>
<event-store.version>2.0.0-RC7</event-store.version>
<framework-generators.version>2.0.0-RC5</framework-generators.version>
<framework.version>6.0.0-RC8</framework.version>
<event-store.version>2.0.0-RC8</event-store.version>
<framework-generators.version>2.0.0-RC6</framework-generators.version>
<file.service.version>1.17.10</file.service.version>

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

0 comments on commit e968235

Please sign in to comment.