source: trunk/src/test/java/omq/test/temporal/ProvaTest.java

Last change on this file was 84, checked in by stoda, 11 years ago

Default queues added, default exchange enabled, more control in remote queues added.
Tests verified and changed Persistent test to show how to make persistent messages.

File size: 3.0 KB
Line 
1package omq.test.temporal;
2
3import static org.junit.Assert.assertEquals;
4
5import java.util.Arrays;
6import java.util.Collection;
7import java.util.Properties;
8
9import omq.common.broker.Broker;
10import omq.common.util.ParameterQueue;
11import omq.common.util.Serializer;
12import omq.test.calculator.Calculator;
13import omq.test.calculator.CalculatorImpl;
14
15import org.junit.After;
16import org.junit.BeforeClass;
17import org.junit.Test;
18import org.junit.runner.RunWith;
19import org.junit.runners.Parameterized;
20import org.junit.runners.Parameterized.Parameters;
21
22/**
23 *
24 * @author Sergi Toda <sergi.toda@estudiants.urv.cat>
25 *
26 */
27@RunWith(value = Parameterized.class)
28public class ProvaTest {
29
30        @BeforeClass
31        public static void serverTest() throws Exception {
32                Properties env = new Properties();
33                env.setProperty(ParameterQueue.USER_NAME, "guest");
34                env.setProperty(ParameterQueue.USER_PASS, "guest");
35
36                // Get host info of rabbimq (where it is)
37                env.setProperty(ParameterQueue.RABBIT_HOST, "127.0.0.1");
38                env.setProperty(ParameterQueue.RABBIT_PORT, "5672");
39                env.setProperty(ParameterQueue.DURABLE_QUEUE, "false");
40                env.setProperty(ParameterQueue.ENABLE_COMPRESSION, "false");
41
42                // Set info about where the message will be sent
43                env.setProperty(ParameterQueue.RPC_EXCHANGE, "rpc_exchange");
44                env.setProperty(ParameterQueue.RETRY_TIME_CONNECTION, "2000");
45
46                CalculatorImpl calc = new CalculatorImpl();
47
48                Broker broker = new Broker(env);
49                broker.bind("calculator1", calc);
50
51                System.out.println("Server started");
52        }
53
54        private static Broker broker;
55        private static Calculator remoteCalc;
56
57        public ProvaTest(String type) throws Exception {
58                Properties env = new Properties();
59                env.setProperty(ParameterQueue.USER_NAME, "guest");
60                env.setProperty(ParameterQueue.USER_PASS, "guest");
61
62                // Set host info of rabbimq (where it is)
63                env.setProperty(ParameterQueue.RABBIT_HOST, "127.0.0.1");
64                env.setProperty(ParameterQueue.RABBIT_PORT, "5672");
65                env.setProperty(ParameterQueue.DURABLE_QUEUE, "false");
66                env.setProperty(ParameterQueue.PROXY_SERIALIZER, type);
67                env.setProperty(ParameterQueue.ENABLE_COMPRESSION, "false");
68
69                // Set info about where the message will be sent
70                env.setProperty(ParameterQueue.RPC_EXCHANGE, "rpc_exchange");
71                // env.setProperty(ParameterQueue.DEBUGFILE, "c:\\middlewareDebug");
72
73                // Set info about the queue & the exchange where the ResponseListener
74                // will listen to.
75                env.setProperty(ParameterQueue.RPC_REPLY_QUEUE, "reply_queue");
76
77                broker = new Broker(env);
78                remoteCalc = broker.lookup("calculator1", Calculator.class);
79        }
80
81        @Parameters
82        public static Collection<Object[]> data() {
83                Object[][] data = new Object[][] { { Serializer.JAVA } /*
84                                                                                                                                 * , {
85                                                                                                                                 * Serializer
86                                                                                                                                 * .gson }, {
87                                                                                                                                 * Serializer
88                                                                                                                                 * .kryo }
89                                                                                                                                 */};
90                return Arrays.asList(data);
91        }
92
93        @After
94        public void stop() throws Exception {
95                broker.stopBroker();
96        }
97
98        @Test
99        public void add() throws Exception {
100                int x = 10;
101                int y = 20;
102
103                int sync = remoteCalc.add(x, y);
104                int sum = x + y;
105
106                assertEquals(sum, sync);
107        }
108
109}
Note: See TracBrowser for help on using the repository browser.