Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

Source code: org/activemq/io/impl/ActiveMQMapMessageReaderTest.java


1   /*
2    * Created on Mar 8, 2004 To change the template for this generated file go to Window - Preferences - Java - Code
3    * Generation - Code and Comments
4    */
5   package org.activemq.io.impl;
6   
7   import java.io.IOException;
8   import java.util.HashMap;
9   import javax.jms.JMSException;
10  import org.activemq.message.ActiveMQMapMessage;
11  import org.activemq.message.Packet;
12  
13  /**
14   * @author Rob To change the template for this generated type comment go to Window - Preferences - Java - Code
15   *         Generation - Code and Comments
16   */
17  public class ActiveMQMapMessageReaderTest extends ActiveMQMessageReaderTest {
18  
19    private HashMap table;
20    public static void main(String[] args) {
21      junit.textui.TestRunner.run(ActiveMQMapMessageReaderTest.class);
22    }
23  
24    /*
25     * @see TestCase#setUp()
26     */
27    protected void setUp() throws Exception {
28      super.setUp();
29      this.table = new HashMap();
30      for (int i = 0; i < 10; i++) {
31        String str = "test" + i;
32        this.table.put(str, str);
33      }
34    }
35  
36    /*
37     * @see TestCase#tearDown()
38     */
39    protected void tearDown() throws Exception {
40      super.tearDown();
41    }
42  
43    /**
44     * Constructor for ActiveMQTextMessageReaderTest.
45     * 
46     * @param arg0
47     */
48    public ActiveMQMapMessageReaderTest(String arg0) {
49      super(arg0);
50    }
51  
52    public void testGetPacketType() {
53      ActiveMQMapMessage msg = new ActiveMQMapMessage();
54      assertTrue(msg.getPacketType() == Packet.ACTIVEMQ_MAP_MESSAGE);
55    }
56  
57    public void testReadPacket() {
58          DefaultWireFormat wf = new DefaultWireFormat();
59      ActiveMQMapMessageReader reader = new ActiveMQMapMessageReader(wf);
60      ActiveMQMapMessageWriter writer = new ActiveMQMapMessageWriter(wf);
61      ActiveMQMapMessage msg1 = new ActiveMQMapMessage();
62      try {
63        msg1.setTable(this.table);
64        super.initializeMessage(msg1);
65        byte[] data = writer.writePacketToByteArray(msg1);
66        ActiveMQMapMessage msg2 = (ActiveMQMapMessage) reader.readPacketFromByteArray(data);
67        super.testEquals(msg1, msg2);
68        assertTrue(msg1.getTable().equals(msg2.getTable()));
69      }
70          catch(JMSException jmsEx){
71              jmsEx.printStackTrace();
72              assertTrue(false);
73          }
74      catch (IOException e) {
75        e.printStackTrace();
76        assertTrue(false);
77      }
78    }
79  
80    public void testTime() {
81  
82          DefaultWireFormat wf = new DefaultWireFormat();
83      ActiveMQMapMessageReader reader = new ActiveMQMapMessageReader(wf);
84      ActiveMQMapMessageWriter writer = new ActiveMQMapMessageWriter(wf);
85      ActiveMQMapMessage msg1 = new ActiveMQMapMessage();
86  
87      ActiveMQMapMessage msg2 = null;
88      try {
89        int count = 10000;
90        long startTime = System.currentTimeMillis();
91  
92        msg1.setTable(this.table);
93        super.initializeMessage(msg1);
94        for (int i = 0; i < count; i++) {
95          byte[] data = writer.writePacketToByteArray(msg1);
96          msg2 = (ActiveMQMapMessage) reader.readPacketFromByteArray(data);
97        }
98        long finishTime = System.currentTimeMillis();
99        long totalTime = finishTime - startTime;
100       long ps = (count * 1000) / totalTime;
101       System.out.println("Time taken :" + totalTime + " for " + count + "iterations, = " + ps + " per sec.");
102 
103     }
104     catch (Throwable e) {
105       e.printStackTrace();
106       assertTrue(false);
107     }
108   }
109 
110 }