Search in sources :

Example 1 with Index

use of org.fusesource.hawtdb.api.Index in project camel by apache.

the class HawtDBAggregateNotLostRemovedWhenConfirmedTest method testHawtDBAggregateNotLostRemovedWhenConfirmed.

@Test
public void testHawtDBAggregateNotLostRemovedWhenConfirmed() throws Exception {
    getMockEndpoint("mock:result").expectedBodiesReceived("ABCDE");
    template.sendBodyAndHeader("direct:start", "A", "id", 123);
    template.sendBodyAndHeader("direct:start", "B", "id", 123);
    template.sendBodyAndHeader("direct:start", "C", "id", 123);
    template.sendBodyAndHeader("direct:start", "D", "id", 123);
    template.sendBodyAndHeader("direct:start", "E", "id", 123);
    assertMockEndpointsSatisfied(30, TimeUnit.SECONDS);
    Thread.sleep(1000);
    String exchangeId = getMockEndpoint("mock:result").getReceivedExchanges().get(0).getExchangeId();
    // the exchange should NOT be in the completed repo as it was confirmed
    final HawtDBFile hawtDBFile = repo.getHawtDBFile();
    final HawtDBCamelCodec codec = new HawtDBCamelCodec();
    final Buffer confirmKeyBuffer = codec.marshallKey(exchangeId);
    Buffer bf = hawtDBFile.execute(new Work<Buffer>() {

        public Buffer execute(Transaction tx) {
            Index<Buffer, Buffer> index = hawtDBFile.getRepositoryIndex(tx, "repo1-completed", false);
            return index.get(confirmKeyBuffer);
        }
    });
    // assert the exchange was deleted
    assertNull(bf);
}
Also used : Buffer(org.fusesource.hawtbuf.Buffer) Transaction(org.fusesource.hawtdb.api.Transaction) Index(org.fusesource.hawtdb.api.Index) Test(org.junit.Test)

Example 2 with Index

use of org.fusesource.hawtdb.api.Index in project camel by apache.

the class HawtDBAggregateNotLostTest method testHawtDBAggregateNotLost.

@Test
public void testHawtDBAggregateNotLost() throws Exception {
    getMockEndpoint("mock:aggregated").expectedBodiesReceived("ABCDE");
    getMockEndpoint("mock:result").expectedMessageCount(0);
    template.sendBodyAndHeader("direct:start", "A", "id", 123);
    template.sendBodyAndHeader("direct:start", "B", "id", 123);
    template.sendBodyAndHeader("direct:start", "C", "id", 123);
    template.sendBodyAndHeader("direct:start", "D", "id", 123);
    template.sendBodyAndHeader("direct:start", "E", "id", 123);
    assertMockEndpointsSatisfied(30, TimeUnit.SECONDS);
    Thread.sleep(1000);
    String exchangeId = getMockEndpoint("mock:aggregated").getReceivedExchanges().get(0).getExchangeId();
    // the exchange should be in the completed repo where we should be able to find it
    final HawtDBFile hawtDBFile = repo.getHawtDBFile();
    final HawtDBCamelCodec codec = new HawtDBCamelCodec();
    final Buffer confirmKeyBuffer = codec.marshallKey(exchangeId);
    Buffer bf = hawtDBFile.execute(new Work<Buffer>() {

        public Buffer execute(Transaction tx) {
            Index<Buffer, Buffer> index = hawtDBFile.getRepositoryIndex(tx, "repo1-completed", false);
            return index.get(confirmKeyBuffer);
        }
    });
    // assert the exchange was not lost and we got all the information still
    assertNotNull(bf);
    Exchange completed = codec.unmarshallExchange(context, bf);
    assertNotNull(completed);
    // should retain the exchange id
    assertEquals(exchangeId, completed.getExchangeId());
    assertEquals("ABCDE", completed.getIn().getBody());
    assertEquals(123, completed.getIn().getHeader("id"));
    assertEquals("size", completed.getProperty(Exchange.AGGREGATED_COMPLETED_BY));
    assertEquals(5, completed.getProperty(Exchange.AGGREGATED_SIZE));
    // will store correlation keys as String
    assertEquals("123", completed.getProperty(Exchange.AGGREGATED_CORRELATION_KEY));
}
Also used : Buffer(org.fusesource.hawtbuf.Buffer) Exchange(org.apache.camel.Exchange) Transaction(org.fusesource.hawtdb.api.Transaction) Index(org.fusesource.hawtdb.api.Index) Test(org.junit.Test)

Aggregations

Buffer (org.fusesource.hawtbuf.Buffer)2 Index (org.fusesource.hawtdb.api.Index)2 Transaction (org.fusesource.hawtdb.api.Transaction)2 Test (org.junit.Test)2 Exchange (org.apache.camel.Exchange)1