Skip to content

Instantly share code, notes, and snippets.

public class IteratorDataSourceConsumer {
private IteratorDataSource iteratorDataSource;
public void consume() {
iteratorDataSource.getAllEntities().forEachRemaining(entity -> {
//doStuff
});
}
}
@codingtim
codingtim / UdpServer.kt
Created April 5, 2017 10:44
Simple udp server with netty 4.1 and kotlin
import io.netty.bootstrap.Bootstrap
import io.netty.channel.ChannelHandlerContext
import io.netty.channel.SimpleChannelInboundHandler
import io.netty.channel.nio.NioEventLoopGroup
import io.netty.channel.socket.nio.NioDatagramChannel
import io.netty.util.CharsetUtil
import io.netty.util.concurrent.DefaultThreadFactory
import kotlinx.coroutines.experimental.async
import kotlinx.coroutines.experimental.newFixedThreadPoolContext
@codingtim
codingtim / ApiCaller.java
Created November 18, 2018 14:25
WebClient calling an imaginary web api
class ApiCaller {
private WebClient webClient;
ApiCaller(WebClient webClient) {
this.webClient = webClient;
}
Mono<SimpleResponseDto> callApi() {
return webClient.put()
@codingtim
codingtim / ApiCallerTest.java
Last active November 18, 2018 14:44
Test for ApiCaller with MockWebServer
class ApiCallerTest {
private final MockWebServer mockWebServer = new MockWebServer();
private final ApiCaller apiCaller = new ApiCaller(WebClient.create(mockWebServer.url("/").toString()));
@AfterEach
void tearDown() throws IOException {
mockWebServer.shutdown();
}
@Test
void revoked() throws IOException {
get("https://revoked.sca1a.amazontrust.com/", urlConnection -> {
assertThatExceptionOfType(SSLHandshakeException.class)
.isThrownBy(urlConnection::getResponseCode)
.withRootCauseInstanceOf(CertificateRevokedException.class);
});
}