KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > activemq > memory > buffer > MemoryBufferTestSupport


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.memory.buffer;
19
20 import junit.framework.TestCase;
21
22 import org.apache.activemq.command.ActiveMQMessage;
23 import org.apache.commons.logging.Log;
24 import org.apache.commons.logging.LogFactory;
25
26 /**
27  *
28  * @version $Revision: 1.1 $
29  */

30 public abstract class MemoryBufferTestSupport extends TestCase {
31     protected static final Log log = LogFactory.getLog(MemoryBufferTestSupport.class);
32
33     protected abstract MessageBuffer createMessageBuffer();
34
35     protected MessageBuffer buffer = createMessageBuffer();
36     protected MessageQueue qA = buffer.createMessageQueue();
37     protected MessageQueue qB = buffer.createMessageQueue();
38     protected MessageQueue qC = buffer.createMessageQueue();
39     protected int messageCount;
40
41     protected void setUp() throws Exception JavaDoc {
42         buffer = createMessageBuffer();
43         qA = buffer.createMessageQueue();
44         qB = buffer.createMessageQueue();
45         qC = buffer.createMessageQueue();
46     }
47
48     protected void dump() {
49         log.info("Dumping current state");
50         dumpQueue(qA, "A");
51         dumpQueue(qB, "B");
52         dumpQueue(qC, "C");
53     }
54
55     protected void dumpQueue(MessageQueue queue, String JavaDoc name) {
56         log.info(" " + name + " = " + queue.getList());
57     }
58
59     protected ActiveMQMessage createMessage(int size) throws Exception JavaDoc {
60         DummyMessage answer = new DummyMessage(size);
61         answer.setIntProperty("counter", ++messageCount);
62         answer.setJMSMessageID("" + messageCount);
63         return answer;
64     }
65
66 }
67
Popular Tags