changeset 94:a7dd6094e493

adding AgentWebStorageTest testsuite
author Jana Fabrikova <jfabriko@redhat.com>
date Wed, 18 Sep 2013 16:09:51 +0200
parents 3e7000a3900e
children a876bdda9ad8
files ChangeLog Makefile scripts/stop_all_therm_agents.sh src/org/thermostat/qa/testsuites/AgentWebStorageTest.java
diffstat 4 files changed, 311 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/ChangeLog	Wed Sep 18 16:03:19 2013 +0200
+++ b/ChangeLog	Wed Sep 18 16:09:51 2013 +0200
@@ -1,3 +1,13 @@
+2013-09-18  Jana Fabrikova  <jfabriko@redhat.com>
+
+	* scripts/stop_all_therm_agents.sh:
+	modification kill -9 instead of kill
+	* src/org/thermostat/qa/testsuites/AgentWebStorageTest.java:
+	adding new testsuite with 4 testcases
+	* Makefile:
+	adding AgentWebStorageTest to the list of classes and to 
+	the runtests goal
+
 2013-09-18  Jana Fabrikova  <jfabriko@redhat.com>
 
 	* src/org/thermostat/qa/framework/ThermostatTest.java:
--- a/Makefile	Wed Sep 18 16:03:19 2013 +0200
+++ b/Makefile	Wed Sep 18 16:09:51 2013 +0200
@@ -40,7 +40,8 @@
 	GuiClientSmokeTest \
 	CliClientSmokeTest \
 	GuiClientDBModificationsSmokeTest \
-	CliClientDBModificationsSmokeTest
+	CliClientDBModificationsSmokeTest \
+	AgentWebStorageTest
 
 ALL_CLASSES = \
 	$(BUILD_DIR)/$(ANNOTATIONS_PACKAGE)/TestTypes.class \
@@ -78,7 +79,8 @@
 	$(BUILD_DIR)/$(TEST_PACKAGE)/SmokeTests.class \
 	$(BUILD_DIR)/$(TEST_PACKAGE)/StorageSmokeTest.class \
 	$(BUILD_DIR)/$(TEST_PACKAGE)/GuiClientDBModificationsSmokeTest.class \
-	$(BUILD_DIR)/$(TEST_PACKAGE)/CliClientDBModificationsSmokeTest.class
+	$(BUILD_DIR)/$(TEST_PACKAGE)/CliClientDBModificationsSmokeTest.class \
+	$(BUILD_DIR)/$(TEST_PACKAGE)/AgentWebStorageTest.class
 
 all:	build runtests
 
--- a/scripts/stop_all_therm_agents.sh	Wed Sep 18 16:03:19 2013 +0200
+++ b/scripts/stop_all_therm_agents.sh	Wed Sep 18 16:09:51 2013 +0200
@@ -1,2 +1,2 @@
-kill $(jps | grep Thermostat | cut -d' ' -f1)
+kill -9 $(jps | grep Thermostat | cut -d' ' -f1)
 
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/org/thermostat/qa/testsuites/AgentWebStorageTest.java	Wed Sep 18 16:09:51 2013 +0200
@@ -0,0 +1,296 @@
+/*
+
+    ThermostatQA - test framework for Thermostat Monitoring Tool
+
+    Copyright 2013 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.qa.testsuites;
+
+import java.awt.AWTException;
+import java.io.IOException;
+import java.util.List;
+
+import org.thermostat.qa.framework.Assert;
+import org.thermostat.qa.framework.GuiRobot;
+import org.thermostat.qa.framework.ThermostatGuiTest;
+import org.thermostat.qa.framework.ThermostatTest;
+import org.thermostat.qa.framework.ThermostatUtilities.GuiThread;
+
+/**
+ * Class AgentTest
+ * contains basic smoke tests for starting the Thermostat agent. Starting the agent without
+ * various parts of web storage (which should not work) and with web storage is checked.
+ *
+ */
+public class AgentWebStorageTest extends ThermostatGuiTest
+{
+    private static final String[] THERM_AGENT_WITH_TOMCAT_ONLY_THERMOSTAT_LOGS = new String[] {
+        "com.mongodb.MongoException.Network: Read operation to server /127.0.0.1:27518 failed on database thermostat",
+        "java.net.ConnectException: Connection refused"
+        };
+    private static final String[] THERM_AGENT_WITH_TOMCAT_ONLY_CATALINA_LOGS = new String[] {
+        "WebStorageEndPoint: Initializing web service",
+        "WebStorageEndPoint: THERMOSTAT_HOME == /home/jfabriko/thermostaty/testing_thermostat/thermostat/distribution/target/image",
+        "WARNING - MongoConnection: Failed to connect to storage",
+        "com.mongodb.MongoException.Network: Read operation to server /127.0.0.1:27518 failed on database thermostat",
+        "java.net.ConnectException: Connection refused"
+    };
+   
+    private static final String[] THERM_AGENT_WITH_WEB_STORAGE_THERMOSTAT_LOGS = new String[] {
+        "WebStorageEndPoint: Initializing web service",
+        "WebStorageEndPoint: THERMOSTAT_HOME == /home/jfabriko/thermostaty/testing_thermostat/thermostat/distribution/target/image",
+        "MongoConnection: Using plain socket for mongodb://",
+        "WebStorageEndPoint: (id: 0) registered non-aggreate category: vm-cpu-stats|com.redhat.thermostat.vm.cpu.common.model.VmCpuStat|{timeStamp=Key: timeStamp, agentId=Key: agentId, vmId=Key: vmId, cpuLoad=Key: cpuLoad}",
+        "WebStorageEndPoint: (id: 1) registered non-aggreate category: vm-heap-info|com.redhat.thermostat.vm.heap.analysis.common.model.HeapInfo|{timeStamp=Key: timeStamp, agentId=Key: agentId, vmId=Key: vmId, heapId=Key: heapId, heapDumpId=Key: heapDumpId, histogramId=Key: histogramId}",
+        "WebStorageEndPoint: (id: 2) registered non-aggreate category: vm-gc-stats|com.redhat.thermostat.vm.gc.common.model.VmGcStat|{runCount=Key: runCount, timeStamp=Key: timeStamp, agentId=Key: agentId, vmId=Key: vmId, wallTime=Key: wallTime, collectorName=Key: collectorName}",
+        "WebStorageEndPoint: (id: 3) registered non-aggreate category: vm-memory-stats|com.redhat.thermostat.vm.memory.common.model.VmMemoryStat|{timeStamp=Key: timeStamp, generations=Key: generations, agentId=Key: agentId, vmId=Key: vmId}",
+        "WebStorageEndPoint: (id: 4) registered non-aggreate category: numa-stat|com.redhat.thermostat.numa.common.NumaStat|{nodeStats=Key: nodeStats, timeStamp=Key: timeStamp, agentId=Key: agentId}",
+        "WebStorageEndPoint: (id: 5) registered non-aggreate category: numa-host-info|com.redhat.thermostat.numa.common.NumaHostInfo|{agentId=Key: agentId, hostNumNumaNodes=Key: hostNumNumaNodes}",
+        "WebStorageEndPoint: (id: 6) registered non-aggreate category: memory-stats|com.redhat.thermostat.host.memory.common.model.MemoryStat|{total=Key: total, cached=Key: cached, free=Key: free, timeStamp=Key: timeStamp, swapFree=Key: swapFree, swapTotal=Key: swapTotal, buffers=Key: buffers, agentId=Key: agentId, commitLimit=Key: commitLimit}"
+        };
+    private static final String[] THERM_AGENT_WITH_WEB_STORAGE_CATALINA_LOGS = new String[] {
+        "INFO: Deploying web application directory",
+        "/webapps/thermostat",
+        "WebStorageEndPoint: Initializing web service",
+        "WebStorageEndPoint: THERMOSTAT_HOME == /home/jfabriko/thermostaty/testing_thermostat/thermostat/distribution/target/image",
+        "MongoConnection: Using plain socket for mongodb://",
+        "WebStorageEndPoint: (id: 0) registered non-aggreate category: vm-cpu-stats|com.redhat.thermostat.vm.cpu.common.model.VmCpuStat|{timeStamp=Key: timeStamp, agentId=Key: agentId, vmId=Key: vmId, cpuLoad=Key: cpuLoad}",
+        "WebStorageEndPoint: (id: 1) registered non-aggreate category: vm-heap-info|com.redhat.thermostat.vm.heap.analysis.common.model.HeapInfo|{timeStamp=Key: timeStamp, agentId=Key: agentId, vmId=Key: vmId, heapId=Key: heapId, heapDumpId=Key: heapDumpId, histogramId=Key: histogramId}",
+        "WebStorageEndPoint: (id: 2) registered non-aggreate category: vm-gc-stats|com.redhat.thermostat.vm.gc.common.model.VmGcStat|{runCount=Key: runCount, timeStamp=Key: timeStamp, agentId=Key: agentId, vmId=Key: vmId, wallTime=Key: wallTime, collectorName=Key: collectorName}",
+        "WebStorageEndPoint: (id: 3) registered non-aggreate category: vm-memory-stats|com.redhat.thermostat.vm.memory.common.model.VmMemoryStat|{timeStamp=Key: timeStamp, generations=Key: generations, agentId=Key: agentId, vmId=Key: vmId}",
+        "WebStorageEndPoint: (id: 4) registered non-aggreate category: numa-stat|com.redhat.thermostat.numa.common.NumaStat|{nodeStats=Key: nodeStats, timeStamp=Key: timeStamp, agentId=Key: agentId}"
+        };
+    
+    
+    @Override
+    protected void tearDown()
+    {
+        try
+        {
+            restoreNormalStorageConfigFiles();
+        }
+        catch (IOException e)
+        {
+            // TODO Auto-generated catch block
+            e.printStackTrace();
+        }        
+    }
+
+    @Override
+    protected void setUp()
+    {
+        
+        try
+        {
+            eraseTomcatOutputFiles();
+            prepareWebStorageConfigFiles();
+        }
+        catch (IOException e)
+        {
+            // TODO Auto-generated catch block
+            e.printStackTrace();
+        }
+        
+    }
+
+    /**
+     * Method testStartWithoutStorage
+     * tries to start thermostat agent in new thread without previously
+     * starting the storage or tomcat. There should be no thermostat agents
+     * running.
+     * 
+     * This test uses the following scripts:
+     * <ul>
+     * <li><a href="scripts/list_all_therm_agents.sh">list_all_therm_agents.sh</a>,
+     * <li><a href="scripts/stop_all_therm_agents.sh">stop_all_therm_agents.sh</a>.
+     * <ul>
+     * 
+     * @throws IOException
+     */
+    public void testStartWithoutAnyStorage() throws IOException
+    {
+        //start only agent
+        new AgentThread().start();
+        logInfo("runAgentThread", "Thermostat Agent tried to start");
+        
+        //wait till agent stops
+        sleep(FIVE_SEC);
+      
+        //there should not be any agent running (check the jps)
+        List<String> output = runHelperBashScript("list_all_therm_agents.sh");
+        Assert.assertNotNull(output, "error running script 'list_all_therm_agents.sh'");
+        for (String message : output)
+        {
+            logInfo("Agent list:", message);
+        }
+        //to be sure there is no running agent
+        runHelperBashScript("stop_all_therm_agents.sh");
+        
+        Assert.assertTrue(output.size()==0, "there should not be any running thermostat agents");
+    }
+    
+    public void testStartWithTomcatWithoutStorage() throws IOException 
+    {
+        startTomcat();
+        
+        //start only agent
+        new AgentThread().start();
+        logInfo("runAgentThread", "Thermostat Agent tried to start");
+        
+        //wait till agent stops
+        sleep(FIVE_SEC);
+      
+        
+        stopTomcat();
+
+        //switch off the agent that probably runs, because tomcat was on
+        runHelperBashScript("stop_all_therm_agents.sh");
+        
+        //analyse the contents of logs in tomcat
+        createTomcatThermostatOutputFiles();
+        
+        List<String> outputs = getTomcatOutputs("catalina-logs.txt");
+        checkPresenceOfPatterns(outputs, THERM_AGENT_WITH_TOMCAT_ONLY_CATALINA_LOGS);
+        /*for(String s : outputs)
+        {
+            logInfo("+Tomcat-Storage catalina-logs.txt: ", s);
+        }*/
+        
+        outputs = getTomcatOutputs("thermostat-web-storage-logs.txt");
+        checkPresenceOfPatterns(outputs, THERM_AGENT_WITH_TOMCAT_ONLY_THERMOSTAT_LOGS);
+        /*for(String s : outputs)
+        {
+            logInfo("+Tomcat-Storage thermostat-web-storage-logs.txt: ", s);
+        }*/
+        
+        outputs = getTomcatOutputs("localhost_access_logs.txt");
+        /*for(String s : outputs)
+        {
+            logInfo("+Tomcat-Storage localhost_access_logs.txt: ", s);
+        }*/
+      
+    }
+    
+    public void testStartWithStorageWithoutTomcat() throws IOException
+    {
+        startStorage();
+        
+        //start only agent
+        new AgentThread().start();
+        logInfo("runAgentThread", "Thermostat Agent tried to start");
+        
+        //wait till agent stops
+        sleep(FIVE_SEC);
+      
+        //there should not be any agent running (check the jps)
+        List<String> output = runHelperBashScript("list_all_therm_agents.sh");
+
+        //to be sure there are no running agents
+        runHelperBashScript("stop_all_therm_agents.sh");
+
+        stopStorage();
+
+        Assert.assertNotNull(output, "error running script 'list_all_therm_agents.sh'");
+        for (String message : output)
+        {
+            logInfo("Agent list:", message);
+        }
+        Assert.assertTrue(output.size()==0, "there should not be any running thermostat agents");
+    }
+    
+    /**
+     * Method testStartAgent
+     * starts the storage and then tries to start thermostat agent in a new
+     * thread. There should be one thermostat agent running.
+     * 
+     * This test uses the following scripts:
+     * <ul>
+     * <li><a href="scripts/list_all_therm_agents.sh">list_all_therm_agents.sh</a>,
+     * <li><a href="scripts/stop_all_therm_agents.sh">stop_all_therm_agents.sh</a>.
+     * <ul>
+     * 
+     * @throws IOException
+     * @throws AWTException 
+     */
+    public void testStartAgent() throws IOException, AWTException
+    {
+        startWebStorage();
+        
+        //start agent
+        new AgentThread().start();
+        logInfo("runAgentThread", "Thermostat Agent tried to start");
+        
+        //check if the agent is running (jps)
+        List<String> output = runHelperBashScript("list_all_therm_agents.sh");
+        Assert.assertNotNull(output, "error running script 'list_all_therm_agents.sh'");
+        Assert.assertTrue(output.size()>0, "there should be >0 running thermostat agents");
+
+        //let the agent write some data
+        sleep(5000);
+        
+        //stop the agent
+        output = runHelperBashScript("stop_all_therm_agents.sh");
+        Assert.assertNotNull(output, "error running script 'stop_all_therm_agents.sh'");
+        
+      // runThermostatGuiInANewThread();
+        //sleep(3000);
+       // stopGUI(new GuiRobot());
+        
+        stopWebStorage();
+        
+        sleep(3000);
+        
+      //analyse the contents of logs in tomcat
+        createTomcatThermostatOutputFiles();
+        
+        List<String> outputs = getTomcatOutputs("catalina-logs.txt");
+                
+        checkPresenceOfPatterns(outputs,THERM_AGENT_WITH_WEB_STORAGE_CATALINA_LOGS);
+        
+        outputs = getTomcatOutputs("thermostat-web-storage-logs.txt");
+                
+        checkPresenceOfPatterns(outputs,THERM_AGENT_WITH_WEB_STORAGE_THERMOSTAT_LOGS);
+        
+        outputs = getTomcatOutputs("localhost_access_logs.txt");        
+    }
+    
+    /*
+    public void testStartAgentWithBadLogin(){
+        //copy bad login info into agent conf
+        //try to run
+        //there should not be any agents
+        //interesting logs
+        //copy back the good login info
+    }*/
+    
+    public static void main(String[] args) {
+        new AgentWebStorageTest().doTests(args);
+    }
+
+}