Skip to content

Commit 747285b

Browse files
committed
add PersistentConsistentHashBalancerAlgorithmTest
1 parent fe64e2a commit 747285b

File tree

4 files changed

+153
-172
lines changed

4 files changed

+153
-172
lines changed

jar/src/main/java/org/mobicents/tools/sip/balancer/PersistentConsistentHashBalancerAlgorithm.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -82,13 +82,13 @@ public synchronized void nodeRemoved(SIPNode node) {
8282
}
8383

8484
private void dumpNodes() {
85-
String nodes = "I am " + getBalancerContext().externalHost + ". I see the following nodes are in cache right now (" + (nodesArrayV6.length + nodesArrayV4.length) + "):\n";
86-
85+
String nodes = "I am " + getBalancerContext().externalHost + ". I see the following nodes are in cache right now(IPV6 and IPv4) (" + (nodesArrayV6 +""+ nodesArrayV4) + "):\n";
86+
if(nodesArrayV4!=null)
8787
for(Object object : nodesArrayV4) {
8888
SIPNode node = (SIPNode) object;
8989
nodes += node.toString() + " [ALIVE:" + isAlive(node) + "]\n";
9090
}
91-
91+
if(nodesArrayV6!=null)
9292
for(Object object : nodesArrayV6) {
9393
SIPNode node = (SIPNode) object;
9494
nodes += node.toString() + " [ALIVE:" + isAlive(node) + "]\n";
Lines changed: 17 additions & 169 deletions
Original file line numberDiff line numberDiff line change
@@ -1,170 +1,18 @@
11
<?xml version="1.0" encoding="UTF-8"?>
2-
3-
<jbosscache xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4-
xmlns="urn:jboss:jbosscache-core:config:3.0">
5-
6-
<!--
7-
isolation levels supported: READ_COMMITTED and REPEATABLE_READ
8-
nodeLockingSchemes: mvcc, pessimistic (deprecated), optimistic
9-
(deprecated)
10-
-->
11-
<locking isolationLevel="REPEATABLE_READ"
12-
lockParentForChildInsertRemove="false" lockAcquisitionTimeout="20000"
13-
nodeLockingScheme="mvcc" writeSkewCheck="false" concurrencyLevel="500" />
14-
15-
<!--
16-
Used to register a transaction manager and participate in ongoing
17-
transactions.
18-
-->
19-
<transaction
20-
transactionManagerLookupClass="org.jboss.cache.transaction.JBossTransactionManagerLookup"
21-
syncRollbackPhase="false" syncCommitPhase="false" />
22-
23-
<!--
24-
Used to register JMX statistics in any available MBean server
25-
-->
26-
<jmxStatistics enabled="false" />
27-
28-
<!--
29-
If region based marshalling is used, defines whether new regions are
30-
inactive on startup.
31-
-->
32-
<startup regionsInactiveOnStartup="false" />
33-
34-
<!--
35-
Used to register JVM shutdown hooks. hookBehavior: DEFAULT, REGISTER,
36-
DONT_REGISTER
37-
-->
38-
<shutdown hookBehavior="DEFAULT" />
39-
40-
<!--
41-
Used to define async listener notification thread pool size
42-
-->
43-
<listeners asyncPoolSize="1" asyncQueueSize="100000" />
44-
45-
<!--
46-
Used to enable invocation batching and allow the use of
47-
Cache.startBatch()/endBatch() methods.
48-
-->
49-
<invocationBatching enabled="false" />
50-
51-
<!--
52-
serialization related configuration, used for replication and cache
53-
loading
54-
-->
55-
<serialization objectInputStreamPoolSize="12"
56-
objectOutputStreamPoolSize="14" version="3.0.0"
57-
marshallerClass="org.jboss.cache.marshall.CacheMarshaller300"
58-
useLazyDeserialization="false" useRegionBasedMarshalling="false" />
59-
60-
<!--
61-
This element specifies that the cache is clustered. modes supported:
62-
replication (r) or invalidation (i).
63-
-->
64-
<clustering mode="replication" clusterName="MCBALANCER">
65-
66-
<!--
67-
Defines whether to retrieve state on startup
68-
-->
69-
<stateRetrieval timeout="20000" fetchInMemoryState="true" />
70-
71-
<!--
72-
Network calls are synchronous.
73-
74-
<sync replTimeout="20000" /> -->
75-
<!--
76-
Uncomment this for async replication.
77-
-->
78-
<!---->
79-
<async useReplQueue="true" replQueueInterval="10000"
80-
replQueueMaxElements="500" serializationExecutorPoolSize="20"
81-
serializationExecutorQueueSize="5000000"/>
82-
83-
84-
<!-- Uncomment to use Buddy Replication -->
85-
<!--
86-
<buddy enabled="true" poolName="myBuddyPoolReplicationGroup"
87-
communicationTimeout="2000"> <dataGravitation auto="true"
88-
removeOnFind="true" searchBackupTrees="true"/> <locator
89-
class="org.jboss.cache.buddyreplication.NextMemberBuddyLocator">
90-
<properties> numBuddies = 1 ignoreColocatedBuddies = true
91-
</properties> </locator> </buddy>
92-
-->
93-
94-
<!--
95-
Configures the JGroups channel. Looks up a JGroups config file on the
96-
classpath or filesystem. udp.xml ships with jgroups.jar and will be
97-
picked up by the class loader.
98-
-->
99-
<jgroupsConfig>
100-
101-
<UDP
102-
mcast_addr="${jgroups.udp.mcast_addr:228.10.10.10}"
103-
mcast_port="${jgroups.udp.mcast_port:18811}"
104-
discard_incompatible_packets="true"
105-
max_bundle_size="60000"
106-
max_bundle_timeout="30"
107-
ip_ttl="${jgroups.udp.ip_ttl:2}"
108-
enable_bundling="true"
109-
thread_pool.enabled="true"
110-
thread_pool.min_threads="1"
111-
thread_pool.max_threads="25"
112-
thread_pool.keep_alive_time="5000"
113-
thread_pool.queue_enabled="false"
114-
thread_pool.queue_max_size="100"
115-
thread_pool.rejection_policy="Run"
116-
oob_thread_pool.enabled="true"
117-
oob_thread_pool.min_threads="1"
118-
oob_thread_pool.max_threads="8"
119-
oob_thread_pool.keep_alive_time="5000"
120-
oob_thread_pool.queue_enabled="false"
121-
oob_thread_pool.queue_max_size="100"
122-
oob_thread_pool.rejection_policy="Run"/>
123-
<PING timeout="2000"
124-
num_initial_members="3"/>
125-
<MERGE2 max_interval="30000"
126-
min_interval="10000"/>
127-
<FD_SOCK/>
128-
<FD timeout="10000" max_tries="5" />
129-
<VERIFY_SUSPECT timeout="1500" />
130-
<BARRIER />
131-
<pbcast.NAKACK
132-
use_mcast_xmit="false" gc_lag="0"
133-
retransmit_timeout="300,600,1200,2400,4800"
134-
discard_delivered_msgs="true"/>
135-
<UNICAST timeout="300,600,1200,2400,3600"/>
136-
<pbcast.STABLE stability_delay="1000" desired_avg_gossip="50000"
137-
max_bytes="400000"/>
138-
<VIEW_SYNC avg_send_interval="60000" />
139-
<pbcast.GMS print_local_addr="true" join_timeout="3000"
140-
view_bundling="true"/>
141-
<FC max_credits="20000000"
142-
min_threshold="0.10"/>
143-
<FRAG2 frag_size="60000" />
144-
<pbcast.STATE_TRANSFER />
145-
146-
147-
148-
</jgroupsConfig>
149-
</clustering>
150-
151-
<!--
152-
Define custom interceptors. All custom interceptors need to extend
153-
org.jboss.cache.interceptors.base.CommandInterceptor
154-
-->
155-
156-
<!--
157-
<customInterceptors> <interceptor position="first"
158-
class="org.jboss.cache.config.parsing.custominterceptors.AaaCustomInterceptor">
159-
<property name="attrOne" value="value1" /> <property name="attrTwo"
160-
value="value2" /> </interceptor> <interceptor position="last"
161-
class="org.jboss.cache.config.parsing.custominterceptors.BbbCustomInterceptor"/>
162-
<interceptor index="3"
163-
class="org.jboss.cache.config.parsing.custominterceptors.AaaCustomInterceptor"/>
164-
<interceptor before="org.jboss.cache.interceptors.CallInterceptor"
165-
class="org.jboss.cache.config.parsing.custominterceptors.BbbCustomInterceptor"/>
166-
<interceptor after="org.jboss.cache.interceptors.CallInterceptor"
167-
class="org.jboss.cache.config.parsing.custominterceptors.AaaCustomInterceptor"/>
168-
</customInterceptors>
169-
-->
170-
</jbosscache>
2+
<infinispan>
3+
<global>
4+
<globalJmxStatistics>
5+
</globalJmxStatistics>
6+
<transport clusterName="lb-infinispan">
7+
<properties>
8+
<property name="configurationFile" value="jgroups-udp.xml" />
9+
</properties>
10+
</transport>
11+
</global>
12+
13+
<default>
14+
<clustering mode="repl">
15+
<sync/>
16+
</clustering>
17+
</default>
18+
</infinispan>
Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
/*
2+
* TeleStax, Open Source Cloud Communications
3+
* Copyright 2011-2015, Telestax Inc and individual contributors
4+
* by the @authors tag.
5+
*
6+
* This program is free software: you can redistribute it and/or modify
7+
* under the terms of the GNU Affero General Public License as
8+
* published by the Free Software Foundation; either version 3 of
9+
* the License, or (at your option) any later version.
10+
*
11+
* This program is distributed in the hope that it will be useful,
12+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14+
* GNU Affero General Public License for more details.
15+
*
16+
* You should have received a copy of the GNU Affero General Public License
17+
* along with this program. If not, see <http://www.gnu.org/licenses/>
18+
*/
19+
20+
package org.mobicents.tools.sip.balancer.algorithms;
21+
22+
import static org.junit.Assert.*;
23+
24+
import javax.sip.ListeningPoint;
25+
import javax.sip.message.Response;
26+
27+
import org.junit.After;
28+
import org.junit.Before;
29+
import org.junit.Test;
30+
import org.mobicents.tools.configuration.LoadBalancerConfiguration;
31+
import org.mobicents.tools.sip.balancer.AppServer;
32+
import org.mobicents.tools.sip.balancer.BalancerRunner;
33+
import org.mobicents.tools.sip.balancer.PersistentConsistentHashBalancerAlgorithm;
34+
import org.mobicents.tools.sip.balancer.operation.Shootist;
35+
36+
/**
37+
* @author Konstantin Nosach (kostyantyn.nosach@telestax.com)
38+
*/
39+
40+
public class PersistentConsistentHashBalancerAlgorithmTest {
41+
42+
BalancerRunner balancer;
43+
int numNodes = 2;
44+
int numShootist = 2;
45+
AppServer[] servers = new AppServer[numNodes];
46+
Shootist [] shootists = new Shootist [numShootist];
47+
48+
@Before
49+
public void setUp() throws Exception {
50+
for(int i = 0; i < shootists.length; i++)
51+
{
52+
shootists[i] = new Shootist("udp",5060,5033+i);
53+
shootists[i].callerSendsBye = true;
54+
}
55+
balancer = new BalancerRunner();
56+
LoadBalancerConfiguration lbConfig = new LoadBalancerConfiguration();
57+
lbConfig.getSipConfiguration().getExternalLegConfiguration().setUdpPort(5060);
58+
lbConfig.getSipConfiguration().getInternalLegConfiguration().setUdpPort(5065);
59+
lbConfig.getSipConfiguration().getAlgorithmConfiguration().setAlgorithmClass(PersistentConsistentHashBalancerAlgorithm.class.getName());
60+
lbConfig.getSipConfiguration().getAlgorithmConfiguration().setSipHeaderAffinityKey("From");
61+
lbConfig.getSipConfiguration().getAlgorithmConfiguration()
62+
.setPersistentConsistentHashCacheConfiguration(PersistentConsistentHashBalancerAlgorithmTest.class.getClassLoader().getResource("infinispan-cache.xml").getFile());
63+
balancer.start(lbConfig);
64+
65+
for(int q=0;q<servers.length;q++)
66+
{
67+
servers[q] = new AppServer("node" + q,4060+q , "127.0.0.1", 2000, 5060, 5065, "0", ListeningPoint.UDP);
68+
servers[q].start();
69+
}
70+
Thread.sleep(5000);
71+
}
72+
73+
@After
74+
public void tearDown() throws Exception {
75+
for(Shootist s :shootists)
76+
s.stop();
77+
78+
for(AppServer as: servers) {
79+
as.stop();
80+
}
81+
balancer.stop();
82+
}
83+
84+
@Test
85+
public void testInviteByeLandOnDifferentNodes() throws Exception {
86+
for(int i = 0; i < shootists.length; i++)
87+
{
88+
shootists[i].sendInitialInvite();
89+
Thread.sleep(5000);
90+
shootists[i].sendBye();
91+
Thread.sleep(2000);
92+
}
93+
assertNotEquals(servers[0].getTestSipListener().isInviteReceived(),servers[1].getTestSipListener().isInviteReceived());
94+
assertNotEquals(servers[0].getTestSipListener().isAckReceived(),servers[1].getTestSipListener().isAckReceived());
95+
assertNotEquals(servers[0].getTestSipListener().getByeReceived(),servers[1].getTestSipListener().getByeReceived());
96+
97+
for(Shootist s :shootists)
98+
{
99+
boolean wasRinging = false;
100+
boolean wasOk = false;
101+
for(Response res : s.responses)
102+
{
103+
if(res.getStatusCode() != Response.RINGING)
104+
wasRinging = true;
105+
if(res.getStatusCode() != Response.OK)
106+
wasOk = true;
107+
}
108+
assertTrue(wasOk);
109+
assertTrue(wasRinging);
110+
}
111+
}
112+
}
113+
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<infinispan>
3+
4+
<global>
5+
<globalJmxStatistics>
6+
</globalJmxStatistics>
7+
<transport clusterName="lb-infinispan">
8+
<properties>
9+
<property name="configurationFile" value="jgroups-udp.xml" />
10+
</properties>
11+
</transport>
12+
</global>
13+
14+
<default>
15+
<clustering mode="repl">
16+
<sync/>
17+
</clustering>
18+
</default>
19+
20+
</infinispan>

0 commit comments

Comments
 (0)