1 14 15 package org.apache.activemq.perf; 16 17 import javax.jms.ConnectionFactory ; 18 import javax.jms.DeliveryMode ; 19 import javax.jms.Destination ; 20 import javax.jms.JMSException ; 21 import org.apache.activemq.ActiveMQConnectionFactory; 22 import org.apache.activemq.ActiveMQPrefetchPolicy; 23 import org.apache.activemq.broker.BrokerService; 24 import org.apache.activemq.xbean.BrokerFactoryBean; 25 import org.springframework.core.io.ClassPathResource; 26 import org.springframework.core.io.Resource; 27 28 31 public class SlowConsumerTopicTest extends SimpleTopicTest{ 32 33 protected PerfConsumer[] slowConsumers; 34 protected int NUMBER_OF_SLOW_CONSUMERS=1; 35 36 protected void setUp() throws Exception { 37 NUMBER_OF_CONSUMERS=0; 38 PAYLOAD_SIZE=10 * 1024; 39 super.setUp(); 40 slowConsumers=new SlowConsumer[NUMBER_OF_SLOW_CONSUMERS]; 41 for(int i=0;i<NUMBER_OF_SLOW_CONSUMERS;i++){ 42 slowConsumers[i]=createSlowConsumer(factory,destination,i); 43 slowConsumers[i].start(); 44 } 45 } 46 47 protected PerfConsumer createSlowConsumer(ConnectionFactory fac,Destination dest,int number) throws JMSException { 48 return new SlowConsumer(fac,dest); 49 } 50 51 protected PerfProducer createProducer(ConnectionFactory fac,Destination dest,int number,byte[] payload) 52 throws JMSException { 53 PerfProducer result=super.createProducer(fac,dest,number,payload); 54 result.setDeliveryMode(DeliveryMode.NON_PERSISTENT); 55 return result; 56 } 57 58 protected BrokerService createBroker() throws Exception { 59 Resource resource=new ClassPathResource("org/apache/activemq/perf/slowConsumerBroker.xml"); 60 BrokerFactoryBean factory=new BrokerFactoryBean(resource); 61 factory.afterPropertiesSet(); 62 BrokerService broker=factory.getBroker(); 63 broker.start(); 64 return broker; 65 } 66 67 protected ActiveMQConnectionFactory createConnectionFactory() throws Exception { 68 ActiveMQConnectionFactory result = super.createConnectionFactory(); 69 ActiveMQPrefetchPolicy policy = new ActiveMQPrefetchPolicy(); 70 policy.setTopicPrefetch(1000); 71 result.setPrefetchPolicy(policy); 72 return result; 73 } 74 } 75 | Popular Tags |