Search in sources :

Example 1 with IntSupplier

use of java.util.function.IntSupplier in project geode by apache.

the class StatisticsImplTest method invokeSuppliersShouldLogErrorOnlyOnce.

@Test
public void invokeSuppliersShouldLogErrorOnlyOnce() {
    final Logger originalLogger = StatisticsImpl.logger;
    try {
        final Logger logger = mock(Logger.class);
        StatisticsImpl.logger = logger;
        IntSupplier supplier1 = mock(IntSupplier.class);
        when(supplier1.getAsInt()).thenThrow(NullPointerException.class);
        stats.setIntSupplier(4, supplier1);
        assertEquals(1, stats.invokeSuppliers());
        verify(logger, times(1)).warn(anyString(), anyString(), anyInt(), isA(NullPointerException.class));
        assertEquals(1, stats.invokeSuppliers());
        // Make sure the logger isn't invoked again
        verify(logger, times(1)).warn(anyString(), anyString(), anyInt(), isA(NullPointerException.class));
    } finally {
        StatisticsImpl.logger = originalLogger;
    }
}
Also used : IntSupplier(java.util.function.IntSupplier) Logger(org.apache.logging.log4j.Logger) UnitTest(org.apache.geode.test.junit.categories.UnitTest) Test(org.junit.Test)

Example 2 with IntSupplier

use of java.util.function.IntSupplier in project geode by apache.

the class StatisticsImplTest method badSupplierParamShouldThrowError.

@Test
public void badSupplierParamShouldThrowError() {
    IntSupplier supplier1 = mock(IntSupplier.class);
    when(supplier1.getAsInt()).thenReturn(23);
    thrown.expect(IllegalArgumentException.class);
    stats.setIntSupplier(23, supplier1);
}
Also used : IntSupplier(java.util.function.IntSupplier) UnitTest(org.apache.geode.test.junit.categories.UnitTest) Test(org.junit.Test)

Example 3 with IntSupplier

use of java.util.function.IntSupplier in project intellij-community by JetBrains.

the class Foo method m.

void m() {
    Runnable r = Collections::emptyList;
    Runnable r2 = () -> {
        IntSupplier s = () -> 1;
        Runnable r3 = () -> {
        };
    };
    IntSupplier s2 = () -> 1;
}
Also used : IntSupplier(java.util.function.IntSupplier)

Example 4 with IntSupplier

use of java.util.function.IntSupplier in project intellij-community by JetBrains.

the class Foo method m2.

void m2() {
    Runnable r = () -> {
        Runnable r3 = () -> {
            IntSupplier s2 = () -> 1;
            Runnable r4 = () -> {
            };
        };
        IntSupplier s = () -> 1;
    };
}
Also used : IntSupplier(java.util.function.IntSupplier)

Example 5 with IntSupplier

use of java.util.function.IntSupplier in project aeron by real-logic.

the class SendSelectReceiveUdpPing method run.

private void run() throws IOException {
    final Histogram histogram = new Histogram(TimeUnit.SECONDS.toNanos(10), 3);
    final ByteBuffer buffer = ByteBuffer.allocateDirect(Configuration.MTU_LENGTH_DEFAULT);
    final DatagramChannel receiveChannel = DatagramChannel.open();
    Common.init(receiveChannel);
    receiveChannel.bind(new InetSocketAddress("localhost", Common.PONG_PORT));
    final DatagramChannel sendChannel = DatagramChannel.open();
    Common.init(sendChannel);
    final Selector selector = Selector.open();
    final IntSupplier handler = () -> {
        try {
            buffer.clear();
            receiveChannel.receive(buffer);
            final long receivedSequenceNumber = buffer.getLong(0);
            final long timestamp = buffer.getLong(SIZE_OF_LONG);
            if (receivedSequenceNumber != sequenceNumber) {
                throw new IllegalStateException("Data Loss:" + sequenceNumber + " to " + receivedSequenceNumber);
            }
            final long duration = System.nanoTime() - timestamp;
            histogram.recordValue(duration);
        } catch (final IOException ex) {
            ex.printStackTrace();
        }
        return 1;
    };
    receiveChannel.register(selector, OP_READ, handler);
    final AtomicBoolean running = new AtomicBoolean(true);
    SigInt.register(() -> running.set(false));
    while (running.get()) {
        measureRoundTrip(histogram, SEND_ADDRESS, buffer, sendChannel, selector, running);
        histogram.reset();
        System.gc();
        LockSupport.parkNanos(1000 * 1000 * 1000);
    }
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) Histogram(org.HdrHistogram.Histogram) IntSupplier(java.util.function.IntSupplier) InetSocketAddress(java.net.InetSocketAddress) DatagramChannel(java.nio.channels.DatagramChannel) IOException(java.io.IOException) ByteBuffer(java.nio.ByteBuffer) Selector(java.nio.channels.Selector)

Aggregations

IntSupplier (java.util.function.IntSupplier)34 Test (org.junit.Test)13 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)6 UnitTest (org.apache.geode.test.junit.categories.UnitTest)6 IOException (java.io.IOException)5 ByteBuffer (java.nio.ByteBuffer)5 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)5 InetSocketAddress (java.net.InetSocketAddress)4 DatagramChannel (java.nio.channels.DatagramChannel)4 Selector (java.nio.channels.Selector)4 SelectionKey (java.nio.channels.SelectionKey)3 ArrayList (java.util.ArrayList)3 List (java.util.List)3 AtomicReference (java.util.concurrent.atomic.AtomicReference)3 Supplier (java.util.function.Supplier)3 Collectors (java.util.stream.Collectors)3 FrameDescriptor (com.oracle.truffle.api.frame.FrameDescriptor)2 WeakReference (java.lang.ref.WeakReference)2 Arrays (java.util.Arrays)2 Collection (java.util.Collection)2