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);
}
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);
}
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);
}
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());
}
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();
}
Aggregations