changeset 182:98c90d0f337d

added new tests (normal + compatibility) src/org/thermostat/qa2/tests/compatibility/DBCompatibilityTest.java: - basic storage/agent tests just try to run setup for "other" Thermostat run storage (agent), and then run storage (agent) of "tested" thermostat on a same db - profile / heapDump tries to collect profiling data / do a heap dump ("other thermostat") and then look for that data from "tested" thermostat using same db src/org/thermostat/qa2/tests/AgentSaveOnExitTest.java: - use same code as profile/heapDump compatiblity tests, but tests if SAVE_ON_EXIT option in agent.properties works correctly
author Zdenek Zambersky <zzambers@redhat.com>
date Fri, 15 May 2015 19:00:54 +0200
parents e37e710e45df
children 67f1ec14b9cd
files src/org/thermostat/qa2/tests/AgentSaveOnExitTest.java src/org/thermostat/qa2/tests/compatibility/DBCompatibilityTest.java
diffstat 2 files changed, 254 insertions(+), 14 deletions(-) [+]
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/org/thermostat/qa2/tests/AgentSaveOnExitTest.java	Fri May 15 19:00:54 2015 +0200
@@ -0,0 +1,193 @@
+/*
+ ThermostatQA - test framework for Thermostat Monitoring Tool
+
+ Copyright 2015 Red Hat, Inc.
+
+ This file is part of ThermostatQA
+
+ ThermostatQA is distributed under the GNU General Public License,
+ version 2 or any later version (with a special exception described
+ below, commonly known as the "Classpath Exception").
+
+ A copy of GNU General Public License (GPL) is included in this
+ distribution, in the file COPYING.
+
+ Linking ThermostatQA code with other modules is making a combined work
+ based on ThermostatQA.  Thus, the terms and conditions of the GPL
+ cover the whole combination.
+
+ As a special exception, the copyright holders of ThermostatQA give you
+ permission to link this code with independent modules to produce an
+ executable, regardless of the license terms of these independent
+ modules, and to copy and distribute the resulting executable under
+ terms of your choice, provided that you also meet, for each linked
+ independent module, the terms and conditions of the license of that
+ module.  An independent module is a module which is not derived from
+ or based on ThermostatQA code.  If you modify ThermostatQA, you may
+ extend this exception to your version of the software, but you are
+ not obligated to do so.  If you do not wish to do so, delete this
+ exception statement from your version.
+ */
+package org.thermostat.qa2.tests;
+
+import java.util.List;
+import static org.thermostat.qa2.framework.Assert.assertFalse;
+import static org.thermostat.qa2.framework.Assert.assertNotNull;
+import static org.thermostat.qa2.framework.Assert.assertNull;
+import static org.thermostat.qa2.framework.Assert.assertRuns;
+import static org.thermostat.qa2.framework.Assert.assertTrue;
+import org.thermostat.qa2.framework.annotations.RunGnomeKeyring;
+import org.thermostat.qa2.framework.annotations.SetupStorage;
+import org.thermostat.qa2.framework.annotations.Test;
+import org.thermostat.qa2.framework.services.ThermostatAgent;
+import org.thermostat.qa2.framework.services.ThermostatFullStorage;
+import org.thermostat.qa2.framework.utils.CommonUtilities;
+import org.thermostat.qa2.framework.utils.ThermostatUtilities;
+
+/**
+ *
+ * @author Zdeněk Žamberský
+ */
+@RunGnomeKeyring
+public class AgentSaveOnExitTest {
+
+    /* storage and agent of first thermostat (target1) are started, heap dump is performed, storage and agent are stopped
+     storage of second thermostat (target2) is started, heap dump is expected or not expected to be in db, based on saveOnExit value */
+    public static void heapDumpTestImpl(String target1, String target2, boolean saveOnExit) throws Exception {
+        // first thermostat
+        ThermostatFullStorage thermostatOtherStorage = new ThermostatFullStorage(target1);
+        ThermostatAgent thermostatOtherAgent = new ThermostatAgent(target1);
+        thermostatOtherStorage.start();
+        thermostatOtherAgent.start();
+        assertRuns(thermostatOtherAgent, "Agent should be running");
+
+        String[] vmLineSegments = ThermostatUtilities.getRunningVmLine(target1).split(" ");
+        String hostId = vmLineSegments[0];
+        String vmId = vmLineSegments[2];
+
+        String heapDump = ThermostatUtilities.getHeapDumpLine(target1, hostId, vmId);
+        assertNull(heapDump, "there should not be any heap dump yet");
+
+        ThermostatUtilities.dumpHeap(target1, hostId, vmId);
+        heapDump = ThermostatUtilities.getHeapDumpLine(target1, hostId, vmId);
+        assertNotNull(heapDump, "there should be heap dump in db");
+
+        thermostatOtherAgent.stop();
+        thermostatOtherStorage.stop();
+
+        // second thermostat
+        ThermostatFullStorage thermostatStorage = new ThermostatFullStorage(target2);
+        thermostatStorage.start();
+
+        heapDump = ThermostatUtilities.getHeapDumpLine(target2, hostId, vmId);
+        if (saveOnExit) {
+            assertNotNull(heapDump, "there should be heap dump in db");
+        } else {
+            assertNull(heapDump, "there should not be any heap dump in db");
+        }
+        thermostatStorage.stop();
+    }
+
+    static boolean containsProfilingData(List<String> profileOutput) {
+        int counter = 0;
+        int size = profileOutput.size();
+        for (; counter < size; ++counter) {
+            String line = profileOutput.get(counter);
+            if (line.contains("% Time") && line.contains("Time (ms)") && line.contains("Method Name")) {
+                return true;
+            }
+        }
+        return false;
+    }
+
+    /* storage and agent of first thermostat (target1) are started, profiling is performed, storage and agent are stopped
+     storage of second thermostat (target2) is started, profiling data are expected or not expected to be in db, based on saveOnExit value */
+    public static void profileTestImpl(String target1, String target2, boolean saveOnExit) throws Exception {
+        // first thermostat
+        ThermostatFullStorage thermostatOtherStorage = new ThermostatFullStorage(target1);
+        ThermostatAgent thermostatOtherAgent = new ThermostatAgent(target1);
+        thermostatOtherStorage.start();
+        thermostatOtherAgent.start();
+        assertRuns(thermostatOtherAgent, "Agent should be running");
+
+        String[] vmLineSegments = ThermostatUtilities.getRunningVmLine(target1).split(" ");
+        String hostId = vmLineSegments[0];
+        String vmId = vmLineSegments[2];
+
+        List<String> profileOutput = ThermostatUtilities.profileVm(target1, hostId, vmId, "show");
+        assertFalse(containsProfilingData(profileOutput), "there should not be any profiling data in db yet");
+
+        ThermostatUtilities.profileVm(target1, hostId, vmId, "start");
+        CommonUtilities.sleep(5000);
+        ThermostatUtilities.profileVm(target1, hostId, vmId, "stop");
+
+        profileOutput = ThermostatUtilities.profileVm(target1, hostId, vmId, "show");
+        assertTrue(containsProfilingData(profileOutput), "there should be profiling data in db");
+
+        thermostatOtherAgent.stop();
+        thermostatOtherStorage.stop();
+
+        // second thermostat
+        ThermostatFullStorage thermostatStorage = new ThermostatFullStorage(target2);
+        thermostatStorage.start();
+
+        profileOutput = ThermostatUtilities.profileVm(target2, hostId, vmId, "show");
+        if (saveOnExit) {
+            assertTrue(containsProfilingData(profileOutput), "there should be profiling data in db");
+        } else {
+            assertFalse(containsProfilingData(profileOutput), "there should not be any profiling data in db");
+        }
+        thermostatStorage.stop();
+    }
+
+    public static String target = "tested";
+
+    @Test
+    @SetupStorage(type = "mongo", agentSaveOnExit = true)
+    public void heapDumpSave() throws Exception {
+        heapDumpTestImpl(target, target, true);
+    }
+
+    @Test
+    @SetupStorage(type = "mongo", agentSaveOnExit = false)
+    public void heapDumpNotSave() throws Exception {
+        heapDumpTestImpl(target, target, false);
+    }
+
+    @Test
+    @SetupStorage(type = "web", agentSaveOnExit = true)
+    public void heapDumpWebSave() throws Exception {
+        heapDumpTestImpl(target, target, true);
+    }
+
+    @Test
+    @SetupStorage(type = "web", agentSaveOnExit = false)
+    public void heapDumpWebNotSave() throws Exception {
+        heapDumpTestImpl(target, target, false);
+    }
+
+    @Test
+    @SetupStorage(type = "mongo", agentSaveOnExit = true)
+    public void profileSave() throws Exception {
+        profileTestImpl(target, target, true);
+    }
+
+    @Test
+    @SetupStorage(type = "mongo", agentSaveOnExit = false)
+    public void profileNotSave() throws Exception {
+        profileTestImpl(target, target, false);
+    }
+
+    @Test
+    @SetupStorage(type = "web", agentSaveOnExit = true)
+    public void profileWebSave() throws Exception {
+        profileTestImpl(target, target, true);
+    }
+
+    @Test
+    @SetupStorage(type = "web", agentSaveOnExit = false)
+    public void profileWebNotSave() throws Exception {
+        profileTestImpl(target, target, false);
+    }
+
+}
--- a/src/org/thermostat/qa2/tests/compatibility/DBCompatibilityTest.java	Fri May 15 18:51:56 2015 +0200
+++ b/src/org/thermostat/qa2/tests/compatibility/DBCompatibilityTest.java	Fri May 15 19:00:54 2015 +0200
@@ -31,49 +31,48 @@
 package org.thermostat.qa2.tests.compatibility;
 
 import static org.thermostat.qa2.framework.Assert.*;
+import org.thermostat.qa2.framework.annotations.RunGnomeKeyring;
 import org.thermostat.qa2.framework.annotations.SetupStorage;
 import org.thermostat.qa2.framework.annotations.Test;
 import org.thermostat.qa2.framework.annotations.ThermostatSetupTarget;
 import org.thermostat.qa2.framework.services.ThermostatAgent;
-import org.thermostat.qa2.framework.services.ThermostatStorage;
+import org.thermostat.qa2.framework.services.ThermostatFullStorage;
+import org.thermostat.qa2.framework.utils.CommonUtilities;
+import org.thermostat.qa2.tests.AgentSaveOnExitTest;
 
 /**
  *
  * @author Zdeněk Žamberský
  */
-// setup "mongo" storage for "other" thermostat before every test
-@SetupStorage(type = "mongo")
 @ThermostatSetupTarget("other")
+@RunGnomeKeyring
 public class DBCompatibilityTest {
 
-    @Test
-    public void simpleStorageTest() throws Exception {
+    public static void basicStorageImpl() throws Exception {
         // "other" thermostat
-        ThermostatStorage thermostatOtherStorage = new ThermostatStorage("other");
+        ThermostatFullStorage thermostatOtherStorage = new ThermostatFullStorage("other");
         thermostatOtherStorage.start();
-        Thread.sleep(5000);
+        CommonUtilities.sleep(5000);
         thermostatOtherStorage.stop();
 
         // "tested" thermostat
-        ThermostatStorage thermostatStorage = new ThermostatStorage("tested");
+        ThermostatFullStorage thermostatStorage = new ThermostatFullStorage("tested");
         thermostatStorage.start(); // if it fails to start it throws exception
         // thermostatStorage is stopped automatically by framework       
     }
 
-    @Test
-    public void simpleStorageAgentTest() throws Exception {
+    public static void basicStorageAgentImpl() throws Exception {
         // "other" thermostat
-        ThermostatStorage thermostatOtherStorage = new ThermostatStorage("other");
+        ThermostatFullStorage thermostatOtherStorage = new ThermostatFullStorage("other");
         ThermostatAgent thermostatOtherAgent = new ThermostatAgent("other");
         thermostatOtherStorage.start();
         thermostatOtherAgent.start();
-        Thread.sleep(10000);
-        assertTrue(thermostatOtherAgent.isRunning(), "Agent should be running");
+        assertRuns(thermostatOtherAgent, "Agent should be running");
         thermostatOtherAgent.stop();
         thermostatOtherStorage.stop();
 
         // "tested" thermostat
-        ThermostatStorage thermostatStorage = new ThermostatStorage("tested");
+        ThermostatFullStorage thermostatStorage = new ThermostatFullStorage("tested");
         ThermostatAgent thermostatAgent = new ThermostatAgent("tested");
         thermostatStorage.start();
         thermostatAgent.start();
@@ -82,4 +81,52 @@
         // thermostat storage and agent are stopped automatically by framework       
     }
 
+    @Test
+    @SetupStorage(type = "mongo")
+    public void basicStorage() throws Exception {
+        basicStorageImpl();
+    }
+
+    @Test
+    @SetupStorage(type = "mongo")
+    public void basicAgent() throws Exception {
+        basicStorageAgentImpl();
+    }
+
+    @Test
+    @SetupStorage(type = "web")
+    public void basicStorageWeb() throws Exception {
+        basicStorageImpl();
+    }
+
+    @Test
+    @SetupStorage(type = "web")
+    public void basicAgentWeb() throws Exception {
+        basicStorageAgentImpl();
+    }
+
+    @Test
+    @SetupStorage(type = "mongo", agentSaveOnExit = true)
+    public void heapDump() throws Exception {
+        AgentSaveOnExitTest.heapDumpTestImpl("other", "tested", true);
+    }
+
+    @Test
+    @SetupStorage(type = "mongo", agentSaveOnExit = true)
+    public void profile() throws Exception {
+        AgentSaveOnExitTest.profileTestImpl("other", "tested", true);
+    }
+
+    @Test
+    @SetupStorage(type = "web", agentSaveOnExit = true)
+    public void heapDumpWeb() throws Exception {
+        AgentSaveOnExitTest.heapDumpTestImpl("other", "tested", true);
+    }
+
+    @Test
+    @SetupStorage(type = "web", agentSaveOnExit = true)
+    public void profileWeb() throws Exception {
+        AgentSaveOnExitTest.profileTestImpl("other", "tested", true);
+    }
+
 }