use of org.apache.pulsar.client.impl.ConnectionPool in project pulsar by apache.
the class ProxyTest method getClientActiveConsumerChangeNotSupported.
private static PulsarClient getClientActiveConsumerChangeNotSupported(ClientConfigurationData conf) throws Exception {
ThreadFactory threadFactory = new DefaultThreadFactory("pulsar-client-io", Thread.currentThread().isDaemon());
EventLoopGroup eventLoopGroup = EventLoopUtil.newEventLoopGroup(conf.getNumIoThreads(), false, threadFactory);
ConnectionPool cnxPool = new ConnectionPool(conf, eventLoopGroup, () -> {
return new ClientCnx(conf, eventLoopGroup, ProtocolVersion.v11_VALUE) {
@Override
protected void handleActiveConsumerChange(CommandActiveConsumerChange change) {
throw new UnsupportedOperationException();
}
};
});
return new PulsarClientImpl(conf, eventLoopGroup, cnxPool);
}
use of org.apache.pulsar.client.impl.ConnectionPool in project pulsar by apache.
the class ProxyParserTest method getClientActiveConsumerChangeNotSupported.
private static PulsarClient getClientActiveConsumerChangeNotSupported(ClientConfigurationData conf) throws Exception {
ThreadFactory threadFactory = new DefaultThreadFactory("pulsar-client-io", Thread.currentThread().isDaemon());
EventLoopGroup eventLoopGroup = EventLoopUtil.newEventLoopGroup(conf.getNumIoThreads(), false, threadFactory);
ConnectionPool cnxPool = new ConnectionPool(conf, eventLoopGroup, () -> {
return new ClientCnx(conf, eventLoopGroup, ProtocolVersion.v11_VALUE) {
@Override
protected void handleActiveConsumerChange(CommandActiveConsumerChange change) {
throw new UnsupportedOperationException();
}
};
});
return new PulsarClientImpl(conf, eventLoopGroup, cnxPool);
}
use of org.apache.pulsar.client.impl.ConnectionPool in project pulsar by yahoo.
the class ProxyParserTest method getClientActiveConsumerChangeNotSupported.
private static PulsarClient getClientActiveConsumerChangeNotSupported(ClientConfigurationData conf) throws Exception {
ThreadFactory threadFactory = new DefaultThreadFactory("pulsar-client-io", Thread.currentThread().isDaemon());
EventLoopGroup eventLoopGroup = EventLoopUtil.newEventLoopGroup(conf.getNumIoThreads(), false, threadFactory);
ConnectionPool cnxPool = new ConnectionPool(conf, eventLoopGroup, () -> {
return new ClientCnx(conf, eventLoopGroup, ProtocolVersion.v11_VALUE) {
@Override
protected void handleActiveConsumerChange(CommandActiveConsumerChange change) {
throw new UnsupportedOperationException();
}
};
});
return new PulsarClientImpl(conf, eventLoopGroup, cnxPool);
}
use of org.apache.pulsar.client.impl.ConnectionPool in project pulsar by yahoo.
the class BrokerServiceThrottlingTest method testLookupThrottlingForClientByBroker.
/**
* Verifies: Broker side throttling:
*
* <pre>
* 1. concurrent_consumer_creation > maxConcurrentLookupRequest at broker
* 2. few of the consumer creation must fail with TooManyLookupRequestException.
* </pre>
*
* @throws Exception
*/
@Test
public void testLookupThrottlingForClientByBroker() throws Exception {
final String topicName = "persistent://prop/ns-abc/newTopic";
@Cleanup PulsarClient pulsarClient = PulsarClient.builder().serviceUrl(pulsar.getBrokerServiceUrl()).statsInterval(0, TimeUnit.SECONDS).ioThreads(20).connectionsPerBroker(20).build();
int newPermits = 1;
admin.brokers().updateDynamicConfiguration("maxConcurrentLookupRequest", Integer.toString(newPermits));
// wait config to be updated
for (int i = 0; i < 5; i++) {
if (pulsar.getConfiguration().getMaxConcurrentLookupRequest() != newPermits) {
Thread.sleep(100 + (i * 10));
} else {
break;
}
}
PulsarServiceNameResolver resolver = new PulsarServiceNameResolver();
resolver.updateServiceUrl(pulsar.getBrokerServiceUrl());
ClientConfigurationData conf = new ClientConfigurationData();
conf.setConnectionsPerBroker(20);
EventLoopGroup eventLoop = EventLoopUtil.newEventLoopGroup(20, false, new DefaultThreadFactory("test-pool", Thread.currentThread().isDaemon()));
ExecutorService executor = Executors.newFixedThreadPool(10);
try (ConnectionPool pool = new ConnectionPool(conf, eventLoop)) {
final int totalConsumers = 20;
List<Future<?>> futures = new ArrayList<>();
// test for partitionMetadataRequest
for (int i = 0; i < totalConsumers; i++) {
long reqId = 0xdeadbeef + i;
Future<?> f = executor.submit(() -> {
ByteBuf request = Commands.newPartitionMetadataRequest(topicName, reqId);
pool.getConnection(resolver.resolveHost()).thenCompose(clientCnx -> clientCnx.newLookup(request, reqId)).get();
return null;
});
futures.add(f);
}
int rejects = 0;
for (Future<?> f : futures) {
try {
f.get();
} catch (ExecutionException e) {
Throwable rootCause = e;
while (rootCause instanceof ExecutionException) {
rootCause = rootCause.getCause();
}
if (rootCause instanceof org.apache.pulsar.client.api.PulsarClientException.TooManyRequestsException) {
rejects++;
} else {
throw e;
}
}
}
assertTrue(rejects > 0);
futures.clear();
// test for lookup
for (int i = 0; i < totalConsumers; i++) {
long reqId = 0xdeadfeef + i;
Future<?> f = executor.submit(() -> {
ByteBuf request = Commands.newLookup(topicName, true, reqId);
pool.getConnection(resolver.resolveHost()).thenCompose(clientCnx -> clientCnx.newLookup(request, reqId)).get();
return null;
});
futures.add(f);
}
rejects = 0;
for (Future<?> f : futures) {
try {
f.get();
} catch (ExecutionException e) {
Throwable rootCause = e;
while (rootCause instanceof ExecutionException) {
rootCause = rootCause.getCause();
}
if (rootCause instanceof org.apache.pulsar.client.api.PulsarClientException.TooManyRequestsException) {
rejects++;
} else {
throw e;
}
}
}
assertTrue(rejects > 0);
} finally {
executor.shutdownNow();
eventLoop.shutdownNow();
}
}
use of org.apache.pulsar.client.impl.ConnectionPool in project incubator-pulsar by apache.
the class ProxyParserTest method getClientActiveConsumerChangeNotSupported.
private static PulsarClient getClientActiveConsumerChangeNotSupported(ClientConfigurationData conf) throws Exception {
ThreadFactory threadFactory = new DefaultThreadFactory("pulsar-client-io", Thread.currentThread().isDaemon());
EventLoopGroup eventLoopGroup = EventLoopUtil.newEventLoopGroup(conf.getNumIoThreads(), false, threadFactory);
ConnectionPool cnxPool = new ConnectionPool(conf, eventLoopGroup, () -> {
return new ClientCnx(conf, eventLoopGroup, ProtocolVersion.v11_VALUE) {
@Override
protected void handleActiveConsumerChange(CommandActiveConsumerChange change) {
throw new UnsupportedOperationException();
}
};
});
return new PulsarClientImpl(conf, eventLoopGroup, cnxPool);
}
Aggregations