Revision: 15084
Author: vladimir.ralev
Date: Sun Nov 7 19:02:46 2010
Log: Update Issue 2082
Test
http://code.google.com/p/mobicents/source/detail?r=15084
Added:
/trunk/tools/sip-balancer/jar/src/test/java/org/mobicents/tools/sip/balancer/algorithms
/trunk/tools/sip-balancer/jar/src/test/java/org/mobicents/tools/sip/balancer/algorithms/WorstCaseAffinityTest.java
=======================================
--- /dev/null
+++
/trunk/tools/sip-balancer/jar/src/test/java/org/mobicents/tools/sip/balancer/algorithms/WorstCaseAffinityTest.java
Sun Nov 7 19:02:46 2010
@@ -0,0 +1,107 @@
+package org.mobicents.tools.sip.balancer.algorithms;
+
+import java.util.Properties;
+
+import junit.framework.TestCase;
+
+import org.mobicents.tools.sip.balancer.AppServer;
+import org.mobicents.tools.sip.balancer.BalancerRunner;
+import org.mobicents.tools.sip.balancer.EventListener;
+import org.mobicents.tools.sip.balancer.WorstCaseUdpTestAffinityAlgorithm;
+import org.mobicents.tools.sip.balancer.operation.Shootist;
+
+public class WorstCaseAffinityTest extends TestCase {
+ BalancerRunner balancer;
+ int numNodes = 2;
+ AppServer[] servers = new AppServer[numNodes];
+ Shootist shootist;
+
+
+ /* (non-Javadoc)
+ * @see junit.framework.TestCase#setUp()
+ */
+ protected void setUp() throws Exception {
+ super.setUp();
+ shootist = new Shootist();
+ balancer = new BalancerRunner();
+ Properties properties = new Properties();
+ properties.setProperty("javax.sip.STACK_NAME",
"SipBalancerForwarder");
+ properties.setProperty("javax.sip.AUTOMATIC_DIALOG_SUPPORT",
"off");
+ // You need 16 for logging traces. 32 for debug + traces.
+ // Your code will limp at 32 but it is best for debugging.
+ properties.setProperty("gov.nist.javax.sip.TRACE_LEVEL", "32");
+ properties.setProperty("gov.nist.javax.sip.DEBUG_LOG",
+ "logs/sipbalancerforwarderdebug.txt");
+ properties.setProperty("gov.nist.javax.sip.SERVER_LOG",
+ "logs/sipbalancerforwarder.xml");
+ properties.setProperty("gov.nist.javax.sip.THREAD_POOL_SIZE",
"2");
+ properties.setProperty("gov.nist.javax.sip.REENTRANT_LISTENER",
"true");
+
properties.setProperty("gov.nist.javax.sip.CANCEL_CLIENT_TRANSACTION_CHECKED", "false");
+ properties.setProperty("algorithmClass",
WorstCaseUdpTestAffinityAlgorithm.class.getName());
+ properties.setProperty("host", "127.0.0.1");
+ properties.setProperty("internalPort", "5065");
+ properties.setProperty("externalPort", "5060");
+ balancer.start(properties);
+
+
+ for(int q=0;q<servers.length;q++) {
+ servers[q] = new AppServer("node" + q,4060+q);
+ servers[q].start();
+ }
+ Thread.sleep(5000);
+ }
+
+ /* (non-Javadoc)
+ * @see junit.framework.TestCase#tearDown()
+ */
+ protected void tearDown() throws Exception {
+ super.tearDown();
+ shootist.stop();
+ for(int q=0;q<servers.length;q++) {
+ servers[q].stop();
+ }
+ balancer.stop();
+ }
+ static AppServer invite;
+ static AppServer bye;
+ public void testInviteByeLandOnDifferentNodes() throws Exception {
+ EventListener failureEventListener = new EventListener() {
+
+ @Override
+ public void uasAfterResponse(int statusCode, AppServer
source) {
+
+ }
+
+ @Override
+ public void uasAfterRequestReceived(String method,
AppServer source) {
+ if(method.equals("INVITE")) invite = source;
+ if(method.equals("BYE")) {
+ bye = source;
+
+ if(bye == invite) TestCase.fail("INVITE and BYE should have landed on
different ndoes");
+ }
+
+
+ }
+
+ @Override
+ public void uacAfterRequestSent(String method,
AppServer source) {
+ // TODO Auto-generated method stub
+
+ }
+
+ @Override
+ public void uacAfterResponse(int statusCode, AppServer
source) {
+ // TODO Auto-generated method stub
+
+ }
+ };
+ for(AppServer as:servers)
as.setEventListener(failureEventListener);
+
+ shootist.callerSendsBye = true;
+ shootist.sendInitialInvite();
+ Thread.sleep(11000);
+ if(invite == null) TestCase.fail("INVITE not seen");
+ if(bye == null) TestCase.fail("BYE not seen");
+ }
+}