Search in sources :

Example 71 with ArrayList

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);
}
Also used : Expression(org.apache.camel.Expression) ArrayList(java.util.ArrayList)

Example 72 with ArrayList

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);
}
Also used : Expression(org.apache.camel.Expression) ArrayList(java.util.ArrayList) Predicate(org.apache.camel.Predicate)

Example 73 with ArrayList

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();
}
Also used : Endpoint(org.apache.camel.Endpoint) Producer(org.apache.camel.Producer) ExecutorService(java.util.concurrent.ExecutorService) ArrayList(java.util.ArrayList) Future(java.util.concurrent.Future) Endpoint(org.apache.camel.Endpoint)

Example 74 with ArrayList

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();
}
Also used : Endpoint(org.apache.camel.Endpoint) Producer(org.apache.camel.Producer) ExecutorService(java.util.concurrent.ExecutorService) ArrayList(java.util.ArrayList) Future(java.util.concurrent.Future) Endpoint(org.apache.camel.Endpoint)

Example 75 with ArrayList

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));
}
Also used : ArrayList(java.util.ArrayList) Iterator(java.util.Iterator) ArrayList(java.util.ArrayList) List(java.util.List)

Aggregations

ArrayList (java.util.ArrayList)55702 Test (org.junit.Test)8169 List (java.util.List)6815 HashMap (java.util.HashMap)5856 IOException (java.io.IOException)3899 Map (java.util.Map)3195 File (java.io.File)3090 HashSet (java.util.HashSet)2245 Iterator (java.util.Iterator)1591 Test (org.testng.annotations.Test)1074 SQLException (java.sql.SQLException)1046 ResultSet (java.sql.ResultSet)1017 Date (java.util.Date)997 Set (java.util.Set)917 LinkedHashMap (java.util.LinkedHashMap)886 PreparedStatement (java.sql.PreparedStatement)882 Collection (java.util.Collection)751 LinkedList (java.util.LinkedList)677 BufferedReader (java.io.BufferedReader)663 Path (org.apache.hadoop.fs.Path)611