@Test
  public void testSemaphorePreventsFilterChain() throws Exception {
    Configuration configuration = m_injector.getInstance(Configuration.class);
    EasyMock.expect(configuration.getViewRequestThreadPoolMaxSize()).andReturn(1).atLeastOnce();
    EasyMock.expect(configuration.getViewRequestThreadPoolTimeout()).andReturn(2000).atLeastOnce();
    EasyMock.expect(configuration.getClientThreadPoolSize()).andReturn(25).atLeastOnce();

    // servlet mocks
    HttpServletRequest request = createNiceMock(HttpServletRequest.class);
    HttpServletResponse response = createStrictMock(HttpServletResponse.class);
    FilterChain filterChain = createStrictMock(FilterChain.class);

    // semaphore
    EasyMock.expect(m_mockSemaphore.tryAcquire(2000, TimeUnit.MILLISECONDS)).andReturn(false);

    // response
    response.sendError(EasyMock.eq(HttpServletResponse.SC_SERVICE_UNAVAILABLE), EasyMock.anyString());
    EasyMock.expectLastCall().once();

    replayAll();

    ViewThrottleFilter filter = new ViewThrottleFilter();
    m_injector.injectMembers(filter);
    filter.init(null);
    filter.doFilter(request, response, filterChain);

    verifyAll();
  }
Tests that the failure to acquire the {@link Semaphore} stops the request
and returns a {@link HttpServletResponse#SC_SERVICE_UNAVAILABLE}.

@throws Exception
ambari-server/src/test/java/org/apache/ambari/server/view/ViewThrottleFilterTest.java