Search in sources :

Example 6 with ServiceDiscovererEvent

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));
}
Also used : ServiceDiscovererEvent(io.servicetalk.client.api.ServiceDiscovererEvent) DefaultServiceDiscovererEvent(io.servicetalk.client.api.DefaultServiceDiscovererEvent) UnknownHostException(java.net.UnknownHostException) Subscription(io.servicetalk.concurrent.PublisherSource.Subscription) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) MethodSource(org.junit.jupiter.params.provider.MethodSource)

Example 7 with ServiceDiscovererEvent

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);
}
Also used : ServiceDiscovererEvent(io.servicetalk.client.api.ServiceDiscovererEvent) DefaultServiceDiscovererEvent(io.servicetalk.client.api.DefaultServiceDiscovererEvent) Subscription(io.servicetalk.concurrent.PublisherSource.Subscription)

Example 8 with ServiceDiscovererEvent

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);
}
Also used : ServiceDiscovererEvent(io.servicetalk.client.api.ServiceDiscovererEvent) DefaultServiceDiscovererEvent(io.servicetalk.client.api.DefaultServiceDiscovererEvent) Subscription(io.servicetalk.concurrent.PublisherSource.Subscription) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) MethodSource(org.junit.jupiter.params.provider.MethodSource)

Example 9 with ServiceDiscovererEvent

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;
}
Also used : ServiceDiscovererEvent(io.servicetalk.client.api.ServiceDiscovererEvent) DefaultServiceDiscovererEvent(io.servicetalk.client.api.DefaultServiceDiscovererEvent) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Subscription(io.servicetalk.concurrent.PublisherSource.Subscription)

Example 10 with ServiceDiscovererEvent

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();
}
Also used : ServiceDiscovererEvent(io.servicetalk.client.api.ServiceDiscovererEvent) DefaultServiceDiscovererEvent(io.servicetalk.client.api.DefaultServiceDiscovererEvent) ArrayBlockingQueue(java.util.concurrent.ArrayBlockingQueue) CountDownLatch(java.util.concurrent.CountDownLatch) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) MethodSource(org.junit.jupiter.params.provider.MethodSource)

Aggregations

ServiceDiscovererEvent (io.servicetalk.client.api.ServiceDiscovererEvent)28 DefaultServiceDiscovererEvent (io.servicetalk.client.api.DefaultServiceDiscovererEvent)27 Subscription (io.servicetalk.concurrent.PublisherSource.Subscription)24 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)20 MethodSource (org.junit.jupiter.params.provider.MethodSource)20 UnknownHostException (java.net.UnknownHostException)10 InetSocketAddress (java.net.InetSocketAddress)4 HostAndPort (io.servicetalk.transport.api.HostAndPort)2 ArrayList (java.util.ArrayList)2 Collection (java.util.Collection)2 ByteBuf (io.netty.buffer.ByteBuf)1 EventLoop (io.netty.channel.EventLoop)1 SocketChannel (io.netty.channel.socket.SocketChannel)1 DefaultDnsQuestion (io.netty.handler.codec.dns.DefaultDnsQuestion)1 DefaultDnsRecordDecoder.decodeName (io.netty.handler.codec.dns.DefaultDnsRecordDecoder.decodeName)1 DnsRawRecord (io.netty.handler.codec.dns.DnsRawRecord)1 DnsRecord (io.netty.handler.codec.dns.DnsRecord)1 SRV (io.netty.handler.codec.dns.DnsRecordType.SRV)1 ResolvedAddressTypes (io.netty.resolver.ResolvedAddressTypes)1 DefaultDnsCache (io.netty.resolver.dns.DefaultDnsCache)1