Revision: 7383
Author: vladimir.ralev
Date: Thu Aug 6 04:28:40 2009
Log: Tests for Issue 867
http://code.google.com/p/mobicents/issues/detail?id=867
http://code.google.com/p/mobicents/source/detail?r=7383
Added:
/trunk/servers/sip-servlets/sip-servlets-test-suite/testsuite/src/test/java/org/mobicents/servlet/sip/testsuite/proxy/SequentialProxyTest.java
Modified:
/trunk/servers/sip-servlets/sip-servlets-test-suite/applications/proxy-sip-servlet/src/main/java/org/mobicents/servlet/sip/testsuite/ProxySipServlet.java
/trunk/servers/sip-servlets/sip-servlets-test-suite/testsuite/src/test/java/org/mobicents/servlet/sip/testsuite/proxy/Shootist.java
=======================================
--- /dev/null
+++
/trunk/servers/sip-servlets/sip-servlets-test-suite/testsuite/src/test/java/org/mobicents/servlet/sip/testsuite/proxy/SequentialProxyTest.java
Thu Aug 6 04:28:40 2009
@@ -0,0 +1,109 @@
+/*
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.mobicents.servlet.sip.testsuite.proxy;
+
+import org.mobicents.servlet.sip.SipServletTestCase;
+
+public class SequentialProxyTest extends SipServletTestCase {
+
+ protected Shootist shootist;
+
+ protected Shootme shootme;
+
+ protected Cutme cutme;
+
+ private static final int TIMEOUT = 10000;
+
+ public SequentialProxyTest(String name) {
+ super(name);
+
+ this.sipIpAddress="0.0.0.0";
+ }
+
+ @Override
+ public void setUp() throws Exception {
+ super.setUp();
+ this.shootist = new Shootist(false);
+ shootist.setOutboundProxy(false);
+ this.shootme = new Shootme(5057);
+ this.cutme = new Cutme();
+ }
+
+ public void testFirstTargetTimeout() {
+ this.shootme.init("stackName");
+ this.cutme.init();
+ this.shootist.init("sequential", false);
+ for (int q = 0; q < 20; q++) {
+ if (shootist.ended == false && cutme.canceled == false)
+ try {
+ Thread.sleep(TIMEOUT);
+ } catch (InterruptedException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+ }
+ if (shootist.ended == false)
+ fail("Conversation not complete!");
+ if (cutme.canceled == false)
+ fail("The party that was supposed to be cancelled didn't
cancel.");
+ }
+
+ // Here we want to test if the seq proxy will continue to check next
branches
+ public void testFirstTargetResponds() {
+ this.shootme.init("stackName");
+ this.cutme.init();
+ this.shootist.init("sequential-reverse", false);
+ for (int q = 0; q < 20; q++) {
+ if (shootist.ended == false && cutme.canceled == false)
+ try {
+ Thread.sleep(TIMEOUT);
+ } catch (InterruptedException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+ }
+ if (shootist.ended == false)
+ fail("Conversation not complete!");
+ if (cutme.canceled == true)
+ fail("This party must not ever be contacted");
+ }
+
+ @Override
+ public void tearDown() throws Exception {
+ shootist.destroy();
+ shootme.destroy();
+ cutme.destroy();
+ super.tearDown();
+ }
+
+ @Override
+ public void deployApplication() {
+ assertTrue(tomcat
+ .deployContext(
+ projectHome
+
+ "/sip-servlets-test-suite/applications/proxy-sip-servlet/src/main/sipapp",
+ "sip-test-context",
"sip-test"));
+ }
+
+ @Override
+ protected String getDarConfigurationFile() {
+ return "file:///"
+ + projectHome
+ +
"/sip-servlets-test-suite/testsuite/src/test/resources/"
+
+ "org/mobicents/servlet/sip/testsuite/proxy/simple-sip-servlet-dar.properties";
+ }
+}
=======================================
---
/trunk/servers/sip-servlets/sip-servlets-test-suite/applications/proxy-sip-servlet/src/main/java/org/mobicents/servlet/sip/testsuite/ProxySipServlet.java
Mon Jul 27 08:30:00 2009
+++
/trunk/servers/sip-servlets/sip-servlets-test-suite/applications/proxy-sip-servlet/src/main/java/org/mobicents/servlet/sip/testsuite/ProxySipServlet.java
Thu Aug 6 04:28:40 2009
@@ -68,63 +68,78 @@
+ request.getMethod());
//This is a proxying sample.
SipFactory sipFactory = (SipFactory)
getServletContext().getAttribute(SIP_FACTORY);
-
+
String host = "127.0.0.1";
SipURI fromURI = ((SipURI)request.getFrom().getURI());
if(USE_HOSTNAME.equals(fromURI.getUser())) {
host = "localhost";
logger.info("using Host Name for proxy test");
}
-
+
URI uri1 = sipFactory.createAddress("sip:receiver@" + host
+ ":5057").getURI();
URI uri2 = sipFactory.createAddress("sip:cutme@" + host
+ ":5056").getURI();
-
- ArrayList<URI> uris = new ArrayList<URI>();
- uris.add(uri1);
- if(!fromURI.getUser().equals("unique-location")) {
- uris.add(uri2);
- }
- Proxy proxy = request.getProxy();
- List<SipURI> outboundInterfaces =
(List<SipURI>)getServletContext().getAttribute(OUTBOUND_INTERFACES);
-
- if(outboundInterfaces == null) throw new NullPointerException("Outbound
interfaces should not be null");
-
- SipURI obi = null;
-
- for(SipURI uri:outboundInterfaces) {
- if(uri.toString().indexOf("127.0.0.1")>0) {
- // pick the lo interface, since its universal
on all machines
- proxy.setOutboundInterface(new
InetSocketAddress(InetAddress.getByName(uri.getHost()),uri.getPort()));
- obi = uri;
- break;
- }
- }
-
- if(obi == null) throw new NullPointerException("No loopback interface
found.");
-
- boolean recordRoute = true;
- if(NON_RECORD_ROUTING.equals(fromURI.getUser())) {
- recordRoute = false;
- logger.info("not record routing");
- }
-
//proxy.setOutboundInterface((SipURI)sipFactory.createAddress("sip:[email protected]:5070").getURI());
- proxy.setRecordRoute(recordRoute);
- proxy.setSupervised(true);
- if(recordRoute) {
- proxy.getRecordRouteURI().setParameter("testparamname",
"TESTVALUE");
- }
- proxy.setParallel(true);
- if(CHECK_URI.equals(fromURI.getUser())) {
- Address routeAddress =
sipFactory.createAddress("sip:127.0.0.1:5057");
- request.pushRoute(routeAddress);
- Address ra = request.getAddressHeader("Route");
- logger.info("doInvite: ra = " + ra);
- URI uri = ra.getURI(); // this causes NPE
- logger.info("doInvite: uri = " + uri);
- proxy.setParallel(false);
- }
- proxy.setProxyTimeout(4);
- proxy.proxyTo(uris);
+
if(request.getFrom().getURI().toString().contains("sequential")) {
+ Proxy proxy = request.getProxy();
+ proxy.setParallel(false);
+ proxy.setProxyTimeout(5);
+ proxy.setRecordRoute(true);
+ ArrayList<URI> uris = new ArrayList<URI>();
+
if(request.getFrom().getURI().toString().contains("sequential-reverse")) {
+ uris.add(uri1);
+ uris.add(uri2);
+ } else {
+ uris.add(uri2);
+ uris.add(uri1);
+ }
+ proxy.proxyTo(uris);
+ } else {
+ ArrayList<URI> uris = new ArrayList<URI>();
+ uris.add(uri1);
+ if(!fromURI.getUser().equals("unique-location")) {
+ uris.add(uri2);
+ }
+ Proxy proxy = request.getProxy();
+ List<SipURI> outboundInterfaces =
(List<SipURI>)getServletContext().getAttribute(OUTBOUND_INTERFACES);
+
+ if(outboundInterfaces == null) throw new NullPointerException("Outbound
interfaces should not be null");
+
+ SipURI obi = null;
+
+ for(SipURI uri:outboundInterfaces) {
+ if(uri.toString().indexOf("127.0.0.1")>0) {
+ // pick the lo interface, since its
universal on all machines
+ proxy.setOutboundInterface(new
InetSocketAddress(InetAddress.getByName(uri.getHost()),uri.getPort()));
+ obi = uri;
+ break;
+ }
+ }
+
+ if(obi == null) throw new NullPointerException("No loopback interface
found.");
+
+ boolean recordRoute = true;
+ if(NON_RECORD_ROUTING.equals(fromURI.getUser())) {
+ recordRoute = false;
+ logger.info("not record routing");
+ }
+
//proxy.setOutboundInterface((SipURI)sipFactory.createAddress("sip:[email protected]:5070").getURI());
+ proxy.setRecordRoute(recordRoute);
+ proxy.setSupervised(true);
+ if(recordRoute) {
+ proxy.getRecordRouteURI().setParameter("testparamname",
"TESTVALUE");
+ }
+ proxy.setParallel(true);
+ if(CHECK_URI.equals(fromURI.getUser())) {
+ Address routeAddress =
sipFactory.createAddress("sip:127.0.0.1:5057");
+ request.pushRoute(routeAddress);
+ Address ra = request.getAddressHeader("Route");
+ logger.info("doInvite: ra = " + ra);
+ URI uri = ra.getURI(); // this causes NPE
+ logger.info("doInvite: uri = " + uri);
+ proxy.setParallel(false);
+ }
+ proxy.setProxyTimeout(4);
+ proxy.proxyTo(uris);
+ }
}
/**
=======================================
---
/trunk/servers/sip-servlets/sip-servlets-test-suite/testsuite/src/test/java/org/mobicents/servlet/sip/testsuite/proxy/Shootist.java
Wed Jun 3 04:36:53 2009
+++
/trunk/servers/sip-servlets/sip-servlets-test-suite/testsuite/src/test/java/org/mobicents/servlet/sip/testsuite/proxy/Shootist.java
Thu Aug 6 04:28:40 2009
@@ -232,7 +232,11 @@
// If the caller is supposed to send the bye
if ( !byeTaskRunning && dialog != null) {
byeTaskRunning = true;
- new Timer().schedule(new ByeTask(dialog), 4000) ;
+
if(!response.getHeader("From").toString().contains("sequential")) {
+ new Timer().schedule(new ByeTask(dialog), 4000)
;
+ } else {
+ new Timer().schedule(new ByeTask(dialog), 9000)
;
+ }
}
System.out.println("transaction state is " + tid.getState());
//System.out.println("Dialog = " + tid.getDialog());