Search in sources :

Example 1 with IntStoreHeader

use of org.neo4j.kernel.impl.store.IntStoreHeader in project neo4j by neo4j.

the class AbstractRecordFormatTest method verifyWriteAndRead.

private <R extends AbstractBaseRecord> void verifyWriteAndRead(Supplier<RecordFormat<R>> formatSupplier, Supplier<Generator<R>> generatorSupplier, Supplier<RecordKey<R>> keySupplier) throws IOException {
    // GIVEN
    try (PagedFile storeFile = pageCache.map(new File("store-" + name.getMethodName()), PAGE_SIZE, CREATE)) {
        RecordFormat<R> format = formatSupplier.get();
        RecordKey<R> key = keySupplier.get();
        Generator<R> generator = generatorSupplier.get();
        int recordSize = format.getRecordSize(new IntStoreHeader(DATA_SIZE));
        BatchingIdSequence idSequence = new BatchingIdSequence(random.nextBoolean() ? idSureToBeOnTheNextPage(PAGE_SIZE, recordSize) : 10);
        // WHEN
        long time = currentTimeMillis();
        long endTime = time + TEST_TIME;
        long i = 0;
        for (; i < TEST_ITERATIONS && currentTimeMillis() < endTime; i++) {
            R written = generator.get(recordSize, format, i % 5);
            R read = format.newRecord();
            try {
                writeRecord(written, format, storeFile, recordSize, idSequence);
                readAndVerifyRecord(written, read, format, key, storeFile, recordSize);
                idSequence.reset();
            } catch (Throwable t) {
                Exceptions.setMessage(t, t.getMessage() + " : written:" + written + ", read:" + read + ", seed:" + random.seed() + ", iteration:" + i);
                throw t;
            }
        }
    }
}
Also used : BatchingIdSequence(org.neo4j.unsafe.impl.batchimport.store.BatchingIdSequence) PagedFile(org.neo4j.io.pagecache.PagedFile) IntStoreHeader(org.neo4j.kernel.impl.store.IntStoreHeader) PagedFile(org.neo4j.io.pagecache.PagedFile) File(java.io.File)

Example 2 with IntStoreHeader

use of org.neo4j.kernel.impl.store.IntStoreHeader in project neo4j by neo4j.

the class PropertyRecordFormatTest method writeAndReadRecordWithRelativeReferences.

@Test
public void writeAndReadRecordWithRelativeReferences() throws IOException {
    int recordSize = recordFormat.getRecordSize(new IntStoreHeader(DATA_SIZE));
    long recordId = 0xF1F1F1F1F1F1L;
    int recordOffset = pageCursor.getOffset();
    PropertyRecord record = createRecord(recordFormat, recordId);
    recordFormat.write(record, pageCursor, recordSize);
    PropertyRecord recordFromStore = recordFormat.newRecord();
    recordFromStore.setId(recordId);
    resetCursor(pageCursor, recordOffset);
    recordFormat.read(recordFromStore, pageCursor, RecordLoad.NORMAL, recordSize);
    // records should be the same
    assertEquals(record.getNextProp(), recordFromStore.getNextProp());
    assertEquals(record.getPrevProp(), recordFromStore.getPrevProp());
    // now lets try to read same data into a record with different id - we should get different absolute references
    resetCursor(pageCursor, recordOffset);
    PropertyRecord recordWithOtherId = recordFormat.newRecord();
    recordWithOtherId.setId(1L);
    recordFormat.read(recordWithOtherId, pageCursor, RecordLoad.NORMAL, recordSize);
    verifyDifferentReferences(record, recordWithOtherId);
}
Also used : PropertyRecord(org.neo4j.kernel.impl.store.record.PropertyRecord) IntStoreHeader(org.neo4j.kernel.impl.store.IntStoreHeader) Test(org.junit.Test)

Aggregations

IntStoreHeader (org.neo4j.kernel.impl.store.IntStoreHeader)2 File (java.io.File)1 Test (org.junit.Test)1 PagedFile (org.neo4j.io.pagecache.PagedFile)1 PropertyRecord (org.neo4j.kernel.impl.store.record.PropertyRecord)1 BatchingIdSequence (org.neo4j.unsafe.impl.batchimport.store.BatchingIdSequence)1