Search in sources :

Example 1 with ChannelFactory

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());
        }
    });
}
Also used : InternalRemoteCacheManager(org.infinispan.client.hotrod.test.InternalRemoteCacheManager) RemoteCacheManagerCallable(org.infinispan.client.hotrod.test.RemoteCacheManagerCallable) HotRodServer(org.infinispan.server.hotrod.HotRodServer) ChannelFactory(org.infinispan.client.hotrod.impl.transport.netty.ChannelFactory)

Example 2 with ChannelFactory

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());
        }
    });
}
Also used : InternalRemoteCacheManager(org.infinispan.client.hotrod.test.InternalRemoteCacheManager) RemoteCacheManagerCallable(org.infinispan.client.hotrod.test.RemoteCacheManagerCallable) ChannelFactory(org.infinispan.client.hotrod.impl.transport.netty.ChannelFactory)

Example 3 with ChannelFactory

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());
        }
    });
}
Also used : InternalRemoteCacheManager(org.infinispan.client.hotrod.test.InternalRemoteCacheManager) RemoteCacheManagerCallable(org.infinispan.client.hotrod.test.RemoteCacheManagerCallable) ChannelFactory(org.infinispan.client.hotrod.impl.transport.netty.ChannelFactory)

Example 4 with ChannelFactory

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);
}
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 5 with ChannelFactory

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;
}
Also used : ProtoStreamMarshaller(org.infinispan.commons.marshall.ProtoStreamMarshaller) Marshaller(org.infinispan.commons.marshall.Marshaller) KeyAffinityService(org.infinispan.affinity.KeyAffinityService) InetSocketAddress(java.net.InetSocketAddress) Address(org.infinispan.remoting.transport.Address) NoopChannelOperation(org.infinispan.client.hotrod.test.NoopChannelOperation) InetSocketAddress(java.net.InetSocketAddress) Channel(io.netty.channel.Channel) ChannelFactory(org.infinispan.client.hotrod.impl.transport.netty.ChannelFactory) InternalRemoteCacheManager(org.infinispan.client.hotrod.test.InternalRemoteCacheManager) ProtoStreamMarshaller(org.infinispan.commons.marshall.ProtoStreamMarshaller) ExecutorService(java.util.concurrent.ExecutorService)

Aggregations

ChannelFactory (org.infinispan.client.hotrod.impl.transport.netty.ChannelFactory)13 InternalRemoteCacheManager (org.infinispan.client.hotrod.test.InternalRemoteCacheManager)6 RemoteCacheManagerCallable (org.infinispan.client.hotrod.test.RemoteCacheManagerCallable)4 Channel (io.netty.channel.Channel)3 InetSocketAddress (java.net.InetSocketAddress)3 SocketAddress (java.net.SocketAddress)3 HashMap (java.util.HashMap)3 NoopChannelOperation (org.infinispan.client.hotrod.test.NoopChannelOperation)3 List (java.util.List)2 Map (java.util.Map)2 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)2 Collectors (java.util.stream.Collectors)2 DataFormat (org.infinispan.client.hotrod.DataFormat)2 Configuration (org.infinispan.client.hotrod.configuration.Configuration)2 ClientStatistics (org.infinispan.client.hotrod.impl.ClientStatistics)2 Codec (org.infinispan.client.hotrod.impl.protocol.Codec)2 HotRodServer (org.infinispan.server.hotrod.HotRodServer)2 AbstractScheduledEventExecutor (io.netty.util.concurrent.AbstractScheduledEventExecutor)1 HashSet (java.util.HashSet)1 Set (java.util.Set)1