### Question:
Race { public static void start(Context context, String[] urls, Listener listener) { Prober prober = new GoProber(context); start(prober, urls, listener); }  static void start(Context context, String[] urls, Listener listener);  }### Answer:
@Test public void Success() throws Exception { final int N = 7; String[] urls = new String[N]; Semaphore done = new Semaphore(0); Race.start(new SuccessProber(), urls, (int index) -> { assertTrue(index >= 0); assertTrue(index < N); done.release(); if (done.availablePermits() > 1) { fail(); } }); done.acquire(); }
@Test public void AllFail() throws Exception { final int N = 7; String[] urls = new String[N]; for (int i = 0; i < N; ++i) { urls[i] = String.format("server%d", i); } Semaphore done = new Semaphore(0); Race.start(new FailProber(), urls, (int index) -> { assertEquals(-1, index); done.release(); }); done.acquire(); }
@Test public void HalfFail() throws Exception { final int N = 7; String[] urls = new String[N]; for (int i = 0; i < N; ++i) { urls[i] = String.format("%d", i); } Semaphore done = new Semaphore(0); Race.start(new HalfProber(), urls, (int index) -> { assertTrue(index >= 0); assertTrue(index < N); assertEquals(0, index % 2); done.release(); }); done.acquire(); }