use of org.neo4j.adversaries.Adversary in project neo4j by neo4j.
the class FileSenderTest method sendLargeFileWithUnreliableReadBufferSize.
@Test
public void sendLargeFileWithUnreliableReadBufferSize() throws Exception {
// given
byte[] bytes = new byte[MAX_SIZE * 3];
random.nextBytes(bytes);
File smallFile = testDirectory.file("smallFile");
try (StoreChannel storeChannel = fs.create(smallFile)) {
storeChannel.write(ByteBuffer.wrap(bytes));
}
Adversary adversary = new RandomAdversary(0.9, 0.0, 0.0);
AdversarialFileSystemAbstraction afs = new AdversarialFileSystemAbstraction(adversary, fs);
FileSender fileSender = new FileSender(afs.open(smallFile, "r"));
// when + then
assertFalse(fileSender.isEndOfInput());
assertEquals(FileChunk.create(copyOfRange(bytes, 0, MAX_SIZE), false), fileSender.readChunk(allocator));
assertEquals(FileChunk.create(copyOfRange(bytes, MAX_SIZE, MAX_SIZE * 2), false), fileSender.readChunk(allocator));
assertEquals(FileChunk.create(copyOfRange(bytes, MAX_SIZE * 2, bytes.length), true), fileSender.readChunk(allocator));
assertNull(fileSender.readChunk(allocator));
assertTrue(fileSender.isEndOfInput());
}
use of org.neo4j.adversaries.Adversary in project neo4j by neo4j.
the class BatchingTransactionAppenderConcurrencyTest method shouldHaveAllConcurrentAppendersSeePanic.
/*
* There was an issue where if multiple concurrent appending threads did append and they moved on
* to await a force, where the force would fail and the one doing the force would raise a panic...
* the other threads may not notice the panic and move on to mark those transactions as committed
* and notice the panic later (which would be too late).
*/
@Test
void shouldHaveAllConcurrentAppendersSeePanic() throws Throwable {
// GIVEN
Adversary adversary = new ClassGuardedAdversary(new CountingAdversary(1, true), failMethod(TransactionLogFile.class, "force"));
EphemeralFileSystemAbstraction efs = new EphemeralFileSystemAbstraction();
FileSystemAbstraction fs = new AdversarialFileSystemAbstraction(adversary, efs);
life.add(new FileSystemLifecycleAdapter(fs));
DatabaseHealth databaseHealth = new DatabaseHealth(mock(DatabasePanicEventGenerator.class), NullLog.getInstance());
LogFiles logFiles = LogFilesBuilder.builder(databaseLayout, fs).withLogVersionRepository(logVersionRepository).withTransactionIdStore(transactionIdStore).withDatabaseHealth(databaseHealth).withLogEntryReader(new VersionAwareLogEntryReader(new TestCommandReaderFactory())).withStoreId(StoreId.UNKNOWN).build();
life.add(logFiles);
final BatchingTransactionAppender appender = life.add(new BatchingTransactionAppender(logFiles, logRotation, transactionMetadataCache, transactionIdStore, databaseHealth));
life.start();
// WHEN
int numberOfAppenders = 10;
final CountDownLatch trap = new CountDownLatch(numberOfAppenders);
final LogAppendEvent beforeForceTrappingEvent = new LogAppendEvent.Empty() {
@Override
public LogForceWaitEvent beginLogForceWait() {
trap.countDown();
awaitLatch(trap);
return super.beginLogForceWait();
}
};
Race race = new Race();
for (int i = 0; i < numberOfAppenders; i++) {
race.addContestant(() -> {
// Good, we know that this test uses an adversarial file system which will throw
// an exception in LogFile#force, and since all these transactions
// will append and be forced in the same batch, where the force will fail then
// all these transactions should fail. If there's any transaction not failing then
// it just didn't notice the panic, which would be potentially hazardous.
assertThrows(IOException.class, () -> appender.append(tx(), beforeForceTrappingEvent));
});
}
// THEN perform the race. The relevant assertions are made inside the contestants.
race.go();
}
use of org.neo4j.adversaries.Adversary in project neo4j by neo4j.
the class PageCacheRule method pageCachePostConstruct.
protected void pageCachePostConstruct(PageCacheConfig overriddenConfig) {
if (selectConfig(baseConfig.inconsistentReads, overriddenConfig.inconsistentReads, TRUE)) {
AtomicBoolean controller = selectConfig(baseConfig.nextReadIsInconsistent, overriddenConfig.nextReadIsInconsistent, null);
Adversary adversary = controller != null ? new AtomicBooleanInconsistentReadAdversary(controller) : new RandomInconsistentReadAdversary();
pageCache = new AdversarialPageCache(pageCache, adversary);
}
if (selectConfig(baseConfig.accessChecks, overriddenConfig.accessChecks, false)) {
pageCache = new AccessCheckingPageCache(pageCache);
}
}
Aggregations