use of io.servicetalk.client.api.ServiceDiscovererEvent in project servicetalk by apple.
the class DefaultDnsClientTest method unknownHostDiscover.
@ParameterizedTest(name = "missing-record-status={0}")
@MethodSource("missingRecordStatus")
void unknownHostDiscover(ServiceDiscovererEvent.Status missingRecordStatus) throws Exception {
setup(missingRecordStatus);
TestPublisherSubscriber<ServiceDiscovererEvent<InetAddress>> subscriber = dnsQuery("unknown.com");
Subscription subscription = subscriber.awaitSubscription();
subscription.request(Long.MAX_VALUE);
assertThat(subscriber.awaitOnError(), instanceOf(UnknownHostException.class));
}
use of io.servicetalk.client.api.ServiceDiscovererEvent in project servicetalk by apple.
the class DefaultDnsClientTest method srvExceptionInSubscriberOnNext.
@ParameterizedTest(name = "missing-record-status={0}")
@MethodSource("missingRecordStatus")
void srvExceptionInSubscriberOnNext(ServiceDiscovererEvent.Status missingRecordStatus) throws Exception {
setup(missingRecordStatus);
client.closeAsync().toFuture().get();
client = dnsClientBuilder(missingRecordStatus).srvHostNameRepeatDelay(ofMillis(50), ofMillis(10)).build();
final String domain = "sd.servicetalk.io";
final String targetDomain1 = "target1.mysvc.servicetalk.io";
final String ip = nextIp();
final int targetPort = 9876;
final int ttl = DEFAULT_TTL + 10;
recordStore.addIPv4Address(targetDomain1, ttl, ip);
recordStore.addSrv(domain, targetDomain1, targetPort, DEFAULT_TTL);
CountDownLatch latchOnError = new CountDownLatch(1);
BlockingQueue<ServiceDiscovererEvent<InetSocketAddress>> queue = new ArrayBlockingQueue<>(10);
toSource(client.dnsSrvQuery(domain).flatMapConcatIterable(identity())).subscribe(mockThrowSubscriber(latchOnError, queue));
assertEvent(queue.take(), ip, targetPort, AVAILABLE);
assertEvent(queue.take(), ip, targetPort, missingRecordStatus);
// Remove the srv address because the mapped publishers don't propagate errors, so we want the outer SRV resolve
// to fail.
recordStore.removeSrv(domain, targetDomain1, targetPort, DEFAULT_TTL);
latchOnError.await();
}
use of io.servicetalk.client.api.ServiceDiscovererEvent in project servicetalk by apple.
the class DefaultDnsClientTest method singleDiscoverDuplicateRecords.
@ParameterizedTest(name = "missing-record-status={0}")
@MethodSource("missingRecordStatus")
void singleDiscoverDuplicateRecords(ServiceDiscovererEvent.Status missingRecordStatus) throws Exception {
setup(missingRecordStatus);
final String dupIp = nextIp();
final String domain = "servicetalk.io";
final String[] ips = new String[] { nextIp(), nextIp(), dupIp, dupIp, nextIp() };
recordStore.addIPv4Address(domain, DEFAULT_TTL, ips);
TestPublisherSubscriber<ServiceDiscovererEvent<InetAddress>> subscriber = dnsQuery(domain);
Subscription subscription = subscriber.awaitSubscription();
subscription.request(ips.length);
List<ServiceDiscovererEvent<InetAddress>> signals = subscriber.takeOnNext(ips.length - 1);
boolean assertedDup = false;
for (String ip : ips) {
if (ip.equals(dupIp)) {
if (!assertedDup) {
assertedDup = true;
assertHasEvent(signals, ip, AVAILABLE);
}
} else {
assertHasEvent(signals, ip, AVAILABLE);
}
}
}
use of io.servicetalk.client.api.ServiceDiscovererEvent in project servicetalk by apple.
the class DefaultDnsClientTest method singleDiscoverMultipleRecords.
@ParameterizedTest(name = "missing-record-status={0}")
@MethodSource("missingRecordStatus")
void singleDiscoverMultipleRecords(ServiceDiscovererEvent.Status missingRecordStatus) throws Exception {
setup(missingRecordStatus);
final String domain = "servicetalk.io";
final String[] ips = new String[] { nextIp(), nextIp(), nextIp(), nextIp(), nextIp() };
recordStore.addIPv4Address(domain, DEFAULT_TTL, ips);
TestPublisherSubscriber<ServiceDiscovererEvent<InetAddress>> subscriber = dnsQuery(domain);
Subscription subscription = subscriber.awaitSubscription();
subscription.request(ips.length);
List<ServiceDiscovererEvent<InetAddress>> signals = subscriber.takeOnNext(ips.length);
for (String ip : ips) {
assertHasEvent(signals, ip, AVAILABLE);
}
// Remove all the ips
recordStore.removeIPv4Address(domain, DEFAULT_TTL, ips);
subscription.request(1);
assertThat(subscriber.awaitOnError(), instanceOf(UnknownHostException.class));
}
use of io.servicetalk.client.api.ServiceDiscovererEvent in project servicetalk by apple.
the class DefaultDnsClientTest method singleADiscover.
@ParameterizedTest(name = "missing-record-status={0}")
@MethodSource("missingRecordStatus")
void singleADiscover(ServiceDiscovererEvent.Status missingRecordStatus) throws Exception {
setup(missingRecordStatus);
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(1);
assertEvent(subscriber.takeOnNext(), ip, AVAILABLE);
// Remove the ip
recordStore.removeIPv4Address(domain, DEFAULT_TTL, ip);
subscription.request(1);
assertThat(subscriber.awaitOnError(), instanceOf(UnknownHostException.class));
}
Aggregations