-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add integration test for event catchup
- Loading branch information
amckenzie
committed
Apr 1, 2019
1 parent
47d9552
commit cb52fb4
Showing
5 changed files
with
98 additions
and
9 deletions.
There are no files selected for viewing
22 changes: 22 additions & 0 deletions
22
.../example-it/src/test/java/uk/gov/justice/services/example/cakeshop/it/EventCatchupIT.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
67 changes: 67 additions & 0 deletions
67
...it/src/test/java/uk/gov/justice/services/example/cakeshop/it/helpers/JmxMBeanFactory.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters