View Javadoc

1   /*
2    * EL4J, the Extension Library for the J2EE, adds incremental enhancements to
3    * the spring framework, http://el4j.sf.net
4    * Copyright (C) 2006 by ELCA Informatique SA, Av. de la Harpe 22-24,
5    * 1000 Lausanne, Switzerland, http://www.elca.ch
6    *
7    * EL4J is published under the GNU Lesser General Public License (LGPL)
8    * Version 2.1. See http://www.gnu.org/licenses/
9    *
10   * This program is distributed in the hope that it will be useful,
11   * but WITHOUT ANY WARRANTY; without even the implied warranty of
12   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13   * GNU Lesser General Public License for more details.
14   *
15   * For alternative licensing, please contact info@elca.ch
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   * This class tests the idempotent invocation interceptor that handles retrials
33   * by itself.
34   *
35   * @svnLink $Revision: 3879 $;$Date: 2009-08-04 15:13:46 +0200 (Di, 04. Aug 2009) $;$Author: swismer $;$URL: https://el4j.svn.sourceforge.net/svnroot/el4j/branches/el4j_3_1/el4j/framework/tests/remoting/apps/functional_tests/src/test/java/ch/elca/el4j/tests/services/remoting/loadbalancing/client/roundrobin/LbRoundRobinTest.java $
36   *
37   * @author Stefan Pleisch (SPL)
38   */
39  public class LbRoundRobinTest {
40  
41  	/** Define the server names and ports to connect to */
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  	} // <init>
55  
56  	/**
57  	 * Tests whether the server/DB properly abort the transaction upon reception
58  	 * of a special flag.
59  	 *
60  	 * @see #THROW_IDEMPOTENTINVOCATION_EXCEPTION
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  		} // catch
96  	} // testSecondAccess()
97  
98  	/** {@inheritDoc} */
99  	protected void runTest() {
100 		testNextProtocol();
101 	} // runTest()
102 
103 	/** {@inheritDoc} */
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 	} // getInclusiveConfigLocations()
112 
113 	protected Logger getLog() {
114 		return s_logger;
115 	} // getLog()
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 		} // if
124 		return m_obj;
125 	} // getTestObj
126 
127 	/**
128 	 * Private logger.
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 } // CLASS ClientMultipleServerTestCase