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