use of org.apache.commons.lang3.mutable.MutableLong in project neo4j by neo4j.
the class GBPTreeTest method shouldRemapFileIfMappedWithPageSizeLargerThanCreationSize.
@Test
public void shouldRemapFileIfMappedWithPageSizeLargerThanCreationSize() throws Exception {
// WHEN
int pageSize = 1024;
pageCache = createPageCache(pageSize);
List<Long> expectedData = new ArrayList<>();
for (long i = 0; i < 100; i++) {
expectedData.add(i);
}
try (GBPTree<MutableLong, MutableLong> index = new GBPTree<>(pageCache, indexFile, layout, pageSize / 2, NO_MONITOR, NO_HEADER)) {
// Insert some data
try (Writer<MutableLong, MutableLong> writer = index.writer()) {
MutableLong key = new MutableLong();
MutableLong value = new MutableLong();
for (Long insert : expectedData) {
key.setValue(insert);
value.setValue(insert);
writer.put(key, value);
}
}
index.checkpoint(IOLimiter.unlimited());
}
// THEN
try (GBPTree<MutableLong, MutableLong> index = new GBPTree<>(pageCache, indexFile, layout, 0, NO_MONITOR, NO_HEADER)) {
MutableLong fromInclusive = new MutableLong(0L);
MutableLong toExclusive = new MutableLong(200L);
try (RawCursor<Hit<MutableLong, MutableLong>, IOException> seek = index.seek(fromInclusive, toExclusive)) {
int i = 0;
while (seek.next()) {
Hit<MutableLong, MutableLong> hit = seek.get();
assertEquals(hit.key().getValue(), expectedData.get(i));
assertEquals(hit.value().getValue(), expectedData.get(i));
i++;
}
}
}
}
use of org.apache.commons.lang3.mutable.MutableLong in project neo4j by neo4j.
the class GBPTreeTest method shouldAllowClosingWriterMultipleTimes.
@Test
public void shouldAllowClosingWriterMultipleTimes() throws Exception {
// GIVEN
index = createIndex(256);
Writer<MutableLong, MutableLong> writer = index.writer();
writer.put(new MutableLong(0), new MutableLong(1));
writer.close();
// WHEN
writer.close();
// THEN that should be OK
}
use of org.apache.commons.lang3.mutable.MutableLong in project neo4j by neo4j.
the class GBPTreeTest method checkPointShouldLockOutWriter.
/* Check-pointing tests */
@Test
public void checkPointShouldLockOutWriter() throws Exception {
// GIVEN
CheckpointControlledMonitor monitor = new CheckpointControlledMonitor();
index = createIndex(1024, monitor);
long key = 10;
try (Writer<MutableLong, MutableLong> writer = index.writer()) {
writer.put(new MutableLong(key), new MutableLong(key));
}
// WHEN
monitor.enabled = true;
Thread checkpointer = new Thread(throwing(() -> index.checkpoint(IOLimiter.unlimited())));
checkpointer.start();
monitor.barrier.awaitUninterruptibly();
// now we're in the smack middle of a checkpoint
Thread t2 = new Thread(throwing(() -> index.writer().close()));
t2.start();
t2.join(200);
assertTrue(Arrays.toString(checkpointer.getStackTrace()), t2.isAlive());
monitor.barrier.release();
// THEN
t2.join();
}
use of org.apache.commons.lang3.mutable.MutableLong in project neo4j by neo4j.
the class InternalTreeLogicTest method shouldMergeValueInLeafAtParentKey.
@Test
public void shouldMergeValueInLeafAtParentKey() throws Exception {
// GIVEN
initialize();
for (int i = 0; numberOfRootSplits == 0; i++) {
insert(i, i);
}
// WHEN
generationManager.checkpoint();
long key = structurePropagation.rightKey.longValue();
int toAdd = 5;
insert(key, toAdd, ADDER);
// THEN
goTo(readCursor, rootId);
long rightChild = childAt(readCursor, 1, stableGeneration, unstableGeneration);
goTo(readCursor, rightChild);
int searchResult = KeySearch.search(readCursor, node, key(key), new MutableLong(), keyCount());
assertTrue(KeySearch.isHit(searchResult));
int pos = KeySearch.positionOf(searchResult);
assertEquals(0, pos);
assertEquals(key, keyAt(pos).longValue());
assertEquals(key + toAdd, valueAt(pos).longValue());
}
use of org.apache.commons.lang3.mutable.MutableLong in project neo4j by neo4j.
the class InternalTreeLogicTest method remove.
private MutableLong remove(long key, MutableLong into) throws IOException {
insertKey.setValue(key);
MutableLong result = treeLogic.remove(cursor, structurePropagation, insertKey, into, stableGeneration, unstableGeneration);
handleAfterChange();
return result;
}
Aggregations