use of org.neo4j.io.pagecache.impl.ByteBufferPage in project neo4j by neo4j.
the class PageSwapperTest method mustThrowNullPointerExceptionFromReadWhenPageArrayElementsAreNull.
@Test
public void mustThrowNullPointerExceptionFromReadWhenPageArrayElementsAreNull() 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, 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 readMustNotReopenExplicitlyClosedChannel.
@Test
public void readMustNotReopenExplicitlyClosedChannel() throws Exception {
String filename = "a";
File file = file(filename);
ByteBufferPage page = createPage();
PageSwapperFactory swapperFactory = createSwapperFactory();
PageSwapper swapper = createSwapperAndFile(swapperFactory, file);
swapper.write(0, page);
swapper.close();
try {
swapper.read(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 mustCreateNonExistingFileWithCreateFlag.
@Test
public void mustCreateNonExistingFileWithCreateFlag() throws Exception {
PageSwapperFactory factory = createSwapperFactory();
PageSwapper pageSwapper = createSwapperAndFile(factory, file("does not exist"));
// After creating the file, we must also be able to read and write
ByteBufferPage page = createPage();
page.putLong(X, 0);
pageSwapper.write(0, page);
clear(page);
pageSwapper.read(0, page);
assertThat(page.getLong(0), is(X));
}
use of org.neo4j.io.pagecache.impl.ByteBufferPage in project neo4j by neo4j.
the class PageSwapperTest method positionedVectoredWriteMustWorkOnSubsequenceOfGivenArray.
@Test
public void positionedVectoredWriteMustWorkOnSubsequenceOfGivenArray() 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));
pageB.putInt(6, 0);
pageC.putInt(7, 0);
bytesWritten = swapper.write(1, pages, 1, 2);
assertThat(bytesWritten, is(8L));
pageA.putInt(0, 0);
pageB.putInt(0, 0);
pageC.putInt(0, 0);
pageD.putInt(0, 0);
long bytesRead = swapper.read(0, pages, 0, 4);
assertThat(bytesRead, is(16L));
int[] actualValues = { pageA.getInt(0), pageB.getInt(0), pageC.getInt(0), pageD.getInt(0) };
int[] expectedValues = { 1, 6, 7, 4 };
assertThat(actualValues, is(expectedValues));
}
use of org.neo4j.io.pagecache.impl.ByteBufferPage in project neo4j by neo4j.
the class PageSwapperTest method mustNotOverwriteDataInOtherFiles.
@Test
public void mustNotOverwriteDataInOtherFiles() throws Exception {
File fileA = file("a");
File fileB = file("b");
PageSwapperFactory factory = createSwapperFactory();
PageSwapper swapperA = createSwapperAndFile(factory, fileA);
PageSwapper swapperB = createSwapperAndFile(factory, fileB);
ByteBufferPage page = createPage();
page.putLong(X, 0);
swapperA.write(0, page);
page.putLong(Y, 8);
swapperB.write(0, page);
clear(page);
swapperA.read(0, page);
assertThat(page.getLong(0), is(X));
assertThat(page.getLong(8), is(0L));
}
Aggregations