| 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.spi.ILoggingEvent; |
| 20 |
|
import org.testng.annotations.AfterMethod; |
| 21 |
|
import org.testng.annotations.BeforeTest; |
| 22 |
|
import org.testng.annotations.Test; |
| 23 |
|
import uk.co.gidley.jmxmonitor.uk.co.gidley.testAppender.TestAppender; |
| 24 |
|
|
| 25 |
|
import javax.management.InstanceAlreadyExistsException; |
| 26 |
|
import javax.management.MBeanRegistrationException; |
| 27 |
|
import javax.management.MBeanServer; |
| 28 |
|
import javax.management.MalformedObjectNameException; |
| 29 |
|
import javax.management.NotCompliantMBeanException; |
| 30 |
|
import javax.management.ObjectInstance; |
| 31 |
|
import javax.management.ObjectName; |
| 32 |
|
import java.lang.management.ManagementFactory; |
| 33 |
|
import java.util.List; |
| 34 |
|
|
| 35 |
|
import static org.hamcrest.Matchers.equalTo; |
| 36 |
|
import static org.hamcrest.MatcherAssert.assertThat; |
| 37 |
|
|
| 38 |
|
|
| 39 |
|
|
| 40 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (25) |
Complexity: 6 |
Complexity Density: 0.35 |
|
| 41 |
|
public class MultiNamedMBeanTest extends BaseMonitoringTest { |
| 42 |
|
private ObjectInstance ping1; |
| 43 |
|
private ObjectInstance ping2; |
| 44 |
|
|
| 45 |
|
|
| 46 |
|
|
| 47 |
|
|
| 48 |
|
|
| 49 |
|
|
| 50 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (14) |
Complexity: 3 |
Complexity Density: 0.3 |
1
PASS
|
|
| 51 |
1
|
@Test... |
| 52 |
|
public void TestMultiNamedMBean() throws InterruptedException { |
| 53 |
|
|
| 54 |
1
|
List<ILoggingEvent> events = TestAppender.getEvents(); |
| 55 |
|
|
| 56 |
1
|
boolean ping1Found = false; |
| 57 |
1
|
boolean ping2Found = false; |
| 58 |
|
|
| 59 |
1
|
for (ILoggingEvent event : events) { |
| 60 |
2
|
if (event.getFormattedMessage().startsWith("Ping 1")) { |
| 61 |
1
|
ping1Found = true; |
| 62 |
|
} |
| 63 |
2
|
if (event.getFormattedMessage().startsWith("Ping 2")) { |
| 64 |
1
|
ping2Found = true; |
| 65 |
|
} |
| 66 |
|
} |
| 67 |
|
|
| 68 |
1
|
assertThat(ping1Found, equalTo(true)); |
| 69 |
1
|
assertThat(ping2Found, equalTo(true)); |
| 70 |
|
} |
| 71 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 72 |
1
|
@Override... |
| 73 |
|
public String getConfiguration() { |
| 74 |
1
|
return "src/test/resources/monitoring/MultiNamedMBeanConfiguration.properties"; |
| 75 |
|
} |
| 76 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 77 |
548
|
@Override... |
| 78 |
|
public int waitForEvents() { |
| 79 |
548
|
return 2; |
| 80 |
|
} |
| 81 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (5) |
Complexity: 1 |
Complexity Density: 0.2 |
|
| 82 |
1
|
@Override... |
| 83 |
|
public void registerTestMBeans() throws MalformedObjectNameException, MBeanRegistrationException, InstanceAlreadyExistsException, NotCompliantMBeanException { |
| 84 |
1
|
MBeanServer mBeanServer = ManagementFactory.getPlatformMBeanServer(); |
| 85 |
|
|
| 86 |
1
|
ObjectName bean1 = new ObjectName("uk.co.gidley.jmxmonitor:type=Bean1[guff]"); |
| 87 |
1
|
ObjectName bean2 = new ObjectName("uk.co.gidley.jmxmonitor:type=Bean1[guff2]"); |
| 88 |
1
|
ping1 = mBeanServer.registerMBean(new Ping("1"), bean1); |
| 89 |
1
|
ping2 = mBeanServer.registerMBean(new Ping("2"), bean2); |
| 90 |
|
} |
| 91 |
|
|
|
|
|
| - |
Uncovered Elements: 0 (0) |
Complexity: 0 |
Complexity Density: - |
|
| 92 |
|
public interface PingMBean { |
| 93 |
|
|
| 94 |
|
public String getDiscriminator(); |
| 95 |
|
|
| 96 |
|
public void setDiscriminator(String discriminator); |
| 97 |
|
|
| 98 |
|
public Boolean getPing(); |
| 99 |
|
} |
| 100 |
|
|
|
|
|
| 75% |
Uncovered Elements: 2 (8) |
Complexity: 4 |
Complexity Density: 1 |
|
| 101 |
|
public class Ping implements PingMBean { |
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 102 |
2
|
private Ping(String discriminator) {... |
| 103 |
2
|
this.discriminator = discriminator; |
| 104 |
|
} |
| 105 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 106 |
6
|
@Override... |
| 107 |
|
public String getDiscriminator() { |
| 108 |
6
|
return discriminator; |
| 109 |
|
} |
| 110 |
|
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 111 |
0
|
@Override... |
| 112 |
|
public void setDiscriminator(String discriminator) { |
| 113 |
0
|
this.discriminator = discriminator; |
| 114 |
|
} |
| 115 |
|
|
| 116 |
|
private String discriminator; |
| 117 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 118 |
6
|
@Override... |
| 119 |
|
public Boolean getPing() { |
| 120 |
6
|
return true; |
| 121 |
|
} |
| 122 |
|
} |
| 123 |
|
} |