1 22 package org.jboss.test.jbossmq.stress; 23 24 import junit.framework.TestSuite; 25 import junit.framework.Assert; 26 27 import org.jboss.test.jbossmq.MQBase; 28 29 35 36 public class QueueTest extends MQBase 37 { 38 39 public QueueTest(String name) 40 { 41 super(name); 42 } 43 44 48 public void runQueueSubscriberPartOne() throws Exception 49 { 50 try 51 { 52 drainQueue(); 54 55 int ic = getIterationCount(); 56 57 IntRangeMessageFilter f1 = new IntRangeMessageFilter(javax.jms.Message .class, 59 "QUEUE_NR", 60 0, 61 ic / 2); 62 63 QueueWorker sub1 = new QueueWorker(SUBSCRIBER, 64 TRANS_NONE, 65 f1); 66 Thread t1 = new Thread (sub1); 67 t1.start(); 68 69 IntRangeMessageCreator c1 = new IntRangeMessageCreator("QUEUE_NR", 71 0); 72 QueueWorker pub1 = new QueueWorker(PUBLISHER, 73 TRANS_NONE, 74 c1, 75 ic / 2); 76 pub1.connect(); 77 pub1.publish(); 78 79 Assert.assertEquals("Publisher did not publish correct number of messages " + pub1.getMessageHandled(), 80 ic / 2, 81 pub1.getMessageHandled()); 82 83 log.debug("Sleeping for " + ((ic * 10) / 60000) + " minutes"); 85 sleep(ic * 10); 87 88 Assert.assertEquals("Subscriber did not get correct number of messages " + sub1.getMessageHandled(), 89 ic / 2, 90 sub1.getMessageHandled()); 91 92 sub1.close(); 94 t1.interrupt(); 95 96 pub1.publish(ic / 2); 98 Assert.assertEquals("Publisher did not publish correct number of messages " + pub1.getMessageHandled(), ic, 99 pub1.getMessageHandled()); 100 101 pub1.close(); 102 } 103 catch (Throwable t) 104 { 105 log.error("Error in test: " + t, t); 106 throw new Exception (t.getMessage()); 107 } 108 } 109 110 114 public void runQueueSubscriberPartTwo() throws Exception 115 { 116 try 117 { 118 int ic = getIterationCount(); 119 IntRangeMessageFilter f1 = new IntRangeMessageFilter(javax.jms.Message .class, 121 "QUEUE_NR", 122 0, 123 ic / 2); 124 125 QueueWorker sub1 = new QueueWorker(SUBSCRIBER, 126 TRANS_NONE, 127 f1); 128 129 Thread t2 = new Thread (sub1); 131 t2.start(); 132 133 log.debug("Sleeping for " + ((ic * 10) / 60000) + " minutes"); 134 sleep(ic * 10); 135 Assert.assertEquals("Subscriber did not get correct number of messages " + sub1.getMessageHandled(), ic / 2, 136 sub1.getMessageHandled()); 137 138 sub1.close(); 140 t2.interrupt(); 141 142 } 143 catch (Throwable t) 144 { 145 log.error("Error in test: " + t, t); 146 throw new Exception (t.getMessage()); 147 } 148 } 149 150 153 public void testQueueSubscriber() throws Exception 154 { 155 runQueueSubscriberPartOne(); 156 runQueueSubscriberPartTwo(); 157 } 158 159 public static junit.framework.Test suite() throws Exception 160 { 161 162 TestSuite suite = new TestSuite(); 163 suite.addTest(new QueueSubOne("testQueueSubscriber")); 164 165 return suite; 166 } 167 168 public static void main(String [] args) 169 { 170 171 } 172 173 } | Popular Tags |