use of org.junit.jupiter.api.function.Executable in project netty by netty.
the class DnsNameResolverTest method testFollowCNAMELoop.
@Test
public void testFollowCNAMELoop() throws IOException {
TestDnsServer dnsServer2 = new TestDnsServer(new RecordStore() {
@Override
public Set<ResourceRecord> getRecords(QuestionRecord question) {
Set<ResourceRecord> records = new LinkedHashSet<ResourceRecord>(4);
records.add(new TestDnsServer.TestResourceRecord("x." + question.getDomainName(), RecordType.A, Collections.<String, Object>singletonMap(DnsAttribute.IP_ADDRESS.toLowerCase(), "10.0.0.99")));
records.add(new TestDnsServer.TestResourceRecord("cname2.netty.io", RecordType.CNAME, Collections.<String, Object>singletonMap(DnsAttribute.DOMAIN_NAME.toLowerCase(), "cname.netty.io")));
records.add(new TestDnsServer.TestResourceRecord("cname.netty.io", RecordType.CNAME, Collections.<String, Object>singletonMap(DnsAttribute.DOMAIN_NAME.toLowerCase(), "cname2.netty.io")));
records.add(new TestDnsServer.TestResourceRecord(question.getDomainName(), RecordType.CNAME, Collections.<String, Object>singletonMap(DnsAttribute.DOMAIN_NAME.toLowerCase(), "cname.netty.io")));
return records;
}
});
dnsServer2.start();
DnsNameResolver resolver = null;
try {
DnsNameResolverBuilder builder = newResolver().recursionDesired(false).resolvedAddressTypes(ResolvedAddressTypes.IPV4_ONLY).maxQueriesPerResolve(16).nameServerProvider(new SingletonDnsServerAddressStreamProvider(dnsServer2.localAddress()));
resolver = builder.build();
final DnsNameResolver finalResolver = resolver;
assertThrows(UnknownHostException.class, new Executable() {
@Override
public void execute() throws Throwable {
finalResolver.resolveAll("somehost.netty.io").syncUninterruptibly().getNow();
}
});
} finally {
dnsServer2.stop();
if (resolver != null) {
resolver.close();
}
}
}
use of org.junit.jupiter.api.function.Executable in project netty by netty.
the class DnsNameResolverTest method testAddressAlreadyInUse.
@Test
public void testAddressAlreadyInUse() throws Exception {
DatagramSocket datagramSocket = new DatagramSocket();
try {
assertTrue(datagramSocket.isBound());
try {
final DnsNameResolver resolver = newResolver().localAddress(datagramSocket.getLocalSocketAddress()).build();
try {
Throwable cause = assertThrows(UnknownHostException.class, new Executable() {
@Override
public void execute() throws Throwable {
resolver.resolve("netty.io").sync();
}
});
assertThat(cause.getCause(), Matchers.<Throwable>instanceOf(BindException.class));
} finally {
resolver.close();
}
} catch (IllegalStateException cause) {
// We might also throw directly here... in this case let's verify that we use the correct exception.
assertThat(cause.getCause(), Matchers.<Throwable>instanceOf(BindException.class));
}
} finally {
datagramSocket.close();
}
}
use of org.junit.jupiter.api.function.Executable in project netty by netty.
the class LongPriorityQueueTest method mustThrowWhenAddingNoValue.
@Test
public void mustThrowWhenAddingNoValue() {
final LongPriorityQueue pq = new LongPriorityQueue();
assertThrows(IllegalArgumentException.class, new Executable() {
@Override
public void execute() {
pq.offer(LongPriorityQueue.NO_VALUE);
}
});
}
use of org.junit.jupiter.api.function.Executable in project netty by netty.
the class UnpooledTest method testGetBytesByteBuffer2.
@Test
public void testGetBytesByteBuffer2() {
byte[] bytes = { 'a', 'b', 'c', 'd', 'e', 'f', 'g' };
// Ensure destination buffer is bigger then what is wrapped in the ByteBuf.
final ByteBuffer nioBuffer = ByteBuffer.allocate(bytes.length + 1);
final ByteBuf wrappedBuffer = wrappedBuffer(bytes, 0, bytes.length);
try {
assertThrows(IndexOutOfBoundsException.class, new Executable() {
@Override
public void execute() throws Throwable {
wrappedBuffer.getBytes(wrappedBuffer.readerIndex(), nioBuffer);
}
});
} finally {
wrappedBuffer.release();
}
}
use of org.junit.jupiter.api.function.Executable in project netty by netty.
the class SlicedByteBufTest method testGetBytesByteBuffer.
@Override
@Test
public void testGetBytesByteBuffer() {
byte[] bytes = { 'a', 'b', 'c', 'd', 'e', 'f', 'g' };
// Ensure destination buffer is bigger then what is wrapped in the ByteBuf.
final ByteBuffer nioBuffer = ByteBuffer.allocate(bytes.length + 1);
final ByteBuf wrappedBuffer = Unpooled.wrappedBuffer(bytes).slice(0, bytes.length - 1);
try {
assertThrows(IndexOutOfBoundsException.class, new Executable() {
@Override
public void execute() {
wrappedBuffer.getBytes(wrappedBuffer.readerIndex(), nioBuffer);
}
});
} finally {
wrappedBuffer.release();
}
}
Aggregations