private StreamPumper(InputStream in, StreamConsumer streamConsumer, String prefix, String encoding) { this(in, streamConsumer, prefix, encoding, new SystemTimeClock()); }
public DateTime timeoutTime(Timeout timeout) { return timeoutTime(timeout.inMillis()); }
public DateTime currentDateTime() { return new DateTime(currentTime()); }
@Test public void shouldGiveTimeoutTime() throws Exception { DateTime expected = new DateTime().plusMillis((int) Timeout.NINETY_SECONDS.inMillis()); DateTime actual = new SystemTimeClock().timeoutTime(Timeout.NINETY_SECONDS); assertThat(actual.equals(expected) || actual.isAfter(expected),is(true)); } }
public void sleepForSeconds(long seconds) throws InterruptedException { sleepForMillis(seconds * 1000); }
public TempFiles() { this.clock = new SystemTimeClock(); Runtime.getRuntime().addShutdownHook(new Thread(cleanupHook)); }
public static PerfTimer start(String message) { return start(message, new SystemTimeClock()); }
public void fetch(DefaultGoPublisher goPublisher, FetchArtifactBuilder fetchArtifactBuilder) { try { String fetchMsg = String.format("Fetching artifact [%s] from [%s]", fetchArtifactBuilder.getSrc(), fetchArtifactBuilder.jobLocatorForDisplay()); goPublisher.taggedConsumeLineWithPrefix(DefaultGoPublisher.OUT, fetchMsg); fetchArtifactBuilder.fetch(new DownloadAction(httpService, goPublisher, new SystemTimeClock()), urlService); } catch (Exception e) { String fetchMsg = String.format("Failed to save artifact [%s] to [%s]", fetchArtifactBuilder.getSrc(), fetchArtifactBuilder.getDest()); LOGGER.error(fetchMsg, e); goPublisher.taggedConsumeLineWithPrefix(DefaultGoPublisher.ERR, fetchMsg); throw new RuntimeException(e); } }
@After public void tearDown() { ServerHealthState.clock = new SystemTimeClock(); }
@After public void tearDown() { ServerHealthState.clock = new SystemTimeClock(); }
@Test public void testPumping() { String line1 = "line1"; String line2 = "line2"; String lines = line1 + "\n" + line2; ByteArrayInputStream inputStream = new ByteArrayInputStream(lines.getBytes()); TestConsumer consumer = new TestConsumer(); StreamPumper pumper = new StreamPumper(inputStream, consumer, "", "utf-8", new SystemTimeClock()); new Thread(pumper).start(); //Check the consumer to see if it got both lines. assertThat(consumer.wasLineConsumed(line1, 1000), is(true)); assertThat(consumer.wasLineConsumed(line2, 1000), is(true)); }
private ConfigCache configCache; private GoConfigCloner cloner = new GoConfigCloner(); private Clock clock = new SystemTimeClock(); private InstanceFactory instanceFactory; private SystemEnvironment systemEnvironment;