changeset 381:e78dfab194a5

PR1046: CLI vm-info display wrong stop time for living vms Reviewed-by: neugens Review-thread: http://icedtea.classpath.org/pipermail/thermostat/2012-June/001849.html
author Omair Majid <omajid@redhat.com>
date Mon, 18 Jun 2012 11:23:40 -0400
parents adbe46431675
children 4b2b830097f3
files tools/src/main/java/com/redhat/thermostat/tools/cli/VMInfoCommand.java tools/src/test/java/com/redhat/thermostat/tools/cli/VMInfoCommandTest.java
diffstat 2 files changed, 35 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/tools/src/main/java/com/redhat/thermostat/tools/cli/VMInfoCommand.java	Mon Jun 18 17:04:47 2012 +0200
+++ b/tools/src/main/java/com/redhat/thermostat/tools/cli/VMInfoCommand.java	Mon Jun 18 11:23:40 2012 -0400
@@ -56,6 +56,8 @@
     private static final String NAME = "vm-info";
     private static final String DESCRIPTION = "shows basic information about a VM";
 
+    private static final String STILL_ALIVE = "<Running>";
+
     @Override
     public void run(CommandContext ctx) throws CommandException {
         DAOFactory daoFactory = ApplicationContext.getInstance().getDAOFactory();
@@ -76,7 +78,11 @@
         TableRenderer table = new TableRenderer(2);
         table.printLine("Process ID:", String.valueOf(vmInfo.getVmPid()));
         table.printLine("Start time:", new Date(vmInfo.getStartTimeStamp()).toString());
-        table.printLine("Stop time:", new Date(vmInfo.getStopTimeStamp()).toString());
+        if (vmInfo.isAlive()) {
+            table.printLine("Stop time:", STILL_ALIVE);
+        } else {
+            table.printLine("Stop time:", new Date(vmInfo.getStopTimeStamp()).toString());
+        }
         table.printLine("Main class:", vmInfo.getMainClass());
         table.printLine("Command line:", vmInfo.getJavaCommandLine());
         table.printLine("Java version:", vmInfo.getJavaVersion());
--- a/tools/src/test/java/com/redhat/thermostat/tools/cli/VMInfoCommandTest.java	Mon Jun 18 17:04:47 2012 +0200
+++ b/tools/src/test/java/com/redhat/thermostat/tools/cli/VMInfoCommandTest.java	Mon Jun 18 11:23:40 2012 -0400
@@ -66,6 +66,7 @@
 import com.redhat.thermostat.common.dao.VmInfoDAO;
 import com.redhat.thermostat.common.dao.VmRef;
 import com.redhat.thermostat.common.model.VmInfo;
+import com.redhat.thermostat.test.Bug;
 import com.redhat.thermostat.test.TestCommandContextFactory;
 
 public class VMInfoCommandTest {
@@ -87,6 +88,7 @@
     private VmInfoDAO vmsDAO;
     private AppContextSetup appContextSetup;
     private TestCommandContextFactory cmdCtxFactory;
+    private VmRef vm;
 
     @Before
     public void setUp() {
@@ -112,7 +114,7 @@
     private void setupDAOs() {
         vmsDAO = mock(VmInfoDAO.class);
         HostRef host = new HostRef("123", "dummy");
-        VmRef vm = new VmRef(host, 234, "dummy");
+        vm = new VmRef(host, 234, "dummy");
         Calendar start = Calendar.getInstance();
         start.set(2012, 5, 7, 15, 32, 0);
         Calendar end = Calendar.getInstance();
@@ -177,6 +179,31 @@
         assertEquals("shows basic information about a VM", cmd.getDescription());
     }
 
+    @Bug(id="1046",
+            summary="CLI vm-info display wrong stop time for living vms",
+            url="http://icedtea.classpath.org/bugzilla/show_bug.cgi?id=1046")
+    @Test
+    public void testStopTime() throws CommandException {
+        Calendar start = Calendar.getInstance();
+        start.set(2012, 5, 7, 15, 32, 0);
+        VmInfo vmInfo = new VmInfo(234, start.getTimeInMillis(), Long.MIN_VALUE, "vmVersion", "javaHome", "mainClass", "commandLine", "vmName", "vmInfo", "vmVersion", "vmArguments", new HashMap<String,String>(), new HashMap<String,String>(), new ArrayList<String>());
+        when(vmsDAO.getVmInfo(vm)).thenReturn(vmInfo);
+
+        SimpleArguments args = new SimpleArguments();
+        args.addArgument("vmId", "234");
+        args.addArgument("hostId", "123");
+        cmd.run(cmdCtxFactory.createContext(args));
+        String expected = "Process ID:      234\n" +
+                          "Start time:      Thu Jun 07 15:32:00 UTC 2012\n" +
+                          "Stop time:       <Running>\n" +
+                          "Main class:      mainClass\n" +
+                          "Command line:    commandLine\n" +
+                          "Java version:    vmVersion\n" +
+                          "Virtual machine: vmName\n" +
+                          "VM arguments:    vmArguments\n";
+        assertEquals(expected, cmdCtxFactory.getOutput());
+    }
+
     @Test
     public void testUsage() {
         String expected = "shows basic information about a VM";