Search in sources :

Example 46 with Theory

use of org.junit.experimental.theories.Theory in project Aeron by real-logic.

the class RetransmitHandlerTest method shouldRetransmitOnMultipleNaks.

@Theory
public void shouldRetransmitOnMultipleNaks(final BiConsumer<RetransmitHandlerTest, Integer> creator) {
    createTermBuffer(creator, 5);
    handler.onNak(TERM_ID, offsetOfFrame(0), ALIGNED_FRAME_LENGTH, TERM_BUFFER_LENGTH, retransmitSender);
    handler.onNak(TERM_ID, offsetOfFrame(1), ALIGNED_FRAME_LENGTH, TERM_BUFFER_LENGTH, retransmitSender);
    currentTime = TimeUnit.MILLISECONDS.toNanos(100);
    handler.processTimeouts(currentTime, retransmitSender);
    final InOrder inOrder = inOrder(retransmitSender);
    inOrder.verify(retransmitSender).resend(TERM_ID, offsetOfFrame(0), ALIGNED_FRAME_LENGTH);
    inOrder.verify(retransmitSender).resend(TERM_ID, offsetOfFrame(1), ALIGNED_FRAME_LENGTH);
}
Also used : InOrder(org.mockito.InOrder) Theory(org.junit.experimental.theories.Theory)

Example 47 with Theory

use of org.junit.experimental.theories.Theory in project Aeron by real-logic.

the class RetransmitHandlerTest method shouldRetransmitOnNakOverMtuLength.

@Theory
public void shouldRetransmitOnNakOverMtuLength(final BiConsumer<RetransmitHandlerTest, Integer> creator) {
    final int numFramesPerMtu = MTU_LENGTH / ALIGNED_FRAME_LENGTH;
    createTermBuffer(creator, numFramesPerMtu * 5);
    handler.onNak(TERM_ID, offsetOfFrame(0), MTU_LENGTH * 2, TERM_BUFFER_LENGTH, retransmitSender);
    currentTime = TimeUnit.MILLISECONDS.toNanos(100);
    handler.processTimeouts(currentTime, retransmitSender);
    verify(retransmitSender).resend(TERM_ID, offsetOfFrame(0), MTU_LENGTH * 2);
}
Also used : DataPoint(org.junit.experimental.theories.DataPoint) Theory(org.junit.experimental.theories.Theory)

Example 48 with Theory

use of org.junit.experimental.theories.Theory in project graphhopper by graphhopper.

the class FareTest method irrelevantAlternatives.

@Theory
public void irrelevantAlternatives(Map<String, Fare> fares, Trip trip) {
    assumeThat("There are at least two fares.", fares.entrySet().size(), is(greaterThanOrEqualTo(2)));
    // If we only use one fare, say, the most expensive one...
    Fare mostExpensiveFare = fares.values().stream().max(Comparator.comparingDouble(f -> f.fare_attribute.price)).get();
    HashMap<String, Fare> singleFare = new HashMap<>();
    singleFare.put(mostExpensiveFare.fare_id, mostExpensiveFare);
    // ..and that still works for our trip..
    assumeThat("There is at least one fare for each segment.", trip.segments.stream().map(segment -> Fares.possibleFares(singleFare, segment)).collect(Collectors.toList()), everyItem(is(not(empty()))));
    double priceWithOneOption = Fares.cheapestFare(singleFare, trip).get().getAmount().doubleValue();
    double priceWithAllOptions = Fares.cheapestFare(fares, trip).get().getAmount().doubleValue();
    assertThat("...it shouldn't get more expensive when we put the cheaper options back.", priceWithAllOptions, lessThanOrEqualTo(priceWithOneOption));
}
Also used : Fare(com.conveyal.gtfs.model.Fare) Theory(org.junit.experimental.theories.Theory)

Example 49 with Theory

use of org.junit.experimental.theories.Theory in project graphhopper by graphhopper.

the class FareTest method canGoAllTheWayOnOneTicket.

@Theory
public void canGoAllTheWayOnOneTicket(Map<String, Fare> fares, Trip trip) throws IOException {
    assumeThat("Only one fare.", fares.size(), equalTo(1));
    Fare onlyFare = fares.values().iterator().next();
    assumeThat("Fare allows the number of transfers we need for our trip.", onlyFare.fare_attribute.transfers, greaterThanOrEqualTo(trip.segments.size()));
    assumeThat("Fare allows the time we need for our trip.", (long) onlyFare.fare_attribute.transfer_duration, greaterThanOrEqualTo(trip.segments.get(trip.segments.size() - 1).getStartTime() - trip.segments.get(0).getStartTime()));
    Amount amount = Fares.cheapestFare(fares, trip).get();
    Assert.assertEquals(BigDecimal.valueOf(onlyFare.fare_attribute.price), amount.getAmount());
}
Also used : Fare(com.conveyal.gtfs.model.Fare) Theory(org.junit.experimental.theories.Theory)

Example 50 with Theory

use of org.junit.experimental.theories.Theory in project grakn by graknlabs.

the class LockTest method whenGettingLockWithNullInPath_LockIsAcquired.

@Theory
public void whenGettingLockWithNullInPath_LockIsAcquired(Locks locks) {
    String lockName = "/\u0000";
    Lock lock = getLock(locks, lockName);
    assertThat(lock.tryLock(), is(true));
    lock.unlock();
}
Also used : Lock(java.util.concurrent.locks.Lock) Theory(org.junit.experimental.theories.Theory)

Aggregations

Theory (org.junit.experimental.theories.Theory)107 DataPoint (org.junit.experimental.theories.DataPoint)23 Test (org.junit.Test)22 Header (io.aeron.logbuffer.Header)15 DirectBuffer (org.agrona.DirectBuffer)15 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)13 DebugReceiveChannelEndpoint (io.aeron.driver.ext.DebugReceiveChannelEndpoint)11 DebugSendChannelEndpoint (io.aeron.driver.ext.DebugSendChannelEndpoint)11 UdpChannel (io.aeron.driver.media.UdpChannel)11 MediaDriver (io.aeron.driver.MediaDriver)8 Lock (java.util.concurrent.locks.Lock)7 InterpreterResult (org.apache.zeppelin.interpreter.InterpreterResult)7 LongAdder (java.util.concurrent.atomic.LongAdder)6 UnsafeBuffer (org.agrona.concurrent.UnsafeBuffer)6 PrimitiveCollection (org.neo4j.collection.primitive.PrimitiveCollection)6 InOrder (org.mockito.InOrder)5 InputStream (java.io.InputStream)4 BaseStream (java.util.stream.BaseStream)4 InterpreterContext (org.apache.zeppelin.interpreter.InterpreterContext)4 Metric (org.springframework.boot.actuate.metrics.Metric)4