Search in sources :

Example 1 with PageCursor

use of org.neo4j.io.pagecache.PageCursor in project neo4j by neo4j.

the class AbstractRecordFormatTest method writeRecord.

private <R extends AbstractBaseRecord> void writeRecord(R record, RecordFormat<R> format, PagedFile storeFile, int recordSize, BatchingIdSequence idSequence) throws IOException {
    try (PageCursor cursor = storeFile.io(0, PagedFile.PF_SHARED_WRITE_LOCK)) {
        assertedNext(cursor);
        if (record.inUse()) {
            format.prepare(record, recordSize, idSequence);
        }
        int offset = Math.toIntExact(record.getId() * recordSize);
        cursor.setOffset(offset);
        format.write(record, cursor, recordSize);
        assertWithinBounds(record, cursor, "writing");
    }
}
Also used : PageCursor(org.neo4j.io.pagecache.PageCursor)

Example 2 with PageCursor

use of org.neo4j.io.pagecache.PageCursor in project neo4j by neo4j.

the class RelationshipGroupRecordFormatTest method shouldReadUnsignedRelationshipTypeId.

@Test
public void shouldReadUnsignedRelationshipTypeId() throws Exception {
    // GIVEN
    try (PageCursor cursor = new StubPageCursor(1, recordSize * 10)) {
        int offset = 10;
        cursor.next();
        RelationshipGroupRecord group = new RelationshipGroupRecord(2).initialize(true, Short.MAX_VALUE + offset, 1, 2, 3, 4, 5);
        cursor.setOffset(offset);
        format.write(group, cursor, recordSize);
        // WHEN
        RelationshipGroupRecord read = new RelationshipGroupRecord(group.getId());
        cursor.setOffset(offset);
        format.read(read, cursor, NORMAL, recordSize);
        // THEN
        assertEquals(group, read);
    }
}
Also used : RelationshipGroupRecord(org.neo4j.kernel.impl.store.record.RelationshipGroupRecord) StubPageCursor(org.neo4j.io.pagecache.StubPageCursor) PageCursor(org.neo4j.io.pagecache.PageCursor) StubPageCursor(org.neo4j.io.pagecache.StubPageCursor) Test(org.junit.Test)

Example 3 with PageCursor

use of org.neo4j.io.pagecache.PageCursor in project neo4j by neo4j.

the class CompositePageCursorTest method putLongOffsettedBeforeFirstPageMustRaiseBoundsFlag.

@Test
public void putLongOffsettedBeforeFirstPageMustRaiseBoundsFlag() throws Exception {
    PageCursor pageCursor = CompositePageCursor.compose(first, PAGE_SIZE, second, PAGE_SIZE);
    pageCursor.putLong(-1, (long) 1);
    assertTrue(pageCursor.checkAndClearBoundsFlag());
    assertFalse(pageCursor.checkAndClearBoundsFlag());
}
Also used : PageCursor(org.neo4j.io.pagecache.PageCursor) StubPageCursor(org.neo4j.io.pagecache.StubPageCursor) Test(org.junit.Test)

Example 4 with PageCursor

use of org.neo4j.io.pagecache.PageCursor in project neo4j by neo4j.

the class CompositePageCursorTest method putByteOffsettedBeyondEndOfViewMustRaiseBoundsFlag.

@Test
public void putByteOffsettedBeyondEndOfViewMustRaiseBoundsFlag() throws Exception {
    PageCursor pageCursor = CompositePageCursor.compose(first, PAGE_SIZE, second, PAGE_SIZE);
    for (int i = 0; i < 3 * PAGE_SIZE; i++) {
        pageCursor.putByte(i, (byte) 1);
    }
    assertTrue(pageCursor.checkAndClearBoundsFlag());
    assertFalse(pageCursor.checkAndClearBoundsFlag());
}
Also used : PageCursor(org.neo4j.io.pagecache.PageCursor) StubPageCursor(org.neo4j.io.pagecache.StubPageCursor) Test(org.junit.Test)

Example 5 with PageCursor

use of org.neo4j.io.pagecache.PageCursor in project neo4j by neo4j.

the class CompositePageCursorTest method getIntOffsettedBeforeFirstPageMustRaiseBoundsFlag.

@Test
public void getIntOffsettedBeforeFirstPageMustRaiseBoundsFlag() throws Exception {
    PageCursor pageCursor = CompositePageCursor.compose(first, PAGE_SIZE, second, PAGE_SIZE);
    pageCursor.getInt(-1);
    assertTrue(pageCursor.checkAndClearBoundsFlag());
    assertFalse(pageCursor.checkAndClearBoundsFlag());
}
Also used : PageCursor(org.neo4j.io.pagecache.PageCursor) StubPageCursor(org.neo4j.io.pagecache.StubPageCursor) Test(org.junit.Test)

Aggregations

PageCursor (org.neo4j.io.pagecache.PageCursor)326 Test (org.junit.jupiter.api.Test)160 StubPageCursor (org.neo4j.io.pagecache.StubPageCursor)126 PagedFile (org.neo4j.io.pagecache.PagedFile)59 IOException (java.io.IOException)49 CursorContext (org.neo4j.io.pagecache.context.CursorContext)46 PageCacheTest (org.neo4j.io.pagecache.PageCacheTest)31 UncheckedIOException (java.io.UncheckedIOException)22 Test (org.junit.Test)22 Path (java.nio.file.Path)16 DelegatingPagedFile (org.neo4j.io.pagecache.DelegatingPagedFile)13 PageCache (org.neo4j.io.pagecache.PageCache)13 ByteArrayPageCursor (org.neo4j.io.pagecache.ByteArrayPageCursor)12 ByteBuffer (java.nio.ByteBuffer)11 UnderlyingStorageException (org.neo4j.exceptions.UnderlyingStorageException)11 DefaultPageCacheTracer (org.neo4j.io.pagecache.tracing.DefaultPageCacheTracer)10 MutableLong (org.apache.commons.lang3.mutable.MutableLong)9 DelegatingPageCache (org.neo4j.io.pagecache.DelegatingPageCache)9 OpenOption (java.nio.file.OpenOption)8 ArrayList (java.util.ArrayList)8