Search in sources :

Example 1 with StubPagedFile

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

the class PagedByteChannelsTest method mustCloseCursorOnClose.

@Theory
public void mustCloseCursorOnClose(ThrowingFunction<PagedFile, ? extends Channel, IOException> channelConstructor) throws Exception {
    AtomicInteger closeCounter = new AtomicInteger();
    PagedFile pf = new StubPagedFile(8192) {

        @Override
        public PageCursor io(long pageId, int pf_flags) throws IOException {
            return new DelegatingPageCursor(super.io(pageId, pf_flags)) {

                @Override
                public void close() {
                    super.close();
                    closeCounter.getAndIncrement();
                }
            };
        }
    };
    channelConstructor.apply(pf).close();
    assertThat(closeCounter.get(), is(1));
}
Also used : PagedFile(org.neo4j.io.pagecache.PagedFile) StubPagedFile(org.neo4j.io.pagecache.StubPagedFile) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) StubPagedFile(org.neo4j.io.pagecache.StubPagedFile) Theory(org.junit.experimental.theories.Theory)

Example 2 with StubPagedFile

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

the class BaseHighLimitRecordFormatTest method mustCheckForOutOfBoundsWhenReadingDoubleRecord.

@Test
public void mustCheckForOutOfBoundsWhenReadingDoubleRecord() throws Exception {
    MyRecordFormat format = new MyRecordFormat();
    StubPageCursor cursor = new StubPageCursor(0, 4);
    cursor.putByte(0, (byte) (HEADER_BIT_RECORD_UNIT + HEADER_BIT_FIRST_RECORD_UNIT));
    StubPagedFile pagedFile = new StubPagedFile(3) {

        @Override
        protected void prepareCursor(StubPageCursor cursor) {
            cursor.putByte(0, (byte) HEADER_BIT_RECORD_UNIT);
        }
    };
    format.shortsPerRecord.add(2);
    format.read(new MyRecord(0), cursor, RecordLoad.NORMAL, 4);
    assertTrue(cursor.checkAndClearBoundsFlag());
}
Also used : StubPageCursor(org.neo4j.io.pagecache.StubPageCursor) StubPagedFile(org.neo4j.io.pagecache.StubPagedFile) Test(org.junit.Test)

Aggregations

StubPagedFile (org.neo4j.io.pagecache.StubPagedFile)2 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1 Test (org.junit.Test)1 Theory (org.junit.experimental.theories.Theory)1 PagedFile (org.neo4j.io.pagecache.PagedFile)1 StubPageCursor (org.neo4j.io.pagecache.StubPageCursor)1