Search in sources :

Example 11 with Exchange

use of org.apache.camel.Exchange in project camel by apache.

the class LevelDBAggregationRepository method get.

public Exchange get(final CamelContext camelContext, final String key) {
    Exchange answer = null;
    try {
        byte[] lDbKey = keyBuilder(repositoryName, key);
        LOG.trace("Getting key index {}", key);
        byte[] rc = levelDBFile.getDb().get(lDbKey);
        if (rc != null) {
            answer = codec.unmarshallExchange(camelContext, new Buffer(rc));
        }
    } catch (IOException e) {
        throw new RuntimeException("Error getting key " + key + " from repository " + repositoryName, e);
    }
    LOG.debug("Getting key  [{}] -> {}", key, answer);
    return answer;
}
Also used : Exchange(org.apache.camel.Exchange) Buffer(org.fusesource.hawtbuf.Buffer) IOException(java.io.IOException)

Example 12 with Exchange

use of org.apache.camel.Exchange in project camel by apache.

the class LevelDBAggregationRepositoryRecoverExistingTest method testExisting.

@Test
public void testExisting() throws Exception {
    LevelDBAggregationRepository repo = new LevelDBAggregationRepository();
    repo.setLevelDBFile(levelDBFile);
    repo.setRepositoryName("repo1");
    repo.setReturnOldExchange(true);
    repo.setUseRecovery(true);
    repo.start();
    // Store it..
    Exchange exchange1 = new DefaultExchange(context);
    exchange1.getIn().setBody("counter:1");
    Exchange actual = repo.add(context, "foo", exchange1);
    assertEquals(null, actual);
    // Remove it, which makes it in the pre confirm stage
    repo.remove(context, "foo", exchange1);
    String id = exchange1.getExchangeId();
    // stop the repo
    repo.stop();
    Thread.sleep(1000);
    // load the repo again
    repo.start();
    // Get it back..
    actual = repo.get(context, "foo");
    assertNull(actual);
    // Recover it
    actual = repo.recover(context, id);
    assertNotNull(actual);
    assertEquals("counter:1", actual.getIn().getBody());
    repo.stop();
}
Also used : DefaultExchange(org.apache.camel.impl.DefaultExchange) Exchange(org.apache.camel.Exchange) DefaultExchange(org.apache.camel.impl.DefaultExchange) Test(org.junit.Test)

Example 13 with Exchange

use of org.apache.camel.Exchange in project camel by apache.

the class LevelDBGetNotFoundTest method testGetNotFound.

@Test
public void testGetNotFound() {
    LevelDBAggregationRepository repo = new LevelDBAggregationRepository();
    repo.setLevelDBFile(levelDBFile);
    repo.setRepositoryName("repo1");
    Exchange exchange = new DefaultExchange(context);
    exchange.getIn().setBody("Hello World");
    Exchange out = repo.get(context, exchange.getExchangeId());
    assertNull("Should not find exchange", out);
}
Also used : DefaultExchange(org.apache.camel.impl.DefaultExchange) Exchange(org.apache.camel.Exchange) DefaultExchange(org.apache.camel.impl.DefaultExchange) Test(org.junit.Test)

Example 14 with Exchange

use of org.apache.camel.Exchange in project camel by apache.

the class LevelDBAggregationRepositoryMultipleRepoTest method testMultipeRepoSameKeyDifferentContent.

@Test
public void testMultipeRepoSameKeyDifferentContent() {
    LevelDBAggregationRepository repo1 = new LevelDBAggregationRepository();
    repo1.setLevelDBFile(levelDBFile);
    repo1.setRepositoryName("repo1");
    LevelDBAggregationRepository repo2 = new LevelDBAggregationRepository();
    repo2.setLevelDBFile(levelDBFile);
    repo2.setRepositoryName("repo2");
    Exchange exchange1 = new DefaultExchange(context);
    exchange1.getIn().setBody("Hello World");
    repo1.add(context, "foo", exchange1);
    Exchange exchange2 = new DefaultExchange(context);
    exchange2.getIn().setBody("Bye World");
    repo2.add(context, "foo", exchange2);
    Exchange actual = repo1.get(context, "foo");
    assertEquals("Hello World", actual.getIn().getBody());
    actual = repo2.get(context, "foo");
    assertEquals("Bye World", actual.getIn().getBody());
}
Also used : DefaultExchange(org.apache.camel.impl.DefaultExchange) Exchange(org.apache.camel.Exchange) DefaultExchange(org.apache.camel.impl.DefaultExchange) Test(org.junit.Test)

Example 15 with Exchange

use of org.apache.camel.Exchange in project camel by apache.

the class LevelDBAggregationRepositoryMultipleRepoTest method testMultipeRepo.

@Test
public void testMultipeRepo() {
    LevelDBAggregationRepository repo1 = new LevelDBAggregationRepository();
    repo1.setLevelDBFile(levelDBFile);
    repo1.setRepositoryName("repo1");
    repo1.setReturnOldExchange(true);
    LevelDBAggregationRepository repo2 = new LevelDBAggregationRepository();
    repo2.setLevelDBFile(levelDBFile);
    repo2.setRepositoryName("repo2");
    repo2.setReturnOldExchange(true);
    // Can't get something we have not put in...
    Exchange actual = repo1.get(context, "missing");
    assertEquals(null, actual);
    actual = repo2.get(context, "missing");
    assertEquals(null, actual);
    // Store it..
    Exchange exchange1 = new DefaultExchange(context);
    exchange1.getIn().setBody("counter:1");
    actual = repo1.add(context, "foo", exchange1);
    assertEquals(null, actual);
    // Get it back..
    actual = repo1.get(context, "foo");
    assertEquals("counter:1", actual.getIn().getBody());
    assertEquals(null, repo2.get(context, "foo"));
    // Change it..
    Exchange exchange2 = new DefaultExchange(context);
    exchange2.getIn().setBody("counter:2");
    actual = repo1.add(context, "foo", exchange2);
    // the old one
    assertEquals("counter:1", actual.getIn().getBody());
    // add to repo2
    Exchange exchange3 = new DefaultExchange(context);
    exchange3.getIn().setBody("Hello World");
    actual = repo2.add(context, "bar", exchange3);
    assertEquals(null, actual);
    assertEquals(null, repo1.get(context, "bar"));
    // Get it back..
    actual = repo1.get(context, "foo");
    assertEquals("counter:2", actual.getIn().getBody());
    assertEquals(null, repo2.get(context, "foo"));
    actual = repo2.get(context, "bar");
    assertEquals("Hello World", actual.getIn().getBody());
    assertEquals(null, repo1.get(context, "bar"));
}
Also used : DefaultExchange(org.apache.camel.impl.DefaultExchange) Exchange(org.apache.camel.Exchange) DefaultExchange(org.apache.camel.impl.DefaultExchange) Test(org.junit.Test)

Aggregations

Exchange (org.apache.camel.Exchange)3446 Test (org.junit.Test)1735 Processor (org.apache.camel.Processor)1405 RouteBuilder (org.apache.camel.builder.RouteBuilder)666 MockEndpoint (org.apache.camel.component.mock.MockEndpoint)640 DefaultExchange (org.apache.camel.impl.DefaultExchange)473 Message (org.apache.camel.Message)379 Endpoint (org.apache.camel.Endpoint)235 HashMap (java.util.HashMap)190 DefaultCamelContext (org.apache.camel.impl.DefaultCamelContext)155 Producer (org.apache.camel.Producer)150 File (java.io.File)120 ArrayList (java.util.ArrayList)117 CamelContext (org.apache.camel.CamelContext)117 List (java.util.List)99 Map (java.util.Map)96 ProducerTemplate (org.apache.camel.ProducerTemplate)94 IOException (java.io.IOException)92 Tx (org.nhindirect.common.tx.model.Tx)83 Predicate (org.apache.camel.Predicate)78