Search in sources :

Example 1 with NoopChannelOperation

use of org.infinispan.client.hotrod.test.NoopChannelOperation in project infinispan by infinispan.

the class CSAIntegrationTest method testRequestsGoToExpectedServer.

@Test(dependsOnMethods = "testHashFunctionReturnsSameValues")
public void testRequestsGoToExpectedServer() throws Exception {
    addInterceptors();
    List<byte[]> keys = new ArrayList<byte[]>();
    for (int i = 0; i < 500; i++) {
        byte[] key = generateKey(i);
        keys.add(key);
        String keyStr = new String(key);
        remoteCache.put(keyStr, "value");
        Channel channel = channelFactory.fetchChannelAndInvoke(marshall(keyStr), null, RemoteCacheManager.cacheNameBytes(), new NoopChannelOperation()).join();
        assertHotRodEquals(addr2hrServer.get(ChannelRecord.of(channel).getUnresolvedAddress()).getCacheManager(), keyStr, "value");
        channelFactory.releaseChannel(channel);
    }
    log.info("Right before first get.");
    for (byte[] key : keys) {
        resetStats();
        String keyStr = new String(key);
        assert remoteCache.get(keyStr).equals("value");
        Channel channel = channelFactory.fetchChannelAndInvoke(marshall(keyStr), null, HotRodConstants.DEFAULT_CACHE_NAME_BYTES, new NoopChannelOperation()).join();
        assertOnlyServerHit(ChannelRecord.of(channel).getUnresolvedAddress());
        channelFactory.releaseChannel(channel);
    }
}
Also used : NoopChannelOperation(org.infinispan.client.hotrod.test.NoopChannelOperation) Channel(io.netty.channel.Channel) ArrayList(java.util.ArrayList) Test(org.testng.annotations.Test)

Example 2 with NoopChannelOperation

use of org.infinispan.client.hotrod.test.NoopChannelOperation 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)

Example 3 with NoopChannelOperation

use of org.infinispan.client.hotrod.test.NoopChannelOperation in project infinispan by infinispan.

the class ServerErrorTest method testErrorWhileDoingPut.

public void testErrorWhileDoingPut(Method m) {
    cache.getAdvancedCache().withStorageMediaType().addListener(new ErrorInducingListener());
    remoteCache = remoteCacheManager.getCache();
    remoteCache.put(k(m), v(m));
    assertEquals(v(m), remoteCache.get(k(m)));
    // Obtain a reference to the single connection in the pool
    ChannelFactory channelFactory = remoteCacheManager.getChannelFactory();
    InetSocketAddress address = InetSocketAddress.createUnresolved(hotrodServer.getHost(), hotrodServer.getPort());
    Channel channel = channelFactory.fetchChannelAndInvoke(address, new NoopChannelOperation()).join();
    // Obtain a reference to the scheduled executor and its task queue
    AbstractScheduledEventExecutor scheduledExecutor = ((AbstractScheduledEventExecutor) channel.eventLoop());
    Queue<?> scheduledTaskQueue = TestingUtil.extractField(scheduledExecutor, "scheduledTaskQueue");
    int scheduledTasksBaseline = scheduledTaskQueue.size();
    // Release the channel back into the pool
    channelFactory.releaseChannel(channel);
    assertEquals(0, channelFactory.getNumActive(address));
    assertEquals(1, channelFactory.getNumIdle(address));
    log.debug("Sending failing operation to server");
    expectException(HotRodClientException.class, () -> remoteCache.put("FailFailFail", "whatever..."));
    assertEquals(0, channelFactory.getNumActive(address));
    assertEquals(1, channelFactory.getNumIdle(address));
    // Check that the operation was completed
    HeaderDecoder headerDecoder = channel.pipeline().get(HeaderDecoder.class);
    assertEquals(0, headerDecoder.registeredOperations());
    // Check that the timeout task was cancelled
    assertEquals(scheduledTasksBaseline, scheduledTaskQueue.size());
    log.debug("Sending new request after server failure");
    remoteCache.put(k(m, 2), v(m, 2));
    assertEquals(v(m, 2), remoteCache.get(k(m, 2)));
}
Also used : HeaderDecoder(org.infinispan.client.hotrod.impl.transport.netty.HeaderDecoder) InetSocketAddress(java.net.InetSocketAddress) NoopChannelOperation(org.infinispan.client.hotrod.test.NoopChannelOperation) Channel(io.netty.channel.Channel) AbstractScheduledEventExecutor(io.netty.util.concurrent.AbstractScheduledEventExecutor) ChannelFactory(org.infinispan.client.hotrod.impl.transport.netty.ChannelFactory)

Example 4 with NoopChannelOperation

use of org.infinispan.client.hotrod.test.NoopChannelOperation in project infinispan by infinispan.

the class CSAIntegrationTest method testHashFunctionReturnsSameValues.

@Test(dependsOnMethods = "testCorrectSetup")
public void testHashFunctionReturnsSameValues() throws InterruptedException {
    for (int i = 0; i < 1000; i++) {
        byte[] key = generateKey(i);
        Channel channel = channelFactory.fetchChannelAndInvoke(key, null, HotRodConstants.DEFAULT_CACHE_NAME_BYTES, new NoopChannelOperation()).join();
        SocketAddress serverAddress = ChannelRecord.of(channel).getUnresolvedAddress();
        CacheContainer cacheContainer = addr2hrServer.get(serverAddress).getCacheManager();
        assertNotNull("For server address " + serverAddress + " found " + cacheContainer + ". Map is: " + addr2hrServer, cacheContainer);
        DistributionManager distributionManager = cacheContainer.getCache().getAdvancedCache().getDistributionManager();
        Address clusterAddress = cacheContainer.getCache().getAdvancedCache().getRpcManager().getAddress();
        ConsistentHash serverCh = distributionManager.getReadConsistentHash();
        int numSegments = serverCh.getNumSegments();
        int keySegment = distributionManager.getCacheTopology().getSegment(key);
        Address serverOwner = serverCh.locatePrimaryOwnerForSegment(keySegment);
        Address serverPreviousOwner = serverCh.locatePrimaryOwnerForSegment((keySegment - 1 + numSegments) % numSegments);
        assert clusterAddress.equals(serverOwner) || clusterAddress.equals(serverPreviousOwner);
        channelFactory.releaseChannel(channel);
    }
}
Also used : ConsistentHash(org.infinispan.distribution.ch.ConsistentHash) SocketAddress(java.net.SocketAddress) Address(org.infinispan.remoting.transport.Address) InetSocketAddress(java.net.InetSocketAddress) NoopChannelOperation(org.infinispan.client.hotrod.test.NoopChannelOperation) CacheContainer(org.infinispan.manager.CacheContainer) Channel(io.netty.channel.Channel) SocketAddress(java.net.SocketAddress) InetSocketAddress(java.net.InetSocketAddress) DistributionManager(org.infinispan.distribution.DistributionManager) Test(org.testng.annotations.Test)

Example 5 with NoopChannelOperation

use of org.infinispan.client.hotrod.test.NoopChannelOperation in project infinispan by infinispan.

the class DroppedConnectionsTest method testClosedConnection.

public void testClosedConnection() throws Exception {
    ConfigurationBuilder clientBuilder = HotRodClientTestingUtil.newRemoteConfigurationBuilder();
    clientBuilder.connectionPool().minIdle(1).maxActive(2).addServer().host(hotRodServer.getHost()).port(hotRodServer.getPort());
    RemoteCacheManager remoteCacheManager = null;
    try {
        remoteCacheManager = new InternalRemoteCacheManager(clientBuilder.build());
        RemoteCache<String, String> rc = remoteCacheManager.getCache();
        ChannelFactory channelFactory = ((InternalRemoteCacheManager) remoteCacheManager).getChannelFactory();
        // make sure a connection is created
        rc.put("k", "v");
        InetSocketAddress address = InetSocketAddress.createUnresolved("127.0.0.1", hotRodServer.getPort());
        assertEquals(0, channelFactory.getNumActive(address));
        assertEquals(1, channelFactory.getNumIdle(address));
        Channel channel = channelFactory.fetchChannelAndInvoke(address, new NoopChannelOperation()).join();
        // now we have a reference to the single connection in pool
        channelFactory.releaseChannel(channel);
        channel.close().sync();
        assertEquals("v", rc.get("k"));
        assertEquals(0, channelFactory.getNumActive(address));
        assertEquals(1, channelFactory.getNumIdle(address));
        Channel channel2 = channelFactory.fetchChannelAndInvoke(address, new NoopChannelOperation()).join();
        assertNotSame(channel.id(), channel2.id());
    } finally {
        HotRodClientTestingUtil.killRemoteCacheManager(remoteCacheManager);
    }
}
Also used : ConfigurationBuilder(org.infinispan.client.hotrod.configuration.ConfigurationBuilder) InternalRemoteCacheManager(org.infinispan.client.hotrod.test.InternalRemoteCacheManager) InternalRemoteCacheManager(org.infinispan.client.hotrod.test.InternalRemoteCacheManager) InetSocketAddress(java.net.InetSocketAddress) NoopChannelOperation(org.infinispan.client.hotrod.test.NoopChannelOperation) Channel(io.netty.channel.Channel) ChannelFactory(org.infinispan.client.hotrod.impl.transport.netty.ChannelFactory)

Aggregations

Channel (io.netty.channel.Channel)5 NoopChannelOperation (org.infinispan.client.hotrod.test.NoopChannelOperation)5 InetSocketAddress (java.net.InetSocketAddress)4 ChannelFactory (org.infinispan.client.hotrod.impl.transport.netty.ChannelFactory)3 InternalRemoteCacheManager (org.infinispan.client.hotrod.test.InternalRemoteCacheManager)2 Address (org.infinispan.remoting.transport.Address)2 Test (org.testng.annotations.Test)2 AbstractScheduledEventExecutor (io.netty.util.concurrent.AbstractScheduledEventExecutor)1 SocketAddress (java.net.SocketAddress)1 ArrayList (java.util.ArrayList)1 ExecutorService (java.util.concurrent.ExecutorService)1 KeyAffinityService (org.infinispan.affinity.KeyAffinityService)1 ConfigurationBuilder (org.infinispan.client.hotrod.configuration.ConfigurationBuilder)1 HeaderDecoder (org.infinispan.client.hotrod.impl.transport.netty.HeaderDecoder)1 Marshaller (org.infinispan.commons.marshall.Marshaller)1 ProtoStreamMarshaller (org.infinispan.commons.marshall.ProtoStreamMarshaller)1 DistributionManager (org.infinispan.distribution.DistributionManager)1 ConsistentHash (org.infinispan.distribution.ch.ConsistentHash)1 CacheContainer (org.infinispan.manager.CacheContainer)1