1 | package omq.test.event; |
---|
2 | |
---|
3 | import static org.junit.Assert.assertEquals; |
---|
4 | |
---|
5 | import java.util.Arrays; |
---|
6 | import java.util.Collection; |
---|
7 | import java.util.Properties; |
---|
8 | |
---|
9 | import omq.common.broker.Broker; |
---|
10 | import omq.common.util.ParameterQueue; |
---|
11 | import omq.common.util.Serializer; |
---|
12 | |
---|
13 | import org.junit.After; |
---|
14 | import org.junit.BeforeClass; |
---|
15 | import org.junit.Test; |
---|
16 | import org.junit.runner.RunWith; |
---|
17 | import org.junit.runners.Parameterized; |
---|
18 | import org.junit.runners.Parameterized.Parameters; |
---|
19 | |
---|
20 | /** |
---|
21 | * |
---|
22 | * @author Sergi Toda <sergi.toda@estudiants.urv.cat> |
---|
23 | * |
---|
24 | */ |
---|
25 | @RunWith(value = Parameterized.class) |
---|
26 | public class MessageTest { |
---|
27 | private static final String NAME = "message_event_test"; |
---|
28 | |
---|
29 | private static Broker broker; |
---|
30 | private static Message serverProxy; |
---|
31 | private static MessageImpl clientM1; |
---|
32 | private static MessageImpl clientM2; |
---|
33 | |
---|
34 | public MessageTest(String type) throws Exception { |
---|
35 | Properties env = new Properties(); |
---|
36 | env.setProperty(ParameterQueue.USER_NAME, "guest"); |
---|
37 | env.setProperty(ParameterQueue.USER_PASS, "guest"); |
---|
38 | |
---|
39 | // Set host info of rabbimq (where it is) |
---|
40 | env.setProperty(ParameterQueue.RABBIT_HOST, "127.0.0.1"); |
---|
41 | env.setProperty(ParameterQueue.RABBIT_PORT, "5672"); |
---|
42 | env.setProperty(ParameterQueue.DURABLE_QUEUE, "false"); |
---|
43 | env.setProperty(ParameterQueue.PROXY_SERIALIZER, type); |
---|
44 | env.setProperty(ParameterQueue.ENABLE_COMPRESSION, "false"); |
---|
45 | |
---|
46 | // Set info about where the message will be sent |
---|
47 | env.setProperty(ParameterQueue.RPC_EXCHANGE, "rpc_exchange"); |
---|
48 | |
---|
49 | // Set info about the queue & the exchange where the ResponseListener |
---|
50 | // will listen to. |
---|
51 | env.setProperty(ParameterQueue.RPC_REPLY_QUEUE, "reply_queue"); |
---|
52 | |
---|
53 | broker = new Broker(env); |
---|
54 | serverProxy = broker.lookupMulti(NAME, Message.class); |
---|
55 | } |
---|
56 | |
---|
57 | @Parameters |
---|
58 | public static Collection<Object[]> data() { |
---|
59 | Object[][] data = new Object[][] { { Serializer.JAVA }, { Serializer.GSON }, { Serializer.KRYO } }; |
---|
60 | return Arrays.asList(data); |
---|
61 | } |
---|
62 | |
---|
63 | @BeforeClass |
---|
64 | public static void client() throws Exception { |
---|
65 | Properties env = new Properties(); |
---|
66 | env.setProperty(ParameterQueue.USER_NAME, "guest"); |
---|
67 | env.setProperty(ParameterQueue.USER_PASS, "guest"); |
---|
68 | |
---|
69 | // Get host info of rabbimq (where it is) |
---|
70 | env.setProperty(ParameterQueue.RABBIT_HOST, "127.0.0.1"); |
---|
71 | env.setProperty(ParameterQueue.RABBIT_PORT, "5672"); |
---|
72 | env.setProperty(ParameterQueue.DURABLE_QUEUE, "false"); |
---|
73 | env.setProperty(ParameterQueue.ENABLE_COMPRESSION, "false"); |
---|
74 | |
---|
75 | // Set info about where the message will be sent |
---|
76 | env.setProperty(ParameterQueue.RPC_EXCHANGE, "rpc_exchange"); |
---|
77 | env.setProperty(ParameterQueue.RETRY_TIME_CONNECTION, "2000"); |
---|
78 | |
---|
79 | Broker broker = new Broker(env); |
---|
80 | clientM1 = new MessageImpl(); |
---|
81 | broker.bind(NAME, clientM1); |
---|
82 | |
---|
83 | Broker broker2 = new Broker(env); |
---|
84 | clientM2 = new MessageImpl(); |
---|
85 | broker2.bind(NAME, clientM2); |
---|
86 | } |
---|
87 | |
---|
88 | @After |
---|
89 | public void stop() throws Exception { |
---|
90 | broker.stopBroker(); |
---|
91 | } |
---|
92 | |
---|
93 | @Test |
---|
94 | public void test() throws Exception { |
---|
95 | String expected = "Hello"; |
---|
96 | serverProxy.setMessage(expected); |
---|
97 | Thread.sleep(200); |
---|
98 | assertEquals(expected, clientM1.getMessage()); |
---|
99 | assertEquals(expected, clientM2.getMessage()); |
---|
100 | serverProxy.setMessage(""); |
---|
101 | Thread.sleep(200); |
---|
102 | } |
---|
103 | |
---|
104 | } |
---|