@Test
public void testGlobalScope() throws Exception {

    TestCollapserTimer timer = new TestCollapserTimer();
    HystrixCollapser<List<String>, String, String> collapser1 = new TestGloballyScopedRequestCollapser(timer, "1");
    Future<String> response1 = collapser1.queue();
    Future<String> response2 = new TestGloballyScopedRequestCollapser(timer, "2").queue();
    // simulate a new request
    RequestCollapserFactory.resetRequest();
    Future<String> response3 = new TestGloballyScopedRequestCollapser(timer, "3").queue();
    Future<String> response4 = new TestGloballyScopedRequestCollapser(timer, "4").queue();
    timer.incrementTime(10); // let time pass that equals the default delay/period
    assertEquals("1", response1.get(1000, TimeUnit.MILLISECONDS));
    assertEquals("2", response2.get(1000, TimeUnit.MILLISECONDS));
    assertEquals("3", response3.get(1000, TimeUnit.MILLISECONDS));
    assertEquals("4", response4.get(1000, TimeUnit.MILLISECONDS));
    // despite having cleared the cache in between we should have a single execution because this is on the global not request cache
    assertEquals(1, HystrixRequestLog.getCurrentRequest().getAllExecutedCommands().size());
    Iterator<HystrixInvokableInfo<?>> cmdIterator = HystrixRequestLog.getCurrentRequest().getAllExecutedCommands().iterator();
    assertEquals(4, cmdIterator.next().getNumberCollapsed());
}