// Path: src/main/java/com/spotify/dns/statistics/DnsReporter.java
// public interface DnsReporter {
//   /**
//    * Report resolve timing.
//    * @return A new timing context.
//    */
//   DnsTimingContext resolveTimer();
// 
//   /**
//    * Report that an empty response has been received from a resolve.
//    */
//   void reportEmpty();
// 
//   /**
//    * Report that a resolve resulting in a failure.
//    * @param error The exception causing the failure.
//    */
//   void reportFailure(Throwable error);
// }
// 
// Path: src/main/java/com/spotify/dns/statistics/DnsTimingContext.java
// @FunctionalInterface
// public interface DnsTimingContext {
//   void stop();
// }


import static org.hamcrest.CoreMatchers.containsString;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.Matchers.containsInAnyOrder;
import static org.junit.Assert.assertThat;
import static org.junit.Assert.assertTrue;
import static org.mockito.Matchers.isA;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
import com.jayway.awaitility.Awaitility;
import com.spotify.dns.statistics.DnsReporter;
import com.spotify.dns.statistics.DnsTimingContext;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.Set;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.TimeUnit;
import org.hamcrest.Matchers;
import org.junit.Before;
import org.junit.Test;
import org.xbill.DNS.SimpleResolver;

  @Test
  public void shouldReturnResultsForValidQuery() throws ExecutionException, InterruptedException {
    assertThat(resolver.resolve("_spotify-client._tcp.spotify.com").isEmpty(), is(false));
    assertThat(resolver.resolveAsync("_spotify-client._tcp.spotify.com").toCompletableFuture().get().isEmpty(), is(false));
  }

  @Test
  public void testCorrectSequenceOfNotifications() {
    ChangeNotifier<LookupResult> notifier = ChangeNotifiers.aggregate(
        DnsSrvWatchers.newBuilder(resolver)
            .polling(100, TimeUnit.MILLISECONDS)
            .build().watch("_spotify-client._tcp.spotify.com"));

    final List<String> changes = Collections.synchronizedList(new ArrayList<>());

    notifier.setListener(changeNotification -> {
      Set<LookupResult> current = changeNotification.current();
      if (!ChangeNotifiers.isInitialEmptyData(current)) {
        changes.add(current.isEmpty() ? "empty" : "data");
      }
    }, true);
    assertThat(changes, Matchers.empty());
    Awaitility.await().atMost(2, TimeUnit.SECONDS).until(() -> changes.size() >= 1);
    assertThat(changes, containsInAnyOrder("data"));
  }

  @Test
  public void shouldTrackMetricsWhenToldTo() throws ExecutionException, InterruptedException {
    final DnsReporter reporter = mock(DnsReporter.class);
// Path: src/main/java/com/spotify/dns/statistics/DnsReporter.java
// public interface DnsReporter {
//   /**
//    * Report resolve timing.
//    * @return A new timing context.
//    */
//   DnsTimingContext resolveTimer();
// 
//   /**
//    * Report that an empty response has been received from a resolve.
//    */
//   void reportEmpty();
// 
//   /**
//    * Report that a resolve resulting in a failure.
//    * @param error The exception causing the failure.
//    */
//   void reportFailure(Throwable error);
// }
// 
// Path: src/main/java/com/spotify/dns/statistics/DnsTimingContext.java
// @FunctionalInterface
// public interface DnsTimingContext {
//   void stop();
// }


// Path: src/test/java/com/spotify/dns/DnsSrvResolversIT.java
import static org.hamcrest.CoreMatchers.containsString;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.Matchers.containsInAnyOrder;
import static org.junit.Assert.assertThat;
import static org.junit.Assert.assertTrue;
import static org.mockito.Matchers.isA;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
import com.jayway.awaitility.Awaitility;
import com.spotify.dns.statistics.DnsReporter;
import com.spotify.dns.statistics.DnsTimingContext;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.Set;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.TimeUnit;
import org.hamcrest.Matchers;
import org.junit.Before;
import org.junit.Test;
import org.xbill.DNS.SimpleResolver;


  @Test
  public void shouldReturnResultsForValidQuery() throws ExecutionException, InterruptedException {
    assertThat(resolver.resolve("_spotify-client._tcp.spotify.com").isEmpty(), is(false));
    assertThat(resolver.resolveAsync("_spotify-client._tcp.spotify.com").toCompletableFuture().get().isEmpty(), is(false));
  }

  @Test
  public void testCorrectSequenceOfNotifications() {
    ChangeNotifier<LookupResult> notifier = ChangeNotifiers.aggregate(
        DnsSrvWatchers.newBuilder(resolver)
            .polling(100, TimeUnit.MILLISECONDS)
            .build().watch("_spotify-client._tcp.spotify.com"));

    final List<String> changes = Collections.synchronizedList(new ArrayList<>());

    notifier.setListener(changeNotification -> {
      Set<LookupResult> current = changeNotification.current();
      if (!ChangeNotifiers.isInitialEmptyData(current)) {
        changes.add(current.isEmpty() ? "empty" : "data");
      }
    }, true);
    assertThat(changes, Matchers.empty());
    Awaitility.await().atMost(2, TimeUnit.SECONDS).until(() -> changes.size() >= 1);
    assertThat(changes, containsInAnyOrder("data"));
  }

  @Test
  public void shouldTrackMetricsWhenToldTo() throws ExecutionException, InterruptedException {
    final DnsReporter reporter = mock(DnsReporter.class);
    final DnsTimingContext timingReporter = mock(DnsTimingContext.class);