use of org.neo4j.io.pagecache.impl.ByteBufferPage in project neo4j by neo4j.
the class PageSwapperTest method positionedVectoredReadFromEmptyFileMustFillPagesWithZeros.
@Test
public void positionedVectoredReadFromEmptyFileMustFillPagesWithZeros() throws Exception {
File file = file("file");
PageSwapperFactory factory = createSwapperFactory();
PageSwapper swapper = createSwapperAndFile(factory, file, 4);
ByteBufferPage page = createPage(4);
page.putInt(1, 0);
assertThat(swapper.read(0, new Page[] { page }, 0, 1), is(0L));
assertThat(page.getInt(0), is(0));
}
use of org.neo4j.io.pagecache.impl.ByteBufferPage in project neo4j by neo4j.
the class PageSwapperTest method vectoredWriteMustNotSwallowInterrupts.
@Test
public void vectoredWriteMustNotSwallowInterrupts() 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, new Page[] { page }, 0, 1), 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, new Page[] { page }, 0, 1), 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 mustThrowNullPointerExceptionFromWriteWhenPageArrayElementsAreNull.
@Test
public void mustThrowNullPointerExceptionFromWriteWhenPageArrayElementsAreNull() throws Exception {
File file = file("file");
PageSwapperFactory factory = createSwapperFactory();
PageSwapper swapper = createSwapperAndFile(factory, file, 4);
ByteBufferPage page = createPage(4);
try {
swapper.write(0, new Page[] { page, page, null, page }, 0, 4);
fail("vectored read with nulls in array should have thrown");
} catch (NullPointerException npe) {
// This is fine
}
}
use of org.neo4j.io.pagecache.impl.ByteBufferPage in project neo4j by neo4j.
the class PageSwapperTest method positionedVectoredReadMustWorkOnSubsequenceOfGivenArray.
@Test
public void positionedVectoredReadMustWorkOnSubsequenceOfGivenArray() 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(1, 0);
pageB.putInt(2, 0);
pageC.putInt(3, 0);
pageD.putInt(4, 0);
Page[] pages = { pageA, pageB, pageC, pageD };
long bytesWritten = swapper.write(0, pages, 0, 4);
assertThat(bytesWritten, is(16L));
pageA.putInt(5, 0);
pageB.putInt(6, 0);
pageC.putInt(7, 0);
pageD.putInt(8, 0);
long bytesRead = swapper.read(1, pages, 1, 2);
assertThat(bytesRead, is(8L));
int[] actualValues = { pageA.getInt(0), pageB.getInt(0), pageC.getInt(0), pageD.getInt(0) };
int[] expectedValues = { 5, 2, 3, 8 };
assertThat(actualValues, is(expectedValues));
}
use of org.neo4j.io.pagecache.impl.ByteBufferPage in project neo4j by neo4j.
the class PageSwapperTest method streamFilesRecursiveRenameMustNotChangeSourceFileContents.
@Test
public void streamFilesRecursiveRenameMustNotChangeSourceFileContents() throws Exception {
PageSwapperFactory factory = createSwapperFactory();
File base = baseDirectory();
File a = new File(base, "a");
File b = new File(base, "b");
ByteBufferPage page = createPage();
PageSwapper swapper = createSwapperAndFile(factory, a);
long expectedValue = 0xdeadbeeffefefeL;
page.putLong(expectedValue, 0);
swapper.write(0, page);
clear(page);
swapper.close();
FileHandle handle = factory.streamFilesRecursive(a).findAny().get();
handle.rename(b);
swapper = createSwapper(factory, b, cachePageSize(), NO_CALLBACK, false);
swapper.read(0, page);
long actualValue = page.getLong(0);
assertThat(actualValue, is(expectedValue));
}
Aggregations