use of io.servicetalk.dns.discovery.netty.DnsServiceDiscovererObserver.DnsResolutionObserver in project servicetalk by apple.
the class DnsServiceDiscovererObserverTest method resolutionCompletedThrows.
@Test
void resolutionCompletedThrows() throws Exception {
DnsServiceDiscovererObserver observer = mock(DnsServiceDiscovererObserver.class);
DnsDiscoveryObserver discoveryObserver = mock(DnsDiscoveryObserver.class);
DnsResolutionObserver resolutionObserver = mock(DnsResolutionObserver.class);
when(observer.onNewDiscovery(anyString())).thenReturn(discoveryObserver);
when(discoveryObserver.onNewResolution(anyString())).thenReturn(resolutionObserver);
doThrow(DELIBERATE_EXCEPTION).when(resolutionObserver).resolutionCompleted(any());
DnsClient client = dnsClient(observer);
Publisher<?> publisher = client.dnsQuery(HOST_NAME);
verifyNoInteractions(observer, discoveryObserver, resolutionObserver);
// Wait until SD returns at least one address:
publisher.takeAtMost(1).ignoreElements().toFuture().get();
verify(observer).onNewDiscovery(HOST_NAME);
verify(discoveryObserver).onNewResolution(HOST_NAME);
verify(resolutionObserver).resolutionCompleted(any());
}
use of io.servicetalk.dns.discovery.netty.DnsServiceDiscovererObserver.DnsResolutionObserver in project servicetalk by apple.
the class DnsServiceDiscovererObserverTest method resolutionFailedThrows.
@Test
void resolutionFailedThrows() throws Exception {
DnsServiceDiscovererObserver observer = mock(DnsServiceDiscovererObserver.class);
DnsDiscoveryObserver discoveryObserver = mock(DnsDiscoveryObserver.class);
DnsResolutionObserver resolutionObserver = mock(DnsResolutionObserver.class);
when(observer.onNewDiscovery(anyString())).thenReturn(discoveryObserver);
when(discoveryObserver.onNewResolution(anyString())).thenReturn(resolutionObserver);
doThrow(DELIBERATE_EXCEPTION).when(resolutionObserver).resolutionFailed(any());
DnsClient client = dnsClient(observer);
Publisher<?> publisher = client.dnsQuery(INVALID);
verifyNoInteractions(observer, discoveryObserver, resolutionObserver);
// Wait until SD returns at least one address:
ExecutionException ee = assertThrows(ExecutionException.class, () -> publisher.takeAtMost(1).ignoreElements().toFuture().get());
verify(observer).onNewDiscovery(INVALID);
verify(discoveryObserver).onNewResolution(INVALID);
verify(resolutionObserver).resolutionFailed(ee.getCause());
}
Aggregations