use of org.neo4j.adversaries.RandomAdversary in project neo4j by neo4j.
the class SingleFilePageSwapperTest method mustHandleMischiefInPositionedRead.
@Test
public void mustHandleMischiefInPositionedRead() throws Exception {
int bytesTotal = 512;
byte[] data = new byte[bytesTotal];
ThreadLocalRandom.current().nextBytes(data);
PageSwapperFactory factory = createSwapperFactory();
factory.setFileSystemAbstraction(getFs());
File file = getFile();
PageSwapper swapper = createSwapper(factory, file, bytesTotal, NO_CALLBACK, true);
try {
swapper.write(0, new ByteBufferPage(wrap(data)));
} finally {
swapper.close();
}
RandomAdversary adversary = new RandomAdversary(0.5, 0.0, 0.0);
factory.setFileSystemAbstraction(new AdversarialFileSystemAbstraction(adversary, getFs()));
swapper = createSwapper(factory, file, bytesTotal, NO_CALLBACK, false);
ByteBufferPage page = createPage(bytesTotal);
try {
for (int i = 0; i < 10_000; i++) {
clear(page);
assertThat(swapper.read(0, page), is((long) bytesTotal));
assertThat(array(page.buffer), is(data));
}
} finally {
swapper.close();
}
}
use of org.neo4j.adversaries.RandomAdversary in project neo4j by neo4j.
the class SingleFilePageSwapperTest method mustHandleMischiefInPositionedWrite.
@Test
public void mustHandleMischiefInPositionedWrite() throws Exception {
int bytesTotal = 512;
byte[] data = new byte[bytesTotal];
ThreadLocalRandom.current().nextBytes(data);
ByteBufferPage zeroPage = createPage(bytesTotal);
clear(zeroPage);
File file = getFile();
PageSwapperFactory factory = createSwapperFactory();
RandomAdversary adversary = new RandomAdversary(0.5, 0.0, 0.0);
factory.setFileSystemAbstraction(new AdversarialFileSystemAbstraction(adversary, getFs()));
PageSwapper swapper = createSwapper(factory, file, bytesTotal, NO_CALLBACK, true);
ByteBufferPage page = createPage(bytesTotal);
try {
for (int i = 0; i < 10_000; i++) {
adversary.setProbabilityFactor(0);
swapper.write(0, zeroPage);
page.putBytes(data, 0, 0, data.length);
adversary.setProbabilityFactor(1);
assertThat(swapper.write(0, page), is((long) bytesTotal));
clear(page);
adversary.setProbabilityFactor(0);
swapper.read(0, page);
assertThat(array(page.buffer), is(data));
}
} finally {
swapper.close();
}
}
use of org.neo4j.adversaries.RandomAdversary in project neo4j by neo4j.
the class SingleFilePageSwapperTest method mustHandleMischiefInPositionedVectoredRead.
@Test
public void mustHandleMischiefInPositionedVectoredRead() throws Exception {
int bytesTotal = 512;
int bytesPerPage = 32;
int pageCount = bytesTotal / bytesPerPage;
byte[] data = new byte[bytesTotal];
ThreadLocalRandom.current().nextBytes(data);
PageSwapperFactory factory = createSwapperFactory();
factory.setFileSystemAbstraction(getFs());
File file = getFile();
PageSwapper swapper = createSwapper(factory, file, bytesTotal, NO_CALLBACK, true);
try {
swapper.write(0, new ByteBufferPage(wrap(data)));
} finally {
swapper.close();
}
RandomAdversary adversary = new RandomAdversary(0.5, 0.0, 0.0);
factory.setFileSystemAbstraction(new AdversarialFileSystemAbstraction(adversary, getFs()));
swapper = createSwapper(factory, file, bytesPerPage, NO_CALLBACK, false);
ByteBufferPage[] pages = new ByteBufferPage[pageCount];
for (int i = 0; i < pageCount; i++) {
pages[i] = createPage(bytesPerPage);
}
byte[] temp = new byte[bytesPerPage];
try {
for (int i = 0; i < 10_000; i++) {
for (ByteBufferPage page : pages) {
clear(page);
}
assertThat(swapper.read(0, pages, 0, pages.length), is((long) bytesTotal));
for (int j = 0; j < pageCount; j++) {
System.arraycopy(data, j * bytesPerPage, temp, 0, bytesPerPage);
assertThat(array(pages[j].buffer), is(temp));
}
}
} finally {
swapper.close();
}
}
use of org.neo4j.adversaries.RandomAdversary in project neo4j by neo4j.
the class PageCacheTest method readableByteChannelMustReadAllBytesInFileConsistently.
@RepeatRule.Repeat(times = 20)
@Test(timeout = SHORT_TIMEOUT_MILLIS)
public void readableByteChannelMustReadAllBytesInFileConsistently() throws Exception {
File file = file("a");
generateFileWithRecords(file, recordCount, recordSize);
configureStandardPageCache();
try (PagedFile pf = pageCache.map(file, filePageSize)) {
RandomAdversary adversary = new RandomAdversary(0.9, 0, 0);
AdversarialPagedFile apf = new AdversarialPagedFile(pf, adversary);
try (ReadableByteChannel channel = apf.openReadableByteChannel()) {
verifyRecordsInFile(channel, recordCount);
}
}
}
use of org.neo4j.adversaries.RandomAdversary in project neo4j by neo4j.
the class RotatingFileOutputStreamSupplierTest method shouldSurviveFilesystemErrors.
@Test
public void shouldSurviveFilesystemErrors() throws Exception {
final RandomAdversary adversary = new RandomAdversary(0.1, 0.1, 0);
adversary.setProbabilityFactor(0);
AdversarialFileSystemAbstraction adversarialFileSystem = new SensibleAdversarialFileSystemAbstraction(adversary, fileSystem);
RotatingFileOutputStreamSupplier supplier = new RotatingFileOutputStreamSupplier(adversarialFileSystem, logFile, 1000, 0, 9, DIRECT_EXECUTOR);
adversary.setProbabilityFactor(1);
writeLines(supplier, 10000);
// run cleanly for a while, to allow it to fill any gaps left in log archive numbers
adversary.setProbabilityFactor(0);
writeLines(supplier, 10000);
assertThat(fileSystem.fileExists(logFile), is(true));
assertThat(fileSystem.fileExists(archiveLogFile1), is(true));
assertThat(fileSystem.fileExists(archiveLogFile2), is(true));
assertThat(fileSystem.fileExists(archiveLogFile3), is(true));
assertThat(fileSystem.fileExists(archiveLogFile4), is(true));
assertThat(fileSystem.fileExists(archiveLogFile5), is(true));
assertThat(fileSystem.fileExists(archiveLogFile6), is(true));
assertThat(fileSystem.fileExists(archiveLogFile7), is(true));
assertThat(fileSystem.fileExists(archiveLogFile8), is(true));
assertThat(fileSystem.fileExists(archiveLogFile9), is(true));
}
Aggregations