use of io.servicetalk.client.api.ServiceDiscovererEvent in project servicetalk by apple.
the class DefaultDnsClientTest method repeatDiscoverNxDomainAndRecover.
@ParameterizedTest(name = "missing-record-status={0}")
@MethodSource("missingRecordStatus")
void repeatDiscoverNxDomainAndRecover(ServiceDiscovererEvent.Status missingRecordStatus) throws Exception {
setup(missingRecordStatus);
client.closeAsync().toFuture().get();
client = dnsClientBuilderWithRetry(missingRecordStatus).inactiveEventsOnError(true).build();
final String ip = nextIp();
final String domain = "servicetalk.io";
recordStore.addIPv4Address(domain, DEFAULT_TTL, ip);
TestPublisherSubscriber<ServiceDiscovererEvent<InetAddress>> subscriber = dnsQuery(domain);
Subscription subscription = subscriber.awaitSubscription();
subscription.request(4);
assertEvent(subscriber.takeOnNext(), ip, AVAILABLE);
recordStore.removeIPv4Address(domain, DEFAULT_TTL, ip);
assertEvent(subscriber.takeOnNext(), ip, missingRecordStatus);
recordStore.addIPv4Address(domain, DEFAULT_TTL, ip);
assertEvent(subscriber.takeOnNext(), ip, AVAILABLE);
}
use of io.servicetalk.client.api.ServiceDiscovererEvent in project servicetalk by apple.
the class DefaultDnsClientTest method preferIpv4.
@ParameterizedTest(name = "missing-record-status={0}")
@MethodSource("missingRecordStatus")
void preferIpv4(ServiceDiscovererEvent.Status missingRecordStatus) throws Exception {
setup(missingRecordStatus);
client.closeAsync().toFuture().get();
client = dnsClientBuilder(missingRecordStatus).completeOncePreferredResolved(false).dnsResolverAddressTypes(IPV4_PREFERRED).build();
final String ipv4 = nextIp();
final String ipv6 = nextIp6();
final String domain = "servicetalk.io";
recordStore.addIPv6Address(domain, DEFAULT_TTL, ipv6);
recordStore.addIPv4Address(domain, DEFAULT_TTL, ipv4);
TestPublisherSubscriber<ServiceDiscovererEvent<InetAddress>> subscriber = dnsQuery(domain);
Subscription subscription = subscriber.awaitSubscription();
subscription.request(Long.MAX_VALUE);
List<ServiceDiscovererEvent<InetAddress>> signals = subscriber.takeOnNext(2);
assertHasEvent(signals, ipv4, AVAILABLE);
assertHasEvent(signals, ipv6, AVAILABLE);
// Remove the ipv4
recordStore.removeIPv4Address(domain, DEFAULT_TTL, ipv4);
assertEvent(subscriber.takeOnNext(), ipv4, missingRecordStatus);
}
use of io.servicetalk.client.api.ServiceDiscovererEvent in project servicetalk by apple.
the class DefaultDnsClientTest method srvRecordFailsGeneratesInactive.
private void srvRecordFailsGeneratesInactive(boolean inactiveEventsOnError, ServiceDiscovererEvent.Status missingRecordStatus) throws Exception {
client.closeAsync().toFuture().get();
client = dnsClientBuilder(missingRecordStatus).inactiveEventsOnError(inactiveEventsOnError).build();
final String domain = "sd.servicetalk.io";
final String targetDomain1 = "target1.mysvc.servicetalk.io";
final String targetDomain2 = "target2.mysvc.servicetalk.io";
final int targetPort = 9876;
final String ip1 = nextIp();
final String ip2 = nextIp();
final int ttl = DEFAULT_TTL + 10;
recordStore.addIPv4Address(targetDomain1, ttl, ip1);
recordStore.addIPv4Address(targetDomain2, ttl, ip2);
recordStore.addSrv(domain, targetDomain1, targetPort, DEFAULT_TTL);
recordStore.addSrv(domain, targetDomain2, targetPort, DEFAULT_TTL);
TestPublisherSubscriber<ServiceDiscovererEvent<InetSocketAddress>> subscriber = dnsSrvQuery(domain);
Subscription subscription = subscriber.awaitSubscription();
subscription.request(10);
List<ServiceDiscovererEvent<InetSocketAddress>> signals = subscriber.takeOnNext(2);
assertHasEvent(signals, ip1, targetPort, AVAILABLE);
assertHasEvent(signals, ip2, targetPort, AVAILABLE);
recordStore.removeSrv(domain, targetDomain1, targetPort, DEFAULT_TTL);
assertEvent(subscriber.takeOnNext(), ip1, targetPort, missingRecordStatus);
recordStore.removeSrv(domain, targetDomain2, targetPort, DEFAULT_TTL);
if (inactiveEventsOnError) {
assertEvent(subscriber.takeOnNext(), ip2, targetPort, missingRecordStatus);
}
assertThat(subscriber.awaitOnError(), instanceOf(UnknownHostException.class));
}
use of io.servicetalk.client.api.ServiceDiscovererEvent in project servicetalk by apple.
the class DefaultDnsClientTest method srvWithCNAMEEntryLowerTTLDoesNotFail.
@ParameterizedTest(name = "missing-record-status={0}")
@MethodSource("missingRecordStatus")
void srvWithCNAMEEntryLowerTTLDoesNotFail(ServiceDiscovererEvent.Status missingRecordStatus) throws Exception {
setup(missingRecordStatus);
final String domain = "sd.servicetalk.io";
final String srvCNAME = "sdcname.servicetalk.io";
final String targetDomain1 = "target1.mysvc.servicetalk.io";
final int targetPort = 9876;
final String ip1 = nextIp();
final int ttl = DEFAULT_TTL + 3;
recordStore.addCNAME(domain, srvCNAME, ttl);
recordStore.addSrv(domain, targetDomain1, targetPort, ttl);
recordStore.addSrv(srvCNAME, targetDomain1, targetPort, 1);
recordStore.addIPv4Address(targetDomain1, ttl, ip1);
TestPublisherSubscriber<ServiceDiscovererEvent<InetSocketAddress>> subscriber = dnsSrvQuery(domain);
Subscription subscription = subscriber.awaitSubscription();
subscription.request(10);
assertEvent(subscriber.takeOnNext(), ip1, targetPort, AVAILABLE);
recordStore.removeSrv(srvCNAME, targetDomain1, targetPort, 1);
assertNull(subscriber.pollTerminal(ttl, SECONDS));
}
use of io.servicetalk.client.api.ServiceDiscovererEvent in project servicetalk by apple.
the class DefaultDnsClientTest method srvRecordRemovalPropagatesError.
@ParameterizedTest(name = "missing-record-status={0}")
@MethodSource("missingRecordStatus")
void srvRecordRemovalPropagatesError(ServiceDiscovererEvent.Status missingRecordStatus) throws Exception {
setup(missingRecordStatus);
final String domain = "sd.servicetalk.io";
final String targetDomain1 = "target1.mysvc.servicetalk.io";
final String targetDomain2 = "target2.mysvc.servicetalk.io";
final int targetPort = 9876;
final String ip1 = nextIp();
final String ip2 = nextIp();
recordStore.addSrv(domain, targetDomain1, targetPort, DEFAULT_TTL);
recordStore.addSrv(domain, targetDomain2, targetPort, DEFAULT_TTL);
recordStore.addIPv4Address(targetDomain1, DEFAULT_TTL + 10, ip1);
recordStore.addIPv4Address(targetDomain2, DEFAULT_TTL + 10, ip2);
TestPublisherSubscriber<ServiceDiscovererEvent<InetSocketAddress>> subscriber = dnsSrvQuery(domain);
Subscription subscription = subscriber.awaitSubscription();
subscription.request(10);
List<ServiceDiscovererEvent<InetSocketAddress>> signals = subscriber.takeOnNext(2);
assertHasEvent(signals, ip1, targetPort, AVAILABLE);
assertHasEvent(signals, ip2, targetPort, AVAILABLE);
// Atomically remove all the SRV records, the next resolution should result in a host not found exception.
recordStore.removeRecords(createSrvRecord(domain, targetDomain1, targetPort, DEFAULT_TTL), createSrvRecord(domain, targetDomain2, targetPort, DEFAULT_TTL));
assertThat(subscriber.awaitOnError(), instanceOf(UnknownHostException.class));
}
Aggregations