use of org.neo4j.io.pagecache.impl.ByteBufferPage in project neo4j by neo4j.
the class PageSwapperTest method mustReopenChannelWhenReadFailsWithAsynchronousCloseException.
@Test
public void mustReopenChannelWhenReadFailsWithAsynchronousCloseException() 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, page);
// 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 vectoredReadMustNotSwallowInterrupts.
@Test
public void vectoredReadMustNotSwallowInterrupts() throws Exception {
File file = file("a");
ByteBufferPage page = createPage();
page.putInt(1, 0);
PageSwapperFactory swapperFactory = createSwapperFactory();
PageSwapper swapper = createSwapperAndFile(swapperFactory, file);
assertThat(swapper.write(0, page), is(sizeOf(page)));
page.putInt(0, 0);
Thread.currentThread().interrupt();
assertThat(swapper.read(0, new Page[] { page }, 0, 1), is(sizeOf(page)));
assertTrue(Thread.currentThread().isInterrupted());
assertThat(page.getInt(0), is(1));
assertThat(swapper.read(0, new Page[] { page }, 0, 1), is(sizeOf(page)));
assertTrue(Thread.currentThread().isInterrupted());
assertThat(page.getInt(0), is(1));
}
use of org.neo4j.io.pagecache.impl.ByteBufferPage in project neo4j by neo4j.
the class PageSwapperTest method streamFilesRecursiveRenameMustNotChangeSourceFileContentsWithReplaceExisting.
@Test
public void streamFilesRecursiveRenameMustNotChangeSourceFileContentsWithReplaceExisting() 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();
swapper = createSwapperAndFile(factory, b);
page.putLong(ThreadLocalRandom.current().nextLong(), 0);
swapper.write(0, page);
swapper.close();
clear(page);
FileHandle handle = factory.streamFilesRecursive(a).findAny().get();
handle.rename(b, REPLACE_EXISTING);
swapper = createSwapper(factory, b, cachePageSize(), NO_CALLBACK, false);
swapper.read(0, page);
long actualValue = page.getLong(0);
assertThat(actualValue, is(expectedValue));
}
use of org.neo4j.io.pagecache.impl.ByteBufferPage in project neo4j by neo4j.
the class PageSwapperTest method readMustNotSwallowInterrupts.
@Test
public void readMustNotSwallowInterrupts() throws Exception {
File file = file("a");
ByteBufferPage page = createPage();
page.putInt(1, 0);
PageSwapperFactory swapperFactory = createSwapperFactory();
PageSwapper swapper = createSwapperAndFile(swapperFactory, file);
assertThat(swapper.write(0, page), is(sizeOf(page)));
page.putInt(0, 0);
Thread.currentThread().interrupt();
assertThat(swapper.read(0, page), is(sizeOf(page)));
assertTrue(Thread.currentThread().isInterrupted());
assertThat(page.getInt(0), is(1));
assertThat(swapper.read(0, page), is(sizeOf(page)));
assertTrue(Thread.currentThread().isInterrupted());
assertThat(page.getInt(0), is(1));
}
use of org.neo4j.io.pagecache.impl.ByteBufferPage in project neo4j by neo4j.
the class PageSwapperTest method truncatedFilesMustBeEmpty.
@Test
public void truncatedFilesMustBeEmpty() throws Exception {
File file = file("file");
PageSwapperFactory factory = createSwapperFactory();
PageSwapper swapper = createSwapperAndFile(factory, file);
assertThat(swapper.getLastPageId(), is(-1L));
ByteBufferPage page = createPage();
page.putInt(0xcafebabe, 0);
swapper.write(10, page);
clear(page);
swapper.read(10, page);
assertThat(page.getInt(0), is(0xcafebabe));
assertThat(swapper.getLastPageId(), is(10L));
swapper.close();
swapper = createSwapper(factory, file, cachePageSize(), NO_CALLBACK, false);
clear(page);
swapper.read(10, page);
assertThat(page.getInt(0), is(0xcafebabe));
assertThat(swapper.getLastPageId(), is(10L));
swapper.truncate();
clear(page);
swapper.read(10, page);
assertThat(page.getInt(0), is(0));
assertThat(swapper.getLastPageId(), is(-1L));
swapper.close();
swapper = createSwapper(factory, file, cachePageSize(), NO_CALLBACK, false);
clear(page);
swapper.read(10, page);
assertThat(page.getInt(0), is(0));
assertThat(swapper.getLastPageId(), is(-1L));
swapper.close();
}
Aggregations