@Test
public void testConfigDataWithStreamOnError() throws IOException, InterruptedException {

    servlet = new HystrixConfigSseServlet(streamOfOnNextThenOnError, 10);
    try {
        servlet.init();
    } catch (ServletException ex) {
    }
    final AtomicInteger writes = new AtomicInteger(0);
    when(mockReq.getParameter("delay")).thenReturn("100");
    when(mockResp.getWriter()).thenReturn(mockPrintWriter);
    Mockito.doAnswer(new Answer<Void>() {
        @Override
        public Void answer(InvocationOnMock invocation) throws Throwable {
            String written = (String) invocation.getArguments()[0];
            System.out.println("ARG : " + written);
            if (!written.contains("ping")) {
                writes.incrementAndGet();
            }
            return null;
        }
    }).when(mockPrintWriter).print(Mockito.anyString());
    Runnable simulateClient = new Runnable() {
        @Override
        public void run() {
            try {
                servlet.doGet(mockReq, mockResp);
            } catch (ServletException ex) {
                fail(ex.getMessage());
            } catch (IOException ex) {
                fail(ex.getMessage());
            }
        }
    };
    Thread t = new Thread(simulateClient);
    t.start();
    try {
        Thread.sleep(1000);
        System.out.println(System.currentTimeMillis() + " Woke up from sleep : " + Thread.currentThread().getName());
    } catch (InterruptedException ex) {
        fail(ex.getMessage());
    }
    assertEquals(1, writes.get());
    assertEquals(0, servlet.getNumberCurrentConnections());
}