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