Search in sources :

Example 21 with ServiceDiscovererEvent

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

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

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

Example 24 with ServiceDiscovererEvent

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

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