use of org.neo4j.io.fs.StoreChannel in project neo4j by neo4j.
the class FreeIdKeeperTest method persistedIdsShouldStillBeCounted.
@Test
public void persistedIdsShouldStillBeCounted() throws Exception {
// given
StoreChannel channel = fs.get().open(new File("id.file"), "rw");
int threshold = 10;
FreeIdKeeper keeper = new FreeIdKeeper(channel, threshold, true);
// we store enough ids to cause overflow to file
for (int i = 0; i < threshold; i++) {
keeper.freeId(i);
}
// and then some more
int extraIds = 3;
for (int i = threshold; i < threshold + extraIds; i++) {
keeper.freeId(i);
}
// then
// the count should be returned correctly
assertEquals(threshold + extraIds, keeper.getCount());
}
use of org.neo4j.io.fs.StoreChannel in project neo4j by neo4j.
the class FreeIdKeeperTest method shouldNotReturnIdsPersistedDuringThisRunIfAggressiveIsFalse.
@Test
public void shouldNotReturnIdsPersistedDuringThisRunIfAggressiveIsFalse() throws Exception {
// given
StoreChannel channel = spy(fs.get().open(new File("id.file"), "rw"));
int threshold = 10;
FreeIdKeeper keeper = new FreeIdKeeper(channel, threshold, false);
// enough ids are persisted to overflow
for (int i = 0; i < threshold; i++) {
keeper.freeId(i);
}
// then
// stuff must have been written to disk
verify(channel, times(1)).write(any(ByteBuffer.class));
// and no ids can be returned
assertEquals(NO_RESULT, keeper.getId());
}
use of org.neo4j.io.fs.StoreChannel in project neo4j by neo4j.
the class FreeIdKeeperTest method shouldOnlyOverflowWhenThresholdIsReached.
@Test
public void shouldOnlyOverflowWhenThresholdIsReached() throws Exception {
// Given
StoreChannel channel = spy(fs.get().open(new File("id.file"), "rw"));
int threshold = 10;
FreeIdKeeper keeper = new FreeIdKeeper(channel, threshold, true);
// because we get the position in the constructor, we need to reset all calls on the spy
reset(channel);
// we free 9 ids
for (int i = 0; i < threshold - 1; i++) {
keeper.freeId(i);
}
// then
verifyZeroInteractions(channel);
// when we free one more
keeper.freeId(10);
// then
verify(channel).write(any(ByteBuffer.class));
}
use of org.neo4j.io.fs.StoreChannel in project neo4j by neo4j.
the class FreeIdKeeperTest method shouldReturnIdsRestoredAndIgnoreNewlyReleasedIfAggressiveReuseIsFalse.
@Test
public void shouldReturnIdsRestoredAndIgnoreNewlyReleasedIfAggressiveReuseIsFalse() throws Exception {
// given
StoreChannel channel = fs.get().open(new File("id.file"), "rw");
int threshold = 10;
FreeIdKeeper keeper = new FreeIdKeeper(channel, threshold, false);
Set<Long> freeIds = new HashSet<>();
for (long i = 0; i < threshold; i++) {
keeper.freeId(i);
freeIds.add(i);
}
keeper.close();
channel.close();
// and then we open a new one over the same file
channel = fs.get().open(new File("id.file"), "rw");
keeper = new FreeIdKeeper(channel, threshold, false);
// we release some ids that spill to disk
for (int i = 0; i < threshold; i++) {
keeper.freeId(i);
}
// we should retrieve all ids restored
for (int i = 0; i < threshold; i++) {
assertTrue(freeIds.remove(keeper.getId()));
}
// then
// we should have no ids to return
assertEquals(NO_RESULT, keeper.getId());
}
use of org.neo4j.io.fs.StoreChannel in project neo4j by neo4j.
the class FreeIdKeeperTest method shouldReturnNoResultIfIdsAreRestoredAndExhaustedAndThereAreFreeIdsFromThisRunWithAggressiveFalse.
@Test
public void shouldReturnNoResultIfIdsAreRestoredAndExhaustedAndThereAreFreeIdsFromThisRunWithAggressiveFalse() throws Exception {
// given
StoreChannel channel = fs.get().open(new File("id.file"), "rw");
int threshold = 10;
FreeIdKeeper keeper = new FreeIdKeeper(channel, threshold, false);
Set<Long> freeIds = new HashSet<>();
for (long i = 0; i < threshold; i++) {
keeper.freeId(i);
freeIds.add(i);
}
keeper.close();
channel.close();
// and then we open a new one over the same file
channel = fs.get().open(new File("id.file"), "rw");
keeper = new FreeIdKeeper(channel, threshold, false);
// we exhaust all ids restored
for (int i = 0; i < threshold; i++) {
assertTrue(freeIds.remove(keeper.getId()));
}
// we release some ids that spill to disk
for (int i = 0; i < threshold; i++) {
keeper.freeId(i);
}
// then
// we should have no ids to return
assertEquals(NO_RESULT, keeper.getId());
}
Aggregations