1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package ch.elca.el4j.tests.services.remoting.loadbalancing.client.roundrobin;
18
19 import static org.junit.Assert.assertEquals;
20 import static org.junit.Assert.fail;
21
22 import org.slf4j.Logger;
23 import org.slf4j.LoggerFactory;
24 import org.junit.Test;
25 import org.springframework.beans.factory.BeanFactory;
26 import org.springframework.context.ApplicationContext;
27
28 import ch.elca.el4j.core.context.ModuleApplicationContext;
29 import ch.elca.el4j.tests.services.remoting.loadbalancing.common.BusinessObject;
30
31
32
33
34
35
36
37
38
39 public class LbRoundRobinTest {
40
41
42 private static final String ServerNameAndPort1 = "localhost:8091" ;
43 private static final String ServerNameAndPort2 = "localhost:8095" ;
44 private static final String ServerNameAndPort3 = "localhost:8098" ;
45
46
47 public LbRoundRobinTest() {
48 super();
49 m_applicationContext = new ModuleApplicationContext(
50 getInclusiveConfigLocations(),
51 (String[]) null,
52 false,
53 null);
54 }
55
56
57
58
59
60
61
62 @Test
63 public void testNextProtocol() {
64 getLog().debug("Starting test 'testIdempotence'....");
65 try {
66 s_logger.debug("-- Calling with hello 1") ;
67 String result = getTestObj().call("hello1") ;
68 assertEquals(ServerNameAndPort1 + " should have executed this code.",
69 ServerNameAndPort1,
70 result);
71 s_logger.debug("-- Calling with hello 2") ;
72 result = getTestObj().call("hello2") ;
73 assertEquals(ServerNameAndPort2 + " should have executed this code.",
74 ServerNameAndPort2,
75 result);
76 s_logger.debug("-- Calling with hello 3") ;
77 result = getTestObj().call("hello3") ;
78 assertEquals(ServerNameAndPort3 + " should have executed this code.",
79 ServerNameAndPort3,
80 result);
81 s_logger.debug("-- Calling with hello 4") ;
82 result = getTestObj().call("hello4") ;
83 assertEquals(ServerNameAndPort1 + " should have executed this code.",
84 ServerNameAndPort1,
85 result);
86 s_logger.debug("-- Calling with hello 5") ;
87 result = getTestObj().call("hello5") ;
88 assertEquals(ServerNameAndPort2 + " should have executed this code.",
89 ServerNameAndPort2,
90 result);
91
92 } catch (Exception e) {
93 e.printStackTrace();
94 fail("Exception occurred: " + e.getMessage());
95 }
96 }
97
98
99 protected void runTest() {
100 testNextProtocol();
101 }
102
103
104 protected String[] getInclusiveConfigLocations() {
105 return new String[] {
106 "classpath*:mandatory/*.xml",
107 "classpath:loadbalancing/client/roundrobin/startup.xml",
108 "classpath:loadbalancing/remoting/roundrobin/loadbalancing-protocol-config.xml",
109 "classpath:loadbalancing/remoting/loadbalancing-generic-protocol-config.xml",
110 "classpath:remoting/loadbalancing/policy/roundrobin-policy-config.xml"};
111 }
112
113 protected Logger getLog() {
114 return s_logger;
115 }
116
117 protected BusinessObject getTestObj() {
118 if (m_obj == null) {
119 BeanFactory factory = (BeanFactory) m_applicationContext;
120
121 m_obj = (BusinessObject) factory.getBean("rmiBusinessObj");
122
123 }
124 return m_obj;
125 }
126
127
128
129
130 private static Logger s_logger = LoggerFactory
131 .getLogger(LbRoundRobinTest.class);
132
133 private ApplicationContext m_applicationContext ;
134
135 private BusinessObject m_obj ;
136
137 }