Search in sources :

Example 16 with Assert

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());
}
Also used : PrepareConsistentRequest(org.apache.cassandra.repair.messages.PrepareConsistentRequest) FailSession(org.apache.cassandra.repair.messages.FailSession) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) RepairMessage(org.apache.cassandra.repair.messages.RepairMessage) Executor(java.util.concurrent.Executor) Assert(org.junit.Assert) ListenableFuture(com.google.common.util.concurrent.ListenableFuture) ArrayList(java.util.ArrayList) List(java.util.List) InetAddress(java.net.InetAddress) RepairSessionResult(org.apache.cassandra.repair.RepairSessionResult) AbstractRepairTest(org.apache.cassandra.repair.AbstractRepairTest) Test(org.junit.Test)

Example 17 with Assert

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());
}
Also used : Assert(org.junit.Assert) File(java.io.File) Test(org.junit.Test)

Example 18 with Assert

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");
}
Also used : Assert(org.junit.Assert) AuthorList(org.jabref.model.entry.AuthorList) Test(org.junit.Test)

Aggregations

Assert (org.junit.Assert)18 Test (org.junit.Test)14 List (java.util.List)7 ArrayList (java.util.ArrayList)5 UUID (java.util.UUID)5 SSTableReader (org.apache.cassandra.io.sstable.format.SSTableReader)5 HashSet (java.util.HashSet)3 Collectors (java.util.stream.Collectors)3 SSTableAddedNotification (org.apache.cassandra.notifications.SSTableAddedNotification)3 ListenableFuture (com.google.common.util.concurrent.ListenableFuture)2 Project (com.intellij.openapi.project.Project)2 Ref (com.intellij.openapi.util.Ref)2 InetAddress (java.net.InetAddress)2 Arrays (java.util.Arrays)2 Collection (java.util.Collection)2 Collections (java.util.Collections)2 HashMap (java.util.HashMap)2 Iterator (java.util.Iterator)2 Map (java.util.Map)2 Set (java.util.Set)2