Search in sources :

Example 1 with ConsistentHash

use of org.infinispan.client.hotrod.impl.consistenthash.ConsistentHash in project infinispan by infinispan.

the class ClientConsistentHashPerfTest method testConsistentHashPerf.

public void testConsistentHashPerf() throws Exception {
    RemoteCacheManager rcm = client(0);
    RemoteCache<Object, Object> cache = rcm.getCache();
    // This will initialize the consistent hash
    cache.put("k", "v");
    ChannelFactory channelFactory = TestingUtil.extractField(rcm, "channelFactory");
    ConsistentHash ch = channelFactory.getConsistentHash(RemoteCacheManager.cacheNameBytes());
    byte[][] keys = new byte[NUM_KEYS][];
    for (int i = 0; i < NUM_KEYS; i++) {
        keys[i] = String.valueOf(i).getBytes(UTF_8);
    }
    SocketAddress aServer = null;
    // warm-up
    for (int i = 0; i < ITERATIONS / 10; i++) {
        SocketAddress server = ch.getServer(keys[i % keys.length]);
        if (server != null)
            aServer = server;
    }
    long startNanos = System.nanoTime();
    for (int i = 0; i < ITERATIONS; i++) {
        SocketAddress server = ch.getServer(keys[i % keys.length]);
        if (server != null)
            aServer = server;
    }
    double duration = System.nanoTime() - startNanos;
    log.infof("Test took %.3f s, average CH lookup was %.3f ns", duration / 1000000000L, duration / ITERATIONS);
}
Also used : RemoteCacheManager(org.infinispan.client.hotrod.RemoteCacheManager) ConsistentHash(org.infinispan.client.hotrod.impl.consistenthash.ConsistentHash) ChannelFactory(org.infinispan.client.hotrod.impl.transport.netty.ChannelFactory) SocketAddress(java.net.SocketAddress)

Example 2 with ConsistentHash

use of org.infinispan.client.hotrod.impl.consistenthash.ConsistentHash in project infinispan by infinispan.

the class ConsistentHashFactoryTest method testNoChDefined.

public void testNoChDefined() {
    ConfigurationBuilder builder = HotRodClientTestingUtil.newRemoteConfigurationBuilder();
    ConsistentHashFactory chf = new ConsistentHashFactory();
    chf.init(builder.build());
    ConsistentHash hash = chf.newConsistentHash(2);
    assertNotNull(hash);
    assertEquals(hash.getClass(), ConsistentHashV2.class);
}
Also used : ConfigurationBuilder(org.infinispan.client.hotrod.configuration.ConfigurationBuilder) ConsistentHash(org.infinispan.client.hotrod.impl.consistenthash.ConsistentHash) ConsistentHashFactory(org.infinispan.client.hotrod.impl.consistenthash.ConsistentHashFactory)

Example 3 with ConsistentHash

use of org.infinispan.client.hotrod.impl.consistenthash.ConsistentHash in project infinispan by infinispan.

the class ConsistentHashFactoryTest method testPropertyCorrectlyRead.

public void testPropertyCorrectlyRead() {
    ConfigurationBuilder builder = HotRodClientTestingUtil.newRemoteConfigurationBuilder();
    builder.consistentHashImpl(2, SomeCustomConsistentHashV2.class);
    ConsistentHashFactory chf = new ConsistentHashFactory();
    chf.init(builder.build());
    ConsistentHash hash = chf.newConsistentHash(2);
    assertNotNull(hash);
    assertEquals(hash.getClass(), SomeCustomConsistentHashV2.class);
}
Also used : ConfigurationBuilder(org.infinispan.client.hotrod.configuration.ConfigurationBuilder) ConsistentHash(org.infinispan.client.hotrod.impl.consistenthash.ConsistentHash) ConsistentHashFactory(org.infinispan.client.hotrod.impl.consistenthash.ConsistentHashFactory)

Example 4 with ConsistentHash

use of org.infinispan.client.hotrod.impl.consistenthash.ConsistentHash in project infinispan by infinispan.

the class ReplicationRetryTest method validateSequenceAndStopServer.

private void validateSequenceAndStopServer() {
    ConsistentHash consistentHash = channelFactory.getConsistentHash(RemoteCacheManager.cacheNameBytes());
    SocketAddress expectedServer;
    resetStats();
    assertNoHits();
    expectedServer = consistentHash.getServer(HotRodTestingUtil.marshall("k"));
    assertNoHits();
    remoteCache.put("k", "v");
    assert strategy.getServers().length == 3;
    assertOnlyServerHit(expectedServer);
    resetStats();
    expectedServer = consistentHash.getServer(HotRodTestingUtil.marshall("k2"));
    remoteCache.put("k2", "v2");
    assertOnlyServerHit(expectedServer);
    resetStats();
    expectedServer = consistentHash.getServer(HotRodTestingUtil.marshall("k3"));
    remoteCache.put("k3", "v3");
    assertOnlyServerHit(expectedServer);
    resetStats();
    expectedServer = consistentHash.getServer(HotRodTestingUtil.marshall("k"));
    assertEquals("v", remoteCache.put("k", "v"));
    assertOnlyServerHit(expectedServer);
    // this would be the next server to be shutdown
    expectedServer = consistentHash.getServer(HotRodTestingUtil.marshall("k"));
    HotRodServer toStop = addr2hrServer.get(expectedServer);
    toStop.stop();
    for (Iterator<EmbeddedCacheManager> ecmIt = cacheManagers.iterator(); ecmIt.hasNext(); ) {
        if (ecmIt.next().getAddress().equals(expectedServer))
            ecmIt.remove();
    }
    TestingUtil.waitForNoRebalance(caches());
}
Also used : ConsistentHash(org.infinispan.client.hotrod.impl.consistenthash.ConsistentHash) HotRodServer(org.infinispan.server.hotrod.HotRodServer) SocketAddress(java.net.SocketAddress) EmbeddedCacheManager(org.infinispan.manager.EmbeddedCacheManager)

Example 5 with ConsistentHash

use of org.infinispan.client.hotrod.impl.consistenthash.ConsistentHash in project infinispan by infinispan.

the class AbstractRetryTest method cacheToHit.

protected AdvancedCache<?, ?> cacheToHit(Object key) {
    ConsistentHash consistentHash = channelFactory.getConsistentHash(RemoteCacheManager.cacheNameBytes());
    SocketAddress expectedServer = consistentHash.getServer(marshall(key));
    return addr2hrServer.get(expectedServer).getCacheManager().getCache().getAdvancedCache();
}
Also used : ConsistentHash(org.infinispan.client.hotrod.impl.consistenthash.ConsistentHash) SocketAddress(java.net.SocketAddress)

Aggregations

ConsistentHash (org.infinispan.client.hotrod.impl.consistenthash.ConsistentHash)5 SocketAddress (java.net.SocketAddress)3 ConfigurationBuilder (org.infinispan.client.hotrod.configuration.ConfigurationBuilder)2 ConsistentHashFactory (org.infinispan.client.hotrod.impl.consistenthash.ConsistentHashFactory)2 RemoteCacheManager (org.infinispan.client.hotrod.RemoteCacheManager)1 ChannelFactory (org.infinispan.client.hotrod.impl.transport.netty.ChannelFactory)1 EmbeddedCacheManager (org.infinispan.manager.EmbeddedCacheManager)1 HotRodServer (org.infinispan.server.hotrod.HotRodServer)1