private void sampleGetRelativeTimeSpanString() { List<String> text = new ArrayList<String>(); DateTime now = DateTime.now(); text.add("Short future: " + DateUtils.getRelativeTimeSpanString(this, now.plusMinutes(25))); text.add("Medium future: " + DateUtils.getRelativeTimeSpanString(this, now.plusHours(5))); text.add("Long future: " + DateUtils.getRelativeTimeSpanString(this, now.plusDays(3))); text.add("Short past: " + DateUtils.getRelativeTimeSpanString(this, now.minusMinutes(25))); text.add("Medium past: " + DateUtils.getRelativeTimeSpanString(this, now.minusHours(5))); text.add("Long past: " + DateUtils.getRelativeTimeSpanString(this, now.minusDays(3))); addSample("DateUtils.getRelativeTimeSpanString()", text); }
private void sampleGetRelativeDateTimeString() { List<String> text = new ArrayList<String>(); DateTime now = DateTime.now(); text.add("Short future: " + DateUtils.getRelativeDateTimeString(this, now.plusMinutes(25), null, 0)); text.add("Medium future: " + DateUtils.getRelativeDateTimeString(this, now.plusHours(5), null, 0)); text.add("Long future: " + DateUtils.getRelativeDateTimeString(this, now.plusDays(3), null, 0)); text.add("Short past: " + DateUtils.getRelativeDateTimeString(this, now.minusMinutes(25), null, 0)); text.add("Medium past: " + DateUtils.getRelativeDateTimeString(this, now.minusHours(5), null, 0)); text.add("Long past: " + DateUtils.getRelativeDateTimeString(this, now.minusDays(3), null, 0)); addSample("DateUtils.getRelativeDateTimeString()", text); }
private void sampleGetRelativeTimeSpanStringWithPreposition() { List<String> text = new ArrayList<String>(); DateTime now = DateTime.now(); text.add("Short future: " + DateUtils.getRelativeTimeSpanString(this, now.plusMinutes(25), true)); text.add("Medium future: " + DateUtils.getRelativeTimeSpanString(this, now.plusHours(5), true)); text.add("Long future: " + DateUtils.getRelativeTimeSpanString(this, now.plusDays(3), true)); text.add("Short past: " + DateUtils.getRelativeTimeSpanString(this, now.minusMinutes(25), true)); text.add("Medium past: " + DateUtils.getRelativeTimeSpanString(this, now.minusHours(5), true)); text.add("Long past: " + DateUtils.getRelativeTimeSpanString(this, now.minusDays(3), true)); addSample("DateUtils.getRelativeTimeSpanString() (with preposition)", text); }
public static void setBuildingState(JobInstance instance) { instance.setAgentUuid("1234"); DateTime now = new DateTime(); Date scheduledDate = now.minusMinutes(5).toDate(); instance.setScheduledDate(scheduledDate); setTransitionConditionally(instance, JobState.Scheduled, scheduledDate); setTransitionConditionally(instance, JobState.Assigned, now.minusMinutes(4).toDate()); setTransitionConditionally(instance, JobState.Preparing, now.minusMinutes(3).toDate()); setTransitionConditionally(instance, JobState.Building, now.minusMinutes(2).toDate()); }
private String buildStreamDetailsURL(URI baseUri, AlertCondition.CheckResult checkResult, Stream stream) { // Return an informational message if the web interface URL hasn't been set if (baseUri == null || isNullOrEmpty(baseUri.getHost())) { return "Please configure 'transport_email_web_interface_url' in your Graylog configuration file."; } int time = 5; if (checkResult.getTriggeredCondition().getParameters().get("time") != null) { time = (int) checkResult.getTriggeredCondition().getParameters().get("time"); } DateTime dateAlertEnd = checkResult.getTriggeredAt(); DateTime dateAlertStart = dateAlertEnd.minusMinutes(time); String alertStart = Tools.getISO8601String(dateAlertStart); String alertEnd = Tools.getISO8601String(dateAlertEnd); return baseUri + "/streams/" + stream.getId() + "/messages?rangetype=absolute&from=" + alertStart + "&to=" + alertEnd + "&q=*"; }
@Override public void doRun() { final DateTime now = Tools.nowUTC(); final int secondOfMinute = now.getSecondOfMinute(); // on the top of every minute, we flush the current throughput if (secondOfMinute == 0) { LOG.trace("Calculating input and output traffic for the previous minute"); final long currentInputBytes = inputCounter.getCount(); final long currentOutputBytes = outputCounter.getCount(); final long currentDecodedBytes = decodedCounter.getCount(); final long inputLastMinute = currentInputBytes - previousInputBytes; previousInputBytes = currentInputBytes; final long outputBytesLastMinute = currentOutputBytes - previousOutputBytes; previousOutputBytes = currentOutputBytes; final long decodedBytesLastMinute = currentDecodedBytes - previousDecodedBytes; previousDecodedBytes = currentDecodedBytes; if (LOG.isDebugEnabled()) { final Size in = Size.bytes(inputLastMinute); final Size out = Size.bytes(outputBytesLastMinute); final Size decoded = Size.bytes(decodedBytesLastMinute); LOG.debug("Traffic in the last minute: in: {} bytes ({} MB), out: {} bytes ({} MB}), decoded: {} bytes ({} MB})", in, in.toMegabytes(), out, out.toMegabytes(), decoded, decoded.toMegabytes()); } final DateTime previousMinute = now.minusMinutes(1); trafficService.updateTraffic(previousMinute, nodeId, inputLastMinute, outputBytesLastMinute, decodedBytesLastMinute); } }
@Test(timeout = 60_000L) public void testShutdownWithPrevTime() throws Exception { EasyMock.expect(req.getAttribute(AuthConfig.DRUID_AUTHORIZATION_CHECKED)) .andReturn(null) .anyTimes(); EasyMock.expect(req.getAttribute(AuthConfig.DRUID_ALLOW_UNSECURED_PATH)).andReturn(null).anyTimes(); EasyMock.expect(req.getAttribute(AuthConfig.DRUID_AUTHENTICATION_RESULT)) .andReturn(AllowAllAuthenticator.ALLOW_ALL_RESULT) .anyTimes(); req.setAttribute(AuthConfig.DRUID_AUTHORIZATION_CHECKED, true); EasyMock.expectLastCall().anyTimes(); EasyMock.replay(req); firehose.shutdown(DateTimes.nowUtc().minusMinutes(2).toString(), req); while (!firehose.isClosed()) { Thread.sleep(50); } }
public static JobInstance building(String jobConfigName, Date startBuildingDate) { final JobInstance instance = new JobInstance(jobConfigName); instance.changeState(JobState.Building, startBuildingDate); instance.setScheduledDate(new DateTime().minusMinutes(5).toDate()); instance.setIdentifier(defaultJobIdentifier(jobConfigName)); return instance; }
/** * Test metric reporting methods, including InMemoryMetricEmitter methods */ @Test public void managerEmitterHandlingTest() throws Exception { // metrics use System.currentTimeMillis, so that method should be the millis provider final DateTime aboutNow = new DateTime(System.currentTimeMillis()); this.emitter.purgeAllData(); final Date from = aboutNow.minusMinutes(1).toDate(); this.metric.notifyManager(); this.emitterWrapper.countDownLatch.await(10L, TimeUnit.SECONDS); final Date to = aboutNow.plusMinutes(1).toDate(); final List<InMemoryHistoryNode> nodes = this.emitter.getMetrics("FakeMetric", from, to, false); assertEquals("Failed to report metric", 1, nodes.size()); assertEquals("Failed to report metric", nodes.get(0).getValue(), 4); }
while ((line = reader.readLine()) != null) { if (i == 15) { // for the 15th line, use a time before the window dt = dt.minusMinutes(10);
while ((line = reader.readLine()) != null) { if (i == 15) { // for the 15th line, use a time before the window dt = dt.minusMinutes(10); } else if (i == 16) { // remember this time to use in the expected response from the groupBy query dtGroupBy = dt;
public static JobInstance buildEndingWithState(JobState endState, JobResult result, String jobConfig) { final JobInstance instance = new JobInstance(jobConfig); instance.setAgentUuid("1234"); instance.setId(1L); instance.setIdentifier(defaultJobIdentifier(jobConfig)); instance.setState(endState); instance.setTransitions(new JobStateTransitions()); DateTime now = new DateTime(); Date scheduledDate = now.minusMinutes(5).toDate(); instance.setScheduledDate(scheduledDate); List<JobState> orderedStates = orderedBuildStates(); DateTime stateDate = new DateTime(scheduledDate); for (JobState stateToCompareTo : orderedStates) { if (endState.compareTo(stateToCompareTo) >= 0) { instance.changeState(stateToCompareTo, stateDate.toDate()); stateDate = stateDate.plusMinutes(1); } } if (endState.equals(JobState.Completed)) { instance.setResult(result); } return instance; }
@Test public void testWorksNoPrefix() throws IOException, DataRecordException { DatePartitionedAvroFileSource source = new DatePartitionedAvroFileSource(); SourceState state = new SourceState(); state.setProp(ConfigurationKeys.SOURCE_FILEBASED_FS_URI, ConfigurationKeys.LOCAL_FS_URI); state.setProp(ConfigurationKeys.EXTRACT_NAMESPACE_NAME_KEY, SOURCE_ENTITY); state.setProp(ConfigurationKeys.SOURCE_FILEBASED_DATA_DIRECTORY, OUTPUT_DIR + Path.SEPARATOR + SOURCE_ENTITY + Path.SEPARATOR + PREFIX); state.setProp(ConfigurationKeys.SOURCE_ENTITY, SOURCE_ENTITY); state.setProp(ConfigurationKeys.SOURCE_MAX_NUMBER_OF_PARTITIONS, 2); state.setProp("date.partitioned.source.partition.pattern", DATE_PATTERN); state.setProp("date.partitioned.source.min.watermark.value", DateTimeFormat.forPattern(DATE_PATTERN).print( this.startDateTime.minusMinutes(1))); state.setProp(ConfigurationKeys.EXTRACT_TABLE_TYPE_KEY, TableType.SNAPSHOT_ONLY); state.setProp("date.partitioned.source.partition.suffix", SUFFIX); //Read data partitioned by minutes, i.e each workunit is assigned records under the same YYYY/MM/dd/HH_mm directory List<WorkUnit> workunits = source.getWorkunits(state); Assert.assertEquals(workunits.size(), 4); verifyWorkUnits(workunits); }
@Test public void testReadPartitionsByMinute() throws IOException, DataRecordException { DatePartitionedAvroFileSource source = new DatePartitionedAvroFileSource(); SourceState state = new SourceState(); state.setProp(ConfigurationKeys.SOURCE_FILEBASED_FS_URI, ConfigurationKeys.LOCAL_FS_URI); state.setProp(ConfigurationKeys.EXTRACT_NAMESPACE_NAME_KEY, SOURCE_ENTITY); state.setProp(ConfigurationKeys.SOURCE_FILEBASED_DATA_DIRECTORY, OUTPUT_DIR + Path.SEPARATOR + SOURCE_ENTITY); state.setProp(ConfigurationKeys.SOURCE_ENTITY, SOURCE_ENTITY); state.setProp(ConfigurationKeys.SOURCE_MAX_NUMBER_OF_PARTITIONS, 2); state.setProp("date.partitioned.source.partition.pattern", DATE_PATTERN); state.setProp("date.partitioned.source.min.watermark.value", DateTimeFormat.forPattern(DATE_PATTERN).print( this.startDateTime.minusMinutes(1))); state.setProp(ConfigurationKeys.EXTRACT_TABLE_TYPE_KEY, TableType.SNAPSHOT_ONLY); state.setProp("date.partitioned.source.partition.prefix", PREFIX); state.setProp("date.partitioned.source.partition.suffix", SUFFIX); //Read data partitioned by minutes, i.e each workunit is assigned records under the same YYYY/MM/dd/HH_mm directory List<WorkUnit> workunits = source.getWorkunits(state); Assert.assertEquals(workunits.size(), 4); verifyWorkUnits(workunits); }
Interval interval = new Interval(t.minusMinutes(1), t.plusMinutes(1));
@Test public void testReadPartitionsByMinuteWithLeadtime() throws IOException, DataRecordException { DatePartitionedAvroFileSource source = new DatePartitionedAvroFileSource(); SourceState state = new SourceState(); state.setProp(ConfigurationKeys.SOURCE_FILEBASED_FS_URI, ConfigurationKeys.LOCAL_FS_URI); state.setProp(ConfigurationKeys.EXTRACT_NAMESPACE_NAME_KEY, SOURCE_ENTITY); state.setProp(ConfigurationKeys.SOURCE_FILEBASED_DATA_DIRECTORY, OUTPUT_DIR + Path.SEPARATOR + SOURCE_ENTITY); state.setProp(ConfigurationKeys.SOURCE_ENTITY, SOURCE_ENTITY); state.setProp(ConfigurationKeys.SOURCE_MAX_NUMBER_OF_PARTITIONS, 2); state.setProp("date.partitioned.source.partition.pattern", DATE_PATTERN); state.setProp("date.partitioned.source.min.watermark.value", DateTimeFormat.forPattern(DATE_PATTERN).print( this.startDateTime.minusMinutes(1))); state.setProp(ConfigurationKeys.EXTRACT_TABLE_TYPE_KEY, TableType.SNAPSHOT_ONLY); state.setProp("date.partitioned.source.partition.prefix", PREFIX); state.setProp("date.partitioned.source.partition.suffix", SUFFIX); state.setProp("date.partitioned.source.partition.lead_time.size", "3"); state.setProp("date.partitioned.source.partition.lead_time.granularity", "HOUR"); /* * Since lead time is 3 hours, only the first WorkUnit (which is 6 hours old, rest are 2hrs) should get * picked up */ List<WorkUnit> workunits = source.getWorkunits(state); Assert.assertEquals(workunits.size(), 1); verifyWorkUnits(workunits, workunits.size()); }
@Test public void testJobStateNotCopiedToWorkUnit() { DatePartitionedAvroFileSource source = new DatePartitionedAvroFileSource(); SourceState state = new SourceState(); state.setProp(ConfigurationKeys.SOURCE_FILEBASED_FS_URI, ConfigurationKeys.LOCAL_FS_URI); state.setProp(ConfigurationKeys.EXTRACT_NAMESPACE_NAME_KEY, SOURCE_ENTITY); state.setProp(ConfigurationKeys.SOURCE_FILEBASED_DATA_DIRECTORY, OUTPUT_DIR + Path.SEPARATOR + SOURCE_ENTITY); state.setProp(ConfigurationKeys.SOURCE_ENTITY, SOURCE_ENTITY); state.setProp(ConfigurationKeys.SOURCE_MAX_NUMBER_OF_PARTITIONS, 2); state.setProp("date.partitioned.source.partition.pattern", DATE_PATTERN); state.setProp("date.partitioned.source.min.watermark.value", DateTimeFormat.forPattern(DATE_PATTERN).print( this.startDateTime.minusMinutes(1))); state.setProp(ConfigurationKeys.EXTRACT_TABLE_TYPE_KEY, TableType.SNAPSHOT_ONLY); state.setProp("date.partitioned.source.partition.prefix", PREFIX); state.setProp("date.partitioned.source.partition.suffix", SUFFIX); String dummyKey = "dummy.job.config"; state.setProp(dummyKey, "dummy"); List<WorkUnit> workunits = source.getWorkunits(state); Assert.assertEquals(workunits.size(), 4); for(WorkUnit wu : workunits) { if (wu instanceof MultiWorkUnit) { for (WorkUnit workUnit : ((MultiWorkUnit) wu).getWorkUnits()) { Assert.assertFalse(workUnit.contains(dummyKey)); } } else { Assert.assertFalse(wu.contains(dummyKey)); } } }
assertEquals("1 minute ago", DateUtils.getRelativeTimeSpanString(ctx, DateTime.now().minusMinutes(1))); assertEquals("30 minutes ago", DateUtils.getRelativeTimeSpanString(ctx, DateTime.now().minusMinutes(30))); assertEquals("in 1 min", DateUtils.getRelativeTimeSpanString(ctx, DateTime.now().plusMinutes(1), DateUtils.FORMAT_ABBREV_RELATIVE)); assertEquals("in 30 mins", DateUtils.getRelativeTimeSpanString(ctx, DateTime.now().plusMinutes(30), DateUtils.FORMAT_ABBREV_RELATIVE)); assertEquals("1 min ago", DateUtils.getRelativeTimeSpanString(ctx, DateTime.now().minusMinutes(1), DateUtils.FORMAT_ABBREV_RELATIVE)); assertEquals("30 mins ago", DateUtils.getRelativeTimeSpanString(ctx, DateTime.now().minusMinutes(30), DateUtils.FORMAT_ABBREV_RELATIVE));
conditions.setNotBefore(DateTime.now().minusMinutes(1)); conditions.setNotOnOrAfter(DateTime.now().plusMinutes(1));
assertEquals("30 seconds ago, 12:34", DateUtils.getRelativeDateTimeString(ctx, mNow.minusSeconds(30), null, 0)); assertEquals("in 30 minutes, 13:05", DateUtils.getRelativeDateTimeString(ctx, mNow.plusMinutes(30), null, 0)); assertEquals("30 minutes ago, 12:05", DateUtils.getRelativeDateTimeString(ctx, mNow.minusMinutes(30), null, 0)); assertEquals("in 3 hours, 15:35", DateUtils.getRelativeDateTimeString(ctx, mNow.plusHours(3), null, 0)); assertEquals("3 hours ago, 09:35", DateUtils.getRelativeDateTimeString(ctx, mNow.minusHours(3), null, 0));