Changeset 70 for trunk/src/test/java/omq/test/event/MessageTest.java
- Timestamp:
- 06/28/13 12:41:11 (11 years ago)
- File:
-
- 1 moved
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/test/java/omq/test/event/MessageTest.java
r67 r70 3 3 import static org.junit.Assert.assertEquals; 4 4 5 import java.util.Arrays; 6 import java.util.Collection; 5 7 import java.util.Properties; 6 8 … … 9 11 import omq.common.util.Serializer; 10 12 13 import org.junit.After; 11 14 import org.junit.BeforeClass; 12 15 import org.junit.Test; 16 import org.junit.runner.RunWith; 17 import org.junit.runners.Parameterized; 18 import org.junit.runners.Parameterized.Parameters; 13 19 14 public class EventTest { 15 private static EventTriggerImpl trigger; 20 @RunWith(value = Parameterized.class) 21 public class MessageTest { 22 private static final String NAME = "message"; 23 24 private static Broker broker; 25 private static Message serverProxy; 26 private static MessageImpl clientM1; 27 private static MessageImpl clientM2; 28 29 public MessageTest(String type) throws Exception { 30 Properties env = new Properties(); 31 env.setProperty(ParameterQueue.USER_NAME, "guest"); 32 env.setProperty(ParameterQueue.USER_PASS, "guest"); 33 34 // Set host info of rabbimq (where it is) 35 env.setProperty(ParameterQueue.SERVER_HOST, "127.0.0.1"); 36 env.setProperty(ParameterQueue.SERVER_PORT, "5672"); 37 env.setProperty(ParameterQueue.DURABLE_QUEUES, "false"); 38 env.setProperty(ParameterQueue.SERIALIZER_NAME, type); 39 env.setProperty(ParameterQueue.ENABLECOMPRESSION, "false"); 40 41 // Set info about where the message will be sent 42 env.setProperty(ParameterQueue.RPC_EXCHANGE, "rpc_exchange"); 43 44 // Set info about the queue & the exchange where the ResponseListener 45 // will listen to. 46 env.setProperty(ParameterQueue.RPC_REPLY_QUEUE, "reply_queue"); 47 env.setProperty(ParameterQueue.EVENT_REPLY_QUEUE, "event_queue"); 48 49 broker = new Broker(env); 50 serverProxy = broker.lookupMulti(NAME, Message.class); 51 } 52 53 @Parameters 54 public static Collection<Object[]> data() { 55 Object[][] data = new Object[][] { { Serializer.JAVA }, { Serializer.GSON }, { Serializer.KRYO } }; 56 return Arrays.asList(data); 57 } 16 58 17 59 @BeforeClass 18 public static void server() throws Exception {60 public static void client() throws Exception { 19 61 Properties env = new Properties(); 20 62 env.setProperty(ParameterQueue.USER_NAME, "guest"); … … 31 73 env.setProperty(ParameterQueue.RETRY_TIME_CONNECTION, "2000"); 32 74 33 trigger = new EventTriggerImpl();34 75 Broker broker = new Broker(env); 76 clientM1 = new MessageImpl(); 77 broker.bind(NAME, clientM1); 35 78 36 broker.startTriggerEvent("trigger", trigger); 79 Broker broker2 = new Broker(env); 80 clientM2 = new MessageImpl(); 81 broker2.bind(NAME, clientM2); 82 } 37 83 38 System.out.println("Server started"); 84 @After 85 public void stop() throws Exception { 86 broker.stopBroker(); 39 87 } 40 88 41 89 @Test 42 public void eventTest() throws Exception { 43 String expected = "This is an event"; 44 String actual = null; 90 public void test() throws Exception { 91 String expected = "Hello"; 45 92 46 Properties env = new Properties(); 47 env.setProperty(ParameterQueue.USER_NAME, "guest"); 48 env.setProperty(ParameterQueue.USER_PASS, "guest"); 93 serverProxy.setMessage(expected); 94 Thread.sleep(200); 95 assertEquals(expected, clientM1.getMessage()); 96 assertEquals(expected, clientM2.getMessage()); 97 serverProxy.setMessage(""); 98 Thread.sleep(200); 99 } 49 100 50 // Set host info of rabbimq (where it is)51 env.setProperty(ParameterQueue.SERVER_HOST, "127.0.0.1");52 env.setProperty(ParameterQueue.SERVER_PORT, "5672");53 env.setProperty(ParameterQueue.DURABLE_QUEUES, "false");54 env.setProperty(ParameterQueue.SERIALIZER_NAME, Serializer.JAVA);55 env.setProperty(ParameterQueue.ENABLECOMPRESSION, "false");56 57 // Set info about where the message will be sent58 env.setProperty(ParameterQueue.RPC_EXCHANGE, "rpc_exchange");59 // env.setProperty(ParameterQueue.DEBUGFILE, "c:\\middlewareDebug");60 61 // Set info about the queue & the exchange where the ResponseListener62 // will listen to.63 env.setProperty(ParameterQueue.RPC_REPLY_QUEUE, "reply_queue");64 env.setProperty(ParameterQueue.EVENT_REPLY_QUEUE, "event_queue");65 66 Broker broker = new Broker(env);67 EventTrigger et = broker.lookup("trigger", EventTrigger.class);68 69 MessageListener ms = new MessageListener();70 et.addListener(ms);71 trigger.triggerEvent(expected);72 Thread.sleep(500);73 actual = ms.getMessage();74 75 assertEquals(expected, actual);76 }77 101 }
Note: See TracChangeset
for help on using the changeset viewer.