You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@karaf.apache.org by jb...@apache.org on 2011/07/25 14:21:39 UTC
svn commit: r1150662 - in /karaf/trunk/shell/commands/src:
main/java/org/apache/karaf/shell/commands/InfoAction.java
test/java/org/apache/karaf/shell/commands/InfoTest.java
Author: jbonofre
Date: Mon Jul 25 12:21:38 2011
New Revision: 1150662
URL: http://svn.apache.org/viewvc?rev=1150662&view=rev
Log:
[KARAF-760] Fix uptime display in the info command
Added:
karaf/trunk/shell/commands/src/test/java/org/apache/karaf/shell/commands/InfoTest.java
Modified:
karaf/trunk/shell/commands/src/main/java/org/apache/karaf/shell/commands/InfoAction.java
Modified: karaf/trunk/shell/commands/src/main/java/org/apache/karaf/shell/commands/InfoAction.java
URL: http://svn.apache.org/viewvc/karaf/trunk/shell/commands/src/main/java/org/apache/karaf/shell/commands/InfoAction.java?rev=1150662&r1=1150661&r2=1150662&view=diff
==============================================================================
--- karaf/trunk/shell/commands/src/main/java/org/apache/karaf/shell/commands/InfoAction.java (original)
+++ karaf/trunk/shell/commands/src/main/java/org/apache/karaf/shell/commands/InfoAction.java Mon Jul 25 12:21:38 2011
@@ -150,18 +150,21 @@ public class InfoAction extends OsgiComm
return fmtI.format((long) (size / 1024)) + " kbytes";
}
- private String printDuration(double uptime) {
+ protected String printDuration(double uptime) {
+ System.out.println("Initial uptime: " + uptime);
uptime /= 1000;
if (uptime < 60) {
return fmtD.format(uptime) + " seconds";
}
uptime /= 60;
+ System.out.println("Uptime in minutes: " + uptime);
if (uptime < 60) {
long minutes = (long) uptime;
String s = fmtI.format(minutes) + (minutes > 1 ? " minutes" : " minute");
return s;
}
uptime /= 60;
+ System.out.println("Uptime in hours: " + uptime);
if (uptime < 24) {
long hours = (long) uptime;
long minutes = (long) ((uptime - hours) * 60);
@@ -172,8 +175,13 @@ public class InfoAction extends OsgiComm
return s;
}
uptime /= 24;
+ System.out.println("Uptime in days: " + uptime);
+
long days = (long) uptime;
- long hours = (long) ((uptime - days) * 60);
+ long hours = (long) ((uptime - days) * 24);
+ System.out.println("Uptime - days: " + (uptime - days));
+ System.out.println("Days: " + days);
+ System.out.println("Hours: " + hours);
String s = fmtI.format(days) + (days > 1 ? " days" : " day");
if (hours != 0) {
s += " " + fmtI.format(hours) + (hours > 1 ? " hours" : "hour");
Added: karaf/trunk/shell/commands/src/test/java/org/apache/karaf/shell/commands/InfoTest.java
URL: http://svn.apache.org/viewvc/karaf/trunk/shell/commands/src/test/java/org/apache/karaf/shell/commands/InfoTest.java?rev=1150662&view=auto
==============================================================================
--- karaf/trunk/shell/commands/src/test/java/org/apache/karaf/shell/commands/InfoTest.java (added)
+++ karaf/trunk/shell/commands/src/test/java/org/apache/karaf/shell/commands/InfoTest.java Mon Jul 25 12:21:38 2011
@@ -0,0 +1,41 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.karaf.shell.commands;
+
+import junit.framework.TestCase;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class InfoTest extends TestCase {
+
+ private static final transient Logger LOGGER = LoggerFactory.getLogger(TestCase.class);
+
+ public void testUptime() throws Exception {
+ InfoAction infoAction = new InfoAction();
+ // uptime 30 seconds
+ assertEquals("30.000 seconds", infoAction.printDuration(30 * 1000));
+ // uptime 2 minutes
+ assertEquals("2 minutes", infoAction.printDuration(2 * 60 * 1000));
+ // uptime 2 hours
+ assertEquals("2 hours", infoAction.printDuration(2 * 3600 * 1000));
+ // update 2 days and 2 hours
+ assertEquals("2 days 2 hours", infoAction.printDuration(50 * 3600 * 1000));
+ }
+
+}