WorkspaceActivityManager { public void update(String wsId, long activityTime) { try { long timeout = getIdleTimeout(wsId); if (timeout > 0) { activityDao.setExpirationTime(wsId, activityTime + timeout); } } catch (ServerException e) { LOG.error(e.getLocalizedMessage(), e); } } @Inject  WorkspaceActivityManager(
      WorkspaceManager workspaceManager,
      WorkspaceActivityDao activityDao,
      EventService eventService,
      @Named("che.limits.workspace.idle.timeout") long timeout,
      @Named("che.limits.workspace.run.timeout") long runTimeout); @VisibleForTesting  WorkspaceActivityManager(
      WorkspaceManager workspaceManager,
      WorkspaceActivityDao activityDao,
      EventService eventService,
      long timeout,
      long runTimeout,
      Clock clock); void update(String wsId, long activityTime); Page<String> findWorkspacesInStatus(
      WorkspaceStatus status, long threshold, int maxItems, long skipCount); long countWorkspacesInStatus(WorkspaceStatus status, long threshold); static final long MINIMAL_TIMEOUT; }
@Test public void shouldAddNewActiveWorkspace() throws Exception { final String wsId = "testWsId"; final long activityTime = 1000L; activityManager.update(wsId, activityTime); verify(workspaceActivityDao, times(1)) .setExpirationTime(eq(wsId), eq(activityTime + DEFAULT_TIMEOUT)); }
@Test public void shouldCeaseToTrackTheWorkspaceActivityAfterStopping() throws Exception { final String wsId = "testWsId"; final long expiredTime = 1000L; activityManager.update(wsId, expiredTime); final EventSubscriber<WorkspaceStatusEvent> subscriber = subscribeAndGetStatusEventSubscriber(); subscriber.onEvent( DtoFactory.newDto(WorkspaceStatusEvent.class) .withStatus(WorkspaceStatus.STOPPED) .withWorkspaceId(wsId)); verify(workspaceActivityDao, times(1)).removeExpiration(eq(wsId)); }