use of org.junit.Assert in project cassandra by apache.
the class CoordinatorSessionTest method failedPrepare.
@Test
public void failedPrepare() {
InstrumentedCoordinatorSession coordinator = createInstrumentedSession();
Executor executor = MoreExecutors.directExecutor();
AtomicBoolean repairSubmitted = new AtomicBoolean(false);
SettableFuture<List<RepairSessionResult>> repairFuture = SettableFuture.create();
Supplier<ListenableFuture<List<RepairSessionResult>>> sessionSupplier = () -> {
repairSubmitted.set(true);
return repairFuture;
};
// coordinator sends prepare requests to create local session and perform anticompaction
AtomicBoolean hasFailures = new AtomicBoolean(false);
Assert.assertFalse(repairSubmitted.get());
Assert.assertTrue(coordinator.sentMessages.isEmpty());
ListenableFuture sessionResult = coordinator.execute(executor, sessionSupplier, hasFailures);
for (InetAddress participant : PARTICIPANTS) {
PrepareConsistentRequest expected = new PrepareConsistentRequest(coordinator.sessionID, COORDINATOR, new HashSet<>(PARTICIPANTS));
assertMessageSent(coordinator, participant, expected);
}
coordinator.sentMessages.clear();
// participants respond to coordinator, and repair begins once all participants have responded with success
Assert.assertEquals(ConsistentSession.State.PREPARING, coordinator.getState());
coordinator.handlePrepareResponse(PARTICIPANT1, true);
Assert.assertEquals(ConsistentSession.State.PREPARING, coordinator.getState());
// participant 2 fails to prepare for consistent repair
Assert.assertFalse(coordinator.failCalled);
coordinator.handlePrepareResponse(PARTICIPANT2, false);
Assert.assertEquals(ConsistentSession.State.FAILED, coordinator.getState());
Assert.assertTrue(coordinator.failCalled);
// additional success messages should be ignored
Assert.assertFalse(coordinator.setRepairingCalled);
coordinator.onSetRepairing = Assert::fail;
coordinator.handlePrepareResponse(PARTICIPANT3, true);
Assert.assertFalse(coordinator.setRepairingCalled);
Assert.assertFalse(repairSubmitted.get());
// all participants should have been notified of session failure
for (InetAddress participant : PARTICIPANTS) {
RepairMessage expected = new FailSession(coordinator.sessionID);
assertMessageSent(coordinator, participant, expected);
}
Assert.assertTrue(sessionResult.isDone());
Assert.assertTrue(hasFailures.get());
}
use of org.junit.Assert in project java-design-patterns by iluwatar.
the class SimpleFileWriterTest method testNonExistentFile.
/**
* Test if the {@link SimpleFileWriter} creates a file if it doesn't exist
*/
@Test
public void testNonExistentFile() throws Exception {
final File nonExistingFile = new File(this.testFolder.getRoot(), "non-existing-file");
assertFalse(nonExistingFile.exists());
new SimpleFileWriter(nonExistingFile.getPath(), Assert::assertNotNull);
assertTrue(nonExistingFile.exists());
}
use of org.junit.Assert in project jabref by JabRef.
the class BibtexNameFormatterTest method testFormatName.
@Test
public void testFormatName() {
{
AuthorList al = AuthorList.parse("Charles Louis Xavier Joseph de la Vall{\\'e}e Poussin");
Assert.assertEquals("de~laVall{\\'e}e~PoussinCharles Louis Xavier~Joseph", BibtexNameFormatter.formatName(al.getAuthor(0), "{vv}{ll}{jj}{ff}", Assert::fail));
}
{
AuthorList al = AuthorList.parse("Charles Louis Xavier Joseph de la Vall{\\'e}e Poussin");
Assert.assertEquals("de~la Vall{\\'e}e~Poussin, C.~L. X.~J.", BibtexNameFormatter.formatName(al.getAuthor(0), "{vv~}{ll}{, jj}{, f.}", Assert::fail));
}
{
AuthorList al = AuthorList.parse("Charles Louis Xavier Joseph de la Vall{\\'e}e Poussin");
Assert.assertEquals("de~la Vall{\\'e}e~Poussin, C.~L. X.~J?", BibtexNameFormatter.formatName(al.getAuthor(0), "{vv~}{ll}{, jj}{, f}?", Assert::fail));
}
AuthorList al = AuthorList.parse("Charles Louis Xavier Joseph de la Vall{\\'e}e Poussin");
Assert.assertEquals("dlVP", BibtexNameFormatter.formatName(al.getAuthor(0), "{v{}}{l{}}", Assert::fail));
assertNameFormatA("Meyer, J?", "Jonathan Meyer and Charles Louis Xavier Joseph de la Vall{\\'e}e Poussin");
assertNameFormatB("J.~Meyer", "Jonathan Meyer and Charles Louis Xavier Joseph de la Vall{\\'e}e Poussin");
assertNameFormatC("Jonathan Meyer", "Jonathan Meyer and Charles Louis Xavier Joseph de la Vall{\\'e}e Poussin");
assertNameFormatA("Masterly, {\\'{E}}?", "{\\'{E}}douard Masterly");
assertNameFormatB("{\\'{E}}.~Masterly", "{\\'{E}}douard Masterly");
assertNameFormatC("{\\'{E}}douard Masterly", "{\\'{E}}douard Masterly");
assertNameFormatA("{\\\"{U}}nderwood, U?", "Ulrich {\\\"{U}}nderwood and Ned {\\~N}et and Paul {\\={P}}ot");
assertNameFormatB("U.~{\\\"{U}}nderwood", "Ulrich {\\\"{U}}nderwood and Ned {\\~N}et and Paul {\\={P}}ot");
assertNameFormatC("Ulrich {\\\"{U}}nderwood", "Ulrich {\\\"{U}}nderwood and Ned {\\~N}et and Paul {\\={P}}ot");
assertNameFormatA("Victor, P.~{\\'E}?", "Paul {\\'E}mile Victor and and de la Cierva y Codorn{\\’\\i}u, Juan");
assertNameFormatB("P.~{\\'E}. Victor", "Paul {\\'E}mile Victor and and de la Cierva y Codorn{\\’\\i}u, Juan");
assertNameFormatC("Paul~{\\'E}mile Victor", "Paul {\\'E}mile Victor and and de la Cierva y Codorn{\\’\\i}u, Juan");
}
Aggregations