Search in sources :

Example 1 with DnsResolutionObserver

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());
}
Also used : DnsDiscoveryObserver(io.servicetalk.dns.discovery.netty.DnsServiceDiscovererObserver.DnsDiscoveryObserver) DnsResolutionObserver(io.servicetalk.dns.discovery.netty.DnsServiceDiscovererObserver.DnsResolutionObserver) Test(org.junit.jupiter.api.Test)

Example 2 with DnsResolutionObserver

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());
}
Also used : DnsDiscoveryObserver(io.servicetalk.dns.discovery.netty.DnsServiceDiscovererObserver.DnsDiscoveryObserver) DnsResolutionObserver(io.servicetalk.dns.discovery.netty.DnsServiceDiscovererObserver.DnsResolutionObserver) ExecutionException(java.util.concurrent.ExecutionException) Test(org.junit.jupiter.api.Test)

Aggregations

DnsDiscoveryObserver (io.servicetalk.dns.discovery.netty.DnsServiceDiscovererObserver.DnsDiscoveryObserver)2 DnsResolutionObserver (io.servicetalk.dns.discovery.netty.DnsServiceDiscovererObserver.DnsResolutionObserver)2 Test (org.junit.jupiter.api.Test)2 ExecutionException (java.util.concurrent.ExecutionException)1