source: trunk/src/test/java/faultToleranceTest/ClientTest.java @ 44

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

Objectmq converted to maven project

File size: 1.9 KB
Line 
1package faultToleranceTest;
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.common.util.Serializer;
10
11import org.junit.BeforeClass;
12import org.junit.Test;
13
14import calculatorTest.Calculator;
15
16public class ClientTest {
17        private static Calculator remoteCalc;
18
19        @BeforeClass
20        public static void startClient() throws Exception {
21                Properties env = new Properties();
22                env.setProperty(ParameterQueue.USER_NAME, "guest");
23                env.setProperty(ParameterQueue.USER_PASS, "guest");
24
25                // Set host info of rabbimq (where it is)
26                env.setProperty(ParameterQueue.SERVER_HOST, "127.0.0.1");
27                env.setProperty(ParameterQueue.SERVER_PORT, "5672");
28                env.setProperty(ParameterQueue.DURABLE_QUEUES, "false");
29                env.setProperty(ParameterQueue.SERIALIZER_NAME, Serializer.java);
30                env.setProperty(ParameterQueue.ENABLECOMPRESSION, "false");
31
32                // Set info about where the message will be sent
33                env.setProperty(ParameterQueue.RPC_EXCHANGE, "rpc_exchange");
34                // env.setProperty(ParameterQueue.DEBUGFILE, "c:\\middlewareDebug");
35
36                // Set info about the queue & the exchange where the ResponseListener
37                // will listen to.
38                env.setProperty(ParameterQueue.RPC_REPLY_QUEUE, "reply_queue");
39                env.setProperty(ParameterQueue.EVENT_REPLY_QUEUE, "event_queue");
40                env.setProperty(ParameterQueue.RETRY_TIME_CONNECTION, "5000");
41
42                Broker.initBroker(env);
43                remoteCalc = (Calculator) Broker.lookup("calculator1", Calculator.class);
44        }
45
46        @Test
47        public void toleranceTest() throws Exception {
48                int x = 10;
49                int y = 20;
50                int sum = 10 + 20;
51
52                int sync = remoteCalc.add(x, y);
53
54                String password = "unpc";
55                String[] command = { "/bin/bash", "-c", "echo " + password + " | sudo -S service rabbitmq-server restart" };
56
57                Runtime runtime = Runtime.getRuntime();
58                runtime.exec(command);
59
60                Thread.sleep(15000);
61                int resp = remoteCalc.add(x, y);
62
63                assertEquals(sum, sync);
64                assertEquals(sum, resp);
65        }
66
67}
Note: See TracBrowser for help on using the repository browser.