Example usage for org.apache.commons.lang.time DurationFormatUtils formatDurationHMS

List of usage examples for org.apache.commons.lang.time DurationFormatUtils formatDurationHMS

Introduction

In this page you can find the example usage for org.apache.commons.lang.time DurationFormatUtils formatDurationHMS.

Prototype

public static String formatDurationHMS(long durationMillis) 

Source Link

Document

Formats the time gap as a string.

The format used is ISO8601-like: H:m:s.S.

Usage

From source file:com.spotify.helios.master.reaper.DeadAgentReaper.java

@Override
void processItem(final String agent) {
    try {//from w ww  . j  ava 2 s  .c  om
        final HostStatus hostStatus = masterModel.getHostStatus(agent);
        if (hostStatus == null || hostStatus.getStatus() != HostStatus.Status.DOWN) {
            // Host not found or host not DOWN -- nothing to do
            return;
        }

        final AgentInfo agentInfo = hostStatus.getAgentInfo();
        if (agentInfo == null) {
            return;
        }

        final long downSince = agentInfo.getStartTime() + agentInfo.getUptime();
        final long downDurationMillis = clock.now().getMillis() - downSince;

        if (downDurationMillis >= timeoutMillis) {
            try {
                log.info("Reaping dead agent '{}' (DOWN for {} hours)", agent,
                        DurationFormatUtils.formatDurationHMS(downDurationMillis));
                masterModel.deregisterHost(agent);
            } catch (Exception e) {
                log.warn("Failed to reap agent '{}'", agent, e);
            }
        }
    } catch (Exception e) {
        log.warn("Failed to determine if agent '{}' should be reaped", agent, e);
    }
}

From source file:com.antsdb.saltedfish.nosql.Validator.java

private void report() {
    long duration = this.endTime - this.startTime;
    if (duration == 0) {
        return;/*from  w w  w.j av a 2s .c om*/
    }
    println("errors found: %s", this.errors);
    println("duration: %s", DurationFormatUtils.formatDurationHMS(duration));
    println("speed: %d/sec", this.count * 1000 / duration);
}

From source file:de.unisb.cs.st.javalanche.mutation.util.ResultDeleter.java

public static void deleteResults(Session session, Query q) {
    @SuppressWarnings("unchecked")
    List<Mutation> mutations = q.list();
    int deletes = 0, flushs = 0;
    StopWatch stp = new StopWatch();
    for (Mutation m : mutations) {
        MutationTestResult result = m.getMutationResult();
        if (result != null) {
            m.setMutationResult(null);/*from   w  w w.jav  a  2s  .  co m*/
            session.delete(result);
            deletes++;
        }
        if (deletes > 20) {
            // 20, same as the JDBC batch size
            // flush a batch of inserts and release memory:
            // see
            // http://www.hibernate.org/hib_docs/reference/en/html/batch.html
            stp.reset();
            stp.start();
            flushs++;
            session.flush();
            // session.clear();
            logger.info("Did flush. It took: " + DurationFormatUtils.formatDurationHMS(stp.getTime()));
            deletes = 0;
        }
    }
    logger.info(String.format("Deleted %d mutation results", mutations.size()));
}

From source file:de.unisb.cs.st.javalanche.mutation.runtime.MutationSwitcher.java

/**
 * Turns the current mutation off./*from  w  w w .j  a  v a  2s . co m*/
 */
public void switchOff() {
    if (currentMutation != null) {
        System.clearProperty(currentMutation.getMutationVariable());
        System.clearProperty(CURRENT_MUTATION_KEY);
        stopWatch.stop();
        logger.info("Disabling mutation: " + currentMutation.getMutationVariable() + " Time active "
                + DurationFormatUtils.formatDurationHMS(stopWatch.getTime()));
        currentMutation = null;
    }
}

From source file:de.unisb.cs.st.javalanche.mutation.runtime.jmx.MutationMxClient.java

public static boolean connect(int i) {
    JMXConnector jmxc = null;/*from   w ww. j a  v a2 s  .c om*/
    JMXServiceURL url = null;

    try {
        url = new JMXServiceURL(MXBeanRegisterer.ADDRESS + i);
        jmxc = JMXConnectorFactory.connect(url, null);
    } catch (MalformedURLException e) {
        e.printStackTrace();
    } catch (IOException e) {
        return false;
        // System.out.println("Could not connect to address: " + url);
        // e.printStackTrace();
    }
    if (jmxc != null) {
        try {
            MBeanServerConnection mbsc = jmxc.getMBeanServerConnection();
            ObjectName objectName = new ObjectName(MXBeanRegisterer.OBJECT_NAME);
            Object numberOfMutations = mbsc.getAttribute(objectName, "NumberOfMutations");
            Object currentTest = mbsc.getAttribute(objectName, "CurrentTest");
            Object currentMutation = mbsc.getAttribute(objectName, "CurrentMutation");
            Object allMutations = mbsc.getAttribute(objectName, "Mutations");
            Object mutationsDuration = mbsc.getAttribute(objectName, "MutationDuration");
            Object testDuration = mbsc.getAttribute(objectName, "TestDuration");
            //            Object mutationSummary = mbsc.getAttribute(objectName,
            //                  "MutationSummary");

            final RuntimeMXBean remoteRuntime = ManagementFactory.newPlatformMXBeanProxy(mbsc,
                    ManagementFactory.RUNTIME_MXBEAN_NAME, RuntimeMXBean.class);

            final MemoryMXBean remoteMemory = ManagementFactory.newPlatformMXBeanProxy(mbsc,
                    ManagementFactory.MEMORY_MXBEAN_NAME, MemoryMXBean.class);
            System.out.print("Connection: " + i + "  ");
            System.out.println("Target VM: " + remoteRuntime.getName() + " - " + remoteRuntime.getVmVendor()
                    + " - " + remoteRuntime.getSpecVersion() + " - " + remoteRuntime.getVmVersion());
            System.out.println(
                    "Running for: " + DurationFormatUtils.formatDurationHMS(remoteRuntime.getUptime()));
            System.out
                    .println("Memory usage: Heap - " + formatMemory(remoteMemory.getHeapMemoryUsage().getUsed())
                            + "  Non Heap - " + formatMemory(remoteMemory.getNonHeapMemoryUsage().getUsed()));

            String mutationDurationFormatted = DurationFormatUtils
                    .formatDurationHMS(Long.parseLong(mutationsDuration.toString()));
            String testDurationFormatted = DurationFormatUtils
                    .formatDurationHMS(Long.parseLong(testDuration.toString()));
            if (DEBUG_ADD) {
                System.out.println("Classpath: " + remoteRuntime.getClassPath());
                System.out.println("Args: " + remoteRuntime.getInputArguments());
                System.out.println("All Mutations: " + allMutations);
            }
            //            System.out.println(mutationSummary);
            System.out.println(
                    "Current mutation (Running for: " + mutationDurationFormatted + "): " + currentMutation);
            System.out.println("Mutations tested: " + numberOfMutations);
            System.out.println("Current test:   (Running for: " + testDurationFormatted + "): " + currentTest);

        } catch (MalformedURLException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        } catch (MalformedObjectNameException e) {
            e.printStackTrace();
        } catch (NullPointerException e) {
            e.printStackTrace();
        } catch (AttributeNotFoundException e) {
            e.printStackTrace();
        } catch (InstanceNotFoundException e) {
            e.printStackTrace();
        } catch (MBeanException e) {
            e.printStackTrace();
        } catch (ReflectionException e) {
            e.printStackTrace();
        } finally {
            try {
                jmxc.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }
    return true;
}

From source file:de.unisb.cs.st.javalanche.mutation.util.DBPerformanceTest.java

private void testInsert() {
    StopWatch stopWatch = new StopWatch();
    stopWatch.start();/*from w  w w.j a  v a  2  s.c o m*/
    QueryManager.saveMutations(getMutations());
    stopWatch.stop();
    System.out.println("Inserting " + LIMIT + " mutations took "
            + DurationFormatUtils.formatDurationHMS(stopWatch.getTime()));

}

From source file:com.antsdb.saltedfish.nosql.HumpbackUtil.java

private void validate() throws Exception {
    long start = System.currentTimeMillis();
    int failures = 0;
    Humpback humpback = Humpback.open(this.home);
    for (GTable table : humpback.getTables()) {
        println("validating %s ...", table.toString());
        try {/*  w w w .  java  2 s  .  c  o  m*/
            Boolean isIndex = null;
            RowIterator scanner = table.scan(0, Long.MAX_VALUE);
            while (scanner.next()) {
                if (isIndex == null) {
                    isIndex = isIndex(humpback, scanner.getRowPointer());
                }
                if (!isIndex) {
                    Row row = scanner.getRow();
                    for (int i = 0; i < row.getMaxColumnId(); i++) {
                        row.get(i);
                    }
                } else {
                    long pKey = scanner.getRowKeyPointer();
                    KeyBytes.create(pKey);
                }
            }
        } catch (Exception x) {
            failures++;
            x.printStackTrace();
        }
    }
    println("tables failed validation: %d", failures);
    long duration = System.currentTimeMillis() - start;
    println("duration: %s", DurationFormatUtils.formatDurationHMS(duration));
}

From source file:com.evolveum.midpoint.web.page.admin.server.currentState.IterativeInformationPanel.java

protected void initLayout() {

    Label executionTime = new Label(ID_EXECUTION_TIME, new AbstractReadOnlyModel<String>() {
        @Override/*from   w w  w.  ja v  a 2  s . c om*/
        public String getObject() {
            TaskDto dto = getModel().getObject().getTaskDto();
            if (dto == null) {
                return null;
            }
            Long started = dto.getLastRunStartTimestampLong();
            Long finished = dto.getLastRunFinishTimestampLong();
            if (started == null) {
                return null;
            }
            if (TaskDtoExecutionStatus.RUNNING.equals(dto.getExecution()) || finished == null
                    || finished < started) {
                return getString("TaskStatePanel.message.executionTime.notFinished",
                        formatDate(new Date(started)),
                        DurationFormatUtils.formatDurationHMS(System.currentTimeMillis() - started));
            } else {
                return getString("TaskStatePanel.message.executionTime.finished", formatDate(new Date(started)),
                        formatDate(new Date(finished)),
                        DurationFormatUtils.formatDurationHMS(finished - started));
            }
        }
    });
    add(executionTime);

    Label processedSuccess = new Label(ID_OBJECTS_PROCESSED_SUCCESS, new AbstractReadOnlyModel<String>() {
        @Override
        public String getObject() {
            TaskCurrentStateDto dto = getModelObject();
            if (dto == null) {
                return null;
            }
            IterativeTaskInformationType info = dto.getIterativeTaskInformationType();
            if (info == null) {
                return null;
            }
            if (info.getTotalSuccessCount() == 0) {
                return "0";
            } else {
                return getString("TaskStatePanel.message.objectsProcessed", info.getTotalSuccessCount());
            }
        }
    });
    add(processedSuccess);

    Label processedSuccessTime = new Label(ID_OBJECTS_PROCESSED_SUCCESS_TIME,
            new AbstractReadOnlyModel<String>() {
                @Override
                public String getObject() {
                    TaskCurrentStateDto dto = getModelObject();
                    if (dto == null) {
                        return null;
                    }
                    IterativeTaskInformationType info = dto.getIterativeTaskInformationType();
                    if (info == null) {
                        return null;
                    }
                    if (info.getTotalSuccessCount() == 0) {
                        return null;
                    } else {
                        return getString("TaskStatePanel.message.objectsProcessedTime",
                                info.getTotalSuccessDuration() / 1000,
                                info.getTotalSuccessDuration() / info.getTotalSuccessCount());
                    }
                }
            });
    add(processedSuccessTime);

    Label lastProcessedSuccess = new Label(ID_LAST_OBJECT_PROCESSED_SUCCESS,
            new AbstractReadOnlyModel<String>() {
                @Override
                public String getObject() {
                    TaskCurrentStateDto dto = getModelObject();
                    if (dto == null) {
                        return null;
                    }
                    IterativeTaskInformationType info = dto.getIterativeTaskInformationType();
                    if (info == null) {
                        return null;
                    }
                    if (info.getLastSuccessObjectDisplayName() == null) {
                        return null;
                    } else {
                        return getString("TaskStatePanel.message.lastObjectProcessed",
                                info.getLastSuccessObjectDisplayName());
                    }
                }
            });
    add(lastProcessedSuccess);

    Label lastProcessedSuccessTime = new Label(ID_LAST_OBJECT_PROCESSED_SUCCESS_TIME,
            new AbstractReadOnlyModel<String>() {
                @Override
                public String getObject() {
                    TaskCurrentStateDto dto = getModelObject();
                    if (dto == null) {
                        return null;
                    }
                    IterativeTaskInformationType info = dto.getIterativeTaskInformationType();
                    if (info == null) {
                        return null;
                    }
                    if (info.getLastSuccessEndTimestamp() == null) {
                        return null;
                    } else {
                        if (showAgo(dto)) {
                            return getString("TaskStatePanel.message.timeInfoWithDurationAndAgo",
                                    formatDate(info.getLastSuccessEndTimestamp()),
                                    DurationFormatUtils.formatDurationWords(System.currentTimeMillis()
                                            - XmlTypeConverter.toMillis(info.getLastSuccessEndTimestamp()),
                                            true, true),
                                    info.getLastSuccessDuration());
                        } else {
                            return getString("TaskStatePanel.message.timeInfoWithDuration",
                                    formatDate(info.getLastSuccessEndTimestamp()),
                                    info.getLastSuccessDuration());
                        }
                    }
                }
            });
    add(lastProcessedSuccessTime);

    Label processedFailure = new Label(ID_OBJECTS_PROCESSED_FAILURE, new AbstractReadOnlyModel<String>() {
        @Override
        public String getObject() {
            TaskCurrentStateDto dto = getModelObject();
            if (dto == null) {
                return null;
            }
            IterativeTaskInformationType info = dto.getIterativeTaskInformationType();
            if (info == null) {
                return null;
            }
            if (info.getTotalFailureCount() == 0) {
                return "0";
            } else {
                return getString("TaskStatePanel.message.objectsProcessed", info.getTotalFailureCount());
            }
        }
    });
    add(processedFailure);

    Label processedFailureTime = new Label(ID_OBJECTS_PROCESSED_FAILURE_TIME,
            new AbstractReadOnlyModel<String>() {
                @Override
                public String getObject() {
                    TaskCurrentStateDto dto = getModelObject();
                    if (dto == null) {
                        return null;
                    }
                    IterativeTaskInformationType info = dto.getIterativeTaskInformationType();
                    if (info == null) {
                        return null;
                    }
                    if (info.getTotalFailureCount() == 0) {
                        return null;
                    } else {
                        return getString("TaskStatePanel.message.objectsProcessedTime",
                                info.getTotalFailureDuration() / 1000,
                                info.getTotalFailureDuration() / info.getTotalFailureCount());
                    }
                }
            });
    add(processedFailureTime);

    Label lastProcessedFailure = new Label(ID_LAST_OBJECT_PROCESSED_FAILURE,
            new AbstractReadOnlyModel<String>() {
                @Override
                public String getObject() {
                    TaskCurrentStateDto dto = getModelObject();
                    if (dto == null) {
                        return null;
                    }
                    IterativeTaskInformationType info = dto.getIterativeTaskInformationType();
                    if (info == null) {
                        return null;
                    }
                    if (info.getLastFailureObjectDisplayName() == null) {
                        return null;
                    } else {
                        return getString("TaskStatePanel.message.lastObjectProcessed",
                                info.getLastFailureObjectDisplayName());
                    }
                }
            });
    add(lastProcessedFailure);

    Label lastProcessedFailureTime = new Label(ID_LAST_OBJECT_PROCESSED_FAILURE_TIME,
            new AbstractReadOnlyModel<String>() {
                @Override
                public String getObject() {
                    TaskCurrentStateDto dto = getModelObject();
                    if (dto == null) {
                        return null;
                    }
                    IterativeTaskInformationType info = dto.getIterativeTaskInformationType();
                    if (info == null) {
                        return null;
                    }
                    if (info.getLastFailureEndTimestamp() == null) {
                        return null;
                    } else {
                        if (showAgo(dto)) {
                            return getString("TaskStatePanel.message.timeInfoWithDurationAndAgo",
                                    formatDate(info.getLastFailureEndTimestamp()),
                                    DurationFormatUtils.formatDurationWords(System.currentTimeMillis()
                                            - XmlTypeConverter.toMillis(info.getLastFailureEndTimestamp()),
                                            true, true),
                                    info.getLastFailureDuration());
                        } else {
                            return getString("TaskStatePanel.message.timeInfoWithDuration",
                                    formatDate(info.getLastFailureEndTimestamp()),
                                    info.getLastFailureDuration());
                        }
                    }
                }
            });
    add(lastProcessedFailureTime);

    Label lastError = new Label(ID_LAST_ERROR, new AbstractReadOnlyModel<String>() {
        @Override
        public String getObject() {
            TaskCurrentStateDto dto = getModelObject();
            if (dto == null) {
                return null;
            }
            IterativeTaskInformationType info = dto.getIterativeTaskInformationType();
            if (info == null) {
                return null;
            }
            return info.getLastFailureExceptionMessage();
        }
    });
    add(lastError);

    Label currentObjectProcessed = new Label(ID_CURRENT_OBJECT_PROCESSED, new AbstractReadOnlyModel<String>() {
        @Override
        public String getObject() {
            TaskCurrentStateDto dto = getModelObject();
            if (dto == null) {
                return null;
            }
            IterativeTaskInformationType info = dto.getIterativeTaskInformationType();
            if (info == null) {
                return null;
            }
            return info.getCurrentObjectDisplayName();
        }
    });
    add(currentObjectProcessed);

    Label currentObjectProcessedTime = new Label(ID_CURRENT_OBJECT_PROCESSED_TIME,
            new AbstractReadOnlyModel<String>() {
                @Override
                public String getObject() {
                    TaskCurrentStateDto dto = getModelObject();
                    if (dto == null) {
                        return null;
                    }
                    IterativeTaskInformationType info = dto.getIterativeTaskInformationType();
                    if (info == null) {
                        return null;
                    }
                    if (info.getCurrentObjectStartTimestamp() == null) {
                        return null;
                    } else {
                        return getString("TaskStatePanel.message.timeInfoWithAgo",
                                formatDate(info.getCurrentObjectStartTimestamp()),
                                DurationFormatUtils.formatDurationWords(System.currentTimeMillis()
                                        - XmlTypeConverter.toMillis(info.getCurrentObjectStartTimestamp()),
                                        true, true));
                    }
                }
            });
    add(currentObjectProcessedTime);

    Label objectsTotal = new Label(ID_OBJECTS_TOTAL, new AbstractReadOnlyModel<String>() {
        @Override
        public String getObject() {
            TaskCurrentStateDto dto = getModelObject();
            if (dto == null) {
                return null;
            }
            IterativeTaskInformationType info = dto.getIterativeTaskInformationType();
            if (info == null) {
                return null;
            }
            int objectsTotal = info.getTotalSuccessCount() + info.getTotalFailureCount();
            if (WALL_CLOCK_AVG_CATEGORIES.contains(dto.getTaskDto().getCategory())) {
                Long avg = getWallClockAverage(dto, objectsTotal);
                if (avg != null) {
                    return getString("TaskStatePanel.message.objectsTotal", objectsTotal, avg);
                }
            }
            return String.valueOf(objectsTotal);
        }
    });
    add(objectsTotal);
}

From source file:de.unisb.cs.st.javalanche.rhino.RhinoTestDriver.java

private void testDirectory(File dir) {
    baseDir = dir.getAbsolutePath();//from  w w w .  jav a 2  s.  co  m
    StopWatch stopWatch = new StopWatch();
    stopWatch.start();
    File[] files = getTestFilesForDir(dir);
    List<String> passingTests = new ArrayList<String>();
    List<SingleTestResult> failingTests = new ArrayList<SingleTestResult>();
    logger.info("Searching in " + dir);
    List<String> failingList = Io.getLinesFromFile(new File("failing.txt"));
    List<String> ignoreList = Io
            .getLinesFromFile(new File("output/271545/post-fix/mozilla/js/tests/rhino-n.tests"));

    int ignore = 0;
    for (File f : files) {
        logger.info("File:  " + f);
        String testName = getRelativeLocation(f);
        logger.info("Test name: " + testName);

        if (ignoreList.contains(testName)) {
            logger.info("Not running test because its on the projects ignore list");
            ignore++;
            continue;
        }
        if (failingList.contains(testName)) {
            String message = "Not running test (Failed in previous run)";
            logger.info(message + testName);
            failingTests.add(new SingleTestResult(testName, message, TestOutcome.ERROR, 0));
            continue;
        }
        MutationTestRunnable testRunnable = getTestRunnable(testName);
        runWithTimeout(testRunnable);
        SingleTestResult result = testRunnable.getResult();
        if (result.hasPassed()) {
            logger.info("Test passed: " + testName);
            passingTests.add(testName);
        } else {
            logger.info("Test failed: " + testName);
            logger.info("Reason: " + result);
            failingTests.add(result);
        }

    }

    stopWatch.stop();
    long time = stopWatch.getTime();
    logger.info("Test Suite took " + DurationFormatUtils.formatDurationHMS(time));
    StringBuilder sbPass = new StringBuilder();
    StringBuilder sbFail = new StringBuilder();
    for (String passingTest : passingTests) {
        sbPass.append(passingTest + "\n");
    }
    for (SingleTestResult failingTestResult : failingTests) {
        sbFail.append(failingTestResult.getTestMessage().getTestCaseName()
                /* + "," + failingTestResult.getTestMessage().getMessage() */
                + "\n");
    }
    Io.writeFile(sbPass.toString(), new File("passingTests.txt"));
    Io.writeFile(sbFail.toString(), new File("failingTests.txt"));
    logger.info("Ignored " + ignore + " tests");
}

From source file:hudson.plugins.robot.model.RobotTestObject.java

/**
 * Wrapper for calling formatting from jelly
 * @return
 */
public String getHumanReadableDuration() {
    return DurationFormatUtils.formatDurationHMS(getDuration());
}