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