Example usage for java.util.concurrent TimeUnit DAYS

List of usage examples for java.util.concurrent TimeUnit DAYS

Introduction

In this page you can find the example usage for java.util.concurrent TimeUnit DAYS.

Prototype

TimeUnit DAYS

To view the source code for java.util.concurrent TimeUnit DAYS.

Click Source Link

Document

Time unit representing twenty four hours.

Usage

From source file:org.zenoss.zep.dao.impl.RangePartitionerIT.java

@Test
public void testRangePartitioner() {
    RangePartitioner partitioner = databaseCompatibility.getRangePartitioner(this.dataSource, "range_partition",
            "col_ts", 1, TimeUnit.DAYS);
    assertEquals(0, partitioner.listPartitions().size());
    /*//from www  . j  a  v a 2  s  . c o  m
     * Initialize partitions with 5 previous days partitions and 10 future
     * partitions.
     */
    int numBefore = 0, numAfter = 0;
    partitioner.createPartitions(5, 10);
    Timestamp time = new Timestamp(System.currentTimeMillis());
    List<Partition> partitions = partitioner.listPartitions();
    assertEquals(15, partitions.size());
    for (Partition partition : partitions) {
        if (partition.getRangeLessThan().before(time)) {
            numBefore++;
        } else {
            numAfter++;
        }
    }
    assertEquals(5, numBefore);
    assertEquals(10, numAfter);

    // Try to create partitions which overlap existing ranges and verify it doesn't create any.
    assertEquals(0, partitioner.createPartitions(10, 10));
    assertEquals(0, partitioner.createPartitions(0, 5));

    // Create two additional ones in the future and verify it only creates those two
    assertEquals(2, partitioner.createPartitions(5, 12));
    assertEquals(17, partitioner.listPartitions().size());

    // Test pruning partitions older than 3 days ago
    numBefore = 0;
    numAfter = 0;
    partitioner.pruneAndCreatePartitions(3, TimeUnit.DAYS, 0, 0);
    partitions = partitioner.listPartitions();
    assertEquals(15, partitions.size());
    for (Partition partition : partitions) {
        if (partition.getRangeLessThan().before(time)) {
            numBefore++;
        } else {
            numAfter++;
        }
    }
    assertEquals(3, numBefore);
    assertEquals(12, numAfter);

    // Test pruning partitions again, expecting same results
    numBefore = 0;
    numAfter = 0;
    partitioner.pruneAndCreatePartitions(3, TimeUnit.DAYS, 0, 0);
    partitions = partitioner.listPartitions();
    assertEquals(15, partitions.size());
    for (Partition partition : partitions) {
        if (partition.getRangeLessThan().before(time)) {
            numBefore++;
        } else {
            numAfter++;
        }
    }
    assertEquals(3, numBefore);
    assertEquals(12, numAfter);

    // Test dropping partitions
    partitioner.removeAllPartitions();
    assertEquals(0, partitioner.listPartitions().size());
}

From source file:com.smartitengineering.cms.spi.lock.impl.distributed.ZKLock.java

public void lock() {
    boolean locked = false;
    try {/*from   ww  w  . j  a v a 2s  . co  m*/
        locked = tryLock(1, TimeUnit.DAYS);
    } catch (Exception ex) {
        logger.warn(ex.getMessage(), ex);
    }
    if (!locked) {
        throw new IllegalStateException("Could not attain lock!");
    }
}

From source file:org.sonarsource.sonarlint.core.container.global.GlobalTempFolderProviderTest.java

@Test
public void cleanUpOld() throws IOException {
    long creationTime = System.currentTimeMillis() - TimeUnit.DAYS.toMillis(100);
    File workingDir = temp.newFolder();

    for (int i = 0; i < 3; i++) {
        File tmp = new File(workingDir, ".sonartmp_" + i);
        tmp.mkdirs();/*from  w ww  .j  a v  a 2  s.c  o  m*/
        setFileCreationDate(tmp, creationTime);
    }

    tempFolderProvider.provide(StandaloneGlobalConfiguration.builder().setWorkDir(workingDir.toPath()).build());
    // this also checks that all other temps were deleted
    assertThat(getCreatedTempDir(workingDir)).exists();

    FileUtils.deleteQuietly(workingDir);
}

From source file:org.eclipse.skalli.core.rest.admin.StatisticsQuery.java

StatisticsQuery(Map<String, String> params, long now) {
    if (params.containsKey(PARAM_ALL)) {
        from = 0;/*from w  w  w  .j  a v  a  2s. c  om*/
        to = 0;
    } else {
        period = Math.abs(getTimeInterval(params.get(PARAM_PERIOD)));
        from = parseDateTime(params.get(PARAM_FROM), now);
        to = parseDateTime(params.get(PARAM_TO), now);
        if (from <= 0 && to <= 0) {
            to = now;
            from = period != 0 ? to - period : to - TimeUnit.MILLISECONDS.convert(1, TimeUnit.DAYS);
        } else if (from > 0 && to <= 0) {
            to = period != 0 ? from + period : now;
        } else if (from <= 0 && to > 0) {
            from = period != 0 ? to - period : 0;
        } else {
            // both from/to given: ignore period
        }
        from = Math.min(now, from);
        to = Math.min(now, to);
        if (from > to) {
            from = to;
        }
    }

    included = CollectionUtils.asSet(StringUtils.split(params.get(PARAM_INCLUDE), ','));
    excluded = CollectionUtils.asSet(StringUtils.split(params.get(PARAM_EXCLUDE), ','));
    filters = CollectionUtils.asSet(StringUtils.split(params.get(PARAM_FILTERS), ','));
    if (filters.contains("summary")) { //$NON-NLS-1$
        setFilter("summary"); //$NON-NLS-1$
    }
}

From source file:com.ignorelist.kassandra.steam.scraper.HtmlTagLoader.java

public HtmlTagLoader(Path cachePath, int cacheExpiryDays) {
    cache = new FileCache(cachePath, new CacheLoader<String, InputStream>() {
        @Override//  w w w  .  j  a v  a 2 s  .c  o  m
        public InputStream load(String k) throws Exception {
            URL url = new URL(buildPageUrl(k));
            return URLUtil.openInputStream(url);
        }
    }, TimeUnit.DAYS, cacheExpiryDays);
}

From source file:org.mitre.openid.connect.service.impl.InMemoryClientLogoLoadingService.java

/**
 * /*from  w w w.  j  av  a2 s . c  o  m*/
 */
public InMemoryClientLogoLoadingService(HttpClient httpClient) {

    cache = CacheBuilder.newBuilder().maximumSize(100).expireAfterAccess(14, TimeUnit.DAYS)
            .build(new ClientLogoFetcher(httpClient));

}

From source file:net.duckling.ddl.service.sync.ChunkUploadSessionService.java

@Override
public String create(Long clbId, String status) {
    String sessionId = generateSessonId(clbId);
    RBucket<ChunkUploadSession> bucket = redisson.getBucket(sessionId);
    ChunkUploadSession data = new ChunkUploadSession(clbId, status);
    bucket.set(data, EXPIRE_DAYS, TimeUnit.DAYS);
    return sessionId;
}

From source file:org.apache.hadoop.hive.common.type.HiveIntervalDayTime.java

public int getHours() {
    return (int) (TimeUnit.SECONDS.toHours(totalSeconds) % TimeUnit.DAYS.toHours(1));
}

From source file:com.linkedin.pinot.core.startree.StarTreeIndexTestSegmentHelper.java

private static Schema buildSegment(String segmentDirName, String segmentName, HllConfig hllConfig,
        boolean enableOffHeapFormat) throws Exception {
    final int rows = (int) MathUtils.factorial(NUM_DIMENSIONS) * 100;
    Schema schema = new Schema();

    for (int i = 0; i < NUM_DIMENSIONS; i++) {
        String dimName = "d" + (i + 1);
        DimensionFieldSpec dimensionFieldSpec = new DimensionFieldSpec(dimName, FieldSpec.DataType.STRING,
                true);//from  www . j  a va 2s  . c  o m
        schema.addField(dimName, dimensionFieldSpec);
    }

    schema.setTimeFieldSpec(new TimeFieldSpec(TIME_COLUMN_NAME, FieldSpec.DataType.INT, TimeUnit.DAYS));
    for (int i = 0; i < NUM_METRICS; i++) {
        String metricName = "m" + (i + 1);
        MetricFieldSpec metricFieldSpec = new MetricFieldSpec(metricName, FieldSpec.DataType.INT);
        schema.addField(metricName, metricFieldSpec);
    }

    SegmentGeneratorConfig config = new SegmentGeneratorConfig(schema);
    config.setEnableStarTreeIndex(true);
    config.setOutDir(segmentDirName);
    config.setFormat(FileFormat.AVRO);
    config.setSegmentName(segmentName);
    config.setHllConfig(hllConfig);
    config.setStarTreeIndexSpec(buildStarTreeIndexSpec(enableOffHeapFormat));

    Random random = new Random(RANDOM_SEED);
    final List<GenericRow> data = new ArrayList<>();
    for (int row = 0; row < rows; row++) {
        HashMap<String, Object> map = new HashMap<>();
        // Dim columns.
        for (int i = 0; i < NUM_DIMENSIONS / 2; i++) {
            String dimName = schema.getDimensionFieldSpecs().get(i).getName();
            map.put(dimName, dimName + "-v" + row % (NUM_DIMENSIONS - i));
        }
        // Random values make cardinality of d3, d4 column values larger to better test hll
        for (int i = NUM_DIMENSIONS / 2; i < NUM_DIMENSIONS; i++) {
            String dimName = schema.getDimensionFieldSpecs().get(i).getName();
            map.put(dimName, dimName + "-v" + random.nextInt(i * 100));
        }

        // Metric columns.
        for (int i = 0; i < NUM_METRICS; i++) {
            String metName = schema.getMetricFieldSpecs().get(i).getName();
            map.put(metName, random.nextInt(METRIC_MAX_VALUE));
        }

        // Time column.
        map.put(TIME_COLUMN_NAME, row % 7);

        GenericRow genericRow = new GenericRow();
        genericRow.init(map);
        data.add(genericRow);
    }

    SegmentIndexCreationDriverImpl driver = new SegmentIndexCreationDriverImpl();
    RecordReader reader = createReader(schema, data);
    driver.init(config, reader);
    driver.build();

    LOGGER.info("Built segment {} at {}", segmentName, segmentDirName);
    return schema;
}