use of io.servicetalk.client.api.ServiceDiscovererEvent in project servicetalk by apple.
the class DefaultDnsClientTest method repeatDiscoverMultipleHosts.
@ParameterizedTest(name = "missing-record-status={0}")
@MethodSource("missingRecordStatus")
void repeatDiscoverMultipleHosts(ServiceDiscovererEvent.Status missingRecordStatus) throws Exception {
setup(missingRecordStatus);
final String ip1 = nextIp();
final String domain1 = "servicetalk.io";
final String ip2 = nextIp();
final String domain2 = "backup.servicetalk.io";
recordStore.addIPv4Address(domain1, DEFAULT_TTL, ip1);
recordStore.addIPv4Address(domain2, DEFAULT_TTL, ip2);
TestPublisherSubscriber<ServiceDiscovererEvent<InetAddress>> subscriber1 = dnsQuery(domain1);
Subscription subscription1 = subscriber1.awaitSubscription();
subscription1.request(1);
TestPublisherSubscriber<ServiceDiscovererEvent<InetAddress>> subscriber2 = dnsQuery(domain2);
Subscription subscription2 = subscriber2.awaitSubscription();
subscription2.request(1);
assertEvent(subscriber1.takeOnNext(), ip1, AVAILABLE);
assertEvent(subscriber2.takeOnNext(), ip2, AVAILABLE);
// Remove all the IPs
recordStore.removeIPv4Address(domain1, DEFAULT_TTL, ip1);
recordStore.removeIPv4Address(domain2, DEFAULT_TTL, ip2);
subscription1.request(1);
subscription2.request(1);
assertThat(subscriber1.awaitOnError(), instanceOf(UnknownHostException.class));
assertThat(subscriber2.awaitOnError(), instanceOf(UnknownHostException.class));
}
use of io.servicetalk.client.api.ServiceDiscovererEvent in project servicetalk by apple.
the class DefaultDnsClientTest method srvAAAAFailsGeneratesInactive.
private void srvAAAAFailsGeneratesInactive(boolean inactiveEventsOnError, ServiceDiscovererEvent.Status missingRecordStatus) throws Exception {
client.closeAsync().toFuture().get();
client = dnsClientBuilder(missingRecordStatus).inactiveEventsOnError(inactiveEventsOnError).srvHostNameRepeatDelay(ofMillis(200), ofMillis(10)).dnsResolverAddressTypes(IPV4_PREFERRED).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 = nextIp6();
final String ip2 = nextIp();
final int ttl = DEFAULT_TTL + 10;
recordStore.addIPv6Address(targetDomain1, DEFAULT_TTL, ip1);
recordStore.addIPv4Address(targetDomain2, ttl, ip2);
recordStore.addSrv(domain, targetDomain1, targetPort, ttl);
recordStore.addSrv(domain, targetDomain2, targetPort, ttl);
TestPublisherSubscriber<ServiceDiscovererEvent<InetSocketAddress>> subscriber = dnsSrvQuery(domain);
Subscription subscription = subscriber.awaitSubscription();
subscription.request(Long.MAX_VALUE);
List<ServiceDiscovererEvent<InetSocketAddress>> signals = subscriber.takeOnNext(2);
assertHasEvent(signals, ip1, targetPort, AVAILABLE);
assertHasEvent(signals, ip2, targetPort, AVAILABLE);
recordStore.removeIPv6Address(targetDomain1, DEFAULT_TTL, ip1);
assertEvent(subscriber.takeOnNext(), ip1, targetPort, missingRecordStatus);
recordStore.addIPv6Address(targetDomain1, DEFAULT_TTL, ip1);
assertEvent(subscriber.takeOnNext(), ip1, targetPort, AVAILABLE);
}
use of io.servicetalk.client.api.ServiceDiscovererEvent in project servicetalk by apple.
the class DefaultDnsClientTest method multipleSrvChangeSingleADiscover.
@ParameterizedTest(name = "missing-record-status={0}")
@MethodSource("missingRecordStatus")
void multipleSrvChangeSingleADiscover(ServiceDiscovererEvent.Status missingRecordStatus) throws Exception {
setup(missingRecordStatus);
final String domain = "mysvc.apple.com";
final String targetDomain1 = "target1.mysvc.apple.com";
final String targetDomain2 = "target2.mysvc.apple.com";
final String targetDomain3 = "target3.mysvc.apple.com";
final int targetPort1 = 9876;
final int targetPort2 = 9877;
final int targetPort3 = 9879;
final String ip1 = nextIp();
final String ip2 = nextIp();
final String ip3 = nextIp();
recordStore.addSrv(domain, targetDomain1, targetPort1, DEFAULT_TTL);
recordStore.addSrv(domain, targetDomain2, targetPort2, 1);
recordStore.addSrv(domain, targetDomain3, targetPort3, DEFAULT_TTL);
recordStore.addIPv4Address(targetDomain1, DEFAULT_TTL, ip1);
recordStore.addIPv4Address(targetDomain2, DEFAULT_TTL, ip2);
recordStore.addIPv4Address(targetDomain3, DEFAULT_TTL, ip3);
TestPublisherSubscriber<ServiceDiscovererEvent<InetSocketAddress>> subscriber = dnsSrvQuery(domain);
Subscription subscription = subscriber.awaitSubscription();
subscription.request(4);
List<ServiceDiscovererEvent<InetSocketAddress>> signals = subscriber.takeOnNext(3);
assertHasEvent(signals, ip1, targetPort1, AVAILABLE);
assertHasEvent(signals, ip2, targetPort2, AVAILABLE);
assertHasEvent(signals, ip3, targetPort3, AVAILABLE);
recordStore.removeSrv(domain, targetDomain2, targetPort2, 1);
assertEvent(subscriber.takeOnNext(), ip2, targetPort2, missingRecordStatus);
}
use of io.servicetalk.client.api.ServiceDiscovererEvent in project servicetalk by apple.
the class DefaultDnsClientTest method mockThrowSubscriber.
private static <T> Subscriber<ServiceDiscovererEvent<T>> mockThrowSubscriber(CountDownLatch latchOnError, Queue<ServiceDiscovererEvent<T>> queue) {
@SuppressWarnings("unchecked") Subscriber<ServiceDiscovererEvent<T>> subscriber = mock(Subscriber.class);
AtomicInteger onNextCount = new AtomicInteger();
doAnswer(a -> {
Subscription s = a.getArgument(0);
s.request(Long.MAX_VALUE);
return null;
}).when(subscriber).onSubscribe(any(Subscription.class));
doAnswer(a -> {
latchOnError.countDown();
return null;
}).when(subscriber).onError(any());
doAnswer(a -> {
queue.add(a.getArgument(0));
if (onNextCount.getAndIncrement() == 0) {
throw DELIBERATE_EXCEPTION;
}
return null;
}).when(subscriber).onNext(any());
return subscriber;
}
use of io.servicetalk.client.api.ServiceDiscovererEvent in project servicetalk by apple.
the class DefaultDnsClientTest method exceptionInSubscriberOnNext.
@ParameterizedTest(name = "missing-record-status={0}")
@MethodSource("missingRecordStatus")
void exceptionInSubscriberOnNext(ServiceDiscovererEvent.Status missingRecordStatus) throws Exception {
setup(missingRecordStatus);
final String domain = "servicetalk.io";
final String ip = nextIp();
recordStore.addIPv4Address(domain, DEFAULT_TTL, ip);
CountDownLatch latchOnError = new CountDownLatch(1);
BlockingQueue<ServiceDiscovererEvent<InetAddress>> queue = new ArrayBlockingQueue<>(10);
toSource(client.dnsQuery(domain).flatMapConcatIterable(identity())).subscribe(mockThrowSubscriber(latchOnError, queue));
assertEvent(queue.take(), ip, AVAILABLE);
latchOnError.await();
}
Aggregations