Author: borges
Date: 2011-07-27 13:23:37 -0400 (Wed, 27 Jul 2011)
New Revision: 11052
Modified:
branches/HORNETQ-720_Replication/tests/integration-tests/src/test/java/org/hornetq/tests/integration/cluster/failover/AsynchronousFailoverTest.java
branches/HORNETQ-720_Replication/tests/integration-tests/src/test/java/org/hornetq/tests/integration/cluster/failover/FailBackAutoTest.java
branches/HORNETQ-720_Replication/tests/integration-tests/src/test/java/org/hornetq/tests/util/CountDownSessionFailureListener.java
Log:
Reduce code duplication.
Modified:
branches/HORNETQ-720_Replication/tests/integration-tests/src/test/java/org/hornetq/tests/integration/cluster/failover/AsynchronousFailoverTest.java
===================================================================
---
branches/HORNETQ-720_Replication/tests/integration-tests/src/test/java/org/hornetq/tests/integration/cluster/failover/AsynchronousFailoverTest.java 2011-07-27
16:36:09 UTC (rev 11051)
+++
branches/HORNETQ-720_Replication/tests/integration-tests/src/test/java/org/hornetq/tests/integration/cluster/failover/AsynchronousFailoverTest.java 2011-07-27
17:23:37 UTC (rev 11052)
@@ -15,7 +15,6 @@
import java.util.ArrayList;
import java.util.List;
-import java.util.concurrent.CountDownLatch;
import junit.framework.Assert;
@@ -28,10 +27,10 @@
import org.hornetq.api.core.client.ClientProducer;
import org.hornetq.api.core.client.ClientSession;
import org.hornetq.api.core.client.ServerLocator;
-import org.hornetq.api.core.client.SessionFailureListener;
import org.hornetq.core.client.impl.ClientSessionFactoryInternal;
import org.hornetq.core.client.impl.DelegatingSession;
import org.hornetq.core.logging.Logger;
+import org.hornetq.tests.util.CountDownSessionFailureListener;
import org.hornetq.tests.util.TransportConfigurationUtils;
/**
@@ -47,26 +46,12 @@
{
private static final Logger log = Logger.getLogger(AsynchronousFailoverTest.class);
- private volatile MyListener listener;
+ private volatile CountDownSessionFailureListener listener;
private volatile ClientSessionFactoryInternal sf;
private final Object lockFail = new Object();
- class MyListener implements SessionFailureListener
- {
- CountDownLatch latch = new CountDownLatch(1);
-
- public void connectionFailed(final HornetQException me, boolean failedOver)
- {
- latch.countDown();
- }
-
- public void beforeReconnect(final HornetQException me)
- {
- }
- }
-
public void testNonTransactional() throws Throwable
{
runTest(new TestRunner()
@@ -256,12 +241,10 @@
ClientSession session = sf.createSession(true, true, 0);
- MyListener listener = new MyListener();
+ listener = new CountDownSessionFailureListener();
session.addFailureListener(listener);
- this.listener = listener;
-
ClientProducer producer = session.createProducer(FailoverTestBase.ADDRESS);
final int numMessages = 1000;
@@ -380,15 +363,14 @@
try
{
- MyListener listener = new MyListener();
- this.listener = listener;
boolean retry = false;
final int numMessages = 1000;
session = sf.createSession(false, false);
+ listener = new CountDownSessionFailureListener();
session.addFailureListener(listener);
do
Modified:
branches/HORNETQ-720_Replication/tests/integration-tests/src/test/java/org/hornetq/tests/integration/cluster/failover/FailBackAutoTest.java
===================================================================
---
branches/HORNETQ-720_Replication/tests/integration-tests/src/test/java/org/hornetq/tests/integration/cluster/failover/FailBackAutoTest.java 2011-07-27
16:36:09 UTC (rev 11051)
+++
branches/HORNETQ-720_Replication/tests/integration-tests/src/test/java/org/hornetq/tests/integration/cluster/failover/FailBackAutoTest.java 2011-07-27
17:23:37 UTC (rev 11052)
@@ -20,7 +20,6 @@
import junit.framework.Assert;
-import org.hornetq.api.core.HornetQException;
import org.hornetq.api.core.SimpleString;
import org.hornetq.api.core.TransportConfiguration;
import org.hornetq.api.core.client.ClientConsumer;
@@ -28,12 +27,12 @@
import org.hornetq.api.core.client.ClientProducer;
import org.hornetq.api.core.client.ClientSession;
import org.hornetq.api.core.client.ClientSessionFactory;
-import org.hornetq.api.core.client.SessionFailureListener;
import org.hornetq.core.client.impl.ClientSessionFactoryInternal;
import org.hornetq.core.client.impl.ServerLocatorInternal;
import org.hornetq.core.config.ClusterConnectionConfiguration;
import org.hornetq.core.server.impl.InVMNodeManager;
import org.hornetq.jms.client.HornetQTextMessage;
+import org.hornetq.tests.util.CountDownSessionFailureListener;
import org.hornetq.tests.util.TransportConfigurationUtils;
/**
@@ -80,7 +79,7 @@
ClientSession session = sendAndConsume(sf, true);
- MyListener listener = new MyListener(latch);
+ CountDownSessionFailureListener listener = new
CountDownSessionFailureListener(latch);
session.addFailureListener(listener);
@@ -104,7 +103,7 @@
final CountDownLatch latch2 = new CountDownLatch(1);
- listener = new MyListener(latch2);
+ listener = new CountDownSessionFailureListener(latch2);
session.addFailureListener(listener);
@@ -134,11 +133,10 @@
locator.setFailoverOnInitialConnection(true);
locator.setReconnectAttempts(-1);
ClientSessionFactoryInternal sf = createSessionFactoryAndWaitForTopology(locator,
2);
- CountDownLatch latch = new CountDownLatch(1);
ClientSession session = sendAndConsume(sf, true);
- MyListener listener = new MyListener(latch);
+ CountDownSessionFailureListener listener = new CountDownSessionFailureListener();
session.addFailureListener(listener);
@@ -148,7 +146,7 @@
backupServer.start();
- assertTrue(latch.await(5, TimeUnit.SECONDS));
+ assertTrue(listener.getLatch().await(5, TimeUnit.SECONDS));
ClientProducer producer = session.createProducer(FailoverTestBase.ADDRESS);
@@ -160,15 +158,13 @@
session.removeFailureListener(listener);
- CountDownLatch latch2 = new CountDownLatch(1);
+ listener = new CountDownSessionFailureListener();
- listener = new MyListener(latch2);
-
session.addFailureListener(listener);
liveServer.start();
- assertTrue(latch2.await(5, TimeUnit.SECONDS));
+ assertTrue(listener.getLatch().await(5, TimeUnit.SECONDS));
message = session.createMessage(true);
@@ -180,7 +176,7 @@
session.removeFailureListener(listener);
- listener = new MyListener(latch3);
+ listener = new CountDownSessionFailureListener(latch3);
session.addFailureListener(listener);
@@ -309,23 +305,4 @@
message.getBodyBuffer().writeString("message" + i);
}
- class MyListener implements SessionFailureListener
- {
- private final CountDownLatch latch;
-
- public MyListener(CountDownLatch latch)
- {
- this.latch = latch;
- }
-
- public void connectionFailed(final HornetQException me, boolean failedOver)
- {
- latch.countDown();
- }
-
- public void beforeReconnect(HornetQException exception)
- {
- System.out.println("MyListener.beforeReconnect");
- }
- }
}
Modified:
branches/HORNETQ-720_Replication/tests/integration-tests/src/test/java/org/hornetq/tests/util/CountDownSessionFailureListener.java
===================================================================
---
branches/HORNETQ-720_Replication/tests/integration-tests/src/test/java/org/hornetq/tests/util/CountDownSessionFailureListener.java 2011-07-27
16:36:09 UTC (rev 11051)
+++
branches/HORNETQ-720_Replication/tests/integration-tests/src/test/java/org/hornetq/tests/util/CountDownSessionFailureListener.java 2011-07-27
17:23:37 UTC (rev 11052)
@@ -9,21 +9,31 @@
{
private final CountDownLatch latch;
+ public CountDownSessionFailureListener()
+ {
+ latch = new CountDownLatch(1);
+ }
+
public CountDownSessionFailureListener(CountDownLatch latch)
{
this.latch = latch;
}
+
@Override
public void connectionFailed(HornetQException exception, boolean failedOver)
{
latch.countDown();
}
+ public CountDownLatch getLatch()
+ {
+ return latch;
+ }
+
@Override
public void beforeReconnect(HornetQException exception)
{
- // TODO Auto-generated method stub
-
+ // No-op
}
}
Show replies by date