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;
}
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();
}
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);
}
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());
}
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"));
}
Aggregations