Search in sources :

Example 1 with Record

use of org.neo4j.io.pagecache.randomharness.Record in project neo4j by neo4j.

the class PageCacheTest method mustReadZerosFromBeyondEndOfFile.

@Test(timeout = SEMI_LONG_TIMEOUT_MILLIS)
public void mustReadZerosFromBeyondEndOfFile() throws Exception {
    StandardRecordFormat recordFormat = new StandardRecordFormat();
    File[] files = { file("1"), file("2"), file("3"), file("4"), file("5"), file("6"), file("7"), file("8"), file("9"), file("0"), file("A"), file("B") };
    for (int fileId = 0; fileId < files.length; fileId++) {
        File file = files[fileId];
        StoreChannel channel = fs.open(file, "rw");
        for (int recordId = 0; recordId < fileId + 1; recordId++) {
            Record record = recordFormat.createRecord(file, recordId);
            recordFormat.writeRecord(record, channel);
        }
        channel.close();
    }
    int pageSize = nextPowerOf2(recordFormat.getRecordSize() * (files.length + 1));
    getPageCache(fs, 2, pageSize, PageCacheTracer.NULL, PageCursorTracerSupplier.NULL);
    int fileId = files.length;
    while (fileId-- > 0) {
        File file = files[fileId];
        try (PagedFile pf = pageCache.map(file, pageSize);
            PageCursor cursor = pf.io(0, PF_SHARED_READ_LOCK)) {
            int pageCount = 0;
            while (cursor.next()) {
                pageCount++;
                recordFormat.assertRecordsWrittenCorrectly(cursor);
            }
            assertThat("pages in file " + file, pageCount, greaterThan(0));
        }
    }
}
Also used : AdversarialPagedFile(org.neo4j.adversaries.pagecache.AdversarialPagedFile) StoreChannel(org.neo4j.io.fs.StoreChannel) DelegatingStoreChannel(org.neo4j.graphdb.mockfs.DelegatingStoreChannel) StandardRecordFormat(org.neo4j.io.pagecache.randomharness.StandardRecordFormat) Record(org.neo4j.io.pagecache.randomharness.Record) AdversarialPagedFile(org.neo4j.adversaries.pagecache.AdversarialPagedFile) File(java.io.File) Test(org.junit.Test)

Aggregations

File (java.io.File)1 Test (org.junit.Test)1 AdversarialPagedFile (org.neo4j.adversaries.pagecache.AdversarialPagedFile)1 DelegatingStoreChannel (org.neo4j.graphdb.mockfs.DelegatingStoreChannel)1 StoreChannel (org.neo4j.io.fs.StoreChannel)1 Record (org.neo4j.io.pagecache.randomharness.Record)1 StandardRecordFormat (org.neo4j.io.pagecache.randomharness.StandardRecordFormat)1