QueueWaitAvailableBrowsersChecker extends WaitAvailableBrowsersChecker { @Override protected void onWait(String user, String browser, Version version, String requestId, int waitAttempt) { super.onWait(user, browser, version, requestId, waitAttempt); if (waitAttempt == 0) { input.produce(new SessionRequestEnqueued() .withRequestId(requestId) .withUser(user) .withBrowser(browser) .withVersion(version.getNumber()) ); } }  @AggregationKey String aggregationKey(SessionRequest event); @BeforeTransit void onBeforeRequest(WaitAvailableBrowserState state, SessionRequest event); @OnTransit void onDequeued(WaitAvailableBrowserState state, SessionRequestDequeued event); @OnTransit void onEnqueued(WaitAvailableBrowserState state, SessionRequestEnqueued event); @OnTimer(cron = "${grid.router.queue.request.timeout.cron}", readOnly = false) void checkAndExpireTimedoutRequests(WaitAvailableBrowserState state);  }
@Test public void testExpiredRequestsRemoval() throws Exception { queue.onWait("user", "firefox", version("33"), "reqId", 0); await().atMost(4, SECONDS).until(() -> state("user-firefox-33"), notNullValue()); assertThat(state("user-firefox-33").size(), equalTo(1)); sleep(1000); helper.invokeTimersFor(QueueWaitAvailableBrowsersChecker.class); await().atMost(2, SECONDS).until(() -> state("user-firefox-33").size(), equalTo(0)); }