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;
}
}
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);
}
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;
}
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;
};
}
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);
}
}
Aggregations