use of com.rabbitmq.client.ConnectionFactory in project rabbitmq-java-client by rabbitmq.
the class ScalabilityTest method run.
public Results run() throws Exception {
Connection con = new ConnectionFactory() {
{
setHost(params.host);
setPort(params.port);
}
}.newConnection();
Channel channel = con.createChannel();
Results r = new Results(params.maxBindingExp);
for (int y = 0; y < params.maxBindingExp; y++) {
final int maxBindings = pow(params.base, y);
String[] routingKeys = new String[maxBindings];
for (int b = 0; b < maxBindings; b++) {
routingKeys[b] = UUID.randomUUID().toString();
}
Stack<String> queues = new Stack<String>();
int maxQueueExp = Math.min(params.maxQueueExp, params.maxExp - y);
System.out.println("---------------------------------");
System.out.println("| bindings = " + maxBindings + ", messages = " + params.messageCount);
System.out.println("| Routing");
int q = 0;
// create queues & bindings, time routing
Measurements creation = new CreationMeasurements(maxQueueExp);
float[] routingTimes = new float[maxQueueExp];
for (int x = 0; x < maxQueueExp; x++) {
final int maxQueues = pow(params.base, x);
for (; q < maxQueues; q++) {
AMQP.Queue.DeclareOk ok = channel.queueDeclare();
queues.push(ok.getQueue());
for (int b = 0; b < maxBindings; b++) {
channel.queueBind(ok.getQueue(), "amq.direct", routingKeys[b]);
}
}
creation.addDataPoint(x);
float routingTime = timeRouting(channel, routingKeys);
routingTimes[x] = routingTime;
printTime(params.base, x, routingTime);
}
r.routingTimes[y] = routingTimes;
float[] creationTimes = creation.analyse(params.base);
r.creationTimes[y] = creationTimes;
System.out.println("| Creating");
printTimes(params.base, creationTimes);
// delete queues & bindings
Measurements deletion = new DeletionMeasurements(maxQueueExp);
for (int x = maxQueueExp - 1; x >= 0; x--) {
final int maxQueues = (x == 0) ? 0 : pow(params.base, x - 1);
for (; q > maxQueues; q--) {
channel.queueDelete(queues.pop());
}
deletion.addDataPoint(x);
}
float[] deletionTimes = deletion.analyse(params.base);
r.deletionTimes[y] = deletionTimes;
System.out.println("| Deleting");
printTimes(params.base, deletionTimes);
}
channel.close();
con.close();
return r;
}
use of com.rabbitmq.client.ConnectionFactory in project rabbitmq-java-client by rabbitmq.
the class BlockedConnection method connection.
private Connection connection(final CountDownLatch latch) throws IOException, TimeoutException {
ConnectionFactory factory = TestUtils.connectionFactory();
Connection connection = factory.newConnection();
connection.addBlockedListener(new BlockedListener() {
public void handleBlocked(String reason) throws IOException {
try {
unblock();
} catch (InterruptedException e) {
e.printStackTrace();
}
}
public void handleUnblocked() throws IOException {
latch.countDown();
}
});
return connection;
}
use of com.rabbitmq.client.ConnectionFactory in project rabbitmq-java-client by rabbitmq.
the class ChannelLimitNegotiation method channelMaxLowerThanServerMinimum.
@Test
public void channelMaxLowerThanServerMinimum() throws Exception {
int n = 64;
ConnectionFactory cf = TestUtils.connectionFactory();
cf.setRequestedChannelMax(n);
Connection conn = cf.newConnection();
assertEquals(n, conn.getChannelMax());
}
use of com.rabbitmq.client.ConnectionFactory in project rabbitmq-java-client by rabbitmq.
the class ChannelLimitNegotiation method openingTooManyChannels.
@Test
public void openingTooManyChannels() throws Exception {
int n = 48;
try {
Host.rabbitmqctl("eval 'application:set_env(rabbit, channel_max, " + n + ").'");
ConnectionFactory cf = TestUtils.connectionFactory();
Connection conn = cf.newConnection();
assertEquals(n, conn.getChannelMax());
for (int i = 1; i <= n; i++) {
assertNotNull(conn.createChannel(i));
}
// ChannelManager guards against channel.open being sent
assertNull(conn.createChannel(n + 1));
// Construct a channel directly
final ChannelN ch = new ChannelN(((AutorecoveringConnection) conn).getDelegate(), n + 1, new ConsumerWorkService(Executors.newSingleThreadExecutor(), Executors.defaultThreadFactory(), ConnectionFactory.DEFAULT_SHUTDOWN_TIMEOUT));
conn.addShutdownListener(new ShutdownListener() {
public void shutdownCompleted(ShutdownSignalException cause) {
// make sure channel.open continuation is released
ch.processShutdownSignal(cause, true, true);
}
});
ch.open();
fail("expected channel.open to cause a connection exception");
} catch (IOException e) {
checkShutdownSignal(530, e);
} finally {
Host.rabbitmqctl("eval 'application:set_env(rabbit, channel_max, 0).'");
}
}
use of com.rabbitmq.client.ConnectionFactory in project rabbitmq-java-client by rabbitmq.
the class LoopbackUsers method getFactory.
private ConnectionFactory getFactory(String name, String addr) {
ConnectionFactory factory = TestUtils.connectionFactory();
factory.setUsername(name);
factory.setPassword(name);
factory.setHost(addr);
return factory;
}
Aggregations