@Test
  public void testRequestTTL() throws Exception {
    InputStream jmxInputStream = IOUtils.toInputStream("{ \"beans\": [] }");

    // only allow a single call to the mock
    StreamProvider streamProvider = createStrictMock(StreamProvider.class);
    EasyMock.expect(streamProvider.readFrom(JMX_URL)).andReturn(jmxInputStream).once();

    replayAll();

    m_service.startAsync();
    m_service.awaitRunning(METRICS_SERVICE_TIMEOUT, TimeUnit.SECONDS);

    // make the service synchronous
    m_service.setThreadPoolExecutor(new SynchronousThreadPoolExecutor());

    // make 100 requests in rapid succession to the same URL
    for (int i = 0; i < 100; i++) {
      m_service.submitRequest(MetricSourceType.JMX, streamProvider, JMX_URL);
    }

    verifyAll();
  }
Tests that many requests to the same URL do not invoke the stream provider
more than once.
ambari-server/src/test/java/org/apache/ambari/server/state/services/MetricsRetrievalServiceTest.java