use of org.neo4j.io.pagecache.impl.ByteBufferPage in project neo4j by neo4j.
the class PageSwapperTest method writeMustNotReopenExplicitlyClosedChannel.
@Test
public void writeMustNotReopenExplicitlyClosedChannel() throws Exception {
File file = file("a");
ByteBufferPage page = createPage();
PageSwapperFactory swapperFactory = createSwapperFactory();
PageSwapper swapper = createSwapperAndFile(swapperFactory, file);
swapper.close();
try {
swapper.write(0, page);
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 positionedVectoredWriteMustFlushAllBuffersInOrder.
@Test
public void positionedVectoredWriteMustFlushAllBuffersInOrder() throws Exception {
File file = file("file");
PageSwapperFactory factory = createSwapperFactory();
PageSwapper swapper = createSwapperAndFile(factory, file, 4);
ByteBufferPage pageA = createPage(4);
ByteBufferPage pageB = createPage(4);
ByteBufferPage pageC = createPage(4);
ByteBufferPage pageD = createPage(4);
pageA.putInt(2, 0);
pageB.putInt(3, 0);
pageC.putInt(4, 0);
pageD.putInt(5, 0);
swapper.write(1, new Page[] { pageA, pageB, pageC, pageD }, 0, 4);
ByteBufferPage result = createPage(4);
swapper.read(0, result);
assertThat(result.getInt(0), is(0));
result.putInt(0, 0);
assertThat(swapper.read(1, result), is(4L));
assertThat(result.getInt(0), is(2));
result.putInt(0, 0);
assertThat(swapper.read(2, result), is(4L));
assertThat(result.getInt(0), is(3));
result.putInt(0, 0);
assertThat(swapper.read(3, result), is(4L));
assertThat(result.getInt(0), is(4));
result.putInt(0, 0);
assertThat(swapper.read(4, result), is(4L));
assertThat(result.getInt(0), is(5));
result.putInt(0, 0);
assertThat(swapper.read(5, result), is(0L));
assertThat(result.getInt(0), is(0));
}
use of org.neo4j.io.pagecache.impl.ByteBufferPage in project neo4j by neo4j.
the class PageSwapperTest method mustReopenChannelWhenWriteFailsWithAsynchronousCloseException.
@Test
public void mustReopenChannelWhenWriteFailsWithAsynchronousCloseException() throws Exception {
ByteBufferPage page = createPage();
page.putLong(X, 0);
page.putLong(Y, 8);
page.putInt(Z, 16);
File file = file("a");
PageSwapperFactory swapperFactory = createSwapperFactory();
PageSwapper swapper = createSwapperAndFile(swapperFactory, file);
Thread.currentThread().interrupt();
swapper.write(0, page);
// Clear the interrupted flag and assert that it was still raised
assertTrue(Thread.interrupted());
// This must not throw because we should still have a usable channel
swapper.force();
clear(page);
swapper.read(0, page);
assertThat(page.getLong(0), is(X));
assertThat(page.getLong(8), is(Y));
assertThat(page.getInt(16), is(Z));
}
use of org.neo4j.io.pagecache.impl.ByteBufferPage in project neo4j by neo4j.
the class PageSwapperTest method positionedVectoredReadMustFillAllBuffersInOrder.
@Test
public void positionedVectoredReadMustFillAllBuffersInOrder() throws Exception {
File file = file("file");
PageSwapperFactory factory = createSwapperFactory();
PageSwapper swapper = createSwapperAndFile(factory, file, 4);
ByteBufferPage output = createPage();
output.putInt(2, 0);
swapper.write(1, output);
output.putInt(3, 0);
swapper.write(2, output);
output.putInt(4, 0);
swapper.write(3, output);
output.putInt(5, 0);
swapper.write(4, output);
ByteBufferPage pageA = createPage(4);
ByteBufferPage pageB = createPage(4);
ByteBufferPage pageC = createPage(4);
ByteBufferPage pageD = createPage(4);
// Read 4 pages of 4 bytes each
assertThat(swapper.read(1, new Page[] { pageA, pageB, pageC, pageD }, 0, 4), is(4 * 4L));
assertThat(pageA.getInt(0), is(2));
assertThat(pageB.getInt(0), is(3));
assertThat(pageC.getInt(0), is(4));
assertThat(pageD.getInt(0), is(5));
}
use of org.neo4j.io.pagecache.impl.ByteBufferPage in project neo4j by neo4j.
the class PageSwapperTest method vectoredWriteMustReadNothingWhenLengthIsZero.
@Test
public void vectoredWriteMustReadNothingWhenLengthIsZero() throws Exception {
File file = file("file");
PageSwapperFactory factory = createSwapperFactory();
PageSwapper swapper = createSwapperAndFile(factory, file, 4);
ByteBufferPage pageA = createPage(4);
ByteBufferPage pageB = createPage(4);
pageA.putInt(1, 0);
pageB.putInt(2, 0);
Page[] pages = { pageA, pageB };
swapper.write(0, pages, 0, 2);
pageA.putInt(3, 0);
pageB.putInt(4, 0);
swapper.write(0, pages, 0, 0);
swapper.read(0, pages, 0, 2);
int[] expectedValues = { 1, 2 };
int[] actualValues = { pageA.getInt(0), pageB.getInt(0) };
assertThat(actualValues, is(expectedValues));
}
Aggregations