1 | package omq.test.temporal; |
---|
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 | import omq.test.calculator.Calculator; |
---|
13 | import omq.test.calculator.CalculatorImpl; |
---|
14 | |
---|
15 | import org.junit.After; |
---|
16 | import org.junit.BeforeClass; |
---|
17 | import org.junit.Test; |
---|
18 | import org.junit.runner.RunWith; |
---|
19 | import org.junit.runners.Parameterized; |
---|
20 | import org.junit.runners.Parameterized.Parameters; |
---|
21 | |
---|
22 | @RunWith(value = Parameterized.class) |
---|
23 | public class ProvaTest { |
---|
24 | |
---|
25 | @BeforeClass |
---|
26 | public static void serverTest() throws Exception { |
---|
27 | Properties env = new Properties(); |
---|
28 | env.setProperty(ParameterQueue.USER_NAME, "guest"); |
---|
29 | env.setProperty(ParameterQueue.USER_PASS, "guest"); |
---|
30 | |
---|
31 | // Get host info of rabbimq (where it is) |
---|
32 | env.setProperty(ParameterQueue.SERVER_HOST, "127.0.0.1"); |
---|
33 | env.setProperty(ParameterQueue.SERVER_PORT, "5672"); |
---|
34 | env.setProperty(ParameterQueue.DURABLE_QUEUES, "false"); |
---|
35 | env.setProperty(ParameterQueue.ENABLECOMPRESSION, "false"); |
---|
36 | |
---|
37 | // Set info about where the message will be sent |
---|
38 | env.setProperty(ParameterQueue.RPC_EXCHANGE, "rpc_exchange"); |
---|
39 | env.setProperty(ParameterQueue.RETRY_TIME_CONNECTION, "2000"); |
---|
40 | |
---|
41 | CalculatorImpl calc = new CalculatorImpl(); |
---|
42 | |
---|
43 | Broker broker = new Broker(env); |
---|
44 | broker.bind("calculator1", calc); |
---|
45 | |
---|
46 | System.out.println("Server started"); |
---|
47 | } |
---|
48 | |
---|
49 | private static Broker broker; |
---|
50 | private static Calculator remoteCalc; |
---|
51 | |
---|
52 | public ProvaTest(String type) throws Exception { |
---|
53 | Properties env = new Properties(); |
---|
54 | env.setProperty(ParameterQueue.USER_NAME, "guest"); |
---|
55 | env.setProperty(ParameterQueue.USER_PASS, "guest"); |
---|
56 | |
---|
57 | // Set host info of rabbimq (where it is) |
---|
58 | env.setProperty(ParameterQueue.SERVER_HOST, "127.0.0.1"); |
---|
59 | env.setProperty(ParameterQueue.SERVER_PORT, "5672"); |
---|
60 | env.setProperty(ParameterQueue.DURABLE_QUEUES, "false"); |
---|
61 | env.setProperty(ParameterQueue.SERIALIZER_NAME, type); |
---|
62 | env.setProperty(ParameterQueue.ENABLECOMPRESSION, "false"); |
---|
63 | |
---|
64 | // Set info about where the message will be sent |
---|
65 | env.setProperty(ParameterQueue.RPC_EXCHANGE, "rpc_exchange"); |
---|
66 | // env.setProperty(ParameterQueue.DEBUGFILE, "c:\\middlewareDebug"); |
---|
67 | |
---|
68 | // Set info about the queue & the exchange where the ResponseListener |
---|
69 | // will listen to. |
---|
70 | env.setProperty(ParameterQueue.RPC_REPLY_QUEUE, "reply_queue"); |
---|
71 | env.setProperty(ParameterQueue.EVENT_REPLY_QUEUE, "event_queue"); |
---|
72 | |
---|
73 | broker = new Broker(env); |
---|
74 | remoteCalc = broker.lookup("calculator1", Calculator.class); |
---|
75 | } |
---|
76 | |
---|
77 | @Parameters |
---|
78 | public static Collection<Object[]> data() { |
---|
79 | Object[][] data = new Object[][] { { Serializer.JAVA } /* |
---|
80 | * , { |
---|
81 | * Serializer |
---|
82 | * .gson }, { |
---|
83 | * Serializer |
---|
84 | * .kryo } |
---|
85 | */}; |
---|
86 | return Arrays.asList(data); |
---|
87 | } |
---|
88 | |
---|
89 | @After |
---|
90 | public void stop() throws Exception { |
---|
91 | broker.stopBroker(); |
---|
92 | } |
---|
93 | |
---|
94 | @Test |
---|
95 | public void add() throws Exception { |
---|
96 | int x = 10; |
---|
97 | int y = 20; |
---|
98 | |
---|
99 | int sync = remoteCalc.add(x, y); |
---|
100 | int sum = x + y; |
---|
101 | |
---|
102 | assertEquals(sum, sync); |
---|
103 | } |
---|
104 | |
---|
105 | } |
---|