source: branches/supervisor/src/test/java/omq/test/serializer/CalculatorTest.java @ 96

Last change on this file since 96 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: 2.4 KB
Line 
1package omq.test.serializer;
2
3import static org.junit.Assert.assertEquals;
4
5import java.util.Properties;
6
7import omq.common.broker.Broker;
8import omq.common.util.ParameterQueue;
9import omq.test.calculator.Calculator;
10import omq.test.calculator.CalculatorImpl;
11
12import org.junit.BeforeClass;
13import org.junit.Test;
14
15/**
16 *
17 * @author Sergi Toda <sergi.toda@estudiants.urv.cat>
18 *
19 */
20public class CalculatorTest {
21
22        private static Broker broker;
23        private static Calculator remoteCalc;
24
25        public CalculatorTest() throws Exception {
26                Properties env = new Properties();
27                env.setProperty(ParameterQueue.USER_NAME, "guest");
28                env.setProperty(ParameterQueue.USER_PASS, "guest");
29
30                // Set host info of rabbimq (where it is)
31                env.setProperty(ParameterQueue.RABBIT_HOST, "127.0.0.1");
32                env.setProperty(ParameterQueue.RABBIT_PORT, "5672");
33                env.setProperty(ParameterQueue.DURABLE_QUEUE, "false");
34                env.setProperty(ParameterQueue.ENABLE_COMPRESSION, "false");
35
36                // Set info about where the message will be sent
37                env.setProperty(ParameterQueue.RPC_EXCHANGE, "rpc_exchange");
38                // env.setProperty(ParameterQueue.DEBUGFILE, "c:\\middlewareDebug");
39
40                // Set info about the queue & the exchange where the ResponseListener
41                // will listen to.
42                env.setProperty(ParameterQueue.RPC_REPLY_QUEUE, "reply_queue");
43
44                broker = new Broker(env);
45                remoteCalc = broker.lookup("calculator1", Calculator.class);
46        }
47
48        @BeforeClass
49        public static void server() throws Exception {
50                Properties env = new Properties();
51                env.setProperty(ParameterQueue.USER_NAME, "guest");
52                env.setProperty(ParameterQueue.USER_PASS, "guest");
53
54                // Get host info of rabbimq (where it is)
55                env.setProperty(ParameterQueue.RABBIT_HOST, "127.0.0.1");
56                env.setProperty(ParameterQueue.RABBIT_PORT, "5672");
57                env.setProperty(ParameterQueue.DURABLE_QUEUE, "false");
58                env.setProperty(ParameterQueue.ENABLE_COMPRESSION, "false");
59
60                // Set info about where the message will be sent
61                env.setProperty(ParameterQueue.RPC_EXCHANGE, "rpc_exchange");
62                env.setProperty(ParameterQueue.RETRY_TIME_CONNECTION, "2000");
63
64                CalculatorImpl calc = new CalculatorImpl();
65                CalculatorImpl calc2 = new CalculatorImpl();
66
67                Broker broker = new Broker(env);
68                broker.bind("calculator1", calc);
69                broker.bind("calculator2", calc2);
70
71                System.out.println("Server started");
72        }
73
74        @Test
75        public void add() throws Exception {
76                int x = 10;
77                int y = 20;
78
79                int sync = remoteCalc.add(x, y);
80                int sum = x + y;
81
82                assertEquals(sum, sync);
83        }
84}
Note: See TracBrowser for help on using the repository browser.