use of java.util.ArrayList in project camel by apache.
the class ExpressionBuilderTest method testSortLines.
public void testSortLines() throws Exception {
Expression expression = sortExpression(body().tokenize(",").getExpression(), new SortByName());
exchange.getIn().setBody("Jonathan,Claus,James,Hadrian");
List<String> expected = new ArrayList<String>(Arrays.asList(new String[] { "Claus", "Hadrian", "James", "Jonathan" }));
assertExpression(expression, exchange, expected);
}
use of java.util.ArrayList in project camel by apache.
the class ExpressionBuilderTest method testTokenize.
public void testTokenize() throws Exception {
Expression expression = tokenizeExpression(headerExpression("location"), ",");
List<String> expected = new ArrayList<String>(Arrays.asList(new String[] { "Islington", "London", "UK" }));
assertExpression(expression, exchange, expected);
Predicate predicate = contains(tokenizeExpression(headerExpression("location"), ","), constantExpression("London"));
assertPredicate(predicate, exchange, true);
predicate = contains(tokenizeExpression(headerExpression("location"), ","), constantExpression("Manchester"));
assertPredicate(predicate, exchange, false);
}
use of java.util.ArrayList 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 java.util.ArrayList 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 java.util.ArrayList in project camel by apache.
the class SimpleTest method testCollateEven.
public void testCollateEven() throws Exception {
List<Object> data = new ArrayList<Object>();
data.add("A");
data.add("B");
data.add("C");
data.add("D");
data.add("E");
data.add("F");
exchange.getIn().setBody(data);
Iterator it = (Iterator) evaluateExpression("${collate(3)}", null);
List chunk = (List) it.next();
List chunk2 = (List) it.next();
assertFalse(it.hasNext());
assertEquals(3, chunk.size());
assertEquals(3, chunk2.size());
assertEquals("A", chunk.get(0));
assertEquals("B", chunk.get(1));
assertEquals("C", chunk.get(2));
assertEquals("D", chunk2.get(0));
assertEquals("E", chunk2.get(1));
assertEquals("F", chunk2.get(2));
}
Aggregations