KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > activemq > command > MessageSendTest


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.command;
19
20 import java.io.IOException JavaDoc;
21
22 import junit.framework.Test;
23
24 import org.apache.activemq.util.ByteSequence;
25
26 public class MessageSendTest extends DataStructureTestSupport {
27
28     public static Test suite() {
29         return suite(MessageSendTest.class);
30     }
31
32     public static void main(String JavaDoc[] args) {
33         junit.textui.TestRunner.run(suite());
34     }
35
36     public void initCombosForTestMessageSendMarshaling() {
37         addCombinationValues("cacheEnabled", new Object JavaDoc[] { Boolean.TRUE, Boolean.FALSE });
38     }
39
40     public void testMessageSendMarshaling() throws IOException JavaDoc {
41         ActiveMQMessage message = new ActiveMQMessage();
42         message.setCommandId((short) 1);
43         message.setDestination(new ActiveMQQueue("queue"));
44         message.setGroupID("group");
45         message.setGroupSequence(4);
46         message.setCorrelationId("correlation");
47         message.setMessageId(new MessageId("c1:1:1", 1));
48
49         assertBeanMarshalls(message);
50         assertBeanMarshalls(message);
51
52     }
53
54     public void xtestPerformance() throws IOException JavaDoc {
55         ActiveMQMessage message = new ActiveMQMessage();
56         message.setProducerId(new ProducerId(new SessionId(new ConnectionId(new ConnectionId("test")), 1), 1));
57         message.setMessageId(new MessageId(message.getProducerId(), 1));
58         message.setCommandId((short) 1);
59         message.setGroupID("group");
60         message.setGroupSequence(4);
61         message.setCorrelationId("correlation");
62         message.setContent(new ByteSequence(new byte[1024], 0, 1024));
63         message.setTimestamp(System.currentTimeMillis());
64         message.setDestination(new ActiveMQQueue("TEST"));
65
66         int p = 1000000;
67
68         long start = System.currentTimeMillis();
69         for (int i = 0; i < p; i++) {
70             marshalAndUnmarshall(message, wireFormat);
71         }
72         long end = System.currentTimeMillis();
73
74         log.info("marshaled/unmarshaled: " + p + " msgs at " + (p * 1000f / (end - start)) + " msgs/sec");
75     }
76 }
77
Popular Tags