[jboss-cvs] JBoss Messaging SVN: r4569 - trunk/tests/src/org/jboss/messaging/tests/unit/core/server/impl.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Tue Jun 24 06:36:07 EDT 2008
Author: ataylor
Date: 2008-06-24 06:36:06 -0400 (Tue, 24 Jun 2008)
New Revision: 4569
Added:
trunk/tests/src/org/jboss/messaging/tests/unit/core/server/impl/MessagingServerPacketHandlerTest.java
trunk/tests/src/org/jboss/messaging/tests/unit/core/server/impl/MessagingServiceImplTest.java
trunk/tests/src/org/jboss/messaging/tests/unit/core/server/impl/QueueFactoryImplTest.java
Log:
more tests
Added: trunk/tests/src/org/jboss/messaging/tests/unit/core/server/impl/MessagingServerPacketHandlerTest.java
===================================================================
--- trunk/tests/src/org/jboss/messaging/tests/unit/core/server/impl/MessagingServerPacketHandlerTest.java (rev 0)
+++ trunk/tests/src/org/jboss/messaging/tests/unit/core/server/impl/MessagingServerPacketHandlerTest.java 2008-06-24 10:36:06 UTC (rev 4569)
@@ -0,0 +1,141 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005-2008, 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;
+
+import org.easymock.EasyMock;
+import org.easymock.IAnswer;
+import org.jboss.messaging.core.exception.MessagingException;
+import org.jboss.messaging.core.remoting.Packet;
+import org.jboss.messaging.core.remoting.PacketReturner;
+import org.jboss.messaging.core.remoting.RemotingService;
+import org.jboss.messaging.core.remoting.impl.wireformat.CreateConnectionRequest;
+import org.jboss.messaging.core.remoting.impl.wireformat.CreateConnectionResponse;
+import org.jboss.messaging.core.remoting.impl.wireformat.Ping;
+import org.jboss.messaging.core.remoting.impl.wireformat.Pong;
+import org.jboss.messaging.core.server.MessagingServer;
+import org.jboss.messaging.core.server.impl.MessagingServerPacketHandler;
+import org.jboss.messaging.core.version.Version;
+import org.jboss.messaging.tests.util.UnitTestCase;
+
+/**
+ * @author <a href="ataylor at redhat.com">Andy Taylor</a>
+ */
+public class MessagingServerPacketHandlerTest extends UnitTestCase
+{
+ public void testIdIsZero()
+ {
+ MessagingServer server = EasyMock.createStrictMock(MessagingServer.class);
+ MessagingServerPacketHandler messagingServerPacketHandler = new MessagingServerPacketHandler(server);
+ EasyMock.replay(server);
+ assertEquals(0, messagingServerPacketHandler.getID());
+ EasyMock.verify(server);
+ }
+
+ public void testHandleCreateConnection() throws Exception
+ {
+ MessagingServer server = EasyMock.createStrictMock(MessagingServer.class);
+ Version serverVersion = EasyMock.createStrictMock(Version.class);
+ CreateConnectionRequest packet = new CreateConnectionRequest(123, "andy", "taylor");
+ CreateConnectionResponse createConnectionResponse = new CreateConnectionResponse(1, serverVersion );
+ PacketReturner sender = EasyMock.createStrictMock(PacketReturner.class);
+ MessagingServerPacketHandler messagingServerPacketHandler = new MessagingServerPacketHandler(server);
+ EasyMock.expect(server.createConnection("andy", "taylor", 123, sender)).andReturn(createConnectionResponse);
+ EasyMock.replay(server, sender);
+ assertEquals(createConnectionResponse, messagingServerPacketHandler.doHandle(packet, sender));
+ EasyMock.verify(server, sender);
+ }
+
+ public void testHandlePing() throws Exception
+ {
+ MessagingServer server = EasyMock.createStrictMock(MessagingServer.class);
+ RemotingService remotingService = EasyMock.createStrictMock(RemotingService.class);
+ final Ping packet = new Ping(456);
+ PacketReturner sender = EasyMock.createStrictMock(PacketReturner.class);
+ MessagingServerPacketHandler messagingServerPacketHandler = new MessagingServerPacketHandler(server);
+ EasyMock.expect(server.getRemotingService()).andStubReturn(remotingService);
+ EasyMock.expect(remotingService.isSession(789l)).andReturn(true);
+ EasyMock.expect(sender.getSessionID()).andStubReturn(789);
+ sender.send((Packet) EasyMock.anyObject());
+ EasyMock.expectLastCall().andAnswer(new IAnswer<Object>()
+ {
+ public Object answer() throws Throwable
+ {
+ Pong decodedPong = (Pong) EasyMock.getCurrentArguments()[0];
+ assertEquals(decodedPong.getSessionID(), 456);
+ assertEquals(decodedPong.getTargetID(), packet.getResponseTargetID());
+ assertEquals(decodedPong.isSessionFailed(), false);
+ return null;
+ }
+ });
+ EasyMock.replay(server, sender, remotingService);
+ messagingServerPacketHandler.doHandle(packet, sender);
+ EasyMock.verify(server, sender, remotingService);
+ }
+
+ public void testHandlePingNoSession() throws Exception
+ {
+ MessagingServer server = EasyMock.createStrictMock(MessagingServer.class);
+ RemotingService remotingService = EasyMock.createStrictMock(RemotingService.class);
+ final Ping packet = new Ping(456);
+ PacketReturner sender = EasyMock.createStrictMock(PacketReturner.class);
+ MessagingServerPacketHandler messagingServerPacketHandler = new MessagingServerPacketHandler(server);
+ EasyMock.expect(server.getRemotingService()).andStubReturn(remotingService);
+ EasyMock.expect(remotingService.isSession(789l)).andReturn(false);
+ EasyMock.expect(sender.getSessionID()).andStubReturn(789);
+ sender.send((Packet) EasyMock.anyObject());
+ EasyMock.expectLastCall().andAnswer(new IAnswer<Object>()
+ {
+ public Object answer() throws Throwable
+ {
+ Pong decodedPong = (Pong) EasyMock.getCurrentArguments()[0];
+ assertEquals(decodedPong.getSessionID(), 456);
+ assertEquals(decodedPong.getTargetID(), packet.getResponseTargetID());
+ assertEquals(decodedPong.isSessionFailed(), true);
+ return null;
+ }
+ });
+ EasyMock.replay(server, sender, remotingService);
+ messagingServerPacketHandler.doHandle(packet, sender);
+ EasyMock.verify(server, sender, remotingService);
+ }
+
+ public void testUnsupportedPacket() throws Exception
+ {
+ MessagingServer server = EasyMock.createStrictMock(MessagingServer.class);
+ Packet packet = EasyMock.createStrictMock(Packet.class);
+ PacketReturner sender = EasyMock.createStrictMock(PacketReturner.class);
+ MessagingServerPacketHandler messagingServerPacketHandler = new MessagingServerPacketHandler(server);
+ EasyMock.expect(packet.getType()).andReturn(Byte.MAX_VALUE);
+ EasyMock.replay(server, packet, sender);
+ try
+ {
+ messagingServerPacketHandler.doHandle(packet, sender);
+ fail("should throw exception");
+ }
+ catch (Exception e)
+ {
+ MessagingException messagingException = (MessagingException) e;
+ assertEquals(messagingException.getCode(), MessagingException.UNSUPPORTED_PACKET);
+ }
+ EasyMock.verify(server, packet, sender);
+ }
+}
Added: trunk/tests/src/org/jboss/messaging/tests/unit/core/server/impl/MessagingServiceImplTest.java
===================================================================
--- trunk/tests/src/org/jboss/messaging/tests/unit/core/server/impl/MessagingServiceImplTest.java (rev 0)
+++ trunk/tests/src/org/jboss/messaging/tests/unit/core/server/impl/MessagingServiceImplTest.java 2008-06-24 10:36:06 UTC (rev 4569)
@@ -0,0 +1,93 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005-2008, 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;
+
+import org.easymock.EasyMock;
+import org.jboss.messaging.core.config.Configuration;
+import org.jboss.messaging.core.config.impl.ConfigurationImpl;
+import org.jboss.messaging.core.persistence.StorageManager;
+import org.jboss.messaging.core.persistence.impl.nullpm.NullStorageManager;
+import org.jboss.messaging.core.remoting.RemotingService;
+import org.jboss.messaging.core.server.MessagingServer;
+import org.jboss.messaging.core.server.MessagingService;
+import org.jboss.messaging.core.server.impl.MessagingServiceImpl;
+import org.jboss.messaging.tests.util.UnitTestCase;
+
+/**
+ * @author <a href="ataylor at redhat.com">Andy Taylor</a>
+ */
+public class MessagingServiceImplTest extends UnitTestCase
+{
+ public void testStart() throws Exception
+ {
+ MessagingServer messagingServer = EasyMock.createStrictMock(MessagingServer.class);
+ StorageManager storageManager = EasyMock.createStrictMock(StorageManager.class);
+ RemotingService remotingService = EasyMock.createStrictMock(RemotingService.class);
+ remotingService.start();
+ storageManager.start();
+ messagingServer.start();
+ EasyMock.replay(messagingServer, storageManager, remotingService);
+ MessagingService messagingService = new MessagingServiceImpl(messagingServer, storageManager, remotingService);
+ messagingService.start();
+ EasyMock.verify(messagingServer, storageManager, remotingService);
+ assertEquals(messagingService.getServer(), messagingServer);
+ }
+
+ public void testStop() throws Exception
+ {
+ MessagingServer messagingServer = EasyMock.createStrictMock(MessagingServer.class);
+ StorageManager storageManager = EasyMock.createStrictMock(StorageManager.class);
+ RemotingService remotingService = EasyMock.createStrictMock(RemotingService.class);
+ remotingService.start();
+ storageManager.start();
+ messagingServer.start();
+ remotingService.stop();
+ storageManager.stop();
+ messagingServer.stop();
+ EasyMock.replay(messagingServer, storageManager, remotingService);
+ MessagingService messagingService = new MessagingServiceImpl(messagingServer, storageManager, remotingService);
+ messagingService.start();
+ messagingService.stop();
+ EasyMock.verify(messagingServer, storageManager, remotingService);
+ }
+
+ public void testNewNullStorageMessagingServer() throws Exception
+ {
+ Configuration config = new ConfigurationImpl();
+ MessagingService messagingService = MessagingServiceImpl.newNullStorageMessagingServer(config);
+ messagingService.start();
+ assertTrue(messagingService.isStarted());
+ assertEquals(messagingService.getServer().getStorageManager().getClass(), NullStorageManager.class);
+ messagingService.stop();
+ assertFalse(messagingService.isStarted());
+ }
+
+ public void testNewNullStorageMessagingServerDefault() throws Exception
+ {
+ MessagingService messagingService = MessagingServiceImpl.newNullStorageMessagingServer();
+ messagingService.start();
+ assertTrue(messagingService.isStarted());
+ assertEquals(messagingService.getServer().getStorageManager().getClass(), NullStorageManager.class);
+ messagingService.stop();
+ assertFalse(messagingService.isStarted());
+ }
+}
Added: trunk/tests/src/org/jboss/messaging/tests/unit/core/server/impl/QueueFactoryImplTest.java
===================================================================
--- trunk/tests/src/org/jboss/messaging/tests/unit/core/server/impl/QueueFactoryImplTest.java (rev 0)
+++ trunk/tests/src/org/jboss/messaging/tests/unit/core/server/impl/QueueFactoryImplTest.java 2008-06-24 10:36:06 UTC (rev 4569)
@@ -0,0 +1,89 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005-2008, 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;
+
+import org.easymock.EasyMock;
+import org.jboss.messaging.core.filter.Filter;
+import org.jboss.messaging.core.server.Queue;
+import org.jboss.messaging.core.server.impl.QueueFactoryImpl;
+import org.jboss.messaging.core.server.impl.RoundRobinDistributionPolicy;
+import org.jboss.messaging.core.settings.HierarchicalRepository;
+import org.jboss.messaging.core.settings.impl.QueueSettings;
+import org.jboss.messaging.tests.util.UnitTestCase;
+import org.jboss.messaging.util.SimpleString;
+
+import java.util.concurrent.ScheduledExecutorService;
+
+/**
+ * @author <a href="ataylor at redhat.com">Andy Taylor</a>
+ */
+public class QueueFactoryImplTest extends UnitTestCase
+{
+ public void testCreateQueue()
+ {
+ ScheduledExecutorService scheduledExecutor = EasyMock.createStrictMock(ScheduledExecutorService.class);
+ HierarchicalRepository<QueueSettings> queueSettingsRepository = EasyMock.createStrictMock(HierarchicalRepository.class);
+ Filter filter = EasyMock.createStrictMock(Filter.class);
+ QueueSettings queueSettings = new QueueSettings();
+ queueSettings.setClustered(true);
+ queueSettings.setMaxSizeBytes(9999);
+ queueSettings.setDistributionPolicyClass("org.jboss.messaging.core.server.impl.RoundRobinDistributionPolicy");
+ EasyMock.expect(queueSettingsRepository.getMatch("testQ")).andReturn(queueSettings);
+ EasyMock.replay(scheduledExecutor, queueSettingsRepository);
+ QueueFactoryImpl queueFactory = new QueueFactoryImpl(scheduledExecutor, queueSettingsRepository);
+ SimpleString qName = new SimpleString("testQ");
+ Queue queue = queueFactory.createQueue(123, qName, filter, true, true);
+ EasyMock.verify(scheduledExecutor, queueSettingsRepository);
+ assertEquals(queue.getDistributionPolicy().getClass(), RoundRobinDistributionPolicy.class);
+ assertEquals(queue.isClustered(), true);
+ assertEquals(queue.getMaxSizeBytes(), 9999);
+ assertEquals(queue.getName(), qName);
+ assertEquals(queue.getPersistenceID(), 123);
+ assertEquals(queue.getFilter(), filter);
+ assertEquals(queue.isDurable(), true);
+ assertEquals(queue.isTemporary(), true);
+ }
+
+ public void testCreateQueue2()
+ {
+ ScheduledExecutorService scheduledExecutor = EasyMock.createStrictMock(ScheduledExecutorService.class);
+ HierarchicalRepository<QueueSettings> queueSettingsRepository = EasyMock.createStrictMock(HierarchicalRepository.class);
+ QueueSettings queueSettings = new QueueSettings();
+ queueSettings.setClustered(false);
+ queueSettings.setMaxSizeBytes(8888);
+ queueSettings.setDistributionPolicyClass(null);
+ EasyMock.expect(queueSettingsRepository.getMatch("testQ2")).andReturn(queueSettings);
+ EasyMock.replay(scheduledExecutor, queueSettingsRepository);
+ QueueFactoryImpl queueFactory = new QueueFactoryImpl(scheduledExecutor, queueSettingsRepository);
+ SimpleString qName = new SimpleString("testQ2");
+ Queue queue = queueFactory.createQueue(456, qName, null, false, false);
+ EasyMock.verify(scheduledExecutor, queueSettingsRepository);
+ assertEquals(queue.getDistributionPolicy().getClass(), RoundRobinDistributionPolicy.class);
+ assertEquals(queue.isClustered(), false);
+ assertEquals(queue.getMaxSizeBytes(), 8888);
+ assertEquals(queue.getName(), qName);
+ assertEquals(queue.getPersistenceID(), 456);
+ assertEquals(queue.getFilter(), null);
+ assertEquals(queue.isDurable(), false);
+ assertEquals(queue.isTemporary(), false);
+ }
+}
More information about the jboss-cvs-commits
mailing list