Search in sources :

Example 1 with RoundRobinBalancingStrategy

use of org.infinispan.client.hotrod.impl.transport.tcp.RoundRobinBalancingStrategy in project infinispan by infinispan.

the class RoundRobinBalancingIntegrationTest method testAddNewHotrodServer.

@Test(dependsOnMethods = "testRoundRobinLoadBalancing")
public void testAddNewHotrodServer() {
    c4 = TestCacheManagerFactory.createCacheManager(hotRodCacheConfiguration()).getCache();
    hotRodServer4 = HotRodClientTestingUtil.startHotRodServer(c4.getCacheManager());
    registerCacheManager(c4.getCacheManager());
    List<SocketAddress> serverAddresses = new ArrayList<>();
    serverAddresses.add(InetSocketAddress.createUnresolved("localhost", hotRodServer1.getPort()));
    serverAddresses.add(InetSocketAddress.createUnresolved("localhost", hotRodServer2.getPort()));
    serverAddresses.add(InetSocketAddress.createUnresolved("localhost", hotRodServer3.getPort()));
    serverAddresses.add(InetSocketAddress.createUnresolved("localhost", hotRodServer4.getPort()));
    RoundRobinBalancingStrategy balancer = getBalancer();
    balancer.setServers(serverAddresses);
    remoteCache.put("k1", "v1");
    remoteCache.put("k2", "v2");
    remoteCache.put("k3", "v3");
    remoteCache.put("k4", "v4");
    assertEquals(1, c1.size());
    assertEquals(1, c2.size());
    assertEquals(1, c3.size());
    assertEquals(1, c4.size());
    assertEquals("v1", remoteCache.get("k1"));
    assertEquals("v2", remoteCache.get("k2"));
    assertEquals("v3", remoteCache.get("k3"));
    assertEquals("v4", remoteCache.get("k4"));
    remoteCache.put("k5", "v2");
    remoteCache.put("k6", "v3");
    remoteCache.put("k7", "v1");
    remoteCache.put("k8", "v2");
    remoteCache.put("k9", "v3");
    remoteCache.put("k10", "v3");
    remoteCache.put("k11", "v3");
    remoteCache.put("k12", "v3");
    assertEquals(3, c1.size());
    assertEquals(3, c2.size());
    assertEquals(3, c3.size());
    assertEquals(3, c4.size());
}
Also used : RoundRobinBalancingStrategy(org.infinispan.client.hotrod.impl.transport.tcp.RoundRobinBalancingStrategy) ArrayList(java.util.ArrayList) SocketAddress(java.net.SocketAddress) InetSocketAddress(java.net.InetSocketAddress) MultipleCacheManagersTest(org.infinispan.test.MultipleCacheManagersTest) Test(org.testng.annotations.Test)

Example 2 with RoundRobinBalancingStrategy

use of org.infinispan.client.hotrod.impl.transport.tcp.RoundRobinBalancingStrategy in project infinispan by infinispan.

the class RoundRobinBalancingStrategyTest method setUp.

@BeforeMethod
public void setUp() {
    strategy = new RoundRobinBalancingStrategy();
    defaultServers = new ArrayList<SocketAddress>();
    defaultServers.add(addr1);
    defaultServers.add(addr2);
    defaultServers.add(addr3);
    strategy.setServers(defaultServers);
}
Also used : RoundRobinBalancingStrategy(org.infinispan.client.hotrod.impl.transport.tcp.RoundRobinBalancingStrategy) SocketAddress(java.net.SocketAddress) InetSocketAddress(java.net.InetSocketAddress) BeforeMethod(org.testng.annotations.BeforeMethod)

Example 3 with RoundRobinBalancingStrategy

use of org.infinispan.client.hotrod.impl.transport.tcp.RoundRobinBalancingStrategy in project infinispan by infinispan.

the class DistTopologyChangeUnderLoadTest method testPutsSucceedWhileTopologyChanges.

public void testPutsSucceedWhileTopologyChanges() throws Exception {
    RemoteCache<Integer, String> remote = client(0).getCache();
    remote.put(1, "v1");
    assertEquals("v1", remote.get(1));
    PutHammer putHammer = new PutHammer();
    Future<Void> putHammerFuture = fork(putHammer);
    HotRodServer newServer = addHotRodServer(getCacheConfiguration());
    // Wait for 2 seconds
    TestingUtil.sleepThread(2000);
    HotRodClientTestingUtil.killServers(newServer);
    TestingUtil.killCacheManagers(newServer.getCacheManager());
    TestingUtil.waitForNoRebalance(cache(0));
    // Execute one more operation to guarantee topology update on the client
    remote.put(-1, "minus one");
    RoundRobinBalancingStrategy strategy = getLoadBalancer(client(0));
    SocketAddress[] servers = strategy.getServers();
    putHammer.stop = true;
    putHammerFuture.get();
    assertEquals(1, servers.length);
}
Also used : HotRodServer(org.infinispan.server.hotrod.HotRodServer) RoundRobinBalancingStrategy(org.infinispan.client.hotrod.impl.transport.tcp.RoundRobinBalancingStrategy) SocketAddress(java.net.SocketAddress)

Example 4 with RoundRobinBalancingStrategy

use of org.infinispan.client.hotrod.impl.transport.tcp.RoundRobinBalancingStrategy in project infinispan by infinispan.

the class RoundRobinBalancingIntegrationTest method testRemoveServers.

@Test(dependsOnMethods = "testStopServer")
public void testRemoveServers() {
    List<SocketAddress> serverAddresses = new ArrayList<>();
    serverAddresses.add(InetSocketAddress.createUnresolved("localhost", hotRodServer1.getPort()));
    serverAddresses.add(InetSocketAddress.createUnresolved("localhost", hotRodServer2.getPort()));
    RoundRobinBalancingStrategy balancer = getBalancer();
    balancer.setServers(serverAddresses);
    remoteCache.put("k1", "v1");
    remoteCache.put("k2", "v2");
    remoteCache.put("k3", "v3");
    remoteCache.put("k4", "v4");
    assertEquals(2, c1.size());
    assertEquals(2, c2.size());
    assertEquals(0, c3.size());
    assertEquals(0, c4.size());
    assertEquals("v1", remoteCache.get("k1"));
    assertEquals("v2", remoteCache.get("k2"));
    assertEquals("v3", remoteCache.get("k3"));
    assertEquals("v4", remoteCache.get("k4"));
    remoteCache.put("k5", "v2");
    remoteCache.put("k6", "v3");
    remoteCache.put("k7", "v1");
    remoteCache.put("k8", "v2");
    remoteCache.put("k9", "v3");
    remoteCache.put("k10", "v3");
    remoteCache.put("k11", "v3");
    remoteCache.put("k12", "v3");
    assertEquals(6, c1.size());
    assertEquals(6, c2.size());
    assertEquals(0, c3.size());
    assertEquals(0, c4.size());
}
Also used : RoundRobinBalancingStrategy(org.infinispan.client.hotrod.impl.transport.tcp.RoundRobinBalancingStrategy) ArrayList(java.util.ArrayList) SocketAddress(java.net.SocketAddress) InetSocketAddress(java.net.InetSocketAddress) MultipleCacheManagersTest(org.infinispan.test.MultipleCacheManagersTest) Test(org.testng.annotations.Test)

Aggregations

SocketAddress (java.net.SocketAddress)4 RoundRobinBalancingStrategy (org.infinispan.client.hotrod.impl.transport.tcp.RoundRobinBalancingStrategy)4 InetSocketAddress (java.net.InetSocketAddress)3 ArrayList (java.util.ArrayList)2 MultipleCacheManagersTest (org.infinispan.test.MultipleCacheManagersTest)2 Test (org.testng.annotations.Test)2 HotRodServer (org.infinispan.server.hotrod.HotRodServer)1 BeforeMethod (org.testng.annotations.BeforeMethod)1