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.apache.hadoop.hbase.client.TestAsyncSingleRequestRpcRetryingCaller.java

@Test
public void testMaxRetries() throws IOException, InterruptedException {
    try {/*from ww w .  j  a va 2  s .c  o  m*/
        CONN.callerFactory.single().table(TABLE_NAME).row(ROW).operationTimeout(1, TimeUnit.DAYS).maxAttempts(3)
                .pause(10, TimeUnit.MILLISECONDS).action((controller, loc, stub) -> failedFuture()).call()
                .get();
        fail();
    } catch (ExecutionException e) {
        assertThat(e.getCause(), instanceOf(RetriesExhaustedException.class));
    }
}

From source file:com.linkedin.pinot.integration.tests.FileBasedSentineTest.java

@BeforeClass
public void setup() throws Exception {
    url = new URL("http://localhost:" + FileBasedServerBrokerStarters.BROKER_CLIENT_PORT + "/query");

    // lets generate data
    final String[] columns = { "dimention1", "dimention2", "dimention3", "dimention4", "metric1",
            "daysSinceEpoch" };
    final Map<String, DataType> dataTypes = new HashMap<String, FieldSpec.DataType>();
    final Map<String, FieldType> fieldTypes = new HashMap<String, FieldType>();

    final Map<String, TimeUnit> timeUnits = new HashMap<String, TimeUnit>();
    final Map<String, Integer> cardinality = new HashMap<String, Integer>();

    // Crate empty range map as the signature of DataGeneratorSpec has changed, and this test does not
    // use metric/time as fieldType.
    final Map<String, IntRange> range = new HashMap<String, IntRange>();

    for (final String col : columns) {
        if (col.equals("dimention1")) {
            dataTypes.put(col, DataType.STRING);
            cardinality.put(col, 1000);/* ww w .jav a  2  s.  co  m*/
        } else {
            dataTypes.put(col, DataType.INT);
            cardinality.put(col, 1000);
        }
        fieldTypes.put(col, FieldType.DIMENSION);
    }

    if (avroDataDir.exists()) {
        FileUtils.deleteDirectory(avroDataDir);
    }

    final DataGeneratorSpec spec = new DataGeneratorSpec(Arrays.asList(columns), cardinality, range, dataTypes,
            fieldTypes, timeUnits, FileFormat.AVRO, avroDataDir.getAbsolutePath(), true);
    generator = new DataGenerator();
    generator.init(spec);
    generator.generate(100000L, 2);
    // lets make segments now

    final File bootstrapDir = new File(FileBasedServerBrokerStarters.SERVER_BOOTSTRAP_DIR);

    if (bootstrapDir.exists()) {
        FileUtils.deleteDirectory(bootstrapDir);
    }

    bootstrapDir.mkdir();

    int counter = 0;
    for (final File avro : avroDataDir.listFiles()) {
        for (final String table : FileBasedServerBrokerStarters.TABLE_NAMES) {
            final SegmentGeneratorConfig genConfig = SegmentTestUtils
                    .getSegmentGenSpecWithSchemAndProjectedColumns(avro,
                            new File(bootstrapDir, "segment-" + counter), "daysSinceEpoch", TimeUnit.DAYS,
                            table);

            final SegmentIndexCreationDriver driver = SegmentCreationDriverFactory.get(null);
            driver.init(genConfig);
            driver.build();

            counter++;
        }
    }

    // lets start the server and the broker now

    starter = new FileBasedServerBrokerStarters();
    starter.startAll();

    // pick some values from here if you need to use it for running filter queries

    final JSONObject selectionRequestResponse = postQuery("select * from 'table1' limit 100",
            "http://localhost:" + FileBasedServerBrokerStarters.BROKER_CLIENT_PORT);

    System.out.println(selectionRequestResponse.toString(1));
}

From source file:org.whispersystems.textsecuregcm.util.Util.java

public static long todayInMillis() {
    return TimeUnit.DAYS.toMillis(TimeUnit.MILLISECONDS.toDays(System.currentTimeMillis()));
}

From source file:example.springdata.elasticsearch.ElasticsearchOperationsTest.java

@Test
public void histogramFacetOnDate() {

    String termField = "date";
    int interval = 30;
    String facetName = "by-date";

    FacetedPage<Conference> firstPage = operations.queryForPage(new NativeSearchQueryBuilder() //
            .withQuery(matchAllQuery()) //
            .withFacet(new HistogramFacetRequestBuilder(facetName).//
                    timeUnit(TimeUnit.DAYS).//
                    interval(interval). //
                    field(termField).build())
            .////w w w .  j  a  v a2 s . c  o m
            build(), Conference.class);

    HistogramResult facet = (HistogramResult) firstPage.getFacet(facetName);

    assertThat(facet.getIntervalUnit(), hasSize(3));
}

From source file:org.opencastproject.kernel.pingback.PingBackService.java

/**
 * Osgi callback that is executed on component activation.
 * /*  ww  w  . jav a2  s.  c om*/
 * @param cc
 *          the component context
 */
public void activate(ComponentContext cc) {
    BundleContext bundleContext = cc.getBundleContext();
    logger.debug("start()");
    // Pingback server, if enabled
    final String pingbackUrl = bundleContext.getProperty("org.opencastproject.anonymous.feedback.url");
    final String hostUrl = bundleContext.getProperty("org.opencastproject.server.url");
    if (StringUtils.isNotBlank(pingbackUrl) && StringUtils.isNotBlank(hostUrl)) {
        try {
            final URI uri = new URI(pingbackUrl);
            pingbackTimer = new Timer("Anonymous Feedback Service", true);
            pingbackTimer.schedule(new TimerTask() {
                public void run() {
                    HttpClient httpClient = new DefaultHttpClient();
                    try {
                        HttpPost post = new HttpPost(uri);
                        List<BasicNameValuePair> params = new ArrayList<BasicNameValuePair>();
                        // TODO: we are currently using drupal to store this information. Use something less demanding so
                        // we can simply post the data.
                        params.add(new BasicNameValuePair(PARAM_NAME_ID, PARAM_VALUE_ID));
                        params.add(new BasicNameValuePair(PARAM_NAME_SUBMITTED, getRuntimeInfo(hostUrl)));
                        UrlEncodedFormEntity entity = new UrlEncodedFormEntity(params);
                        post.setEntity(entity);
                        HttpResponse response = httpClient.execute(post);
                        logger.debug("Received pingback response: {}", response);
                    } catch (Exception e) {
                        logger.info("Unable to send system configuration to opencastproject.org: {}",
                                e.getMessage());
                    } finally {
                        httpClient.getConnectionManager().shutdown();
                    }
                }

            }, TimeUnit.MINUTES.toMillis(1), TimeUnit.DAYS.toMillis(7));
            // wait one minute to send first message, and send once a week thereafter
        } catch (URISyntaxException e1) {
            logger.warn("Can not ping back to '{}'", pingbackUrl);
        }
    }
}

From source file:com.linkedin.pinot.query.aggregation.AggregationMVGroupByMVQueriesTest.java

private void setupSegmentList(int numberOfSegments) throws Exception {
    final String filePath = TestUtils
            .getFileFromResourceUrl(getClass().getClassLoader().getResource(AVRO_DATA));

    if (INDEXES_DIR.exists()) {
        FileUtils.deleteQuietly(INDEXES_DIR);
    }//from   w  ww .  j a  va2s  . com
    INDEXES_DIR.mkdir();

    for (int i = 0; i < numberOfSegments; ++i) {
        final File segmentDir = new File(INDEXES_DIR, "segment_" + i);

        final SegmentGeneratorConfig config = SegmentTestUtils.getSegmentGenSpecWithSchemAndProjectedColumns(
                new File(filePath), segmentDir, "daysSinceEpoch", TimeUnit.DAYS, "test");

        final SegmentIndexCreationDriver driver = SegmentCreationDriverFactory.get(null);
        driver.init(config);
        driver.build();

        LOGGER.debug("built at : {}", segmentDir.getAbsolutePath());
        INDEX_SEGMENT_LIST.add(new OfflineSegmentDataManager(
                ColumnarSegmentLoader.load(new File(segmentDir, driver.getSegmentName()), ReadMode.heap)));
    }
}

From source file:com.tinspx.util.concurrent.DelayedSemaphoreTest.java

/**
 * Test of create method, of class DelayedSemaphore.
 *//* w  w w  .j a va 2  s.c  o  m*/
@Test
@SuppressWarnings("ResultOfObjectAllocationIgnored")
public void testInit() throws InterruptedException {
    new DelayedSemaphore(1, 0, null);
    DelayedSemaphore.create(1, 0);
    DelayedSemaphore.create(1, 1);

    DelayedSemaphore ls = DelayedSemaphore.create(5, 50000000);
    assertEquals(5, ls.permits());
    assertEquals(5, ls.availablePermits());
    assertEquals(50000000, ls.delay());
    assertSame(Ticker.systemTicker(), ls.ticker());
    ls.acquire(); //4
    Thread.sleep(10);
    assertEquals(5, ls.permits());
    assertEquals(4, ls.availablePermits());
    ls.acquire();//3
    ls.acquire();//2
    ls.release();//3
    assertEquals(2, ls.availablePermits());
    Thread.sleep(51);
    assertEquals(3, ls.availablePermits());
    assertEquals(5, ls.permits());

    ls.release(); //4
    ls.release();//5
    try {
        ls.release();
        fail();
    } catch (IllegalStateException ex) {
    }

    assertTrue(ls.tryAcquire(-1, TimeUnit.DAYS));
    assertTrue(ls.tryAcquire(1, -1, TimeUnit.DAYS));
    Thread.sleep(51);
    assertTrue(ls.tryAcquire(2, -1, TimeUnit.DAYS));
    assertEquals(1, ls.availablePermits(0));
    try {
        ls.release(5);
        fail();
    } catch (IllegalArgumentException ex) {
    }
    ls.release(4);
    assertEquals(5, ls.availablePermits(0));
    assertEquals(0, ls.availablePermits(TimeUnit.HOURS.toNanos(1)));

    //acquire invalid args
    try {
        ls.acquire(-1L);
        fail();
    } catch (IllegalArgumentException ex) {
    }
    try {
        ls.acquire(0);
        fail();
    } catch (IllegalArgumentException ex) {
    }
    try {
        ls.acquire(-1);
        fail();
    } catch (IllegalArgumentException ex) {
    }
    try {
        ls.acquire(0, 10);
        fail();
    } catch (IllegalArgumentException ex) {
    }
    try {
        ls.acquire(-1, 10);
        fail();
    } catch (IllegalArgumentException ex) {
    }
    try {
        ls.acquire(1, -1);
        fail();
    } catch (IllegalArgumentException ex) {
    }
    try {
        ls.acquire(2, -1);
        fail();
    } catch (IllegalArgumentException ex) {
    }

    //tryAcquire no timeout, invalid args
    try {
        ls.tryAcquire(-1L);
        fail();
    } catch (IllegalArgumentException ex) {
    }
    try {
        ls.tryAcquire(0);
        fail();
    } catch (IllegalArgumentException ex) {
    }
    try {
        ls.tryAcquire(-1);
        fail();
    } catch (IllegalArgumentException ex) {
    }
    try {
        ls.tryAcquire(0, 10);
        fail();
    } catch (IllegalArgumentException ex) {
    }
    try {
        ls.tryAcquire(-1, 10);
        fail();
    } catch (IllegalArgumentException ex) {
    }
    try {
        ls.tryAcquire(1, -1);
        fail();
    } catch (IllegalArgumentException ex) {
    }
    try {
        ls.tryAcquire(2, -1);
        fail();
    } catch (IllegalArgumentException ex) {
    }

    //tryAcquire with timeout, invalid arguments
    try {
        ls.tryAcquire(-1L, 10, TimeUnit.NANOSECONDS);
        fail();
    } catch (IllegalArgumentException ex) {
    }
    try {
        ls.tryAcquire(0, 10, TimeUnit.NANOSECONDS);
        fail();
    } catch (IllegalArgumentException ex) {
    }
    try {
        ls.tryAcquire(-1, 10, TimeUnit.NANOSECONDS);
        fail();
    } catch (IllegalArgumentException ex) {
    }
    try {
        ls.tryAcquire(0, 10, 10, TimeUnit.NANOSECONDS);
        fail();
    } catch (IllegalArgumentException ex) {
    }
    try {
        ls.tryAcquire(-1, 10, 10, TimeUnit.NANOSECONDS);
        fail();
    } catch (IllegalArgumentException ex) {
    }
    try {
        ls.tryAcquire(1, -1, 10, TimeUnit.NANOSECONDS);
        fail();
    } catch (IllegalArgumentException ex) {
    }
    try {
        ls.tryAcquire(2, -1, 10, TimeUnit.NANOSECONDS);
        fail();
    } catch (IllegalArgumentException ex) {
    }
    try {
        ls.tryAcquire(0L, 10, null);
        fail();
    } catch (NullPointerException ex) {
    }
    try {
        ls.tryAcquire(1, 10, null);
        fail();
    } catch (NullPointerException ex) {
    }
    try {
        ls.tryAcquire(2, 10, null);
        fail();
    } catch (NullPointerException ex) {
    }
    try {
        ls.tryAcquire(1, 0, 10, null);
        fail();
    } catch (NullPointerException ex) {
    }
    try {
        ls.tryAcquire(2, 0, 10, null);
        fail();
    } catch (NullPointerException ex) {
    }

    DelayedSemaphore.create(1, 0);
    try {
        DelayedSemaphore.create(0, 1);
        fail();
    } catch (IllegalArgumentException ex) {
    }
    try {
        DelayedSemaphore.create(1, -1);
        fail();
    } catch (IllegalArgumentException ex) {
    }
    try {
        DelayedSemaphore.create(1, 0, null);
        fail();
    } catch (NullPointerException ex) {
    }
}

From source file:com.linkedin.pinot.query.aggregation.StarTreeQueriesTest.java

@BeforeClass
public void beforeClass() throws Exception {
    testName = StarTreeQueriesTest.class.getSimpleName();
    indexDir = new File(System.getProperty("java.io.tmpdir"), testName);
    if (indexDir.exists()) {
        FileUtils.forceDelete(indexDir);
    }//from  w  ww  . j a  v a 2 s. c  o m
    System.out.println(indexDir);

    avroFile = new File(System.getProperty("java.io.tmpdir"), testName + ".avro");
    if (avroFile.exists()) {
        FileUtils.forceDelete(avroFile);
    }
    avroFile.deleteOnExit();
    createSampleAvroData(avroFile, numRecords, numTimeBuckets);

    final SegmentGeneratorConfig config = SegmentTestUtils.getSegmentGenSpecWithSchemAndProjectedColumns(
            avroFile, indexDir, "daysSinceEpoch", TimeUnit.DAYS, "testTable");
    config.setSegmentNamePostfix("1");
    config.setTimeColumnName("daysSinceEpoch");

    // Set the star tree index config
    StarTreeIndexSpec starTreeIndexSpec = new StarTreeIndexSpec();
    starTreeIndexSpec.setSplitExcludes(Arrays.asList("daysSinceEpoch"));
    starTreeIndexSpec.setMaxLeafRecords(4);
    config.getSchema().setStarTreeIndexSpec(starTreeIndexSpec);

    final SegmentIndexCreationDriver driver = SegmentCreationDriverFactory.get(null);
    driver.init(config);
    driver.build();

    File segmentFile = new File(indexDir, driver.getSegmentName());
    indexSegment = ColumnarSegmentLoader.load(segmentFile, ReadMode.heap);
}

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

@Test
public void testFromToQuery() throws Exception {
    Calendar cal = Calendar.getInstance();
    long now = cal.getTimeInMillis();
    long fromMillis = now - TimeUnit.MILLISECONDS.convert(2, TimeUnit.DAYS);
    long toMillis = now - TimeUnit.MILLISECONDS.convert(1, TimeUnit.DAYS);
    cal.setTimeInMillis(fromMillis);//from  www. ja  v  a  2  s. c  om
    String fromStr = DatatypeConverter.printDateTime(cal);
    cal.setTimeInMillis(toMillis);
    String toStr = DatatypeConverter.printDateTime(cal);
    StatisticsQuery query = new StatisticsQuery(getParams(fromStr, toStr, null), now);
    Assert.assertEquals(fromMillis, query.getFrom());
    Assert.assertEquals(toMillis, query.getTo());

    // period is ignored, if both from and to are specified
    query = new StatisticsQuery(getParams(fromStr, toStr, "3d"), now);
    Assert.assertEquals(fromMillis, query.getFrom());
    Assert.assertEquals(toMillis, query.getTo());

    // from == to
    query = new StatisticsQuery(getParams(fromStr, fromStr, null), now);
    Assert.assertEquals(fromMillis, query.getFrom());
    Assert.assertEquals(fromMillis, query.getTo());

    // from > to
    query = new StatisticsQuery(getParams(toStr, fromStr, null), now);
    Assert.assertEquals(fromMillis, query.getFrom());
    Assert.assertEquals(fromMillis, query.getTo());
}

From source file:org.apache.nifi.toolkit.s2s.SiteToSiteCliMainTest.java

@Test
public void testParseTimeout() throws ParseException {
    expectedTimeoutNs = TimeUnit.DAYS.toNanos(3);
    parseAndCheckExpected(null, SiteToSiteCliMain.TIMEOUT_OPTION, "3 days");
}