use of org.apache.commons.lang3.mutable.MutableLong in project neo4j by neo4j.
the class GBPTreeTest method shouldNotCheckpointOnCloseIfNoChangesHappened.
@Test
public void shouldNotCheckpointOnCloseIfNoChangesHappened() throws Exception {
// GIVEN
CheckpointCounter checkpointCounter = new CheckpointCounter();
// WHEN
GBPTree<MutableLong, MutableLong> index = createIndex(256, checkpointCounter);
int countBefore = checkpointCounter.count;
try (Writer<MutableLong, MutableLong> writer = index.writer()) {
writer.put(new MutableLong(0), new MutableLong(1));
}
index.checkpoint(IOLimiter.unlimited());
assertEquals(countBefore + 1, checkpointCounter.count);
// THEN
closeIndex();
assertEquals(countBefore + 1, checkpointCounter.count);
}
use of org.apache.commons.lang3.mutable.MutableLong in project neo4j by neo4j.
the class GBPTreeTest method shouldSplitCorrectly.
/* Randomized tests */
@Test
public void shouldSplitCorrectly() throws Exception {
// GIVEN
GBPTree<MutableLong, MutableLong> index = createIndex(256);
// WHEN
int count = 1_000;
PrimitiveLongSet seen = Primitive.longSet(count);
try (Writer<MutableLong, MutableLong> writer = index.writer()) {
for (int i = 0; i < count; i++) {
MutableLong key;
do {
key = new MutableLong(random.nextInt(100_000));
} while (!seen.add(key.longValue()));
MutableLong value = new MutableLong(i);
writer.put(key, value);
seen.add(key.longValue());
}
}
// THEN
try (RawCursor<Hit<MutableLong, MutableLong>, IOException> cursor = index.seek(new MutableLong(0), new MutableLong(Long.MAX_VALUE))) {
long prev = -1;
while (cursor.next()) {
MutableLong hit = cursor.get().key();
if (hit.longValue() < prev) {
fail(hit + " smaller than prev " + prev);
}
prev = hit.longValue();
assertTrue(seen.remove(hit.longValue()));
}
if (!seen.isEmpty()) {
fail("expected hits " + Arrays.toString(PrimitiveLongCollections.asArray(seen.iterator())));
}
}
}
use of org.apache.commons.lang3.mutable.MutableLong in project neo4j by neo4j.
the class GBPTreeTest method shouldSeeSimpleInsertions.
/* Insertion and read tests */
@Test
public void shouldSeeSimpleInsertions() throws Exception {
index = createIndex(256);
int count = 1000;
try (Writer<MutableLong, MutableLong> writer = index.writer()) {
for (int i = 0; i < count; i++) {
writer.put(new MutableLong(i), new MutableLong(i));
}
}
try (RawCursor<Hit<MutableLong, MutableLong>, IOException> cursor = index.seek(new MutableLong(0), new MutableLong(Long.MAX_VALUE))) {
for (int i = 0; i < count; i++) {
assertTrue(cursor.next());
assertEquals(i, cursor.get().key().longValue());
}
assertFalse(cursor.next());
}
}
use of org.apache.commons.lang3.mutable.MutableLong in project neo4j by neo4j.
the class GBPTreeTest method shouldReturnNoResultsOnEmptyIndex.
@Test
public void shouldReturnNoResultsOnEmptyIndex() throws Exception {
// GIVEN
index = createIndex(256);
// WHEN
RawCursor<Hit<MutableLong, MutableLong>, IOException> result = index.seek(new MutableLong(0), new MutableLong(10));
// THEN
assertFalse(result.next());
}
use of org.apache.commons.lang3.mutable.MutableLong in project neo4j by neo4j.
the class GBPTreeTest method shouldCheckpointOnCloseAfterChangesHappened.
@Test
public void shouldCheckpointOnCloseAfterChangesHappened() throws Exception {
// GIVEN
CheckpointCounter checkpointCounter = new CheckpointCounter();
// WHEN
GBPTree<MutableLong, MutableLong> index = createIndex(256, checkpointCounter);
int countBefore = checkpointCounter.count;
try (Writer<MutableLong, MutableLong> writer = index.writer()) {
writer.put(new MutableLong(0), new MutableLong(1));
}
// THEN
closeIndex();
assertEquals(countBefore + 1, checkpointCounter.count);
}
Aggregations