@Test public void testScheduleWhenRunBlocks() throws InterruptedException { when(configuration.getRunPeriod()).thenReturn(2); Server server1 = mock(Server.class); when(server1.getHost()).thenReturn("test1"); when(server1.getQueries()).then(new Answer<ImmutableSet>() { @Override public ImmutableSet answer(InvocationOnMock invocationOnMock) throws Throwable { Thread.sleep(10000L); return ImmutableSet.<Query>of(); } }); when(queryExecutorRepository.getExecutor(same(server1))).thenReturn(null); Server server2 = mock(Server.class); when(server2.getHost()).thenReturn("test2"); when(server2.getQueries()).thenReturn(ImmutableSet.<Query>of()); when(queryExecutorRepository.getExecutor(same(server2))).thenReturn(null); serverScheduler.schedule(server1); serverScheduler.schedule(server2); verify(queryExecutorRepository, timeout(6000L).atLeastOnce()).getExecutor(same(server1)); verify(queryExecutorRepository, timeout(6000L).atLeast(2)).getExecutor(same(server2)); }
public void schedule(Server server) { ServerCommand serverCommand = new ServerCommand(server, queryExecutorRepository, resultProcessor); long runPeriod = serverCommand.getRunPeriodSeconds(configuration.getRunPeriod()); ScheduledFuture<?> scheduledFuture = scheduledExecutor.scheduleAtFixedRate(serverCommand, runPeriod, runPeriod, TimeUnit.SECONDS); synchronized (this.scheduledServerCommands) { this.scheduledServerCommands.add(new ScheduledServerCommand(serverCommand, scheduledFuture)); } log.debug("Scheduled job for server {}", serverCommand.getName()); }
ServerScheduler { public void schedule(Server server) { ServerCommand serverCommand = new ServerCommand(server, queryExecutorRepository, resultProcessor); long runPeriod = serverCommand.getRunPeriodSeconds(configuration.getRunPeriod()); ScheduledFuture<?> scheduledFuture = scheduledExecutor.scheduleAtFixedRate(serverCommand, runPeriod, runPeriod, TimeUnit.SECONDS); synchronized (this.scheduledServerCommands) { this.scheduledServerCommands.add(new ScheduledServerCommand(serverCommand, scheduledFuture)); } log.debug("Scheduled job for server {}", serverCommand.getName()); } }
ServerScheduler { public void schedule(Server server) { ServerCommand serverCommand = new ServerCommand(server, queryExecutorRepository, resultProcessor); long runPeriod = serverCommand.getRunPeriodSeconds(configuration.getRunPeriod()); ScheduledFuture<?> scheduledFuture = scheduledExecutor.scheduleAtFixedRate(serverCommand, runPeriod, runPeriod, TimeUnit.SECONDS); synchronized (this.scheduledServerCommands) { this.scheduledServerCommands.add(new ScheduledServerCommand(serverCommand, scheduledFuture)); } log.debug("Scheduled job for server {}", serverCommand.getName()); } @Inject  ServerScheduler(
			@Nonnull JmxTransConfiguration configuration,
			@Nonnull ScheduledExecutorService scheduledExecutor,
			@Nonnull @Named("queryExecutorRepository") ExecutorRepository queryExecutorRepository,
			@Nonnull ResultProcessor resultProcessor); }
ServerScheduler { public void schedule(Server server) { ServerCommand serverCommand = new ServerCommand(server, queryExecutorRepository, resultProcessor); long runPeriod = serverCommand.getRunPeriodSeconds(configuration.getRunPeriod()); ScheduledFuture<?> scheduledFuture = scheduledExecutor.scheduleAtFixedRate(serverCommand, runPeriod, runPeriod, TimeUnit.SECONDS); synchronized (this.scheduledServerCommands) { this.scheduledServerCommands.add(new ScheduledServerCommand(serverCommand, scheduledFuture)); } log.debug("Scheduled job for server {}", serverCommand.getName()); } @Inject  ServerScheduler(
			@Nonnull JmxTransConfiguration configuration,
			@Nonnull ScheduledExecutorService scheduledExecutor,
			@Nonnull @Named("queryExecutorRepository") ExecutorRepository queryExecutorRepository,
			@Nonnull ResultProcessor resultProcessor); void start(); void schedule(Server server); void unscheduleAll(); void stop(); }
ServerScheduler { public void schedule(Server server) { ServerCommand serverCommand = new ServerCommand(server, queryExecutorRepository, resultProcessor); long runPeriod = serverCommand.getRunPeriodSeconds(configuration.getRunPeriod()); ScheduledFuture<?> scheduledFuture = scheduledExecutor.scheduleAtFixedRate(serverCommand, runPeriod, runPeriod, TimeUnit.SECONDS); synchronized (this.scheduledServerCommands) { this.scheduledServerCommands.add(new ScheduledServerCommand(serverCommand, scheduledFuture)); } log.debug("Scheduled job for server {}", serverCommand.getName()); } @Inject  ServerScheduler(
			@Nonnull JmxTransConfiguration configuration,
			@Nonnull ScheduledExecutorService scheduledExecutor,
			@Nonnull @Named("queryExecutorRepository") ExecutorRepository queryExecutorRepository,
			@Nonnull ResultProcessor resultProcessor); void start(); void schedule(Server server); void unscheduleAll(); void stop();  }