1 /** 2 * 3 * Licensed to the Apache Software Foundation (ASF) under one or more 4 * contributor license agreements. See the NOTICE file distributed with 5 * this work for additional information regarding copyright ownership. 6 * The ASF licenses this file to You under the Apache License, Version 2.0 7 * (the "License"); you may not use this file except in compliance with 8 * the License. You may obtain a copy of the License at 9 * 10 * http://www.apache.org/licenses/LICENSE-2.0 11 * 12 * Unless required by applicable law or agreed to in writing, software 13 * distributed under the License is distributed on an "AS IS" BASIS, 14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 * See the License for the specific language governing permissions and 16 * limitations under the License. 17 */ 18 package org.apache.activemq.ra; 19 20 import org.jmock.MockObjectTestCase; 21 22 /** 23 * @version $Revision: 1.1.1.1 $ 24 */ 25 public class ServerSessionImplTest extends MockObjectTestCase { 26 27 /** 28 * Need to re-work this test case, it broke since the amq4 internals changed and 29 * mocks were being using against the internals. 30 * 31 */ 32 public void testDummy() { 33 } 34 35 /* 36 public void testBatch() throws Exception { 37 DummyActiveMQConnection connection = new DummyActiveMQConnection(new ActiveMQConnectionFactory(), 38 null, 39 null, 40 getMockTransportChannel()); 41 ServerSessionPoolImpl pool = new ServerSessionPoolImpl(null, 1); 42 DummyActiveMQSession session = new DummyActiveMQSession(connection); 43 MemoryBoundedQueue queue = connection.getMemoryBoundedQueue("Session(" + session.getSessionId() + ")"); 44 queue.enqueue(new ActiveMQTextMessage()); 45 queue.enqueue(new ActiveMQTextMessage()); 46 queue.enqueue(new ActiveMQTextMessage()); 47 DummyMessageEndpoint endpoint = new DummyMessageEndpoint(); 48 ServerSessionImpl serverSession = new ServerSessionImpl(pool, session, null, endpoint, true, 2); 49 serverSession.run(); 50 assertEquals(2, endpoint.messagesPerBatch.size()); 51 assertEquals(new Integer(2), endpoint.messagesPerBatch.get(0)); 52 assertEquals(new Integer(1), endpoint.messagesPerBatch.get(1)); 53 } 54 55 private class DummyMessageEndpoint implements MessageEndpoint, MessageListener { 56 protected List messagesPerBatch = new ArrayList(); 57 protected int nbMessages = -1000; 58 public void beforeDelivery(Method arg0) throws NoSuchMethodException, ResourceException { 59 nbMessages = 0; 60 } 61 public void afterDelivery() throws ResourceException { 62 messagesPerBatch.add(new Integer(nbMessages)); 63 nbMessages = -1000; 64 } 65 public void release() { 66 } 67 public void onMessage(Message arg0) { 68 nbMessages ++; 69 } 70 } 71 72 private class DummyActiveMQSession extends ActiveMQSession { 73 protected DummyActiveMQSession(ActiveMQConnection connection, SessionId sessionId, int acknowledgeMode, boolean asyncDispatch) throws JMSException { 74 super(connection, sessionId, acknowledgeMode, asyncDispatch); 75 } 76 } 77 78 private class DummyActiveMQConnection extends ActiveMQConnection { 79 protected DummyActiveMQConnection(Transport transport, String userName, String password, JMSStatsImpl factoryStats) throws IOException { 80 super(transport, userName, password, factoryStats); 81 } 82 } 83 84 private TransportChannel getMockTransportChannel() { 85 Mock tc = new Mock(TransportChannel.class); 86 tc.expects(once()).method("setPacketListener"); 87 tc.expects(once()).method("setExceptionListener"); 88 tc.expects(once()).method("addTransportStatusEventListener"); 89 tc.expects(atLeastOnce()).method("asyncSend"); 90 tc.expects(atLeastOnce()).method("send"); 91 return (TransportChannel) tc.proxy(); 92 } 93 */ 94 } 95