Example usage for org.apache.commons.lang3.time DateUtils MILLIS_PER_DAY

List of usage examples for org.apache.commons.lang3.time DateUtils MILLIS_PER_DAY

Introduction

In this page you can find the example usage for org.apache.commons.lang3.time DateUtils MILLIS_PER_DAY.

Prototype

long MILLIS_PER_DAY

To view the source code for org.apache.commons.lang3.time DateUtils MILLIS_PER_DAY.

Click Source Link

Document

Number of milliseconds in a standard day.

Usage

From source file:jproxy.ProxyControl.java

/**
 * Initialise the dynamic domain keystore
 *//*from  w  w w  .  j a  v a 2  s.  co m*/
private void initDynamicKeyStore() throws IOException, GeneralSecurityException {
    if (storePassword != null) { // Assume we have already created the store
        try {
            keyStore = getKeyStore(storePassword.toCharArray());
            for (String alias : KeyToolUtils.getCAaliases()) {
                X509Certificate caCert = (X509Certificate) keyStore.getCertificate(alias);
                if (caCert == null) {
                    keyStore = null; // no CA key - probably the wrong store type.
                    break; // cannot continue
                } else {
                    caCert.checkValidity(new Date(System.currentTimeMillis() + DateUtils.MILLIS_PER_DAY));
                    log.info("Valid alias found for " + alias);
                }
            }
        } catch (IOException e) { // store is faulty, we need to recreate it
            keyStore = null; // if cert is not valid, flag up to recreate it
            if (e.getCause() instanceof UnrecoverableKeyException) {
                log.warn(
                        "Could not read key store " + e.getMessage() + "; cause: " + e.getCause().getMessage());
            } else {
                log.warn("Could not open/read key store " + e.getMessage()); // message includes the file name
            }
        } catch (GeneralSecurityException e) {
            keyStore = null; // if cert is not valid, flag up to recreate it
            log.warn("Problem reading key store: " + e.getMessage());
        }
    }
    if (keyStore == null) { // no existing file or not valid
        storePassword = RandomStringUtils.randomAlphanumeric(20); // Alphanum to avoid issues with command-line quoting
        keyPassword = storePassword; // we use same password for both
        setPassword(storePassword);
        log.info("Creating Proxy CA in " + CERT_PATH_ABS);
        KeyToolUtils.generateProxyCA(CERT_PATH, storePassword, CERT_VALIDITY);
        log.info("Created keystore in " + CERT_PATH_ABS);
        keyStore = getKeyStore(storePassword.toCharArray()); // This should now work
    }
    final String sslDomains = getSslDomains().trim();
    if (sslDomains.length() > 0) {
        final String[] domains = sslDomains.split(",");
        // The subject may be either a host or a domain
        for (String subject : domains) {
            if (isValid(subject)) {
                if (!keyStore.containsAlias(subject)) {
                    log.info("Creating entry " + subject + " in " + CERT_PATH_ABS);
                    KeyToolUtils.generateHostCert(CERT_PATH, storePassword, subject, CERT_VALIDITY);
                    keyStore = getKeyStore(storePassword.toCharArray()); // reload to pick up new aliases
                    // reloading is very quick compared with creating an entry currently
                }
            } else {
                log.warn("Attempt to create an invalid domain certificate: " + subject);
            }
        }
    }
}

From source file:jproxy.ProxyControl.java

/**
 * Initialise the single key JMeter keystore (original behaviour)
 */// w ww.j  av a  2  s .  c o  m
private void initJMeterKeyStore() throws IOException, GeneralSecurityException {
    if (storePassword != null) { // Assume we have already created the store
        try {
            keyStore = getKeyStore(storePassword.toCharArray());
            X509Certificate caCert = (X509Certificate) keyStore.getCertificate(JMETER_SERVER_ALIAS);
            caCert.checkValidity(new Date(System.currentTimeMillis() + DateUtils.MILLIS_PER_DAY));
        } catch (Exception e) { // store is faulty, we need to recreate it
            keyStore = null; // if cert is not valid, flag up to recreate it
            log.warn("Could not open expected file or certificate is not valid " + CERT_PATH_ABS + " "
                    + e.getMessage());
        }
    }
    if (keyStore == null) { // no existing file or not valid
        storePassword = RandomStringUtils.randomAlphanumeric(20); // Alphanum to avoid issues with command-line quoting
        keyPassword = storePassword; // we use same password for both
        setPassword(storePassword);
        log.info("Generating standard keypair in " + CERT_PATH_ABS);
        if (!CERT_PATH.delete()) { // safer to start afresh
            log.warn("Could not delete " + CERT_PATH.getAbsolutePath()
                    + ", this could create issues, stop jmeter, ensure file is deleted and restart again");
        }
        KeyToolUtils.genkeypair(CERT_PATH, JMETER_SERVER_ALIAS, storePassword, CERT_VALIDITY, null, null);
        keyStore = getKeyStore(storePassword.toCharArray()); // This should now work
    }
}

From source file:org.apache.cassandra.cql3.validation.operations.AggregationTest.java

@Test
public void testAggregateWithWriteTimeOrTTL() throws Throwable {
    createTable("CREATE TABLE %s (a int primary key, b int, c int)");

    // Test with empty table
    assertColumnNames(/*from   w  ww  .j  a va2s.  c om*/
            execute("SELECT count(writetime(b)), min(ttl(b)) as min, writetime(b), ttl(c) as first FROM %s"),
            "system.count(writetime(b))", "min", "writetime(b)", "first");
    assertRows(execute("SELECT count(writetime(b)), min(ttl(b)) as min, writetime(b), ttl(c) as first FROM %s"),
            row(0L, null, null, null));

    long today = System.currentTimeMillis() * 1000;
    long yesterday = today - (DateUtils.MILLIS_PER_DAY * 1000);

    final int secondsPerMinute = 60;
    execute("INSERT INTO %s (a, b, c) VALUES (1, 2, null) USING TTL " + (20 * secondsPerMinute));
    execute("INSERT INTO %s (a, b, c) VALUES (2, 4, 6) USING TTL " + (10 * secondsPerMinute));
    execute("INSERT INTO %s (a, b, c) VALUES (4, 8, 12) USING TIMESTAMP " + yesterday);

    assertRows(execute("SELECT count(writetime(b)), count(ttl(b)) FROM %s"), row(3L, 2L));

    UntypedResultSet resultSet = execute("SELECT min(ttl(b)), ttl(b) FROM %s");
    assertEquals(1, resultSet.size());
    Row row = resultSet.one();
    assertTrue(row.getInt("ttl(b)") > (10 * secondsPerMinute));
    assertTrue(row.getInt("system.min(ttl(b))") <= (10 * secondsPerMinute));

    resultSet = execute("SELECT min(writetime(b)), writetime(b) FROM %s");
    assertEquals(1, resultSet.size());
    row = resultSet.one();

    assertTrue(row.getLong("writetime(b)") >= today);
    assertTrue(row.getLong("system.min(writetime(b))") == yesterday);
}

From source file:org.apache.eagle.metric.kafka.TestDataDistributionDaoImpl.java

@Ignore
@Test//from  w  ww  . ja  va  2 s  .co m
public void test() throws Exception {
    System.setProperty("config.resource", "/application.local.conf");
    Config config = ConfigFactory.load();
    String eagleServiceHost = config.getString(EagleConfigConstants.EAGLE_PROPS + "."
            + EagleConfigConstants.EAGLE_SERVICE + "." + EagleConfigConstants.HOST);
    Integer eagleServicePort = config.getInt(EagleConfigConstants.EAGLE_PROPS + "."
            + EagleConfigConstants.EAGLE_SERVICE + "." + EagleConfigConstants.PORT);
    String username = config.getString(EagleConfigConstants.EAGLE_PROPS + "."
            + EagleConfigConstants.EAGLE_SERVICE + "." + EagleConfigConstants.USERNAME);
    String password = config.getString(EagleConfigConstants.EAGLE_PROPS + "."
            + EagleConfigConstants.EAGLE_SERVICE + "." + EagleConfigConstants.PASSWORD);
    String topic = config.getString("dataSourceConfig.topic");
    DataDistributionDao dao = new DataDistributionDaoImpl(eagleServiceHost, eagleServicePort, username,
            password, topic);
    dao.fetchDataDistribution(System.currentTimeMillis() - 2 * DateUtils.MILLIS_PER_DAY,
            System.currentTimeMillis());
}

From source file:org.apache.eagle.metric.kafka.TestGreedyPartition.java

@Ignore
@Test/*from w  w  w.j  a  v a  2s  .c o  m*/
public void test() throws Exception {
    System.setProperty("config.resource", "/application.local.conf");
    Config config = ConfigFactory.load();
    String host = config.getString(EagleConfigConstants.EAGLE_PROPS + "." + EagleConfigConstants.EAGLE_SERVICE
            + "." + EagleConfigConstants.HOST);
    Integer port = config.getInt(EagleConfigConstants.EAGLE_PROPS + "." + EagleConfigConstants.EAGLE_SERVICE
            + "." + EagleConfigConstants.PORT);
    String username = config.getString(EagleConfigConstants.EAGLE_PROPS + "."
            + EagleConfigConstants.EAGLE_SERVICE + "." + EagleConfigConstants.USERNAME);
    String password = config.getString(EagleConfigConstants.EAGLE_PROPS + "."
            + EagleConfigConstants.EAGLE_SERVICE + "." + EagleConfigConstants.PASSWORD);
    String topic = config.getString("dataSourceConfig.topic");
    DataDistributionDao dao = new DataDistributionDaoImpl(host, port, username, password, topic);
    PartitionAlgorithm algorithm = new GreedyPartitionAlgorithm();
    algorithm.partition(dao.fetchDataDistribution(System.currentTimeMillis() - 2 * DateUtils.MILLIS_PER_DAY,
            System.currentTimeMillis()), 4);
}

From source file:org.apache.eagle.service.client.impl.TestEagleServiceQueryBuilder.java

@Test
public void testEagleQuery() throws Exception {
    EagleServiceQueryBuilder builder = new EagleServiceQueryBuilder();
    builder.setStartTime(0).setEndTime(DateUtils.MILLIS_PER_DAY).setPageSize(Integer.MAX_VALUE)
            .addReturnField("field1").addReturnField("field2").addReturnTag("tag1")
            .addSearchTag("tagKey", "tagValue");
    EagleServiceQueryRequest request = builder.buildRequest();
    Assert.assertEquals(/*from  w w w.  j a  v a 2s  .c  o m*/
            "pageSize=2147483647&startTime=1970-01-01%2000:00:00&endTime=1970-01-02%2000:00:00&tagNameValue=tagKey%3DtagValue&outputTag=tag1&outputField=field1&outputField=field2",
            request.getQueryParameterString());
}

From source file:org.apache.jmeter.protocol.http.proxy.JMeterProxyControl.java

/**
 * Initialise the user-provided keystore
 *///from  w  ww .  ja v  a  2  s  .c o m
private void initUserKeyStore() {
    try {
        sslKeyStore = getKeyStore(storePassword.toCharArray());
        X509Certificate caCert = (X509Certificate) sslKeyStore.getCertificate(CERT_ALIAS);
        if (caCert == null) {
            LOG.error("Could not find key with alias " + CERT_ALIAS);
            sslKeyStore = null;
        } else {
            caCert.checkValidity(new Date(System.currentTimeMillis() + DateUtils.MILLIS_PER_DAY));
        }
    } catch (Exception e) {
        sslKeyStore = null;
        LOG.error(
                "Could not open keystore or certificate is not valid " + CERT_PATH_ABS + " " + e.getMessage());
    }
}

From source file:org.apache.jmeter.protocol.http.proxy.JMeterProxyControl.java

/**
 * Initialise the dynamic domain keystore
 *///w  w w.  ja  va2 s  .c  om
private void initDynamicKeyStore() throws IOException, GeneralSecurityException {
    if (storePassword != null) { // Assume we have already created the store
        try {
            sslKeyStore = getKeyStore(storePassword.toCharArray());
            for (String alias : KeyToolUtils.getCAaliases()) {
                X509Certificate caCert = (X509Certificate) sslKeyStore.getCertificate(alias);
                if (caCert == null) {
                    sslKeyStore = null; // no CA key - probably the wrong store type.
                    break; // cannot continue
                } else {
                    caCert.checkValidity(new Date(System.currentTimeMillis() + DateUtils.MILLIS_PER_DAY));
                    LOG.info("Valid alias found for " + alias);
                }
            }
        } catch (IOException e) { // store is faulty, we need to recreate it
            sslKeyStore = null; // if cert is not valid, flag up to recreate it
            if (e.getCause() instanceof UnrecoverableKeyException) {
                LOG.warn(
                        "Could not read key store " + e.getMessage() + "; cause: " + e.getCause().getMessage());
            } else {
                LOG.warn("Could not open/read key store " + e.getMessage()); // message includes the file name
            }
        } catch (GeneralSecurityException e) {
            sslKeyStore = null; // if cert is not valid, flag up to recreate it
            LOG.warn("Problem reading key store: " + e.getMessage());
        }
    }
    if (sslKeyStore == null) { // no existing file or not valid
        storePassword = RandomStringUtils.randomAlphanumeric(20); // Alphanum to avoid issues with command-line quoting
        keyPassword = storePassword; // we use same password for both
        setPassword(storePassword);
        LOG.info("Creating Proxy CA in " + CERT_PATH_ABS);
        KeyToolUtils.generateProxyCA(CERT_PATH, storePassword, CERT_VALIDITY);
        LOG.info("Created keystore in " + CERT_PATH_ABS);
        sslKeyStore = getKeyStore(storePassword.toCharArray()); // This should now work
    }
    final String sslDomains = getSslDomains().trim();
    if (sslDomains.length() > 0) {
        final String[] domains = sslDomains.split(",");
        // The subject may be either a host or a domain
        for (String subject : domains) {
            if (isValid(subject)) {
                if (!sslKeyStore.containsAlias(subject)) {
                    LOG.info("Creating entry " + subject + " in " + CERT_PATH_ABS);
                    KeyToolUtils.generateHostCert(CERT_PATH, storePassword, subject, CERT_VALIDITY);
                    sslKeyStore = getKeyStore(storePassword.toCharArray()); // reload to pick up new aliases
                    // reloading is very quick compared with creating an entry currently
                }
            } else {
                LOG.warn("Attempt to create an invalid domain certificate: " + subject);
            }
        }
    }
}

From source file:org.apache.jmeter.protocol.http.proxy.JMeterProxyControl.java

/**
 * Initialise the single key JMeter keystore (original behaviour)
 *///from  w w  w  .jav  a  2  s .com
private void initJMeterKeyStore() throws IOException, GeneralSecurityException {
    if (storePassword != null) { // Assume we have already created the store
        try {
            sslKeyStore = getKeyStore(storePassword.toCharArray());
            X509Certificate caCert = (X509Certificate) sslKeyStore.getCertificate(JMETER_SERVER_ALIAS);
            caCert.checkValidity(new Date(System.currentTimeMillis() + DateUtils.MILLIS_PER_DAY));
        } catch (Exception e) { // store is faulty, we need to recreate it
            sslKeyStore = null; // if cert is not valid, flag up to recreate it
            LOG.warn("Could not open expected file or certificate is not valid " + CERT_PATH_ABS + " "
                    + e.getMessage());
        }
    }
    if (sslKeyStore == null) { // no existing file or not valid
        storePassword = RandomStringUtils.randomAlphanumeric(20); // Alphanum to avoid issues with command-line quoting
        keyPassword = storePassword; // we use same password for both
        setPassword(storePassword);
        LOG.info("Generating standard keypair in " + CERT_PATH_ABS);
        if (!CERT_PATH.delete()) { // safer to start afresh
            LOG.warn("Could not delete " + CERT_PATH.getAbsolutePath()
                    + ", this could create issues, stop jmeter, ensure file is deleted and restart again");
        }
        KeyToolUtils.genkeypair(CERT_PATH, JMETER_SERVER_ALIAS, storePassword, CERT_VALIDITY, null, null);
        sslKeyStore = getKeyStore(storePassword.toCharArray()); // This should now work
    }
}

From source file:org.apache.rocketmq.broker.yunai.BrokerControllerMasterTest.java

/**
 * broker ?/*from   ww  w. java 2 s  .  c om*/
 */
@Test
public void testBrokerRestart() throws Exception {
    System.setProperty("user.home",
            System.getProperty("user.home") + File.separator + "broker" + File.separator + "master");

    // ?
    System.setProperty(RemotingCommand.REMOTING_VERSION_KEY, Integer.toString(MQVersion.CURRENT_VERSION));
    //
    final NettyServerConfig nettyServerConfig = new NettyServerConfig();
    nettyServerConfig.setListenPort(10911);
    //
    final BrokerConfig brokerConfig = new BrokerConfig();
    brokerConfig.setBrokerName("broker-a");
    brokerConfig.setBrokerId(MixAll.MASTER_ID);
    brokerConfig.setNamesrvAddr("127.0.0.1:9876");
    //
    final MessageStoreConfig messageStoreConfig = new MessageStoreConfig();
    messageStoreConfig.setDeleteWhen("04");
    messageStoreConfig.setFileReservedTime(48);
    messageStoreConfig.setFlushDiskType(FlushDiskType.ASYNC_FLUSH);

    if (true) {
        messageStoreConfig.setBrokerRole(BrokerRole.ASYNC_MASTER);
    } else {
        messageStoreConfig.setBrokerRole(BrokerRole.SYNC_MASTER);
    }

    messageStoreConfig.setDuplicationEnable(false);

    //        BrokerPathConfigHelper.setBrokerConfigPath("/Users/yunai/?/?/Javascript/Story/incubator-rocketmq/conf/broker.conf");
    // broker ?
    BrokerController brokerController = new BrokerController(//
            brokerConfig, //
            nettyServerConfig, //
            new NettyClientConfig(), //
            messageStoreConfig);
    brokerController.initialize();
    brokerController.start();
    //        brokerController.getTopicConfigManager().createTopicInSendMessageBackMethod()
    Thread.sleep(DateUtils.MILLIS_PER_DAY);
}