use of org.apache.camel.Producer in project camel by apache.
the class ServicePoolTest method testThreeEntries.
public void testThreeEntries() throws Exception {
Endpoint endpoint = context.getEndpoint("mock:foo");
Producer producer1 = new MyProducer(endpoint);
Producer producer2 = new MyProducer(endpoint);
Producer producer3 = new MyProducer(endpoint);
producer1 = pool.addAndAcquire(endpoint, producer1);
producer2 = pool.addAndAcquire(endpoint, producer2);
producer3 = pool.addAndAcquire(endpoint, producer3);
assertEquals(0, pool.size());
pool.release(endpoint, producer1);
assertEquals(1, pool.size());
pool.release(endpoint, producer2);
assertEquals(2, pool.size());
pool.release(endpoint, producer3);
assertEquals(3, pool.size());
}
use of org.apache.camel.Producer in project camel by apache.
the class ServicePoolTest method testConcurrent.
public void testConcurrent() throws Exception {
final Endpoint endpoint = context.getEndpoint("mock:foo");
ExecutorService executor = Executors.newFixedThreadPool(5);
List<Future<Integer>> response = new ArrayList<Future<Integer>>();
for (int i = 0; i < 5; i++) {
final int index = i;
Future<Integer> out = executor.submit(new Callable<Integer>() {
public Integer call() throws Exception {
Producer producer = pool.acquire(endpoint);
if (producer == null) {
producer = pool.addAndAcquire(endpoint, new MyProducer(endpoint));
}
assertNotNull(producer);
pool.release(endpoint, producer);
return index;
}
});
response.add(out);
}
for (int i = 0; i < 5; i++) {
assertEquals(i, response.get(i).get().intValue());
}
executor.shutdownNow();
}
use of org.apache.camel.Producer in project camel by apache.
the class ServicePoolTest method testAcquireAddRelease.
public void testAcquireAddRelease() throws Exception {
Endpoint endpoint = context.getEndpoint("mock:foo");
for (int i = 0; i < 10; i++) {
Producer producer = pool.acquire(endpoint);
if (producer == null) {
producer = pool.addAndAcquire(endpoint, new MyProducer(endpoint));
}
assertNotNull(producer);
pool.release(endpoint, producer);
}
}
use of org.apache.camel.Producer in project camel by apache.
the class ServicePoolTest method testConcurrentStress.
public void testConcurrentStress() throws Exception {
final Endpoint endpoint = context.getEndpoint("mock:foo");
ExecutorService executor = Executors.newFixedThreadPool(5);
List<Future<Integer>> response = new ArrayList<Future<Integer>>();
for (int i = 0; i < 5; i++) {
final int index = i;
Future<Integer> out = executor.submit(new Callable<Integer>() {
public Integer call() throws Exception {
for (int j = 0; j < 100; j++) {
Producer producer = pool.acquire(endpoint);
if (producer == null) {
producer = pool.addAndAcquire(endpoint, new MyProducer(endpoint));
}
assertNotNull(producer);
pool.release(endpoint, producer);
}
return index;
}
});
response.add(out);
}
for (int i = 0; i < 5; i++) {
assertEquals(i, response.get(i).get().intValue());
}
executor.shutdownNow();
}
use of org.apache.camel.Producer in project camel by apache.
the class ProducerTest method testReleaseNoJobId.
@Test
public void testReleaseNoJobId() throws Exception {
endpoint.setCommand(BeanstalkCommand.release);
Producer producer = endpoint.createProducer();
assertNotNull("Producer", producer);
assertThat("Producer class", producer, instanceOf(BeanstalkProducer.class));
assertThat("Processor class", ((BeanstalkProducer) producer).getCommand(), instanceOf(ReleaseCommand.class));
final Exchange exchange = template.send(endpoint, ExchangePattern.InOnly, new Processor() {
public void process(Exchange exchange) {
}
});
assertTrue("Exchange failed", exchange.isFailed());
verify(client, never()).release(anyLong(), anyLong(), anyInt());
}
Aggregations