| 1 |
|
|
| 2 |
|
|
| 3 |
|
|
| 4 |
|
|
| 5 |
|
|
| 6 |
|
|
| 7 |
|
|
| 8 |
|
|
| 9 |
|
|
| 10 |
|
|
| 11 |
|
|
| 12 |
|
|
| 13 |
|
|
| 14 |
|
|
| 15 |
|
|
| 16 |
|
|
| 17 |
|
package uk.co.gidley.jmxmonitor.monitoring; |
| 18 |
|
|
| 19 |
|
import ch.qos.logback.classic.BasicConfigurator; |
| 20 |
|
import ch.qos.logback.classic.LoggerContext; |
| 21 |
|
import ch.qos.logback.classic.joran.JoranConfigurator; |
| 22 |
|
import ch.qos.logback.core.joran.spi.JoranException; |
| 23 |
|
import ch.qos.logback.core.util.StatusPrinter; |
| 24 |
|
import org.slf4j.Logger; |
| 25 |
|
import org.slf4j.LoggerFactory; |
| 26 |
|
import org.testng.annotations.AfterMethod; |
| 27 |
|
import org.testng.annotations.BeforeMethod; |
| 28 |
|
import uk.co.gidley.jmxmonitor.RegistryManager; |
| 29 |
|
import uk.co.gidley.jmxmonitor.services.InitialisationException; |
| 30 |
|
import uk.co.gidley.jmxmonitor.services.ThreadManager; |
| 31 |
|
import uk.co.gidley.jmxmonitor.uk.co.gidley.testAppender.TestAppender; |
| 32 |
|
|
| 33 |
|
import javax.management.InstanceAlreadyExistsException; |
| 34 |
|
import javax.management.MBeanRegistrationException; |
| 35 |
|
import javax.management.MalformedObjectNameException; |
| 36 |
|
import javax.management.NotCompliantMBeanException; |
| 37 |
|
|
| 38 |
|
import static org.hamcrest.MatcherAssert.assertThat; |
| 39 |
|
|
| 40 |
|
|
| 41 |
|
|
| 42 |
|
|
|
|
|
| 93.3% |
Uncovered Elements: 2 (30) |
Complexity: 6 |
Complexity Density: 0.25 |
|
| 43 |
|
public abstract class BaseMonitoringTest { |
| 44 |
|
private static final Logger logger = LoggerFactory.getLogger(BaseMonitoringTest.class); |
| 45 |
|
private RegistryManager registryManager; |
| 46 |
|
private Thread jmxMonitorThread; |
| 47 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (18) |
Complexity: 3 |
Complexity Density: 0.21 |
|
| 48 |
2
|
@BeforeMethod... |
| 49 |
|
public void setup() throws InitialisationException, JoranException, InterruptedException, MalformedObjectNameException, MBeanRegistrationException, InstanceAlreadyExistsException, NotCompliantMBeanException { |
| 50 |
2
|
registryManager = new RegistryManager(getConfiguration()); |
| 51 |
|
|
| 52 |
2
|
registerTestMBeans(); |
| 53 |
2
|
jmxMonitorThread = new Thread(new JmxRunner(), "JmxRunner"); |
| 54 |
|
|
| 55 |
2
|
jmxMonitorThread.start(); |
| 56 |
4
|
while (!registryManager.isReadyToRun()) { |
| 57 |
2
|
Thread.sleep(100); |
| 58 |
|
} |
| 59 |
|
|
| 60 |
2
|
LoggerContext lc = (LoggerContext) LoggerFactory.getILoggerFactory(); |
| 61 |
2
|
JoranConfigurator configurator = new JoranConfigurator(); |
| 62 |
2
|
configurator.setContext(lc); |
| 63 |
2
|
lc.reset(); |
| 64 |
2
|
configurator.doConfigure("src/test/resources/logback-inMemory.xml"); |
| 65 |
2
|
StatusPrinter.printInCaseOfErrorsOrWarnings(lc); |
| 66 |
|
|
| 67 |
|
|
| 68 |
|
|
| 69 |
549
|
while (TestAppender.getEvents().size() < waitForEvents()) { |
| 70 |
547
|
Thread.sleep(100); |
| 71 |
|
} |
| 72 |
|
} |
| 73 |
|
|
| 74 |
|
public abstract String getConfiguration(); |
| 75 |
|
|
| 76 |
|
public abstract int waitForEvents(); |
| 77 |
|
|
| 78 |
|
public abstract void registerTestMBeans() throws MalformedObjectNameException, MBeanRegistrationException, InstanceAlreadyExistsException, NotCompliantMBeanException; |
| 79 |
|
|
|
|
|
| 80% |
Uncovered Elements: 2 (10) |
Complexity: 3 |
Complexity Density: 0.3 |
|
| 80 |
2
|
@AfterMethod... |
| 81 |
|
public void tearDown() { |
| 82 |
2
|
LoggerContext lc = (LoggerContext) LoggerFactory.getILoggerFactory(); |
| 83 |
2
|
BasicConfigurator.configure(lc); |
| 84 |
2
|
TestAppender.reset(); |
| 85 |
2
|
try { |
| 86 |
2
|
ThreadManager threadManager = registryManager.getRegistry().getService(ThreadManager.class); |
| 87 |
2
|
threadManager.stop(); |
| 88 |
|
} catch (IllegalStateException e) { |
| 89 |
|
|
| 90 |
|
} |
| 91 |
2
|
try { |
| 92 |
|
|
| 93 |
2
|
jmxMonitorThread.join(); |
| 94 |
|
} catch (InterruptedException e) { |
| 95 |
0
|
logger.error("{}", e); |
| 96 |
0
|
throw new RuntimeException(e); |
| 97 |
|
} |
| 98 |
|
} |
| 99 |
|
|
|
|
|
| 60% |
Uncovered Elements: 2 (5) |
Complexity: 2 |
Complexity Density: 0.5 |
|
| 100 |
|
private class JmxRunner implements Runnable { |
|
|
|
| 50% |
Uncovered Elements: 2 (4) |
Complexity: 2 |
Complexity Density: 0.5 |
|
| 101 |
2
|
@Override... |
| 102 |
|
public void run() { |
| 103 |
2
|
try { |
| 104 |
2
|
registryManager.start(); |
| 105 |
|
} catch (InitialisationException e) { |
| 106 |
0
|
logger.error("{}", e); |
| 107 |
0
|
throw new RuntimeException(e); |
| 108 |
|
} |
| 109 |
|
} |
| 110 |
|
} |
| 111 |
|
} |