Author: ataylor
Date: 2011-03-01 03:16:31 -0500 (Tue, 01 Mar 2011)
New Revision: 10272
Modified:
branches/Branch_2_2_EAP/src/main/org/hornetq/core/client/impl/ServerLocatorImpl.java
branches/Branch_2_2_EAP/src/main/org/hornetq/core/cluster/impl/DiscoveryGroupImpl.java
branches/Branch_2_2_EAP/tests/src/org/hornetq/tests/integration/discovery/DiscoveryTest.java
Log:
fixing unit tests
Modified:
branches/Branch_2_2_EAP/src/main/org/hornetq/core/client/impl/ServerLocatorImpl.java
===================================================================
---
branches/Branch_2_2_EAP/src/main/org/hornetq/core/client/impl/ServerLocatorImpl.java 2011-03-01
03:38:33 UTC (rev 10271)
+++
branches/Branch_2_2_EAP/src/main/org/hornetq/core/client/impl/ServerLocatorImpl.java 2011-03-01
08:16:31 UTC (rev 10272)
@@ -332,7 +332,8 @@
lbAddress,
groupAddress,
discoveryGroupConfiguration.getGroupPort(),
-
discoveryGroupConfiguration.getRefreshTimeout());
+
discoveryGroupConfiguration.getRefreshTimeout(),
+ globalThreadPool);
discoveryGroup.registerListener(this);
Modified:
branches/Branch_2_2_EAP/src/main/org/hornetq/core/cluster/impl/DiscoveryGroupImpl.java
===================================================================
---
branches/Branch_2_2_EAP/src/main/org/hornetq/core/cluster/impl/DiscoveryGroupImpl.java 2011-03-01
03:38:33 UTC (rev 10271)
+++
branches/Branch_2_2_EAP/src/main/org/hornetq/core/cluster/impl/DiscoveryGroupImpl.java 2011-03-01
08:16:31 UTC (rev 10272)
@@ -23,6 +23,7 @@
import java.util.Iterator;
import java.util.List;
import java.util.Map;
+import java.util.concurrent.ExecutorService;
import org.hornetq.api.core.HornetQBuffer;
import org.hornetq.api.core.HornetQBuffers;
@@ -35,6 +36,7 @@
import org.hornetq.core.logging.Logger;
import org.hornetq.core.server.management.Notification;
import org.hornetq.core.server.management.NotificationService;
+import org.hornetq.utils.Future;
import org.hornetq.utils.TypedProperties;
/**
@@ -81,12 +83,15 @@
private NotificationService notificationService;
+ private final ExecutorService globalThreadPool;
+
public DiscoveryGroupImpl(final String nodeID,
final String name,
final InetAddress localBindAddress,
final InetAddress groupAddress,
final int groupPort,
- final long timeout) throws Exception
+ final long timeout,
+ ExecutorService globalThreadPool) throws Exception
{
this.nodeID = nodeID;
@@ -99,6 +104,8 @@
this.groupAddress = groupAddress;
this.groupPort = groupPort;
+
+ this.globalThreadPool = globalThreadPool;
}
public void setNotificationService(final NotificationService notificationService)
@@ -170,15 +177,22 @@
waitLock.notify();
}
- try
+ globalThreadPool.execute(new Runnable()
{
- thread.interrupt();
- thread.join();
- }
- catch (InterruptedException e)
- {
- }
+ public void run()
+ {
+ try
+ {
+ thread.interrupt();
+ thread.join();
+ }
+ catch (InterruptedException e)
+ {
+ }
+ }
+ });
+ waitForRunnablesToComplete();
socket.close();
@@ -431,4 +445,19 @@
return changed;
}
+
+ private void waitForRunnablesToComplete()
+ {
+ // Wait for any create objects runnable to complete
+ Future future = new Future();
+
+ globalThreadPool.execute(future);
+
+ boolean ok = future.await(10000);
+
+ if (!ok)
+ {
+ log.warn("Timed out waiting to stop discovery thread");
+ }
+ }
}
Modified:
branches/Branch_2_2_EAP/tests/src/org/hornetq/tests/integration/discovery/DiscoveryTest.java
===================================================================
---
branches/Branch_2_2_EAP/tests/src/org/hornetq/tests/integration/discovery/DiscoveryTest.java 2011-03-01
03:38:33 UTC (rev 10271)
+++
branches/Branch_2_2_EAP/tests/src/org/hornetq/tests/integration/discovery/DiscoveryTest.java 2011-03-01
08:16:31 UTC (rev 10272)
@@ -23,6 +23,7 @@
import java.util.HashMap;
import java.util.List;
import java.util.Map;
+import java.util.concurrent.Executors;
import junit.framework.Assert;
@@ -90,7 +91,8 @@
null,
groupAddress,
groupPort,
- timeout);
+ timeout,
+ Executors.newFixedThreadPool(1));
dg.start();
@@ -176,7 +178,8 @@
localAddress,
groupAddress,
groupPort,
- timeout);
+ timeout,
+ Executors.newFixedThreadPool(1));
dg.start();
@@ -223,7 +226,8 @@
null,
groupAddress,
groupPort,
- timeout);
+ timeout,
+ Executors.newFixedThreadPool(1));
dg.start();
@@ -281,7 +285,8 @@
bg.addConnector(live1);
- DiscoveryGroup dg = new DiscoveryGroupImpl(nodeID, RandomUtil.randomString(), null,
groupAddress, groupPort, timeout);
+ DiscoveryGroup dg = new DiscoveryGroupImpl(nodeID, RandomUtil.randomString(), null,
groupAddress, groupPort, timeout,
+ Executors.newFixedThreadPool(1));
dg.start();
@@ -372,7 +377,8 @@
null,
groupAddress,
port2,
- timeout);
+ timeout,
+ Executors.newFixedThreadPool(1));
dg.start();
@@ -415,7 +421,8 @@
null,
groupAddress2,
port2,
- timeout);
+ timeout,
+ Executors.newFixedThreadPool(1));
dg.start();
@@ -491,7 +498,8 @@
null,
groupAddress1,
groupPort1,
- timeout);
+ timeout,
+ Executors.newFixedThreadPool(1));
dg1.start();
DiscoveryGroup dg2 = new DiscoveryGroupImpl(RandomUtil.randomString(),
@@ -499,7 +507,8 @@
null,
groupAddress2,
groupPort2,
- timeout);
+ timeout,
+ Executors.newFixedThreadPool(1));
dg2.start();
DiscoveryGroup dg3 = new DiscoveryGroupImpl(RandomUtil.randomString(),
@@ -507,7 +516,8 @@
null,
groupAddress3,
groupPort3,
- timeout);
+ timeout,
+ Executors.newFixedThreadPool(1));
dg3.start();
bg1.broadcastConnectors();
@@ -571,7 +581,8 @@
// null,
// groupAddress,
// groupPort,
-// timeout);
+// timeout,
+// Executors.newFixedThreadPool(1));
//
// dg.start();
//
@@ -610,7 +621,8 @@
null,
groupAddress,
groupPort,
- timeout);
+ timeout,
+ Executors.newFixedThreadPool(1));
MyListener listener1 = new MyListener();
MyListener listener2 = new MyListener();
@@ -699,7 +711,8 @@
null,
groupAddress,
groupPort,
- timeout);
+ timeout,
+ Executors.newFixedThreadPool(1));
MyListener listener1 = new MyListener();
dg.registerListener(listener1);
@@ -865,21 +878,24 @@
null,
groupAddress,
groupPort,
- timeout);
+ timeout,
+ Executors.newFixedThreadPool(1));
DiscoveryGroup dg2 = new DiscoveryGroupImpl(RandomUtil.randomString(),
RandomUtil.randomString(),
null,
groupAddress,
groupPort,
- timeout);
+ timeout,
+ Executors.newFixedThreadPool(1));
DiscoveryGroup dg3 = new DiscoveryGroupImpl(RandomUtil.randomString(),
RandomUtil.randomString(),
null,
groupAddress,
groupPort,
- timeout);
+ timeout,
+ Executors.newFixedThreadPool(1));
dg1.start();
dg2.start();
@@ -924,7 +940,8 @@
null,
groupAddress,
groupPort,
- timeout);
+ timeout,
+ Executors.newFixedThreadPool(1));
dg.setNotificationService(notifService);
Assert.assertEquals(0, notifListener.getNotifications().size());