use of org.mobicents.tools.sip.balancer.AppServer in project load-balancer by RestComm.
the class CustomHeartbeatTest method testCustomHeartbeat.
@Test
public void testCustomHeartbeat() throws Exception {
EventListener failureEventListener = new EventListener() {
@Override
public void uasAfterResponse(int statusCode, AppServer source) {
}
@Override
public void uasAfterRequestReceived(String method, AppServer source) {
// TODO Auto-generated method stub
}
@Override
public void uacAfterRequestSent(String method, AppServer source) {
// TODO Auto-generated method stub
}
@Override
public void uacAfterResponse(int statusCode, AppServer source) {
if (statusCode == 180) {
ringingAppServer = source;
} else {
okAppServer = source;
}
}
};
for (AppServer as : servers) as.setEventListener(failureEventListener);
shootist.callerSendsBye = true;
String fromName = "sender";
String fromHost = "sip-servlets.com";
SipURI fromAddress = servers[0].protocolObjects.addressFactory.createSipURI(fromName, fromHost);
String toUser = "replaces";
String toHost = "sip-servlets.com";
SipURI toAddress = servers[0].protocolObjects.addressFactory.createSipURI(toUser, toHost);
SipURI ruri = servers[0].protocolObjects.addressFactory.createSipURI("usera", "127.0.0.1:5033");
ruri.setLrParam();
SipURI route = servers[0].protocolObjects.addressFactory.createSipURI("lbaddress_InternalPort", "127.0.0.1:5065");
route.setParameter("node_host", "127.0.0.1");
route.setParameter("node_port", "4060");
route.setLrParam();
shootist.start();
// servers[0].sipListener.sendSipRequest("INVITE", fromAddress, toAddress, null, null, false);
// servers[0].sendHeartbeat = false;
// servers[1].sendHeartbeat = false;
servers[0].sipListener.sendSipRequest("OPTIONS", fromAddress, toAddress, "tcpPort=1\nudpPort=2\nhostname=sipHeartbeat\nip=127.0.0.1", route, false, new String[] { "Mobicents-Heartbeat" }, new String[] { "1" }, ruri);
Thread.sleep(4000);
servers[0].sipListener.sendSipRequest("OPTIONS", fromAddress, toAddress, "tcpPort=1\nudpPort=2\nhostname=sipHeartbeat\nip=127.0.0.1", route, false, new String[] { "Mobicents-Heartbeat" }, new String[] { "1" }, ruri);
Thread.sleep(4000);
servers[0].sipListener.sendSipRequest("OPTIONS", fromAddress, toAddress, "tcpPort=1\nudpPort=2\nhostname=sipHeartbeat\nip=127.0.0.1", route, false, new String[] { "Mobicents-Heartbeat" }, new String[] { "1" }, ruri);
Thread.sleep(4000);
servers[0].sipListener.sendSipRequest("OPTIONS", fromAddress, toAddress, "tcpPort=1\nudpPort=2\nhostname=sipHeartbeat\nip=127.0.0.1", route, false, new String[] { "Mobicents-Heartbeat" }, new String[] { "1" }, ruri);
Thread.sleep(4000);
servers[0].sipListener.sendSipRequest("OPTIONS", fromAddress, toAddress, "tcpPort=1\nudpPort=2\nhostname=sipHeartbeat\nip=127.0.0.1", route, false, new String[] { "Mobicents-Heartbeat" }, new String[] { "1" }, ruri);
List<Node> list = balancer.getNodes();
Node node = list.get(0);
assertEquals(node.getHostName(), "sipHeartbeat");
assertEquals(1, list.size());
}
use of org.mobicents.tools.sip.balancer.AppServer in project load-balancer by RestComm.
the class CustomHeartbeatTest method setUp.
@Before
public void setUp() throws Exception {
shootist = new Shootist();
balancer = new BalancerRunner();
LoadBalancerConfiguration lbConfig = new LoadBalancerConfiguration();
lbConfig.getCommonConfiguration().setHost(null);
lbConfig.getSipConfiguration().getExternalLegConfiguration().setHost("127.0.0.1");
lbConfig.getSipConfiguration().getInternalLegConfiguration().setHost("127.0.0.1");
lbConfig.getSipConfiguration().getInternalLegConfiguration().setUdpPort(5065);
balancer.start(lbConfig);
for (int q = 0; q < servers.length; q++) {
servers[q] = new AppServer("node" + q, 4060 + q, "127.0.0.1", 2000, 5060, 5060, "0", ListeningPoint.UDP, 2222 + q);
servers[q].sendHeartbeat = false;
servers[q].start();
}
Thread.sleep(5000);
}
use of org.mobicents.tools.sip.balancer.AppServer in project load-balancer by RestComm.
the class IncorrectAddRecivedInResponseTest method testOKRingingLandOnDifferentNodes.
@Test
public void testOKRingingLandOnDifferentNodes() throws Exception {
EventListener failureEventListener = new EventListener() {
@Override
public void uasAfterResponse(int statusCode, AppServer source) {
}
@Override
public void uasAfterRequestReceived(String method, AppServer source) {
}
@Override
public void uacAfterRequestSent(String method, AppServer source) {
}
@Override
public void uacAfterResponse(int statusCode, AppServer source) {
if (statusCode == 180) {
ringingAppServer = source;
} else if (statusCode == 200) {
okAppServer = source;
}
}
};
for (AppServer as : servers) as.setEventListener(failureEventListener);
shootist.callerSendsBye = true;
String fromName = "senderToNexmo";
String fromHost = "sip-servlets.com";
SipURI fromAddress = servers[0].protocolObjects.addressFactory.createSipURI(fromName, fromHost);
String toUser = "replaces";
String toHost = "sip-servlets.com";
SipURI toAddress = servers[0].protocolObjects.addressFactory.createSipURI(toUser, toHost);
SipURI ruri = servers[0].protocolObjects.addressFactory.createSipURI("usera", "127.0.0.1:5033");
ruri.setLrParam();
SipURI route = servers[0].protocolObjects.addressFactory.createSipURI("lbint", "127.0.0.1:5065");
route.setParameter("node_host", "127.0.0.1");
route.setParameter("node_port", "4060");
route.setTransportParam(ListeningPoint.TCP);
route.setLrParam();
shootist.start();
servers[0].sipListener.sendSipRequest(SIPRequest.INVITE, fromAddress, toAddress, null, route, false, null, null, ruri);
Thread.sleep(16000);
assertTrue(shootist.inviteRequest.getHeader(RecordRouteHeader.NAME).toString().contains("node_host"));
assertSame(servers[0], ringingAppServer);
assertSame(ringingAppServer, okAppServer);
assertNotNull(ringingAppServer);
assertNotNull(okAppServer);
}
use of org.mobicents.tools.sip.balancer.AppServer in project load-balancer by RestComm.
the class InviteTransactionFailover method setUp.
@Before
public void setUp() throws Exception {
shootist = new Shootist();
balancer = new BalancerRunner();
LoadBalancerConfiguration lbConfig = new LoadBalancerConfiguration();
lbConfig.getCommonConfiguration().setHost(null);
lbConfig.getSipConfiguration().getExternalLegConfiguration().setHost("127.0.0.1");
lbConfig.getSipConfiguration().getInternalLegConfiguration().setHost("127.0.0.1");
lbConfig.getSipConfiguration().getInternalLegConfiguration().setUdpPort(5065);
balancer.start(lbConfig);
for (int q = 0; q < servers.length; q++) {
servers[q] = new AppServer("node" + q, 4060 + q, "127.0.0.1", 2000, 5060, 5065, "0", ListeningPoint.UDP, 2222 + q);
servers[q].start();
}
Thread.sleep(5000);
}
use of org.mobicents.tools.sip.balancer.AppServer in project load-balancer by RestComm.
the class InviteTransactionFailover method testSimpleShutdown.
// private void _BAD_testInviteTx() throws Exception {
// ProtocolObjects senderProtocolObjects = new ProtocolObjects("forward-udp-sender",
// "gov.nist", "udp", false, null);
// TestSipListener sender = new TestSipListener(5080, 5060, senderProtocolObjects, true);
// SipProvider senderProvider = sender.createProvider();
//
//
// senderProvider.addSipListener(sender);
//
// senderProtocolObjects.start();
//
// String fromName = "forward-tcp-sender";
// String fromSipAddress = "sip-servlets.com";
// SipURI fromAddress = senderProtocolObjects.addressFactory.createSipURI(
// fromName, fromSipAddress);
//
// String toSipAddress = "sip-servlets.com";
// String toUser = "forward-receiver";
// SipURI toAddress = senderProtocolObjects.addressFactory.createSipURI(
// toUser, toSipAddress);
//
// sender.sendSipRequest("INVITE", fromAddress, toAddress, null, null, false);
// Thread.sleep(20000);
// }
@Test
public void testSimpleShutdown() throws Exception {
EventListener failureEventListener = new EventListener() {
boolean once = false;
@Override
public synchronized void uasAfterResponse(int statusCode, AppServer source) {
if (!once) {
once = true;
System.out.println("HERE " + once);
// source.sendCleanShutdownToBalancers();
}
}
@Override
public void uasAfterRequestReceived(String method, AppServer source) {
// TODO Auto-generated method stub
}
@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(12000);
assertEquals(1, balancer.getNodes().size());
// if(balancer.getNodes().size()!=1) fail("Expected one dead node");
}
Aggregations