Skip to content

Commit

Permalink
Add integration test for event catchup
Browse files Browse the repository at this point in the history
  • Loading branch information
amckenzie committed Apr 1, 2019
1 parent 47d9552 commit cb52fb4
Show file tree
Hide file tree
Showing 5 changed files with 98 additions and 9 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package uk.gov.justice.services.example.cakeshop.it;

import uk.gov.justice.services.example.cakeshop.it.helpers.JmxMBeanFactory;
import uk.gov.justice.services.jmx.CatchupMBean;

import javax.management.remote.JMXConnector;

import org.junit.Test;

public class EventCatchupIT {

private final JmxMBeanFactory jmxMBeanFactory = new JmxMBeanFactory();

@Test
public void shouldRunCatchup() throws Exception {
try (final JMXConnector jmxConnector = jmxMBeanFactory.createJMXConnector()) {
final CatchupMBean catchupMBean = jmxMBeanFactory.getCatchupMBean(jmxConnector);

catchupMBean.doCatchupRequested();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,11 @@ public void getMbeanOperations(ObjectName objectName, final MBeanServerConnectio
}

public JMXConnector getJMXConnector() throws IOException {
int managementPort = Integer.valueOf(System.getProperty(RANDOM_MANAGEMENT_PORT));
final int managementPort = Integer.valueOf(System.getProperty(RANDOM_MANAGEMENT_PORT));

String urlString =
System.getProperty("jmx.service.url","service:jmx:remote+http://" + HOST + ":" + managementPort);
JMXServiceURL serviceURL = new JMXServiceURL(urlString);
final String defaultUrl = "service:jmx:remote+http://" + HOST + ":" + managementPort;
final String urlString = System.getProperty("jmx.service.url", defaultUrl);
final JMXServiceURL serviceURL = new JMXServiceURL(urlString);

return JMXConnectorFactory.connect(serviceURL, null);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
package uk.gov.justice.services.example.cakeshop.it.helpers;

import static java.lang.String.format;
import static javax.management.JMX.newMBeanProxy;
import static uk.gov.justice.services.test.utils.common.host.TestHostProvider.getHost;

import uk.gov.justice.services.jmx.Catchup;
import uk.gov.justice.services.jmx.CatchupMBean;
import uk.gov.justice.services.jmx.MBeanException;
import uk.gov.justice.services.jmx.ObjectNameFactory;
import uk.gov.justice.services.jmx.Shuttering;
import uk.gov.justice.services.jmx.ShutteringMBean;

import java.io.IOException;

import javax.management.MBeanServerConnection;
import javax.management.ObjectName;
import javax.management.remote.JMXConnector;
import javax.management.remote.JMXConnectorFactory;
import javax.management.remote.JMXServiceURL;

public class JmxMBeanFactory {

private static final String HOST = getHost();
private static final String PORT = System.getProperty("random.management.port");

private static final String DEFAULT_URL = "service:jmx:remote+http://" + HOST + ":" + PORT;

private final ObjectNameFactory objectNameFactory = new ObjectNameFactory();

public JMXConnector createJMXConnector() {

final String url = System.getProperty("jmx.service.url", DEFAULT_URL);
try {
final JMXServiceURL serviceURL = new JMXServiceURL(url);

return JMXConnectorFactory.connect(serviceURL, null);
} catch (final IOException e) {
throw new MBeanException(format("Failed to connect to JMX. URL: '%s'", url), e);
}
}

public CatchupMBean getCatchupMBean(final JMXConnector jmxConnector) {

final ObjectName objectName = objectNameFactory.create("catchup", "type", Catchup.class.getSimpleName());

final MBeanServerConnection connection = getMBeanServerConnection(jmxConnector);
return newMBeanProxy(connection, objectName, CatchupMBean.class, true);
}

public ShutteringMBean getShutteringMBean(final JMXConnector jmxConnector) {

final ObjectName objectName = objectNameFactory.create("shuttering", "type", Shuttering.class.getSimpleName());

final MBeanServerConnection connection = getMBeanServerConnection(jmxConnector);
return newMBeanProxy(connection, objectName, ShutteringMBean.class, true);
}


private MBeanServerConnection getMBeanServerConnection(final JMXConnector jmxConnector) {
try {
return jmxConnector.getMBeanServerConnection();
} catch (final IOException e) {
throw new MBeanException("Failed to connect to MBean server", e);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@
<level name="WARN"/>
</logger>
<logger category="uk.gov.justice">
<level name="WARN"/>
<level name="INFO"/>
</logger>
<root-logger>
<level name="WARN"/>
Expand Down
8 changes: 4 additions & 4 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,12 @@
<properties>
<cpp.repo.name>cake-shop</cpp.repo.name>
<common-bom.version>1.29.0</common-bom.version>
<framework.version>6.0.0-SNAPSHOT</framework.version>
<framework.version>6.0.0-M8</framework.version>
<embedded-artemis.version>1.2.0</embedded-artemis.version>
<event-store.version>2.0.0-SNAPSHOT</event-store.version>
<framework-generators.version>2.0.0-SNAPSHOT</framework-generators.version>
<event-store.version>2.0.0-M8</event-store.version>
<framework-generators.version>2.0.0-M7</framework-generators.version>
<file.service.version>1.17.4</file.service.version>
<framework-api.version>4.0.0-SNAPSHOT</framework-api.version>
<framework-api.version>4.0.0-M5</framework-api.version>
<generator-maven-plugin.version>2.6.2</generator-maven-plugin.version>
<json-schema-catalog.version>1.6.0</json-schema-catalog.version>
<jboss-ejb3-ext-api.version>2.2.0.Final</jboss-ejb3-ext-api.version>
Expand Down

0 comments on commit cb52fb4

Please sign in to comment.