| Home >> All >> org >> activemq >> io >> [ impl Javadoc ] |
Source code: org/activemq/io/impl/ActiveMQTextMessageReaderTest.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 javax.jms.JMSException; 9 import org.activemq.message.ActiveMQTextMessage; 10 import org.activemq.message.Packet; 11 12 /** 13 */ 14 public class ActiveMQTextMessageReaderTest extends ActiveMQMessageReaderTest { 15 16 private String testStr; 17 public static void main(String[] args) { 18 junit.textui.TestRunner.run(ActiveMQTextMessageReaderTest.class); 19 } 20 21 /* 22 * @see TestCase#setUp() 23 */ 24 protected void setUp() throws Exception { 25 super.setUp(); 26 StringBuffer buf = new StringBuffer(); 27 char start = 'a'; 28 int total = 1024 * 100; 29 int count = 0; 30 while (count < total) { 31 char c = start; 32 for (int i = 0; i < 26; i++) { 33 buf.append(c); 34 c += 1; 35 count++; 36 } 37 } 38 testStr = buf.toString(); 39 40 } 41 42 /* 43 * @see TestCase#tearDown() 44 */ 45 protected void tearDown() throws Exception { 46 super.tearDown(); 47 } 48 49 /** 50 * Constructor for ActiveMQTextMessageReaderTest. 51 * 52 * @param arg0 53 */ 54 public ActiveMQTextMessageReaderTest(String arg0) { 55 super(arg0); 56 } 57 58 public void testGetPacketType() { 59 ActiveMQTextMessage msg = new ActiveMQTextMessage(); 60 assertTrue(msg.getPacketType() == Packet.ACTIVEMQ_TEXT_MESSAGE); 61 } 62 63 public void testReadPacket() { 64 DefaultWireFormat wf = new DefaultWireFormat(); 65 ActiveMQTextMessageReader reader = new ActiveMQTextMessageReader(wf); 66 ActiveMQTextMessageWriter writer = new ActiveMQTextMessageWriter(wf); 67 ActiveMQTextMessage msg1 = new ActiveMQTextMessage(); 68 try { 69 msg1.setText(this.testStr); 70 super.initializeMessage(msg1); 71 byte[] data = writer.writePacketToByteArray(msg1); 72 ActiveMQTextMessage msg2 = (ActiveMQTextMessage) reader.readPacketFromByteArray(data); 73 super.testEquals(msg1, msg2); 74 assertTrue(msg1.getText().equals(msg2.getText())); 75 } 76 catch (IOException e) { 77 e.printStackTrace(); 78 assertTrue(false); 79 } 80 catch (JMSException ex) { 81 ex.printStackTrace(); 82 assertTrue(false); 83 } 84 } 85 86 public void testTime(){ 87 88 DefaultWireFormat wf = new DefaultWireFormat(); 89 ActiveMQTextMessageReader reader = new ActiveMQTextMessageReader(wf); 90 ActiveMQTextMessageWriter writer = new ActiveMQTextMessageWriter(wf); 91 ActiveMQTextMessage msg1 = new ActiveMQTextMessage(); 92 93 ActiveMQTextMessage msg2 = null; 94 try { 95 int count = 10000; 96 long startTime = System.currentTimeMillis(); 97 //msg1.setText(this.testStr); 98 msg1.setText("this is a test str"); 99 super.initializeMessage(msg1); 100 for (int i = 0; i < count; i++){ 101 byte[] data = writer.writePacketToByteArray(msg1); 102 msg2 = (ActiveMQTextMessage) reader.readPacketFromByteArray(data); 103 } 104 long finishTime = System.currentTimeMillis(); 105 long totalTime = finishTime-startTime; 106 long ps = (count * 1000)/totalTime; 107 System.out.println("Time taken :" + totalTime + " for " + count + "iterations, = " + ps +" per sec."); 108 109 }catch(Throwable e){ 110 e.printStackTrace(); 111 assertTrue(false); 112 } 113 } 114 115 }