[jboss-cvs] JBoss Messaging SVN: r7271 - in trunk: tests/src/org/jboss/messaging/tests/timing/core/server/impl and 5 other directories.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Tue Jun 9 07:30:46 EDT 2009
Author: jmesnil
Date: 2009-06-09 07:30:46 -0400 (Tue, 09 Jun 2009)
New Revision: 7271
Added:
trunk/tests/src/org/jboss/messaging/tests/unit/core/server/impl/fakes/FakePostOffice.java
Modified:
trunk/.classpath
trunk/build-messaging.xml
trunk/build-thirdparty.xml
trunk/tests/src/org/jboss/messaging/tests/timing/core/server/impl/QueueImplTest.java
trunk/tests/src/org/jboss/messaging/tests/timing/jms/bridge/impl/JMSBridgeImplTest.java
trunk/tests/src/org/jboss/messaging/tests/unit/core/paging/impl/PagingStoreImplTest.java
trunk/tests/src/org/jboss/messaging/tests/unit/core/remoting/impl/netty/NettyAcceptorFactoryTest.java
trunk/tests/src/org/jboss/messaging/tests/unit/core/remoting/impl/netty/NettyAcceptorTest.java
trunk/tests/src/org/jboss/messaging/tests/unit/core/remoting/impl/netty/NettyConnectionTest.java
trunk/tests/src/org/jboss/messaging/tests/unit/core/remoting/impl/netty/NettyConnectorTest.java
trunk/tests/src/org/jboss/messaging/tests/unit/core/server/impl/QueueImplTest.java
Log:
JBMESSAGING-1634: Remove easymock
* goodbye easymock, we hardly knew ya...
* rewrote tests using easymocks with either fake objects or inner classes
Modified: trunk/.classpath
===================================================================
--- trunk/.classpath 2009-06-09 11:29:06 UTC (rev 7270)
+++ trunk/.classpath 2009-06-09 11:30:46 UTC (rev 7271)
@@ -97,16 +97,13 @@
<classpathentry kind="lib" path="thirdparty/jboss/microcontainer/lib/jboss-aop-mc-int.jar"/>
<classpathentry kind="lib" path="thirdparty/jboss/jboss-jaspi-api/lib/jboss-jaspi-api.jar"/>
<classpathentry kind="lib" path="thirdparty/jboss/jnpserver/lib/jnpserver.jar" sourcepath="thirdparty/jboss/jnpserver/lib/jnpserver-sources.jar"/>
- <classpathentry kind="lib" path="thirdparty/netty/lib/netty-3.1.0.BETA3.jar"/>
+ <classpathentry kind="lib" path="thirdparty/netty/lib/netty-3.1.0.BETA3.jar" sourcepath="thirdparty/netty/lib/netty-3.1.0.BETA3-sources.jar"/>
<classpathentry kind="lib" path="thirdparty/sun-jaxb/lib/jaxb-api.jar"/>
<classpathentry kind="lib" path="thirdparty/jboss/jboss-common-logging-log4j/lib/jboss-common-logging-log4j.jar"/>
<classpathentry kind="lib" path="thirdparty/jboss/jbossts/lib/jbossts-common.jar"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
<classpathentry kind="lib" path="thirdparty/jboss/jboss-javaee/lib/jboss-javaee.jar"/>
<classpathentry kind="lib" path="thirdparty/jboss/jbosssx-client/lib/jbosssx-client.jar"/>
- <classpathentry kind="lib" path="thirdparty/easymock/lib/easymock.jar" sourcepath="thirdparty/easymock/lib/src.zip"/>
- <classpathentry kind="lib" path="thirdparty/easymock-classextension/lib/easymockclassextension.jar"/>
- <classpathentry kind="lib" path="thirdparty/cglib/lib/cglib.jar"/>
<classpathentry kind="lib" path="tests/tmpfiles"/>
<classpathentry kind="lib" path="thirdparty/jboss/jboss-common-logging-spi/lib/jboss-common-logging-spi.jar"/>
<classpathentry kind="lib" path="thirdparty/jboss/jbossts/lib/jbossjta.jar"/>
Modified: trunk/build-messaging.xml
===================================================================
--- trunk/build-messaging.xml 2009-06-09 11:29:06 UTC (rev 7270)
+++ trunk/build-messaging.xml 2009-06-09 11:30:46 UTC (rev 7271)
@@ -212,8 +212,6 @@
<path refid="jboss.jboss.reflect.classpath"/>
<path refid="jboss.jboss.common.logging.spi.classpath"/>
<path refid="jboss.jboss.mdr.classpath"/>
- <path refid="easymock.easymock.classpath"/>
- <path refid="easymock.classextension.classpath"/>
<path location="${build.jars.dir}/${ra.jar.name}"/>
<path location="${build.jars.dir}/${jms.jar.name}"/>
<path location="${build.jars.dir}/${transports.jar.name}"/>
@@ -232,7 +230,6 @@
<path refid="jboss.jboss.reflect.classpath"/>
<path refid="jboss.jboss.common.logging.spi.classpath"/>
<path refid="jboss.jboss.mdr.classpath"/>
- <path refid="easymock.easymock.classpath"/>
<path location="${build.jars.dir}/${core.jar.name}"/>
<path location="${build.jars.dir}/${jms.jar.name}"/>
<path location="${build.jars.dir}/${transports.jar.name}"/>
@@ -253,7 +250,6 @@
<path location="${build.jars.dir}/jboss-${module.name}.jar"/>
<path refid="junit.junit.classpath"/>
<path refid="jboss.profiler.jvmti.classpath"/>
- <path refid="easymock.easymock.classpath"/>
<path refid="jboss.jbossxb.classpath"/>
</path>
@@ -273,7 +269,6 @@
<path refid="test.compilation.classpath"/>
<path refid="sun.jaxb.classpath"/>
<path refid="apache.log4j.classpath"/>
- <path refid="cglib.classpath"/>
<path refid="jboss.common.core.classpath"/>
<path refid="jboss.aop.classpath"/>
<path refid="trove.trove.classpath"/>
@@ -292,7 +287,6 @@
<pathelement location="${src.schema.dir}"/>
<path refid="test.compilation.classpath"/>
<path refid="apache.log4j.classpath"/>
- <path refid="cglib.classpath"/>
<path refid="jboss.common.core.classpath"/>
<path refid="jboss.aop.classpath"/>
<path refid="trove.trove.classpath"/>
@@ -311,7 +305,6 @@
<path location="${build.jars.dir}/${transports.jar.name}"/>
<path refid="jms.test.compilation.classpath"/>
<path refid="sun.jaxb.classpath"/>
- <path refid="cglib.classpath"/>
<path refid="jboss.common.core.classpath"/>
<path refid="jboss.aop.classpath"/>
<path refid="trove.trove.classpath"/>
Modified: trunk/build-thirdparty.xml
===================================================================
--- trunk/build-thirdparty.xml 2009-06-09 11:29:06 UTC (rev 7270)
+++ trunk/build-thirdparty.xml 2009-06-09 11:30:46 UTC (rev 7271)
@@ -150,14 +150,6 @@
<componentref name="apache-logging" version="1.1.0.jboss"/>
-
- <!--
- required by the timing tests.
- -->
- <componentref name="easymock" version="2.3"/>
- <!-- the extension is used to mock some concrete classes -->
- <componentref name="easymock-classextension" version="2.3"/>
-
</build>
<synchronizeinfo/>
Modified: trunk/tests/src/org/jboss/messaging/tests/timing/core/server/impl/QueueImplTest.java
===================================================================
--- trunk/tests/src/org/jboss/messaging/tests/timing/core/server/impl/QueueImplTest.java 2009-06-09 11:29:06 UTC (rev 7270)
+++ trunk/tests/src/org/jboss/messaging/tests/timing/core/server/impl/QueueImplTest.java 2009-06-09 11:30:46 UTC (rev 7271)
@@ -28,8 +28,6 @@
import java.util.concurrent.ScheduledThreadPoolExecutor;
import java.util.concurrent.TimeUnit;
-import org.easymock.EasyMock;
-import org.easymock.IAnswer;
import org.jboss.messaging.core.logging.Logger;
import org.jboss.messaging.core.server.Consumer;
import org.jboss.messaging.core.server.HandleStatus;
@@ -244,27 +242,24 @@
public void testDeliveryScheduled() throws Exception
{
- Consumer consumer = EasyMock.createStrictMock(Consumer.class);
- Queue queue = new QueueImpl(1, new SimpleString("address1"), queue1, null, false, true, scheduledExecutor, null, null, null);
- MessageReference messageReference = generateReference(queue, 1);
final CountDownLatch countDownLatch = new CountDownLatch(1);
- EasyMock.expect(consumer.handle(messageReference)).andAnswer(new IAnswer<HandleStatus>()
+ Consumer consumer = new FakeConsumer()
{
- public HandleStatus answer() throws Throwable
+ @Override
+ public synchronized HandleStatus handle(MessageReference reference)
{
countDownLatch.countDown();
return HandleStatus.HANDLED;
}
- });
- EasyMock.replay(consumer);
+ };
+ Queue queue = new QueueImpl(1, new SimpleString("address1"), queue1, null, false, true, scheduledExecutor, null, null, null);
+ MessageReference messageReference = generateReference(queue, 1);
queue.addConsumer(consumer);
messageReference.setScheduledDeliveryTime(System.currentTimeMillis() + 2000);
queue.addFirst(messageReference);
- countDownLatch.await(3000, TimeUnit.MILLISECONDS);
-
- EasyMock.verify(consumer);
-
+ boolean gotLatch = countDownLatch.await(3000, TimeUnit.MILLISECONDS);
+ assertTrue(gotLatch);
}
}
Modified: trunk/tests/src/org/jboss/messaging/tests/timing/jms/bridge/impl/JMSBridgeImplTest.java
===================================================================
--- trunk/tests/src/org/jboss/messaging/tests/timing/jms/bridge/impl/JMSBridgeImplTest.java 2009-06-09 11:29:06 UTC (rev 7270)
+++ trunk/tests/src/org/jboss/messaging/tests/timing/jms/bridge/impl/JMSBridgeImplTest.java 2009-06-09 11:30:46 UTC (rev 7271)
@@ -22,34 +22,45 @@
package org.jboss.messaging.tests.timing.jms.bridge.impl;
-import static org.easymock.EasyMock.anyBoolean;
-import static org.easymock.EasyMock.anyInt;
-import static org.easymock.EasyMock.createNiceMock;
-import static org.easymock.EasyMock.createStrictMock;
-import static org.easymock.EasyMock.expect;
-import static org.easymock.EasyMock.expectLastCall;
-import static org.easymock.EasyMock.getCurrentArguments;
-import static org.easymock.EasyMock.isA;
-import static org.easymock.EasyMock.replay;
-import static org.easymock.EasyMock.verify;
+import static org.jboss.messaging.tests.util.RandomUtil.randomString;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.concurrent.atomic.AtomicReference;
+
import javax.jms.Connection;
import javax.jms.ConnectionFactory;
import javax.jms.Destination;
-import javax.jms.ExceptionListener;
import javax.jms.JMSException;
import javax.jms.Message;
import javax.jms.MessageConsumer;
import javax.jms.MessageListener;
import javax.jms.MessageProducer;
import javax.jms.Session;
+import javax.transaction.HeuristicMixedException;
+import javax.transaction.HeuristicRollbackException;
+import javax.transaction.InvalidTransactionException;
+import javax.transaction.NotSupportedException;
+import javax.transaction.RollbackException;
+import javax.transaction.SystemException;
+import javax.transaction.Transaction;
import javax.transaction.TransactionManager;
-import org.easymock.IAnswer;
+import org.jboss.messaging.core.config.Configuration;
+import org.jboss.messaging.core.config.TransportConfiguration;
+import org.jboss.messaging.core.config.impl.ConfigurationImpl;
+import org.jboss.messaging.core.remoting.impl.invm.InVMAcceptorFactory;
+import org.jboss.messaging.core.remoting.impl.invm.InVMConnectorFactory;
+import org.jboss.messaging.core.server.Messaging;
+import org.jboss.messaging.jms.JBossQueue;
import org.jboss.messaging.jms.bridge.ConnectionFactoryFactory;
import org.jboss.messaging.jms.bridge.DestinationFactory;
import org.jboss.messaging.jms.bridge.QualityOfServiceMode;
import org.jboss.messaging.jms.bridge.impl.JMSBridgeImpl;
+import org.jboss.messaging.jms.client.JBossConnectionFactory;
+import org.jboss.messaging.jms.server.JMSServerManager;
+import org.jboss.messaging.jms.server.impl.JMSServerManagerImpl;
+import org.jboss.messaging.tests.unit.util.InVMContext;
import org.jboss.messaging.tests.util.UnitTestCase;
/**
@@ -64,44 +75,119 @@
// Attributes ----------------------------------------------------
+ private static final String SOURCE = randomString();
+
+ private static final String TARGET = randomString();
+
+ private JMSServerManager jmsServer;
+
// Static --------------------------------------------------------
+ protected static TransactionManager newTransactionManager()
+ {
+ return new TransactionManager()
+ {
+ public Transaction suspend() throws SystemException
+ {
+ return null;
+ }
+
+ public void setTransactionTimeout(int arg0) throws SystemException
+ {
+ }
+
+ public void setRollbackOnly() throws IllegalStateException, SystemException
+ {
+ }
+
+ public void rollback() throws IllegalStateException, SecurityException, SystemException
+ {
+ }
+
+ public void resume(Transaction arg0) throws InvalidTransactionException,
+ IllegalStateException,
+ SystemException
+ {
+ }
+
+ public Transaction getTransaction() throws SystemException
+ {
+ return null;
+ }
+
+ public int getStatus() throws SystemException
+ {
+ return 0;
+ }
+
+ public void commit() throws RollbackException,
+ HeuristicMixedException,
+ HeuristicRollbackException,
+ SecurityException,
+ IllegalStateException,
+ SystemException
+ {
+ }
+
+ public void begin() throws NotSupportedException, SystemException
+ {
+ }
+ };
+ }
+
+ private static DestinationFactory newDestinationFactory(final Destination dest)
+ {
+ return new DestinationFactory()
+ {
+ public Destination createDestination() throws Exception
+ {
+ return dest;
+ }
+ };
+ };
+
+ private static ConnectionFactoryFactory newConnectionFactoryFactory(final ConnectionFactory cf)
+ {
+ return new ConnectionFactoryFactory()
+ {
+ public ConnectionFactory createConnectionFactory() throws Exception
+ {
+ return cf;
+ }
+ };
+ }
+
+ private static ConnectionFactory createConnectionFactory()
+ {
+ JBossConnectionFactory cf = new JBossConnectionFactory(new TransportConfiguration(InVMConnectorFactory.class.getName()));
+ // Note! We disable automatic reconnection on the session factory. The bridge needs to do the reconnection
+ cf.setReconnectAttempts(0);
+ cf.setBlockOnNonPersistentSend(true);
+ cf.setBlockOnPersistentSend(true);
+ return cf;
+ }
+
// Constructors --------------------------------------------------
// Public --------------------------------------------------------
public void testStartWithRepeatedFailure() throws Exception
{
- ConnectionFactoryFactory sourceCFF = createStrictMock(ConnectionFactoryFactory.class);
- ConnectionFactory sourceCF = createStrictMock(ConnectionFactory.class);
- Connection sourceConn = createStrictMock(Connection.class);
- Session sourceSession = createStrictMock(Session.class);
- MessageConsumer sourceConsumer = createStrictMock(MessageConsumer.class);
- DestinationFactory sourceDF = createStrictMock(DestinationFactory.class);
- Destination sourceDest = createStrictMock(Destination.class);
- ConnectionFactoryFactory targetCFF = createStrictMock(ConnectionFactoryFactory.class);
- ConnectionFactory targetCF = createStrictMock(ConnectionFactory.class);
- Connection targetConn = createStrictMock(Connection.class);
- Session targetSession = createStrictMock(Session.class);
- MessageProducer targetProducer = createStrictMock(MessageProducer.class);
- DestinationFactory targetDF = createStrictMock(DestinationFactory.class);
- Destination targetDest = createStrictMock(Destination.class);
- TransactionManager tm = createStrictMock(TransactionManager.class);
+ JBossConnectionFactory failingSourceCF = new JBossConnectionFactory(new TransportConfiguration(InVMConnectorFactory.class.getName()))
+ {
+ @Override
+ public Connection createConnection() throws JMSException
+ {
+ throw new JMSException("unable to create a conn");
+ }
+ };
- expect(tm.suspend()).andReturn(null);
- expect(sourceDF.createDestination()).andStubReturn(sourceDest);
- expect(targetDF.createDestination()).andStubReturn(targetDest);
- expect(sourceCFF.createConnectionFactory()).andStubReturn(sourceCF);
- // the source connection can not be created
- expect(sourceCF.createConnection()).andStubThrow(
- new JMSException("unable to create a conn"));
+ ConnectionFactoryFactory sourceCFF = newConnectionFactoryFactory(failingSourceCF);
+ ConnectionFactoryFactory targetCFF = newConnectionFactoryFactory(createConnectionFactory());
+ DestinationFactory sourceDF = newDestinationFactory(new JBossQueue(SOURCE));
+ DestinationFactory targetDF = newDestinationFactory(new JBossQueue(TARGET));
+ TransactionManager tm = newTransactionManager();
- replay(sourceCFF, sourceCF, sourceConn, sourceSession, sourceConsumer,
- sourceDF, sourceDest);
- replay(targetCFF, targetCF, targetConn, targetSession, targetProducer,
- targetDF, targetDest);
- replay(tm);
-
JMSBridgeImpl bridge = new JMSBridgeImpl();
bridge.setSourceConnectionFactoryFactory(sourceCFF);
@@ -124,59 +210,38 @@
assertFalse(bridge.isStarted());
assertTrue(bridge.isFailed());
- verify(sourceCFF, sourceCF, sourceConn, sourceSession, sourceConsumer,
- sourceDF, sourceDest);
- verify(targetCFF, targetCF, targetConn, targetSession, targetProducer,
- targetDF, targetDest);
- verify(tm);
}
public void testStartWithFailureThenSuccess() throws Exception
{
- ConnectionFactoryFactory sourceCFF = createStrictMock(ConnectionFactoryFactory.class);
- ConnectionFactory sourceCF = createStrictMock(ConnectionFactory.class);
- Connection sourceConn = createStrictMock(Connection.class);
- Session sourceSession = createStrictMock(Session.class);
- MessageConsumer sourceConsumer = createStrictMock(MessageConsumer.class);
- DestinationFactory sourceDF = createStrictMock(DestinationFactory.class);
- Destination sourceDest = createStrictMock(Destination.class);
- ConnectionFactoryFactory targetCFF = createStrictMock(ConnectionFactoryFactory.class);
- ConnectionFactory targetCF = createStrictMock(ConnectionFactory.class);
- Connection targetConn = createStrictMock(Connection.class);
- Session targetSession = createStrictMock(Session.class);
- MessageProducer targetProducer = createStrictMock(MessageProducer.class);
- DestinationFactory targetDF = createStrictMock(DestinationFactory.class);
- Destination targetDest = createStrictMock(Destination.class);
- TransactionManager tm = createStrictMock(TransactionManager.class);
+ JBossConnectionFactory failingSourceCF = new JBossConnectionFactory(new TransportConfiguration(InVMConnectorFactory.class.getName()))
+ {
+ boolean firstTime = true;
- expect(tm.suspend()).andReturn(null);
- expect(sourceDF.createDestination()).andStubReturn(sourceDest);
- expect(targetDF.createDestination()).andStubReturn(targetDest);
- expect(sourceCFF.createConnectionFactory()).andStubReturn(sourceCF);
- // the source connection can not be created the 1st time...
- expect(sourceCF.createConnection()).andThrow(
- new JMSException("unable to create a conn"));
- // ... and it succeeds the 2nd time
- expect(sourceCF.createConnection()).andReturn(sourceConn);
- sourceConn.setExceptionListener(isA(ExceptionListener.class));
- expect(sourceConn.createSession(anyBoolean(), anyInt())).andReturn(
- sourceSession);
- expect(sourceSession.createConsumer(sourceDest))
- .andReturn(sourceConsumer);
- sourceConsumer.setMessageListener(isA(MessageListener.class));
- expect(targetCFF.createConnectionFactory()).andReturn(targetCF);
- expect(targetCF.createConnection()).andReturn(targetConn);
- targetConn.setExceptionListener(isA(ExceptionListener.class));
- expect(targetConn.createSession(anyBoolean(), anyInt())).andReturn(
- targetSession);
- expect(targetSession.createProducer(null)).andReturn(targetProducer);
- sourceConn.start();
+ @Override
+ public Connection createConnection() throws JMSException
+ {
+ if (firstTime)
+ {
+ firstTime = false;
+ throw new JMSException("unable to create a conn");
+ }
+ else
+ {
+ return super.createConnection();
+ }
+ }
+ };
+ // Note! We disable automatic reconnection on the session factory. The bridge needs to do the reconnection
+ failingSourceCF.setReconnectAttempts(0);
+ failingSourceCF.setBlockOnNonPersistentSend(true);
+ failingSourceCF.setBlockOnPersistentSend(true);
- replay(sourceCFF, sourceCF, sourceConn, sourceSession, sourceConsumer,
- sourceDF, sourceDest);
- replay(targetCFF, targetCF, targetConn, targetSession, targetProducer,
- targetDF, targetDest);
- replay(tm);
+ ConnectionFactoryFactory sourceCFF = newConnectionFactoryFactory(failingSourceCF);
+ ConnectionFactoryFactory targetCFF = newConnectionFactoryFactory(createConnectionFactory());
+ DestinationFactory sourceDF = newDestinationFactory(new JBossQueue(SOURCE));
+ DestinationFactory targetDF = newDestinationFactory(new JBossQueue(TARGET));
+ TransactionManager tm = newTransactionManager();
JMSBridgeImpl bridge = new JMSBridgeImpl();
@@ -196,74 +261,28 @@
assertFalse(bridge.isStarted());
bridge.start();
- Thread.sleep(50);
+ Thread.sleep(500);
assertTrue(bridge.isStarted());
assertFalse(bridge.isFailed());
- verify(sourceCFF, sourceCF, sourceConn, sourceSession, sourceConsumer,
- sourceDF, sourceDest);
- verify(targetCFF, targetCF, targetConn, targetSession, targetProducer,
- targetDF, targetDest);
- verify(tm);
+ bridge.stop();
}
/*
- * we receive only 1 message. The message is sent when the maxBatchTime
- * expires even if the maxBatchSize is not reached
- */
+ * we receive only 1 message. The message is sent when the maxBatchTime
+ * expires even if the maxBatchSize is not reached
+ */
public void testSendMessagesWhenMaxBatchTimeExpires() throws Exception
{
int maxBatchSize = 2;
long maxBatchTime = 500;
- ConnectionFactoryFactory sourceCFF = createStrictMock(ConnectionFactoryFactory.class);
- ConnectionFactory sourceCF = createStrictMock(ConnectionFactory.class);
- Connection sourceConn = createStrictMock(Connection.class);
- Session sourceSession = createStrictMock(Session.class);
- MessageConsumer sourceConsumer = createStrictMock(MessageConsumer.class);
- DestinationFactory sourceDF = createStrictMock(DestinationFactory.class);
- Destination sourceDest = createStrictMock(Destination.class);
- ConnectionFactoryFactory targetCFF = createStrictMock(ConnectionFactoryFactory.class);
- ConnectionFactory targetCF = createStrictMock(ConnectionFactory.class);
- Connection targetConn = createStrictMock(Connection.class);
- Session targetSession = createStrictMock(Session.class);
- MessageProducer targetProducer = createStrictMock(MessageProducer.class);
- DestinationFactory targetDF = createStrictMock(DestinationFactory.class);
- Destination targetDest = createStrictMock(Destination.class);
- TransactionManager tm = createStrictMock(TransactionManager.class);
- Message message = createNiceMock(Message.class);
+ ConnectionFactoryFactory sourceCFF = newConnectionFactoryFactory(createConnectionFactory());
+ ConnectionFactoryFactory targetCFF = newConnectionFactoryFactory(createConnectionFactory());
+ DestinationFactory sourceDF = newDestinationFactory(new JBossQueue(SOURCE));
+ DestinationFactory targetDF = newDestinationFactory(new JBossQueue(TARGET));
+ TransactionManager tm = newTransactionManager();
- expect(tm.suspend()).andReturn(null);
- expect(sourceDF.createDestination()).andReturn(sourceDest);
- expect(targetDF.createDestination()).andReturn(targetDest);
- expect(sourceCFF.createConnectionFactory()).andReturn(sourceCF);
- expect(sourceCF.createConnection()).andReturn(sourceConn);
- sourceConn.setExceptionListener(isA(ExceptionListener.class));
- expect(sourceConn.createSession(anyBoolean(), anyInt())).andReturn(
- sourceSession);
- expect(sourceSession.createConsumer(sourceDest))
- .andReturn(sourceConsumer);
- SetMessageListenerAnswer answer = new SetMessageListenerAnswer();
- sourceConsumer.setMessageListener(isA(MessageListener.class));
- expectLastCall().andAnswer(answer);
- expect(targetCFF.createConnectionFactory()).andReturn(targetCF);
- expect(targetCF.createConnection()).andReturn(targetConn);
- targetConn.setExceptionListener(isA(ExceptionListener.class));
- expect(targetConn.createSession(anyBoolean(), anyInt())).andReturn(
- targetSession);
- expect(targetSession.createProducer(null)).andReturn(targetProducer);
- sourceConn.start();
-
- targetProducer.send(targetDest, message, 0, 0, 0);
- targetSession.commit();
-
- replay(sourceCFF, sourceCF, sourceConn, sourceSession, sourceConsumer,
- sourceDF, sourceDest);
- replay(targetCFF, targetCF, targetConn, targetSession, targetProducer,
- targetDF, targetDest);
- replay(tm);
- replay(message);
-
JMSBridgeImpl bridge = new JMSBridgeImpl();
assertNotNull(bridge);
@@ -282,86 +301,61 @@
bridge.start();
assertTrue(bridge.isStarted());
- answer.listener.onMessage(message);
+ Connection targetConn = createConnectionFactory().createConnection();
+ Session targetSess = targetConn.createSession(false, Session.AUTO_ACKNOWLEDGE);
+ MessageConsumer consumer = targetSess.createConsumer(targetDF.createDestination());
+ final List<Message> messages = new LinkedList<Message>();
+ MessageListener listener = new MessageListener()
+ {
+ public void onMessage(Message message)
+ {
+ messages.add(message);
+ }
+ };
+ consumer.setMessageListener(listener);
+ targetConn.start();
+
+ Connection sourceConn = createConnectionFactory().createConnection();
+ Session sourceSess = sourceConn.createSession(false, Session.AUTO_ACKNOWLEDGE);
+ MessageProducer producer = sourceSess.createProducer(sourceDF.createDestination());
+ producer.send(sourceSess.createTextMessage());
+ sourceConn.close();
+
+ assertEquals(0, messages.size());
Thread.sleep(3 * maxBatchTime);
- verify(sourceCFF, sourceCF, sourceConn, sourceSession, sourceConsumer,
- sourceDF, sourceDest);
- verify(targetCFF, targetCF, targetConn, targetSession, targetProducer,
- targetDF, targetDest);
- verify(tm);
- verify(message);
+ assertEquals(1, messages.size());
+
+ bridge.stop();
+ assertFalse(bridge.isStarted());
+
+ targetConn.close();
}
public void testExceptionOnSourceAndRetrySucceeds() throws Exception
{
- ConnectionFactoryFactory sourceCFF = createStrictMock(ConnectionFactoryFactory.class);
- ConnectionFactory sourceCF = createStrictMock(ConnectionFactory.class);
- Connection sourceConn = createStrictMock(Connection.class);
- Session sourceSession = createStrictMock(Session.class);
- MessageConsumer sourceConsumer = createStrictMock(MessageConsumer.class);
- DestinationFactory sourceDF = createStrictMock(DestinationFactory.class);
- Destination sourceDest = createStrictMock(Destination.class);
- ConnectionFactoryFactory targetCFF = createStrictMock(ConnectionFactoryFactory.class);
- ConnectionFactory targetCF = createStrictMock(ConnectionFactory.class);
- Connection targetConn = createStrictMock(Connection.class);
- Session targetSession = createStrictMock(Session.class);
- MessageProducer targetProducer = createStrictMock(MessageProducer.class);
- DestinationFactory targetDF = createStrictMock(DestinationFactory.class);
- Destination targetDest = createStrictMock(Destination.class);
- TransactionManager tm = createStrictMock(TransactionManager.class);
- Message message = createNiceMock(Message.class);
+ final AtomicReference<Connection> sourceConn = new AtomicReference<Connection>();
+ JBossConnectionFactory failingSourceCF = new JBossConnectionFactory(new TransportConfiguration(InVMConnectorFactory.class.getName()))
+ {
+ @Override
+ public Connection createConnection() throws JMSException
+ {
+ sourceConn.set(super.createConnection());
+ return sourceConn.get();
+ }
+ };
+ // Note! We disable automatic reconnection on the session factory. The bridge needs to do the reconnection
+ failingSourceCF.setReconnectAttempts(0);
+ failingSourceCF.setBlockOnNonPersistentSend(true);
+ failingSourceCF.setBlockOnPersistentSend(true);
- expect(tm.suspend()).andReturn(null);
- expect(sourceDF.createDestination()).andReturn(sourceDest);
- expect(targetDF.createDestination()).andReturn(targetDest);
- expect(sourceCFF.createConnectionFactory()).andReturn(sourceCF);
- expect(sourceCF.createConnection()).andReturn(sourceConn);
- SetExceptionListenerAnswer exceptionListenerAnswer = new SetExceptionListenerAnswer();
- sourceConn.setExceptionListener(isA(ExceptionListener.class));
- expectLastCall().andAnswer(exceptionListenerAnswer);
- expect(sourceConn.createSession(anyBoolean(), anyInt())).andReturn(
- sourceSession);
- expect(sourceSession.createConsumer(sourceDest))
- .andReturn(sourceConsumer);
- sourceConsumer.setMessageListener(isA(MessageListener.class));
- expect(targetCFF.createConnectionFactory()).andReturn(targetCF);
- expect(targetCF.createConnection()).andReturn(targetConn);
- targetConn.setExceptionListener(isA(ExceptionListener.class));
- expect(targetConn.createSession(anyBoolean(), anyInt())).andReturn(
- targetSession);
- expect(targetSession.createProducer(null)).andReturn(targetProducer);
- sourceConn.start();
+ ConnectionFactoryFactory sourceCFF = newConnectionFactoryFactory(failingSourceCF);
+ ConnectionFactoryFactory targetCFF = newConnectionFactoryFactory(createConnectionFactory());
+ DestinationFactory sourceDF = newDestinationFactory(new JBossQueue(SOURCE));
+ DestinationFactory targetDF = newDestinationFactory(new JBossQueue(TARGET));
+ TransactionManager tm = newTransactionManager();
- //after failure detection, we retry to start the bridge:
- expect(sourceDF.createDestination()).andReturn(sourceDest);
- expect(targetDF.createDestination()).andReturn(targetDest);
- expect(sourceCFF.createConnectionFactory()).andReturn(sourceCF);
- expect(sourceCF.createConnection()).andReturn(sourceConn);
- sourceConn.setExceptionListener(isA(ExceptionListener.class));
- expectLastCall().andAnswer(exceptionListenerAnswer);
- expect(sourceConn.createSession(anyBoolean(), anyInt())).andReturn(
- sourceSession);
- expect(sourceSession.createConsumer(sourceDest))
- .andReturn(sourceConsumer);
- sourceConsumer.setMessageListener(isA(MessageListener.class));
- expect(targetCFF.createConnectionFactory()).andReturn(targetCF);
- expect(targetCF.createConnection()).andReturn(targetConn);
- targetConn.setExceptionListener(isA(ExceptionListener.class));
- expect(targetConn.createSession(anyBoolean(), anyInt())).andReturn(
- targetSession);
- expect(targetSession.createProducer(null)).andReturn(targetProducer);
- sourceConn.start();
-
-
- replay(sourceCFF, sourceCF, sourceConn, sourceSession, sourceConsumer,
- sourceDF, sourceDest);
- replay(targetCFF, targetCF, targetConn, targetSession, targetProducer,
- targetDF, targetDest);
- replay(tm);
- replay(message);
-
JMSBridgeImpl bridge = new JMSBridgeImpl();
assertNotNull(bridge);
@@ -379,82 +373,48 @@
assertFalse(bridge.isStarted());
bridge.start();
assertTrue(bridge.isStarted());
-
- exceptionListenerAnswer.listener.onException(new JMSException("exception on the source"));
+
+ sourceConn.get().getExceptionListener().onException(new JMSException("exception on the source"));
Thread.sleep(4 * bridge.getFailureRetryInterval());
- // reconnection must have succeded
+ // reconnection must have succeeded
assertTrue(bridge.isStarted());
-
- verify(sourceCFF, sourceCF, sourceConn, sourceSession, sourceConsumer,
- sourceDF, sourceDest);
- verify(targetCFF, targetCF, targetConn, targetSession, targetProducer,
- targetDF, targetDest);
- verify(tm);
- verify(message);
+
+ bridge.stop();
+ assertFalse(bridge.isStarted());
}
-
+
public void testExceptionOnSourceAndRetryFails() throws Exception
{
- ConnectionFactoryFactory sourceCFF = createStrictMock(ConnectionFactoryFactory.class);
- ConnectionFactory sourceCF = createStrictMock(ConnectionFactory.class);
- Connection sourceConn = createStrictMock(Connection.class);
- Session sourceSession = createStrictMock(Session.class);
- MessageConsumer sourceConsumer = createStrictMock(MessageConsumer.class);
- DestinationFactory sourceDF = createStrictMock(DestinationFactory.class);
- Destination sourceDest = createStrictMock(Destination.class);
- ConnectionFactoryFactory targetCFF = createStrictMock(ConnectionFactoryFactory.class);
- ConnectionFactory targetCF = createStrictMock(ConnectionFactory.class);
- Connection targetConn = createStrictMock(Connection.class);
- Session targetSession = createStrictMock(Session.class);
- MessageProducer targetProducer = createStrictMock(MessageProducer.class);
- DestinationFactory targetDF = createStrictMock(DestinationFactory.class);
- Destination targetDest = createStrictMock(Destination.class);
- TransactionManager tm = createStrictMock(TransactionManager.class);
- Message message = createNiceMock(Message.class);
+ final AtomicReference<Connection> sourceConn = new AtomicReference<Connection>();
+ JBossConnectionFactory failingSourceCF = new JBossConnectionFactory(new TransportConfiguration(InVMConnectorFactory.class.getName()))
+ {
+ boolean firstTime = true;
- expect(tm.suspend()).andReturn(null);
- expect(sourceDF.createDestination()).andReturn(sourceDest);
- expect(targetDF.createDestination()).andReturn(targetDest);
- expect(sourceCFF.createConnectionFactory()).andReturn(sourceCF);
- expect(sourceCF.createConnection()).andReturn(sourceConn);
- SetExceptionListenerAnswer exceptionListenerAnswer = new SetExceptionListenerAnswer();
- sourceConn.setExceptionListener(isA(ExceptionListener.class));
- expectLastCall().andAnswer(exceptionListenerAnswer);
- expect(sourceConn.createSession(anyBoolean(), anyInt())).andReturn(
- sourceSession);
- expect(sourceSession.createConsumer(sourceDest))
- .andReturn(sourceConsumer);
- sourceConsumer.setMessageListener(isA(MessageListener.class));
- expect(targetCFF.createConnectionFactory()).andReturn(targetCF);
- expect(targetCF.createConnection()).andReturn(targetConn);
- targetConn.setExceptionListener(isA(ExceptionListener.class));
- expect(targetConn.createSession(anyBoolean(), anyInt())).andReturn(
- targetSession);
- expect(targetSession.createProducer(null)).andReturn(targetProducer);
- sourceConn.start();
+ @Override
+ public Connection createConnection() throws JMSException
+ {
+ if (firstTime)
+ {
+ firstTime = false;
+ sourceConn.set(super.createConnection());
+ return sourceConn.get();
+ }
+ else
+ {
+ throw new JMSException("exception while retrying to connect");
+ }
+ }
+ };
+ // Note! We disable automatic reconnection on the session factory. The bridge needs to do the reconnection
+ failingSourceCF.setReconnectAttempts(0);
+ failingSourceCF.setBlockOnNonPersistentSend(true);
+ failingSourceCF.setBlockOnPersistentSend(true);
- //after failure detection, we clean up...
- // and it is stopped
- sourceConn.close();
- targetConn.close();
- // ...retry to start the bridge but it fails...
- expect(sourceDF.createDestination()).andReturn(sourceDest);
- expect(targetDF.createDestination()).andReturn(targetDest);
- expect(sourceCFF.createConnectionFactory()).andReturn(sourceCF);
- expect(sourceCF.createConnection()).andThrow(new JMSException("exception while retrying to connect"));
- // ... so we clean up again...
- sourceConn.close();
- targetConn.close();
- // ... and finally stop the bridge
- sourceConn.close();
- targetConn.close();
-
- replay(sourceCFF, sourceCF, sourceConn, sourceSession, sourceConsumer,
- sourceDF, sourceDest);
- replay(targetCFF, targetCF, targetConn, targetSession, targetProducer,
- targetDF, targetDest);
- replay(tm);
- replay(message);
+ ConnectionFactoryFactory sourceCFF = newConnectionFactoryFactory(failingSourceCF);
+ ConnectionFactoryFactory targetCFF = newConnectionFactoryFactory(createConnectionFactory());
+ DestinationFactory sourceDF = newDestinationFactory(new JBossQueue(SOURCE));
+ DestinationFactory targetDF = newDestinationFactory(new JBossQueue(TARGET));
+ TransactionManager tm = newTransactionManager();
JMSBridgeImpl bridge = new JMSBridgeImpl();
assertNotNull(bridge);
@@ -473,47 +433,47 @@
assertFalse(bridge.isStarted());
bridge.start();
assertTrue(bridge.isStarted());
-
- exceptionListenerAnswer.listener.onException(new JMSException("exception on the source"));
+
+ sourceConn.get().getExceptionListener().onException(new JMSException("exception on the source"));
Thread.sleep(4 * bridge.getFailureRetryInterval());
// reconnection must have failed
assertFalse(bridge.isStarted());
-
- verify(sourceCFF, sourceCF, sourceConn, sourceSession, sourceConsumer,
- sourceDF, sourceDest);
- verify(targetCFF, targetCF, targetConn, targetSession, targetProducer,
- targetDF, targetDest);
- verify(tm);
- verify(message);
+
}
-
+
// Package protected ---------------------------------------------
// Protected -----------------------------------------------------
- // Private -------------------------------------------------------
-
- // Inner classes -------------------------------------------------
-
- class SetExceptionListenerAnswer implements IAnswer
+ @Override
+ protected void setUp() throws Exception
{
- ExceptionListener listener = null;
+ super.setUp();
- public Object answer() throws Throwable
- {
- listener = (ExceptionListener) getCurrentArguments()[0];
- return null;
- }
+ Configuration config = new ConfigurationImpl();
+ config.setFileDeploymentEnabled(false);
+ config.setSecurityEnabled(false);
+ config.getAcceptorConfigurations().add(new TransportConfiguration(InVMAcceptorFactory.class.getName()));
+ InVMContext context = new InVMContext();
+ jmsServer = new JMSServerManagerImpl(Messaging.newMessagingServer(config, false));
+ jmsServer.setContext(context);
+ jmsServer.start();
+
+ jmsServer.createQueue(SOURCE, "/queue/" + SOURCE, null, true);
+ jmsServer.createQueue(TARGET, "/queue/" + TARGET, null, true);
+
}
-
- class SetMessageListenerAnswer implements IAnswer
+
+ @Override
+ protected void tearDown() throws Exception
{
- MessageListener listener = null;
+ jmsServer.stop();
- public Object answer() throws Throwable
- {
- listener = (MessageListener) getCurrentArguments()[0];
- return null;
- }
+ super.tearDown();
}
+
+ // Private -------------------------------------------------------
+
+ // Inner classes -------------------------------------------------
+
}
Modified: trunk/tests/src/org/jboss/messaging/tests/unit/core/paging/impl/PagingStoreImplTest.java
===================================================================
--- trunk/tests/src/org/jboss/messaging/tests/unit/core/paging/impl/PagingStoreImplTest.java 2009-06-09 11:29:06 UTC (rev 7270)
+++ trunk/tests/src/org/jboss/messaging/tests/unit/core/paging/impl/PagingStoreImplTest.java 2009-06-09 11:30:46 UTC (rev 7271)
@@ -54,8 +54,6 @@
import org.jboss.messaging.core.persistence.QueueBindingInfo;
import org.jboss.messaging.core.persistence.StorageManager;
import org.jboss.messaging.core.postoffice.Binding;
-import org.jboss.messaging.core.postoffice.Bindings;
-import org.jboss.messaging.core.postoffice.DuplicateIDCache;
import org.jboss.messaging.core.postoffice.PostOffice;
import org.jboss.messaging.core.remoting.spi.MessagingBuffer;
import org.jboss.messaging.core.server.LargeServerMessage;
@@ -66,8 +64,8 @@
import org.jboss.messaging.core.settings.HierarchicalRepository;
import org.jboss.messaging.core.settings.impl.AddressSettings;
import org.jboss.messaging.core.transaction.ResourceManager;
-import org.jboss.messaging.core.transaction.Transaction;
import org.jboss.messaging.tests.unit.core.journal.impl.fakes.FakeSequentialFileFactory;
+import org.jboss.messaging.tests.unit.core.server.impl.fakes.FakePostOffice;
import org.jboss.messaging.tests.util.RandomUtil;
import org.jboss.messaging.tests.util.UnitTestCase;
import org.jboss.messaging.utils.Pair;
@@ -1101,132 +1099,6 @@
}
- class FakePostOffice implements PostOffice
- {
-
- public Object getNotificationLock()
- {
- return null;
- }
-
- public Bindings getMatchingBindings(SimpleString address)
- {
- return null;
- }
-
- /* (non-Javadoc)
- * @see org.jboss.messaging.core.postoffice.PostOffice#activate()
- */
- public List<Queue> activate()
- {
- return null;
- }
-
- /* (non-Javadoc)
- * @see org.jboss.messaging.core.postoffice.PostOffice#addBinding(org.jboss.messaging.core.postoffice.Binding)
- */
- public void addBinding(final Binding binding) throws Exception
- {
- }
-
- /* (non-Javadoc)
- * @see org.jboss.messaging.core.postoffice.PostOffice#getBinding(org.jboss.messaging.utils.SimpleString)
- */
- public Binding getBinding(final SimpleString uniqueName)
- {
- return null;
- }
-
- /* (non-Javadoc)
- * @see org.jboss.messaging.core.postoffice.PostOffice#getBindingsForAddress(org.jboss.messaging.utils.SimpleString)
- */
- public Bindings getBindingsForAddress(final SimpleString address) throws Exception
- {
- return null;
- }
-
- /* (non-Javadoc)
- * @see org.jboss.messaging.core.postoffice.PostOffice#getDuplicateIDCache(org.jboss.messaging.utils.SimpleString)
- */
- public DuplicateIDCache getDuplicateIDCache(final SimpleString address)
- {
- return null;
- }
-
- /* (non-Javadoc)
- * @see org.jboss.messaging.core.postoffice.PostOffice#getPagingManager()
- */
- public PagingManager getPagingManager()
- {
- return null;
- }
-
- /* (non-Javadoc)
- * @see org.jboss.messaging.core.postoffice.PostOffice#redistribute(org.jboss.messaging.core.server.ServerMessage, org.jboss.messaging.utils.SimpleString, org.jboss.messaging.core.transaction.Transaction)
- */
- public boolean redistribute(final ServerMessage message, final Queue queue, final Transaction tx) throws Exception
- {
- return false;
- }
-
- /* (non-Javadoc)
- * @see org.jboss.messaging.core.postoffice.PostOffice#removeBinding(org.jboss.messaging.utils.SimpleString)
- */
- public Binding removeBinding(final SimpleString uniqueName) throws Exception
- {
- return null;
- }
-
- /* (non-Javadoc)
- * @see org.jboss.messaging.core.postoffice.PostOffice#route(org.jboss.messaging.core.server.ServerMessage)
- */
- public void route(final ServerMessage message) throws Exception
- {
-
- }
-
- /* (non-Javadoc)
- * @see org.jboss.messaging.core.postoffice.PostOffice#route(org.jboss.messaging.core.server.ServerMessage, org.jboss.messaging.core.transaction.Transaction)
- */
- public void route(final ServerMessage message, final Transaction tx) throws Exception
- {
-
- }
-
- /* (non-Javadoc)
- * @see org.jboss.messaging.core.postoffice.PostOffice#sendQueueInfoToQueue(org.jboss.messaging.utils.SimpleString, org.jboss.messaging.utils.SimpleString)
- */
- public void sendQueueInfoToQueue(final SimpleString queueName, final SimpleString address) throws Exception
- {
-
- }
-
- /* (non-Javadoc)
- * @see org.jboss.messaging.core.server.MessagingComponent#isStarted()
- */
- public boolean isStarted()
- {
- return false;
- }
-
- /* (non-Javadoc)
- * @see org.jboss.messaging.core.server.MessagingComponent#start()
- */
- public void start() throws Exception
- {
-
- }
-
- /* (non-Javadoc)
- * @see org.jboss.messaging.core.server.MessagingComponent#stop()
- */
- public void stop() throws Exception
- {
-
- }
-
- }
-
class FakeStoreFactory implements PagingStoreFactory
{
Modified: trunk/tests/src/org/jboss/messaging/tests/unit/core/remoting/impl/netty/NettyAcceptorFactoryTest.java
===================================================================
--- trunk/tests/src/org/jboss/messaging/tests/unit/core/remoting/impl/netty/NettyAcceptorFactoryTest.java 2009-06-09 11:29:06 UTC (rev 7270)
+++ trunk/tests/src/org/jboss/messaging/tests/unit/core/remoting/impl/netty/NettyAcceptorFactoryTest.java 2009-06-09 11:30:46 UTC (rev 7271)
@@ -25,10 +25,13 @@
import java.util.Map;
import java.util.concurrent.Executors;
-import org.easymock.EasyMock;
+import org.jboss.messaging.core.exception.MessagingException;
+import org.jboss.messaging.core.remoting.impl.AbstractBufferHandler;
import org.jboss.messaging.core.remoting.spi.Acceptor;
import org.jboss.messaging.core.remoting.spi.BufferHandler;
+import org.jboss.messaging.core.remoting.spi.Connection;
import org.jboss.messaging.core.remoting.spi.ConnectionLifeCycleListener;
+import org.jboss.messaging.core.remoting.spi.MessagingBuffer;
import org.jboss.messaging.integration.transports.netty.NettyAcceptor;
import org.jboss.messaging.integration.transports.netty.NettyAcceptorFactory;
import org.jboss.messaging.tests.util.UnitTestCase;
@@ -47,8 +50,29 @@
NettyAcceptorFactory factory = new NettyAcceptorFactory();
Map<String, Object> params = new HashMap<String, Object>();
- BufferHandler handler = EasyMock.createStrictMock(BufferHandler.class);
- ConnectionLifeCycleListener listener = EasyMock.createStrictMock(ConnectionLifeCycleListener.class);
+ BufferHandler handler = new AbstractBufferHandler()
+ {
+
+ public void bufferReceived(Object connectionID, MessagingBuffer buffer)
+ {
+ }
+ };
+
+ ConnectionLifeCycleListener listener = new ConnectionLifeCycleListener()
+ {
+
+ public void connectionException(Object connectionID, MessagingException me)
+ {
+ }
+
+ public void connectionDestroyed(Object connectionID)
+ {
+ }
+
+ public void connectionCreated(Connection connection)
+ {
+ }
+ };
Acceptor acceptor = factory.createAcceptor(params, handler, listener, Executors.newCachedThreadPool());
Modified: trunk/tests/src/org/jboss/messaging/tests/unit/core/remoting/impl/netty/NettyAcceptorTest.java
===================================================================
--- trunk/tests/src/org/jboss/messaging/tests/unit/core/remoting/impl/netty/NettyAcceptorTest.java 2009-06-09 11:29:06 UTC (rev 7270)
+++ trunk/tests/src/org/jboss/messaging/tests/unit/core/remoting/impl/netty/NettyAcceptorTest.java 2009-06-09 11:30:46 UTC (rev 7271)
@@ -26,9 +26,12 @@
import java.util.Map;
import java.util.concurrent.Executors;
-import org.easymock.EasyMock;
+import org.jboss.messaging.core.exception.MessagingException;
+import org.jboss.messaging.core.remoting.impl.AbstractBufferHandler;
import org.jboss.messaging.core.remoting.spi.BufferHandler;
+import org.jboss.messaging.core.remoting.spi.Connection;
import org.jboss.messaging.core.remoting.spi.ConnectionLifeCycleListener;
+import org.jboss.messaging.core.remoting.spi.MessagingBuffer;
import org.jboss.messaging.integration.transports.netty.NettyAcceptor;
import org.jboss.messaging.tests.util.UnitTestCase;
@@ -43,24 +46,53 @@
{
public void testStartStop() throws Exception
{
- BufferHandler handler = EasyMock.createStrictMock(BufferHandler.class);
+ BufferHandler handler = new AbstractBufferHandler()
+ {
+
+ public void bufferReceived(Object connectionID, MessagingBuffer buffer)
+ {
+ }
+ };
+
Map<String, Object> params = new HashMap<String, Object>();
- ConnectionLifeCycleListener listener = EasyMock.createStrictMock(ConnectionLifeCycleListener.class);
+ ConnectionLifeCycleListener listener = new ConnectionLifeCycleListener()
+ {
+
+ public void connectionException(Object connectionID, MessagingException me)
+ {
+ }
+
+ public void connectionDestroyed(Object connectionID)
+ {
+ }
+
+ public void connectionCreated(Connection connection)
+ {
+ }
+ };
NettyAcceptor acceptor = new NettyAcceptor(params, handler, listener, Executors.newCachedThreadPool());
acceptor.start();
+ assertTrue(acceptor.isStarted());
acceptor.pause();
acceptor.stop();
+ assertFalse(acceptor.isStarted());
acceptor.start();
+ assertTrue(acceptor.isStarted());
acceptor.pause();
acceptor.stop();
-
+ assertFalse(acceptor.isStarted());
+
acceptor.start();
+ assertTrue(acceptor.isStarted());
acceptor.pause();
acceptor.resume();
acceptor.stop();
+ assertFalse(acceptor.isStarted());
acceptor.start();
+ assertTrue(acceptor.isStarted());
acceptor.stop();
+ assertFalse(acceptor.isStarted());
}
}
Modified: trunk/tests/src/org/jboss/messaging/tests/unit/core/remoting/impl/netty/NettyConnectionTest.java
===================================================================
--- trunk/tests/src/org/jboss/messaging/tests/unit/core/remoting/impl/netty/NettyConnectionTest.java 2009-06-09 11:29:06 UTC (rev 7270)
+++ trunk/tests/src/org/jboss/messaging/tests/unit/core/remoting/impl/netty/NettyConnectionTest.java 2009-06-09 11:30:46 UTC (rev 7271)
@@ -23,7 +23,12 @@
import static org.jboss.messaging.tests.util.RandomUtil.randomInt;
-import org.easymock.EasyMock;
+import java.net.SocketAddress;
+import java.nio.ByteBuffer;
+import java.util.LinkedList;
+import java.util.List;
+
+import org.jboss.messaging.core.buffers.ChannelBuffers;
import org.jboss.messaging.core.exception.MessagingException;
import org.jboss.messaging.core.remoting.spi.Connection;
import org.jboss.messaging.core.remoting.spi.ConnectionLifeCycleListener;
@@ -31,6 +36,10 @@
import org.jboss.messaging.integration.transports.netty.NettyConnection;
import org.jboss.messaging.tests.util.UnitTestCase;
import org.jboss.netty.channel.Channel;
+import org.jboss.netty.channel.ChannelConfig;
+import org.jboss.netty.channel.ChannelFactory;
+import org.jboss.netty.channel.ChannelFuture;
+import org.jboss.netty.channel.ChannelPipeline;
/**
*
@@ -41,82 +50,198 @@
*/
public class NettyConnectionTest extends UnitTestCase
{
- class MyListener implements ConnectionLifeCycleListener
+
+ public void testGetID() throws Exception
{
+ Channel channel = new SimpleChannel(randomInt());
+ NettyConnection conn = new NettyConnection(channel, new MyListener());
- public void connectionCreated(Connection connection)
+ assertEquals(channel.getId().intValue(), conn.getID());
+ }
+
+ public void testWrite() throws Exception
+ {
+ MessagingBuffer buff = ChannelBuffers.wrappedBuffer(ByteBuffer.allocate(128));
+ SimpleChannel channel = new SimpleChannel(randomInt());
+
+ assertEquals(0, channel.getWritten().size());
+
+ NettyConnection conn = new NettyConnection(channel, new MyListener());
+ conn.write(buff);
+
+ assertEquals(1, channel.getWritten().size());
+ assertEquals(buff.getUnderlyingBuffer(), channel.getWritten().get(0));
+ }
+
+ public void testCreateBuffer() throws Exception
+ {
+ Channel channel = new SimpleChannel(randomInt());
+ NettyConnection conn = new NettyConnection(channel, new MyListener());
+
+ final int size = 1234;
+
+ MessagingBuffer buff = conn.createBuffer(size);
+ buff.writeByte((byte)0x00); // Netty buffer does lazy initialization.
+ assertEquals(size, buff.capacity());
+
+ }
+
+ private final class SimpleChannel implements Channel
+ {
+ private final int id;
+
+ private final List<Object> written = new LinkedList<Object>();
+
+ private SimpleChannel(int id)
{
-
-
+ this.id = id;
}
+
+ public List<Object> getWritten()
+ {
+ return written;
+ }
- public void connectionDestroyed(Object connectionID)
+ public int compareTo(Channel arg0)
{
-
-
+ return 0;
}
- public void connectionException(Object connectionID, MessagingException me)
+ public ChannelFuture write(Object arg0, SocketAddress arg1)
{
-
-
+ written.add(arg0);
+ return null;
}
-
- }
-
- public void testGetID() throws Exception
- {
- Channel channel = EasyMock.createStrictMock(Channel.class);
- final int id = randomInt();
-
- EasyMock.expect(channel.getId()).andReturn(id);
+ public ChannelFuture write(Object arg0)
+ {
+ written.add(arg0);
+ return null;
+ }
- NettyConnection conn = new NettyConnection(channel, new MyListener());
+ public ChannelFuture unbind()
+ {
+ return null;
+ }
- EasyMock.replay(channel);
+ public ChannelFuture setReadable(boolean arg0)
+ {
+ return null;
+ }
- assertEquals(id, conn.getID());
+ public ChannelFuture setInterestOps(int arg0)
+ {
+ return null;
+ }
- EasyMock.verify(channel);
- }
+ public boolean isWritable()
+ {
+ return false;
+ }
- public void testWrite() throws Exception
- {
- Channel channel = EasyMock.createStrictMock(Channel.class);
+ public boolean isReadable()
+ {
+ return false;
+ }
- final Object underlying = new Object();
+ public boolean isOpen()
+ {
+ return false;
+ }
- MessagingBuffer buff = EasyMock.createStrictMock(MessagingBuffer.class);
+ public boolean isConnected()
+ {
+ return false;
+ }
- EasyMock.expect(buff.getUnderlyingBuffer()).andReturn(underlying);
+ public boolean isBound()
+ {
+ return false;
+ }
- EasyMock.expect(channel.write(underlying)).andReturn(null);
+ public SocketAddress getRemoteAddress()
+ {
+ return null;
+ }
- NettyConnection conn = new NettyConnection(channel, new MyListener());
+ public ChannelPipeline getPipeline()
+ {
+ return null;
+ }
- EasyMock.replay(channel, buff);
+ public Channel getParent()
+ {
+ return null;
+ }
- conn.write(buff);
+ public SocketAddress getLocalAddress()
+ {
+ return null;
+ }
- EasyMock.verify(channel, buff);
+ public int getInterestOps()
+ {
+ return 0;
+ }
+
+ public Integer getId()
+ {
+ return id;
+ }
+
+ public ChannelFactory getFactory()
+ {
+ return null;
+ }
+
+ public ChannelConfig getConfig()
+ {
+ return null;
+ }
+
+ public ChannelFuture getCloseFuture()
+ {
+ return null;
+ }
+
+ public ChannelFuture disconnect()
+ {
+ return null;
+ }
+
+ public ChannelFuture connect(SocketAddress arg0)
+ {
+ return null;
+ }
+
+ public ChannelFuture close()
+ {
+ return null;
+ }
+
+ public ChannelFuture bind(SocketAddress arg0)
+ {
+ return null;
+ }
}
- public void testCreateBuffer() throws Exception
+ class MyListener implements ConnectionLifeCycleListener
{
- Channel channel = EasyMock.createStrictMock(Channel.class);
- NettyConnection conn = new NettyConnection(channel, new MyListener());
+ public void connectionCreated(Connection connection)
+ {
- EasyMock.replay(channel);
+ }
- final int size = 1234;
+ public void connectionDestroyed(Object connectionID)
+ {
- MessagingBuffer buff = conn.createBuffer(size);
- buff.writeByte((byte) 0x00); // Netty buffer does lazy initialization.
- assertEquals(size, buff.capacity());
+ }
- EasyMock.verify(channel);
+ public void connectionException(Object connectionID, MessagingException me)
+ {
+
+ }
+
}
-
}
Modified: trunk/tests/src/org/jboss/messaging/tests/unit/core/remoting/impl/netty/NettyConnectorTest.java
===================================================================
--- trunk/tests/src/org/jboss/messaging/tests/unit/core/remoting/impl/netty/NettyConnectorTest.java 2009-06-09 11:29:06 UTC (rev 7270)
+++ trunk/tests/src/org/jboss/messaging/tests/unit/core/remoting/impl/netty/NettyConnectorTest.java 2009-06-09 11:30:46 UTC (rev 7271)
@@ -26,9 +26,12 @@
import java.util.Map;
import java.util.concurrent.Executors;
-import org.easymock.EasyMock;
+import org.jboss.messaging.core.exception.MessagingException;
+import org.jboss.messaging.core.remoting.impl.AbstractBufferHandler;
import org.jboss.messaging.core.remoting.spi.BufferHandler;
+import org.jboss.messaging.core.remoting.spi.Connection;
import org.jboss.messaging.core.remoting.spi.ConnectionLifeCycleListener;
+import org.jboss.messaging.core.remoting.spi.MessagingBuffer;
import org.jboss.messaging.integration.transports.netty.NettyConnector;
import org.jboss.messaging.tests.util.UnitTestCase;
@@ -53,21 +56,59 @@
public void testStartStop() throws Exception
{
- BufferHandler handler = EasyMock.createStrictMock(BufferHandler.class);
+ BufferHandler handler = new AbstractBufferHandler()
+ {
+ public void bufferReceived(Object connectionID, MessagingBuffer buffer)
+ {
+ }
+ };
Map<String, Object> params = new HashMap<String, Object>();
- ConnectionLifeCycleListener listener = EasyMock.createStrictMock(ConnectionLifeCycleListener.class);
-
+ ConnectionLifeCycleListener listener = new ConnectionLifeCycleListener()
+ {
+ public void connectionException(Object connectionID, MessagingException me)
+ {
+ }
+
+ public void connectionDestroyed(Object connectionID)
+ {
+ }
+
+ public void connectionCreated(Connection connection)
+ {
+ }
+ };
+
NettyConnector connector = new NettyConnector(params, handler, listener, Executors.newCachedThreadPool());
connector.start();
+ assertTrue(connector.isStarted());
connector.close();
+ assertFalse(connector.isStarted());
}
public void testNullParams() throws Exception
{
- BufferHandler handler = EasyMock.createStrictMock(BufferHandler.class);
+ BufferHandler handler = new AbstractBufferHandler()
+ {
+ public void bufferReceived(Object connectionID, MessagingBuffer buffer)
+ {
+ }
+ };
Map<String, Object> params = new HashMap<String, Object>();
- ConnectionLifeCycleListener listener = EasyMock.createStrictMock(ConnectionLifeCycleListener.class);
+ ConnectionLifeCycleListener listener = new ConnectionLifeCycleListener()
+ {
+ public void connectionException(Object connectionID, MessagingException me)
+ {
+ }
+
+ public void connectionDestroyed(Object connectionID)
+ {
+ }
+
+ public void connectionCreated(Connection connection)
+ {
+ }
+ };
try
{
Modified: trunk/tests/src/org/jboss/messaging/tests/unit/core/server/impl/QueueImplTest.java
===================================================================
--- trunk/tests/src/org/jboss/messaging/tests/unit/core/server/impl/QueueImplTest.java 2009-06-09 11:29:06 UTC (rev 7270)
+++ trunk/tests/src/org/jboss/messaging/tests/unit/core/server/impl/QueueImplTest.java 2009-06-09 11:30:46 UTC (rev 7271)
@@ -23,11 +23,14 @@
package org.jboss.messaging.tests.unit.core.server.impl;
-import org.easymock.EasyMock;
+import java.util.ArrayList;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.concurrent.CountDownLatch;
+import java.util.concurrent.Executors;
+import java.util.concurrent.ScheduledExecutorService;
+
import org.jboss.messaging.core.filter.Filter;
-import org.jboss.messaging.core.paging.PagingManager;
-import org.jboss.messaging.core.paging.PagingStore;
-import org.jboss.messaging.core.postoffice.PostOffice;
import org.jboss.messaging.core.server.Consumer;
import org.jboss.messaging.core.server.Distributor;
import org.jboss.messaging.core.server.HandleStatus;
@@ -38,16 +41,10 @@
import org.jboss.messaging.core.server.impl.RoundRobinDistributor;
import org.jboss.messaging.tests.unit.core.server.impl.fakes.FakeConsumer;
import org.jboss.messaging.tests.unit.core.server.impl.fakes.FakeFilter;
+import org.jboss.messaging.tests.unit.core.server.impl.fakes.FakePostOffice;
import org.jboss.messaging.tests.util.UnitTestCase;
import org.jboss.messaging.utils.SimpleString;
-import java.util.ArrayList;
-import java.util.LinkedList;
-import java.util.List;
-import java.util.concurrent.CountDownLatch;
-import java.util.concurrent.Executors;
-import java.util.concurrent.ScheduledExecutorService;
-
/**
* A QueueTest
*
@@ -439,7 +436,7 @@
public void testChangeConsumersAndDeliver() throws Exception
{
- Queue queue = new QueueImpl(1, address1, queue1, null, false, true, scheduledExecutor, createMockPostOffice(), null, null);
+ Queue queue = new QueueImpl(1, address1, queue1, null, false, true, scheduledExecutor, new FakePostOffice(), null, null);
final int numMessages = 10;
@@ -850,7 +847,7 @@
public void testConsumeWithFiltersAddAndRemoveConsumer() throws Exception
{
- Queue queue = new QueueImpl(1, address1, queue1, null, false, true, scheduledExecutor, createMockPostOffice(), null, null);
+ Queue queue = new QueueImpl(1, address1, queue1, null, false, true, scheduledExecutor, new FakePostOffice(), null, null);
Filter filter = new FakeFilter("fruit", "orange");
@@ -923,7 +920,7 @@
private void testConsumerWithFilters(boolean direct) throws Exception
{
- Queue queue = new QueueImpl(1, address1, queue1, null, false, true, scheduledExecutor, createMockPostOffice(), null, null);
+ Queue queue = new QueueImpl(1, address1, queue1, null, false, true, scheduledExecutor, new FakePostOffice(), null, null);
Filter filter = new FakeFilter("fruit", "orange");
@@ -1011,7 +1008,7 @@
public void testMessageOrder() throws Exception
{
- Consumer consumer = EasyMock.createStrictMock(Consumer.class);
+ FakeConsumer consumer = new FakeConsumer();
Queue queue = new QueueImpl(1, address1, queue1, null, false, true, scheduledExecutor, null, null, null);
MessageReference messageReference = generateReference(queue, 1);
MessageReference messageReference2 = generateReference(queue, 2);
@@ -1019,13 +1016,15 @@
queue.addFirst(messageReference);
queue.addLast(messageReference2);
queue.addFirst(messageReference3);
- EasyMock.expect(consumer.handle(messageReference3)).andReturn(HandleStatus.HANDLED);
- EasyMock.expect(consumer.handle(messageReference)).andReturn(HandleStatus.HANDLED);
- EasyMock.expect(consumer.handle(messageReference2)).andReturn(HandleStatus.HANDLED);
- EasyMock.replay(consumer);
+
+ assertEquals(0, consumer.getReferences().size());
queue.addConsumer(consumer);
queue.deliverNow();
- EasyMock.verify(consumer);
+
+ assertEquals(3, consumer.getReferences().size());
+ assertEquals(messageReference3, consumer.getReferences().get(0));
+ assertEquals(messageReference, consumer.getReferences().get(1));
+ assertEquals(messageReference2, consumer.getReferences().get(2));
}
public void testMessagesAdded() throws Exception
@@ -1068,23 +1067,6 @@
}
- /**
- * @return
- */
- private PostOffice createMockPostOffice() throws Exception
- {
- PagingStore niceStore = EasyMock.createNiceMock(PagingStore.class);
- PagingManager niceManager = EasyMock.createNiceMock(PagingManager.class);
- PostOffice nicePostOffice = EasyMock.createNiceMock(PostOffice.class);
- EasyMock.expect(nicePostOffice.getPagingManager()).andStubReturn(niceManager);
- EasyMock.expect(niceManager.getPageStore((SimpleString)EasyMock.anyObject())).andStubReturn(niceStore);
- EasyMock.replay(niceManager, nicePostOffice, niceStore);
- return nicePostOffice;
- }
-
-
- // Inner classes ---------------------------------------------------------------
-
class AddtoQueueRunner implements Runnable
{
Queue queue;
Added: trunk/tests/src/org/jboss/messaging/tests/unit/core/server/impl/fakes/FakePostOffice.java
===================================================================
--- trunk/tests/src/org/jboss/messaging/tests/unit/core/server/impl/fakes/FakePostOffice.java (rev 0)
+++ trunk/tests/src/org/jboss/messaging/tests/unit/core/server/impl/fakes/FakePostOffice.java 2009-06-09 11:30:46 UTC (rev 7271)
@@ -0,0 +1,162 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005-2009, Red Hat Middleware LLC, and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+
+
+package org.jboss.messaging.tests.unit.core.server.impl.fakes;
+
+import java.util.List;
+
+import org.jboss.messaging.core.paging.PagingManager;
+import org.jboss.messaging.core.postoffice.Binding;
+import org.jboss.messaging.core.postoffice.Bindings;
+import org.jboss.messaging.core.postoffice.DuplicateIDCache;
+import org.jboss.messaging.core.postoffice.PostOffice;
+import org.jboss.messaging.core.server.Queue;
+import org.jboss.messaging.core.server.ServerMessage;
+import org.jboss.messaging.core.transaction.Transaction;
+import org.jboss.messaging.utils.SimpleString;
+
+public class FakePostOffice implements PostOffice
+{
+
+ public Object getNotificationLock()
+ {
+ return null;
+ }
+
+ public Bindings getMatchingBindings(SimpleString address)
+ {
+ return null;
+ }
+
+ /* (non-Javadoc)
+ * @see org.jboss.messaging.core.postoffice.PostOffice#activate()
+ */
+ public List<Queue> activate()
+ {
+ return null;
+ }
+
+ /* (non-Javadoc)
+ * @see org.jboss.messaging.core.postoffice.PostOffice#addBinding(org.jboss.messaging.core.postoffice.Binding)
+ */
+ public void addBinding(final Binding binding) throws Exception
+ {
+ }
+
+ /* (non-Javadoc)
+ * @see org.jboss.messaging.core.postoffice.PostOffice#getBinding(org.jboss.messaging.utils.SimpleString)
+ */
+ public Binding getBinding(final SimpleString uniqueName)
+ {
+ return null;
+ }
+
+ /* (non-Javadoc)
+ * @see org.jboss.messaging.core.postoffice.PostOffice#getBindingsForAddress(org.jboss.messaging.utils.SimpleString)
+ */
+ public Bindings getBindingsForAddress(final SimpleString address) throws Exception
+ {
+ return null;
+ }
+
+ /* (non-Javadoc)
+ * @see org.jboss.messaging.core.postoffice.PostOffice#getDuplicateIDCache(org.jboss.messaging.utils.SimpleString)
+ */
+ public DuplicateIDCache getDuplicateIDCache(final SimpleString address)
+ {
+ return null;
+ }
+
+ /* (non-Javadoc)
+ * @see org.jboss.messaging.core.postoffice.PostOffice#getPagingManager()
+ */
+ public PagingManager getPagingManager()
+ {
+ return null;
+ }
+
+ /* (non-Javadoc)
+ * @see org.jboss.messaging.core.postoffice.PostOffice#redistribute(org.jboss.messaging.core.server.ServerMessage, org.jboss.messaging.utils.SimpleString, org.jboss.messaging.core.transaction.Transaction)
+ */
+ public boolean redistribute(final ServerMessage message, final Queue queue, final Transaction tx) throws Exception
+ {
+ return false;
+ }
+
+ /* (non-Javadoc)
+ * @see org.jboss.messaging.core.postoffice.PostOffice#removeBinding(org.jboss.messaging.utils.SimpleString)
+ */
+ public Binding removeBinding(final SimpleString uniqueName) throws Exception
+ {
+ return null;
+ }
+
+ /* (non-Javadoc)
+ * @see org.jboss.messaging.core.postoffice.PostOffice#route(org.jboss.messaging.core.server.ServerMessage)
+ */
+ public void route(final ServerMessage message) throws Exception
+ {
+
+ }
+
+ /* (non-Javadoc)
+ * @see org.jboss.messaging.core.postoffice.PostOffice#route(org.jboss.messaging.core.server.ServerMessage, org.jboss.messaging.core.transaction.Transaction)
+ */
+ public void route(final ServerMessage message, final Transaction tx) throws Exception
+ {
+
+ }
+
+ /* (non-Javadoc)
+ * @see org.jboss.messaging.core.postoffice.PostOffice#sendQueueInfoToQueue(org.jboss.messaging.utils.SimpleString, org.jboss.messaging.utils.SimpleString)
+ */
+ public void sendQueueInfoToQueue(final SimpleString queueName, final SimpleString address) throws Exception
+ {
+
+ }
+
+ /* (non-Javadoc)
+ * @see org.jboss.messaging.core.server.MessagingComponent#isStarted()
+ */
+ public boolean isStarted()
+ {
+ return false;
+ }
+
+ /* (non-Javadoc)
+ * @see org.jboss.messaging.core.server.MessagingComponent#start()
+ */
+ public void start() throws Exception
+ {
+
+ }
+
+ /* (non-Javadoc)
+ * @see org.jboss.messaging.core.server.MessagingComponent#stop()
+ */
+ public void stop() throws Exception
+ {
+
+ }
+
+}
\ No newline at end of file
More information about the jboss-cvs-commits
mailing list