changeset 2300:6a578d5a1648

Fix Byteman helper tests Reviewed-by: jerboaa Review-thread: http://icedtea.classpath.org/pipermail/thermostat/2016-May/018840.html
author Elliott Baron <ebaron@redhat.com>
date Wed, 18 May 2016 12:13:13 -0400
parents 08d858358908
children a2ac39aa092e
files vm-byteman/byteman-helper/src/main/java/org/jboss/byteman/thermostat/helper/ThermostatHelper.java vm-byteman/byteman-helper/src/test/java/org/jboss/byteman/thermostat/helper/ThermostatHelperTest.java
diffstat 2 files changed, 16 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/vm-byteman/byteman-helper/src/main/java/org/jboss/byteman/thermostat/helper/ThermostatHelper.java	Tue May 17 10:01:03 2016 -0400
+++ b/vm-byteman/byteman-helper/src/main/java/org/jboss/byteman/thermostat/helper/ThermostatHelper.java	Wed May 18 12:13:13 2016 -0400
@@ -50,8 +50,12 @@
  */
 public class ThermostatHelper extends Helper {
     
-    private static Transport transport = new TransportFactory().create();
-    static {
+    // Lock to synchronize initialization of transport between instances
+    private static final Object transportLock = new Object();
+    private static Transport transport = null;
+    
+    static void initTransport() {
+        transport = new TransportFactory().create();
         Runtime.getRuntime().addShutdownHook(new Thread(new Runnable() {
             @Override
             public void run() {
@@ -65,6 +69,12 @@
      */
     protected ThermostatHelper(Rule rule) {
         super(rule);
+        // Initialize transport if not yet done
+        synchronized (transportLock) {
+            if (transport == null) {
+                initTransport();
+            }
+        }
     }
     
     public void send(String marker, String key, String value) {
@@ -104,7 +114,9 @@
     
     // For testing purposes
     static void setTransport(Transport transport) {
-        ThermostatHelper.transport = transport;
+        synchronized (transportLock) {
+            ThermostatHelper.transport = transport;
+        }
     }
 
 }
--- a/vm-byteman/byteman-helper/src/test/java/org/jboss/byteman/thermostat/helper/ThermostatHelperTest.java	Tue May 17 10:01:03 2016 -0400
+++ b/vm-byteman/byteman-helper/src/test/java/org/jboss/byteman/thermostat/helper/ThermostatHelperTest.java	Wed May 18 12:13:13 2016 -0400
@@ -70,7 +70,7 @@
     
     @After
     public void teardown() {
-        ThermostatHelper.setTransport(new TransportFactory().create());
+        ThermostatHelper.setTransport(null);
     }
     
     @Test