Search in sources :

Example 21 with Subscription

use of io.servicetalk.concurrent.PublisherSource.Subscription in project servicetalk by apple.

the class DefaultDnsClientTest method singleSrvMultipleADiscover.

@ParameterizedTest(name = "missing-record-status={0}")
@MethodSource("missingRecordStatus")
void singleSrvMultipleADiscover(ServiceDiscovererEvent.Status missingRecordStatus) throws Exception {
    setup(missingRecordStatus);
    final String domain = "mysvc.apple.com";
    final String targetDomain = "target.mysvc.apple.com";
    final int targetPort = 9876;
    final String ip1 = nextIp();
    final String ip2 = nextIp();
    recordStore.addSrv(domain, targetDomain, targetPort, DEFAULT_TTL);
    recordStore.addIPv4Address(targetDomain, DEFAULT_TTL, ip1, ip2);
    TestPublisherSubscriber<ServiceDiscovererEvent<InetSocketAddress>> subscriber = dnsSrvQuery(domain);
    Subscription subscription = subscriber.awaitSubscription();
    subscription.request(2);
    List<ServiceDiscovererEvent<InetSocketAddress>> signals = subscriber.takeOnNext(2);
    assertHasEvent(signals, ip1, targetPort, AVAILABLE);
    assertHasEvent(signals, ip2, targetPort, 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 Subscription

use of io.servicetalk.concurrent.PublisherSource.Subscription 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 23 with Subscription

use of io.servicetalk.concurrent.PublisherSource.Subscription in project servicetalk by apple.

the class DefaultDnsClientTest method multipleSrvSingleADiscover.

@ParameterizedTest(name = "missing-record-status={0}")
@MethodSource("missingRecordStatus")
void multipleSrvSingleADiscover(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 int targetPort1 = 9876;
    final int targetPort2 = 9878;
    final String ip1 = nextIp();
    final String ip2 = nextIp();
    recordStore.addSrv(domain, targetDomain1, targetPort1, DEFAULT_TTL);
    recordStore.addSrv(domain, targetDomain2, targetPort2, DEFAULT_TTL);
    recordStore.addIPv4Address(targetDomain1, DEFAULT_TTL, ip1);
    recordStore.addIPv4Address(targetDomain2, DEFAULT_TTL, ip2);
    TestPublisherSubscriber<ServiceDiscovererEvent<InetSocketAddress>> subscriber = dnsSrvQuery(domain);
    Subscription subscription = subscriber.awaitSubscription();
    subscription.request(2);
    List<ServiceDiscovererEvent<InetSocketAddress>> signals = subscriber.takeOnNext(2);
    assertHasEvent(signals, ip1, targetPort1, AVAILABLE);
    assertHasEvent(signals, ip2, targetPort2, 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 24 with Subscription

use of io.servicetalk.concurrent.PublisherSource.Subscription 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 25 with Subscription

use of io.servicetalk.concurrent.PublisherSource.Subscription 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)

Aggregations

Subscription (io.servicetalk.concurrent.PublisherSource.Subscription)181 Test (org.junit.jupiter.api.Test)107 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)78 CountDownLatch (java.util.concurrent.CountDownLatch)45 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)44 AtomicReference (java.util.concurrent.atomic.AtomicReference)44 TestPublisherSubscriber (io.servicetalk.concurrent.test.internal.TestPublisherSubscriber)38 DELIBERATE_EXCEPTION (io.servicetalk.concurrent.internal.DeliberateException.DELIBERATE_EXCEPTION)31 Nullable (javax.annotation.Nullable)31 TestSubscription (io.servicetalk.concurrent.api.TestSubscription)30 MethodSource (org.junit.jupiter.params.provider.MethodSource)28 ValueSource (org.junit.jupiter.params.provider.ValueSource)28 PublisherSource (io.servicetalk.concurrent.PublisherSource)27 SourceAdapters.toSource (io.servicetalk.concurrent.api.SourceAdapters.toSource)27 MatcherAssert.assertThat (org.hamcrest.MatcherAssert.assertThat)27 Matchers.is (org.hamcrest.Matchers.is)27 Subscriber (io.servicetalk.concurrent.PublisherSource.Subscriber)26 CyclicBarrier (java.util.concurrent.CyclicBarrier)25 ExecutorService (java.util.concurrent.ExecutorService)25 Mockito.mock (org.mockito.Mockito.mock)25