use of io.netty.channel.ReflectiveChannelFactory in project grpc-java by grpc.
the class NettyClientTransportTest method startServer.
private void startServer(int maxStreamsPerConnection, int maxHeaderListSize) throws IOException {
server = new NettyServer(TestUtils.testServerAddresses(new InetSocketAddress(0)), new ReflectiveChannelFactory<>(NioServerSocketChannel.class), new HashMap<ChannelOption<?>, Object>(), new HashMap<ChannelOption<?>, Object>(), new FixedObjectPool<>(group), new FixedObjectPool<>(group), false, negotiator, Collections.<ServerStreamTracer.Factory>emptyList(), TransportTracer.getDefaultFactory(), maxStreamsPerConnection, false, DEFAULT_WINDOW_SIZE, DEFAULT_MAX_MESSAGE_SIZE, maxHeaderListSize, DEFAULT_SERVER_KEEPALIVE_TIME_NANOS, DEFAULT_SERVER_KEEPALIVE_TIMEOUT_NANOS, MAX_CONNECTION_IDLE_NANOS_DISABLED, MAX_CONNECTION_AGE_NANOS_DISABLED, MAX_CONNECTION_AGE_GRACE_NANOS_INFINITE, true, 0, Attributes.EMPTY, channelz);
server.start(serverListener);
address = TestUtils.testServerAddress((InetSocketAddress) server.getListenSocketAddress());
authority = GrpcUtil.authorityFromHostAndPort(address.getHostString(), address.getPort());
}
use of io.netty.channel.ReflectiveChannelFactory in project netty by netty.
the class DnsNameResolverTest method testCNAMERecursiveResolveMultipleNameServers.
private static void testCNAMERecursiveResolveMultipleNameServers(boolean ipv4Preferred) throws IOException {
final String firstName = "firstname.nettyfoo.com";
final String lastName = "lastname.nettybar.com";
final String ipv4Addr = "1.2.3.4";
final String ipv6Addr = "::1";
final AtomicBoolean hitServer2 = new AtomicBoolean();
final TestDnsServer dnsServer2 = new TestDnsServer(new RecordStore() {
@Override
public Set<ResourceRecord> getRecords(QuestionRecord question) throws DnsException {
hitServer2.set(true);
if (question.getDomainName().equals(firstName)) {
ResourceRecordModifier rm = new ResourceRecordModifier();
rm.setDnsClass(RecordClass.IN);
rm.setDnsName(question.getDomainName());
rm.setDnsTtl(100);
rm.setDnsType(RecordType.CNAME);
rm.put(DnsAttribute.DOMAIN_NAME, lastName);
return Collections.singleton(rm.getEntry());
} else {
throw new DnsException(ResponseCode.REFUSED);
}
}
});
final TestDnsServer dnsServer3 = new TestDnsServer(new RecordStore() {
@Override
public Set<ResourceRecord> getRecords(QuestionRecord question) throws DnsException {
if (question.getDomainName().equals(lastName)) {
ResourceRecordModifier rm = new ResourceRecordModifier();
rm.setDnsClass(RecordClass.IN);
rm.setDnsName(question.getDomainName());
rm.setDnsTtl(100);
rm.setDnsType(question.getRecordType());
switch(question.getRecordType()) {
case A:
rm.put(DnsAttribute.IP_ADDRESS, ipv4Addr);
break;
case AAAA:
rm.put(DnsAttribute.IP_ADDRESS, ipv6Addr);
break;
default:
return null;
}
return Collections.singleton(rm.getEntry());
} else {
throw new DnsException(ResponseCode.REFUSED);
}
}
});
dnsServer2.start();
dnsServer3.start();
DnsNameResolver resolver = null;
try {
AuthoritativeDnsServerCache nsCache = new DefaultAuthoritativeDnsServerCache();
// What we want to test is the following:
// 1. Do a DNS query.
// 2. CNAME is returned, we want to lookup that CNAME on multiple DNS servers
// 3. The first DNS server should fail
// 4. The second DNS server should succeed
// This verifies that we do in fact follow multiple DNS servers in the CNAME resolution.
// The DnsCache is used for the name server cache, but doesn't provide a InetSocketAddress (only InetAddress
// so no port), so we only specify the name server in the cache, and then specify both name servers in the
// fallback name server provider.
nsCache.cache("nettyfoo.com.", dnsServer2.localAddress(), 10000, group.next());
resolver = new DnsNameResolver(group.next(), new ReflectiveChannelFactory<DatagramChannel>(NioDatagramChannel.class), NoopDnsCache.INSTANCE, nsCache, NoopDnsQueryLifecycleObserverFactory.INSTANCE, 3000, ipv4Preferred ? ResolvedAddressTypes.IPV4_ONLY : ResolvedAddressTypes.IPV6_ONLY, true, 10, true, 4096, false, HostsFileEntriesResolver.DEFAULT, new SequentialDnsServerAddressStreamProvider(dnsServer2.localAddress(), dnsServer3.localAddress()), DnsNameResolver.DEFAULT_SEARCH_DOMAINS, 0, true) {
@Override
InetSocketAddress newRedirectServerAddress(InetAddress server) {
int port = hitServer2.get() ? dnsServer3.localAddress().getPort() : dnsServer2.localAddress().getPort();
return new InetSocketAddress(server, port);
}
};
InetAddress resolvedAddress = resolver.resolve(firstName).syncUninterruptibly().getNow();
if (ipv4Preferred) {
assertEquals(ipv4Addr, resolvedAddress.getHostAddress());
} else {
assertEquals(ipv6Addr, NetUtil.toAddressString(resolvedAddress));
}
assertEquals(firstName, resolvedAddress.getHostName());
} finally {
dnsServer2.stop();
dnsServer3.stop();
if (resolver != null) {
resolver.close();
}
}
}
Aggregations