Search in sources :

Example 16 with ServiceDiscovererEvent

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));
}
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 17 with ServiceDiscovererEvent

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();
}
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)

Example 18 with ServiceDiscovererEvent

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);
        }
    }
}
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 19 with ServiceDiscovererEvent

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));
}
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 20 with ServiceDiscovererEvent

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));
}
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)

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