Search in sources :

Example 6 with SortedIndex

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

the class HawtDBGrowIssueTest method testGrowIssue.

@Test
public void testGrowIssue() throws Exception {
    // a 1kb string for testing
    StringBuilder sb = new StringBuilder(size);
    for (int i = 0; i < 1024; i++) {
        sb.append("X");
    }
    // the key
    final Buffer key = codec.marshallKey("foo");
    // we update using the same key, which means we should be able to do this within the file size limit
    for (int i = 0; i < size; i++) {
        final Buffer data = codec.marshallKey(i + "-" + sb.toString());
        log.debug("Updating " + i);
        hawtDBFile.execute(new Work<Object>() {

            public Object execute(Transaction tx) {
                SortedIndex<Buffer, Buffer> index = hawtDBFile.getRepositoryIndex(tx, "repo", true);
                return index.put(key, data);
            }
        });
    }
    // get the last
    Buffer out = hawtDBFile.execute(new Work<Buffer>() {

        public Buffer execute(Transaction tx) {
            SortedIndex<Buffer, Buffer> index = hawtDBFile.getRepositoryIndex(tx, "repo", true);
            return index.get(key);
        }
    });
    String data = codec.unmarshallKey(out);
    log.info(data);
    assertTrue("Should be 1023", data.startsWith("1023"));
    assertEquals(1029, data.length());
}
Also used : Buffer(org.fusesource.hawtbuf.Buffer) Transaction(org.fusesource.hawtdb.api.Transaction) SortedIndex(org.fusesource.hawtdb.api.SortedIndex) Test(org.junit.Test)

Aggregations

Buffer (org.fusesource.hawtbuf.Buffer)6 SortedIndex (org.fusesource.hawtdb.api.SortedIndex)6 Transaction (org.fusesource.hawtdb.api.Transaction)6 IOException (java.io.IOException)5 Exchange (org.apache.camel.Exchange)2 Test (org.junit.Test)1