List of usage examples for java.util.concurrent TimeUnit HOURS
TimeUnit HOURS
To view the source code for java.util.concurrent TimeUnit HOURS.
Click Source Link
From source file:org.apache.metron.profiler.client.stellar.WindowLookbackTest.java
@Test public void testSpecifyingOnlySelector() { String stellarStatement = "PROFILE_WINDOW('1 hour')"; Map<String, Object> variables = new HashMap<>(); StellarProcessor stellar = new StellarProcessor(); List<ProfilePeriod> periods = (List<ProfilePeriod>) stellar.parse(stellarStatement, k -> variables.get(k), resolver, context);/*from ww w. j av a 2 s . c om*/ Assert.assertEquals(TimeUnit.HOURS.toMillis(1) / getDurationMs(), periods.size()); }
From source file:com.linkedin.pinot.core.segment.index.converter.SegmentV1V2ToV3FormatConverterTest.java
@BeforeMethod public void setUp() throws Exception { INDEX_DIR = Files.createTempDirectory(SegmentV1V2ToV3FormatConverter.class.getName() + "_segmentDir") .toFile();// ww w . j a va2 s .c o m final String filePath = TestUtils.getFileFromResourceUrl( SegmentV1V2ToV3FormatConverter.class.getClassLoader().getResource(AVRO_DATA)); // intentionally changed this to TimeUnit.Hours to make it non-default for testing final SegmentGeneratorConfig config = SegmentTestUtils.getSegmentGenSpecWithSchemAndProjectedColumns( new File(filePath), INDEX_DIR, "daysSinceEpoch", TimeUnit.HOURS, "testTable"); config.setSegmentNamePostfix("1"); config.setTimeColumnName("daysSinceEpoch"); final SegmentIndexCreationDriver driver = SegmentCreationDriverFactory.get(null); driver.init(config); driver.build(); segmentDirectory = new File(INDEX_DIR, driver.getSegmentName()); File starTreeFile = new File(segmentDirectory, V1Constants.STAR_TREE_INDEX_FILE); FileUtils.touch(starTreeFile); FileUtils.writeStringToFile(starTreeFile, "This is a star tree index"); Configuration tableConfig = new PropertiesConfiguration(); tableConfig.addProperty(IndexLoadingConfigMetadata.KEY_OF_SEGMENT_FORMAT_VERSION, "v1"); v1LoadingConfig = new IndexLoadingConfigMetadata(tableConfig); tableConfig.clear(); tableConfig.addProperty(IndexLoadingConfigMetadata.KEY_OF_SEGMENT_FORMAT_VERSION, "v3"); v3LoadingConfig = new IndexLoadingConfigMetadata(tableConfig); }
From source file:org.jdal.text.PeriodFormatter.java
/** * convert period and unit to millis//from www .j a v a 2s . c o m * @param value period value * @param unit time unit * @return value in millis. */ private long parse(long value, String unit) { if (DAYS.equalsIgnoreCase(unit)) return TimeUnit.DAYS.toMillis(value); else if (HOURS.equalsIgnoreCase(unit)) return TimeUnit.HOURS.toMillis(value); else if (MINUTES.equalsIgnoreCase(unit)) return TimeUnit.MINUTES.toMillis(value); else if (SECONDS.equalsIgnoreCase(unit)) return TimeUnit.SECONDS.toMillis(value); return 0; }
From source file:org.artifactory.maven.versioning.MavenMetadataVersionComparatorTest.java
public void compare1And2() { VersionNameMavenMetadataVersionComparator comparator = new VersionNameMavenMetadataVersionComparator(); MutableFileInfo olderFileInfo = InfoFactoryHolder.get().createFileInfo(new RepoPathImpl("repo", "2.0")); olderFileInfo.setCreated(System.currentTimeMillis()); ItemNode older = new FileNode(olderFileInfo); MutableFileInfo newerFileInfo = InfoFactoryHolder.get().createFileInfo(new RepoPathImpl("repo", "1.1")); newerFileInfo.setCreated(System.currentTimeMillis() + TimeUnit.HOURS.toMillis(2)); ItemNode newer = new FileNode(newerFileInfo); assertEquals(comparator.compare(older, newer), 1, "The comparison should be version name based"); }
From source file:org.alfresco.bm.report.AbstractEventReporter.java
protected TreeMap<String, ResultSummary> collateResults(boolean chartOnly) { ResultService resultService = getResultService(); // Do a quick check to see if there are results EventRecord firstEvent = resultService.getFirstResult(); if (firstEvent == null) { return new TreeMap<String, ResultSummary>(); }/*www .j a va 2 s . co m*/ EventRecord lastEvent = resultService.getLastResult(); long oneHour = TimeUnit.HOURS.toMillis(1L); long queryWindowStartTime = firstEvent.getStartTime(); long queryWindowEndTime = queryWindowStartTime + oneHour; // Prepare recorded data TreeMap<String, ResultSummary> results = new TreeMap<String, ResultSummary>(); int limit = 10000; int skip = 0; while (true) { List<EventRecord> data = resultService.getResults(queryWindowStartTime, queryWindowEndTime, chartOnly, skip, limit); if (data.size() == 0) { if (queryWindowEndTime > lastEvent.getStartTime()) { // The query window covered all known events, so we're done break; } else { // Push the window up queryWindowStartTime = queryWindowEndTime; queryWindowEndTime += oneHour; skip = 0; // Requery continue; } } for (EventRecord eventRecord : data) { skip++; // Add the data String eventName = eventRecord.getEvent().getName(); ResultSummary resultSummary = results.get(eventName); if (resultSummary == null) { resultSummary = new ResultSummary(eventName); results.put(eventName, resultSummary); } boolean resultSuccess = eventRecord.isSuccess(); long resultTime = eventRecord.getTime(); resultSummary.addSample(resultSuccess, resultTime); } } // Done return results; }
From source file:uk.ac.cam.cl.dtg.segue.dao.LocationManager.java
/** * @param dao// w w w . j av a 2s .co m * - the location history data access object. * @param ipLocationResolver * - the external ip location resolver. * @param postCodeLocationResolver * - the external postCode location resolver. */ @Inject public LocationManager(final LocationHistory dao, final IPLocationResolver ipLocationResolver, final PostCodeLocationResolver postCodeLocationResolver) { this.dao = dao; this.ipLocationResolver = ipLocationResolver; this.postCodeLocationResolver = postCodeLocationResolver; // This cache is here to prevent lots of needless look ups to the database. locationCache = CacheBuilder.newBuilder() .expireAfterWrite(NON_PERSISTENT_CACHE_TIME_IN_HOURS, TimeUnit.HOURS).<String, Location>build(); }
From source file:org.apache.metron.profiler.client.stellar.WindowLookbackTest.java
@Test public void testDenseLookback() throws Exception { State state = test("1 hour", Assertions.NOT_EMPTY, Assertions.CONTIGUOUS); Assert.assertEquals(TimeUnit.HOURS.toMillis(1) / getDurationMs(), state.periods.size()); }
From source file:eu.trentorise.smartcampus.unidataservice.controller.rest.Esse3Controller.java
public Esse3Controller() { cdsCache = CacheBuilder.newBuilder().expireAfterWrite(CACHE_TIME, TimeUnit.HOURS) .build(new CacheLoader<String, List<CalendarCdsData>>() { @Override// ww w.ja va 2 s .c o m public List<CalendarCdsData> load(String key) throws Exception { System.err.println("Loading cds " + key); Map<String, Object> params = new TreeMap<String, Object>(); String pars[] = key.split("_"); params.put("cdsId", pars[0]); params.put("anno", pars[1]); return getFullCdsCalendar(params); } }); adCache = CacheBuilder.newBuilder().expireAfterWrite(CACHE_TIME, TimeUnit.HOURS) .build(new CacheLoader<String, List<CalendarCdsData>>() { @Override public List<CalendarCdsData> load(String key) throws Exception { System.err.println("Loading ad " + key); Map<String, Object> params = new TreeMap<String, Object>(); params.put("adId", key); return getFullAdCalendar(params); } }); }
From source file:com.linkedin.pinot.core.data.readers.MultiplePinotSegmentRecordReaderTest.java
private Schema createPinotSchema() { Schema testSchema = new Schema(); testSchema.setSchemaName("schema"); testSchema.addField(new DimensionFieldSpec(D_SV_1, FieldSpec.DataType.STRING, true)); testSchema.addField(new DimensionFieldSpec(D_SV_2, FieldSpec.DataType.INT, true)); testSchema.addField(new DimensionFieldSpec(D_MV_1, FieldSpec.DataType.STRING, false)); testSchema.addField(new MetricFieldSpec(M1, FieldSpec.DataType.INT)); testSchema.addField(new MetricFieldSpec(M2, FieldSpec.DataType.FLOAT)); testSchema.addField(// w ww. j ava2 s . c om new TimeFieldSpec(new TimeGranularitySpec(FieldSpec.DataType.LONG, TimeUnit.HOURS, TIME))); return testSchema; }
From source file:com.samples.platform.serviceprovider.library.internal.GetBookOperation.java
/** * @param start/*from www . ja va 2s .c o m*/ * @return the duration in 000:00:00.000 format. */ private String requestDuration(final long start) { long millis = System.currentTimeMillis() - start; String hmss = String.format("%03d:%02d:%02d.%03d", TimeUnit.MILLISECONDS.toHours(millis), TimeUnit.MILLISECONDS.toMinutes(millis) - TimeUnit.HOURS.toMinutes(TimeUnit.MILLISECONDS.toHours(millis)), TimeUnit.MILLISECONDS.toSeconds(millis) - TimeUnit.MINUTES.toSeconds(TimeUnit.MILLISECONDS.toMinutes(millis)), TimeUnit.MILLISECONDS.toMillis(millis) - TimeUnit.SECONDS.toMillis(TimeUnit.MILLISECONDS.toSeconds(millis))); return hmss; }