2222import java .lang .System .Logger ;
2323import java .nio .file .Files ;
2424import java .nio .file .Path ;
25+ import java .time .Duration ;
2526import java .util .List ;
2627import java .util .Properties ;
2728import java .util .Set ;
2829import java .util .concurrent .TimeUnit ;
2930
30- import javax .management .JMException ;
3131import javax .management .MBeanServerConnection ;
3232import javax .management .ObjectName ;
3333import javax .management .remote .JMXConnector ;
@@ -65,10 +65,11 @@ public class MonitoringTest {
6565 @ AfterEach
6666 void deleteFiles () throws Exception {
6767 if (jmxConnector != null ) {
68+ LOG .log (INFO , () -> "Closing JMX Connector: " + jmxConnector );
6869 try {
6970 jmxConnector .close ();
7071 } catch (Exception e ) {
71- LOG .log (ERROR , e );
72+ LOG .log (ERROR , "JMX Connector close failed!" , e );
7273 }
7374 }
7475 if (gfEmbeddedProcess != null && gfEmbeddedProcess .isAlive ()) {
@@ -87,6 +88,7 @@ void testJmxMonitoringWithFlashlightAgent() throws Exception {
8788 assertTrue (gfEmbeddedProcess .isAlive (), "gf is alive" );
8889
8990 jmxConnector = getJMXConnector ();
91+ LOG .log (INFO , () -> "Connecting with JMX Connector: " + jmxConnector );
9092 assertNotNull (jmxConnector , "JMX Connector" );
9193 jmxConnector .connect ();
9294 MBeanServerConnection connection = jmxConnector .getMBeanServerConnection ();
@@ -141,7 +143,7 @@ private String getJmxUrl() throws Exception {
141143 * Find GlassFish process by looking for our jar
142144 */
143145 private VirtualMachineDescriptor findVirtualMachineDescriptor () throws Exception {
144- return waitFor ("Virtual machine descriptor" , () -> {
146+ return waitFor (Duration . ofSeconds ( 10L ), "Virtual machine descriptor" , () -> {
145147 for (VirtualMachineDescriptor vmd : VirtualMachine .list ()) {
146148 if (vmd .displayName ().contains ("glassfish-embedded" )) {
147149 LOG .log (INFO , () -> "Detected virtual machine descriptor: " + vmd );
@@ -153,13 +155,22 @@ private VirtualMachineDescriptor findVirtualMachineDescriptor() throws Exception
153155 }
154156
155157 private void bootAmx (MBeanServerConnection connection ) throws Exception {
158+ LOG .log (INFO , "Booting AMX!" );
156159 ObjectName bootAMXObjectName = new ObjectName ("amx-support:type=boot-amx" );
157- waitFor ("bootAMX" , () -> connection .isRegistered (bootAMXObjectName ) ? true : null );
158- assertNotNull (connection .invoke (bootAMXObjectName , "bootAMX" , null , null ), "bootAMX operation" );
160+ waitFor (Duration .ofSeconds (10L ), "bootAMX" , () -> {
161+ final boolean registered = connection .isRegistered (bootAMXObjectName );
162+ LOG .log (INFO , () -> "bootAMX registered: " + registered );
163+ return registered ? true : null ;
164+ });
165+ LOG .log (INFO , "Invoking bootAMX..." );
166+ Object response = connection .invoke (bootAMXObjectName , "bootAMX" , null , null );
167+ LOG .log (INFO , () -> "AMX booted: " + response );
168+ assertNotNull (response , "bootAMX operation" );
159169 }
160170
161- private void verifyMonitoringMBeans (final MBeanServerConnection connection ) throws InterruptedException , IOException , JMException {
162- Set <ObjectName > requestBeans = waitFor ("equest-mon bean" , () -> {
171+ private void verifyMonitoringMBeans (final MBeanServerConnection connection ) throws Exception {
172+ LOG .log (INFO , () -> "Retrieving monitor data using connection: " + connection );
173+ Set <ObjectName > requestBeans = waitFor (Duration .ofSeconds (10L ), "equest-mon bean" , () -> {
163174 Set <ObjectName > result = connection .queryNames (new ObjectName ("amx:type=request-mon,*" ), null );
164175 return result .isEmpty () ? null : result ;
165176 });
0 commit comments