use of org.neo4j.io.pagecache.impl.ByteBufferPage in project neo4j by neo4j.
the class PageSwapperTest method mustReopenChannelWhenVectoredReadFailsWithAsynchronousCloseException.
@Test
public void mustReopenChannelWhenVectoredReadFailsWithAsynchronousCloseException() throws Exception {
File file = file("a");
PageSwapperFactory swapperFactory = createSwapperFactory();
PageSwapper swapper = createSwapperAndFile(swapperFactory, file);
ByteBufferPage page = createPage();
page.putLong(X, 0);
page.putLong(Y, 8);
page.putInt(Z, 16);
swapper.write(0, page);
Thread.currentThread().interrupt();
swapper.read(0, new Page[] { page }, 0, 1);
// Clear the interrupted flag and assert that it was still raised
assertTrue(Thread.interrupted());
assertThat(page.getLong(0), is(X));
assertThat(page.getLong(8), is(Y));
assertThat(page.getInt(16), is(Z));
// This must not throw because we should still have a usable channel
swapper.force();
}
use of org.neo4j.io.pagecache.impl.ByteBufferPage in project neo4j by neo4j.
the class PageSwapperTest method positionedVectoredReadWhereLastPageExtendBeyondEndOfFileMustHaveRemainderZeroFilled.
@Test
public void positionedVectoredReadWhereLastPageExtendBeyondEndOfFileMustHaveRemainderZeroFilled() throws Exception {
File file = file("file");
PageSwapperFactory factory = createSwapperFactory();
PageSwapper swapper = createSwapperAndFile(factory, file, 4);
ByteBufferPage output = createPage(4);
output.putInt(0xFFFF_FFFF, 0);
swapper.write(0, new Page[] { output, output, output, output, output }, 0, 5);
swapper.close();
swapper = createSwapper(factory, file, 8, NO_CALLBACK, false);
ByteBufferPage pageA = createPage(8);
ByteBufferPage pageB = createPage(8);
pageA.putLong(X, 0);
pageB.putLong(Y, 0);
assertThat(swapper.read(1, new Page[] { pageA, pageB }, 0, 2), isOneOf(12L, 16L));
assertThat(pageA.getLong(0), is(0xFFFF_FFFF_FFFF_FFFFL));
assertThat(pageB.getLong(0), is(0xFFFF_FFFF_0000_0000L));
}
use of org.neo4j.io.pagecache.impl.ByteBufferPage in project neo4j by neo4j.
the class PageSwapperTest method writeMustNotSwallowInterrupts.
@Test
public void writeMustNotSwallowInterrupts() throws Exception {
File file = file("a");
ByteBufferPage page = createPage();
page.putInt(1, 0);
PageSwapperFactory swapperFactory = createSwapperFactory();
PageSwapper swapper = createSwapperAndFile(swapperFactory, file);
Thread.currentThread().interrupt();
assertThat(swapper.write(0, page), is(sizeOf(page)));
assertTrue(Thread.currentThread().isInterrupted());
page.putInt(0, 0);
assertThat(swapper.read(0, page), is(sizeOf(page)));
assertThat(page.getInt(0), is(1));
assertThat(swapper.write(0, page), is(sizeOf(page)));
assertTrue(Thread.currentThread().isInterrupted());
page.putInt(0, 0);
assertThat(swapper.read(0, page), is(sizeOf(page)));
assertThat(page.getInt(0), is(1));
}
use of org.neo4j.io.pagecache.impl.ByteBufferPage in project neo4j by neo4j.
the class PageSwapperTest method vectoredWriteMustNotReopenExplicitlyClosedChannel.
@Test
public void vectoredWriteMustNotReopenExplicitlyClosedChannel() throws Exception {
File file = file("a");
ByteBufferPage page = createPage();
PageSwapperFactory swapperFactory = createSwapperFactory();
PageSwapper swapper = createSwapperAndFile(swapperFactory, file);
swapper.close();
try {
swapper.write(0, new Page[] { page }, 0, 1);
fail("Should have thrown because the channel should be closed");
} catch (ClosedChannelException ignore) {
// This is fine.
}
}
use of org.neo4j.io.pagecache.impl.ByteBufferPage in project neo4j by neo4j.
the class PageSwapperTest method mustThrowNullPointerExceptionFromReadWhenPageArrayIsNull.
@Test
public void mustThrowNullPointerExceptionFromReadWhenPageArrayIsNull() throws Exception {
File file = file("file");
PageSwapperFactory factory = createSwapperFactory();
PageSwapper swapper = createSwapperAndFile(factory, file, 4);
ByteBufferPage page = createPage(4);
swapper.write(0, new Page[] { page, page, page, page }, 0, 4);
try {
swapper.read(0, null, 0, 4);
fail("vectored read with null array should have thrown");
} catch (NullPointerException npe) {
// This is fine
}
}
Aggregations