use of org.infinispan.client.hotrod.impl.transport.netty.ChannelFactory in project infinispan by infinispan.
the class PingOnStartupTest method testTopologyFetched.
public void testTopologyFetched() {
HotRodServer hotRodServer2 = server(1);
org.infinispan.client.hotrod.configuration.ConfigurationBuilder clientBuilder = HotRodClientTestingUtil.newRemoteConfigurationBuilder(hotRodServer2);
withRemoteCacheManager(new RemoteCacheManagerCallable(new InternalRemoteCacheManager(clientBuilder.build())) {
@Override
public void call() {
ChannelFactory channelFactory = ((InternalRemoteCacheManager) rcm).getChannelFactory();
for (int i = 0; i < 10; i++) {
if (channelFactory.getServers().size() == 1) {
TestingUtil.sleepThread(1000);
} else {
break;
}
}
assertEquals(2, channelFactory.getServers().size());
}
});
}
use of org.infinispan.client.hotrod.impl.transport.netty.ChannelFactory in project infinispan by infinispan.
the class PingOnStartupTest method testHashAwareIntelligence.
public void testHashAwareIntelligence() {
org.infinispan.client.hotrod.configuration.ConfigurationBuilder clientBuilder = HotRodClientTestingUtil.newRemoteConfigurationBuilder();
clientBuilder.addServer().host("127.0.0.1").port(server(0).getPort());
clientBuilder.clientIntelligence(ClientIntelligence.HASH_DISTRIBUTION_AWARE);
withRemoteCacheManager(new RemoteCacheManagerCallable(new InternalRemoteCacheManager(clientBuilder.build())) {
@Override
public void call() {
rcm.getCache();
ChannelFactory channelFactory = ((InternalRemoteCacheManager) rcm).getChannelFactory();
assertEquals(2, channelFactory.getServers().size());
}
});
}
use of org.infinispan.client.hotrod.impl.transport.netty.ChannelFactory in project infinispan by infinispan.
the class PingOnStartupTest method testTopologyAwareIntelligence.
public void testTopologyAwareIntelligence() {
org.infinispan.client.hotrod.configuration.ConfigurationBuilder clientBuilder = HotRodClientTestingUtil.newRemoteConfigurationBuilder();
clientBuilder.addServer().host("127.0.0.1").port(server(0).getPort());
clientBuilder.clientIntelligence(ClientIntelligence.TOPOLOGY_AWARE);
withRemoteCacheManager(new RemoteCacheManagerCallable(new InternalRemoteCacheManager(clientBuilder.build())) {
@Override
public void call() {
rcm.getCache();
ChannelFactory channelFactory = ((InternalRemoteCacheManager) rcm).getChannelFactory();
assertEquals(2, channelFactory.getServers().size());
}
});
}
use of org.infinispan.client.hotrod.impl.transport.netty.ChannelFactory 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.transport.netty.ChannelFactory in project infinispan by infinispan.
the class DistributionRetryTest method generateKeyAndShutdownServer.
private Object generateKeyAndShutdownServer() throws IOException, ClassNotFoundException, InterruptedException {
resetStats();
Cache<Object, Object> cache = manager(1).getCache();
ExecutorService ex = Executors.newSingleThreadExecutor(getTestThreadFactory("KeyGenerator"));
KeyAffinityService kaf = KeyAffinityServiceFactory.newKeyAffinityService(cache, ex, new ByteKeyGenerator(), 2, true);
Address address = cache.getAdvancedCache().getRpcManager().getTransport().getAddress();
byte[] keyBytes = (byte[]) kaf.getKeyForAddress(address);
String key = ByteKeyGenerator.getStringObject(keyBytes);
ex.shutdownNow();
kaf.stop();
remoteCache.put(key, "v");
assertOnlyServerHit(getAddress(hotRodServer2));
ChannelFactory channelFactory = ((InternalRemoteCacheManager) remoteCacheManager).getChannelFactory();
Marshaller m = new ProtoStreamMarshaller();
Channel channel = channelFactory.fetchChannelAndInvoke(m.objectToByteBuffer(key, 64), null, RemoteCacheManager.cacheNameBytes(), new NoopChannelOperation()).join();
try {
assertEquals(channel.remoteAddress(), new InetSocketAddress(hotRodServer2.getHost(), hotRodServer2.getPort()));
} finally {
channelFactory.releaseChannel(channel);
}
log.info("About to stop Hot Rod server 2");
hotRodServer2.stop();
return key;
}
Aggregations