view src/org/thermostat/qa/testsuites/DBCommandsHeapDumpTest.java @ 162:e8ad3e5e4893

Making testing process automatic
author Zdenek Zambersky <zzambers@redhat.com>
date Wed, 22 Oct 2014 16:42:56 +0200
parents 7fa8af3d3e7d
children af42c142855f
line wrap: on
line source

/*

    ThermostatQA - test framework for Thermostat Monitoring Tool

    Copyright 2014 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.io.IOException;
import java.util.List;

import org.thermostat.qa.annotations.StorageType;
import org.thermostat.qa.annotations.StorageTypes;
import org.thermostat.qa.framework.Assert;
import org.thermostat.qa.framework.ThermostatTest;

/**
 * Class DBCommandsHeapDumpTest
 * contains tests for checking the db scheme for thermostat mongodb
 * storage after a heap dump performed as a standalone command.
 * The test starts storage and one agent and performs commands
 * thermostat list-vms and thermostat dump-heap -a running-vm-host-id
 * -v running-vm-id.
 * Then all the collections that should not be empty after these
 * steps are checked - there should be a non-null record in each
 * (findOne() in the js script for mongo shell), and
 * its elements should be of the right types.
 *
 */
@StorageType(StorageTypes.MONGODB_STORAGE)
public class DBCommandsHeapDumpTest extends ThermostatTest
{
    
    private List<String> scriptOutput;
       
    @Override
    protected void tearDown()
    {

    }

    @Override
    protected void setUp()
    {
        // TODO
        //start storage and agent
        startStorage();
        new AgentThread().start();
        logInfo("runAgentThread", "Thermostat Agent started");
        
        sleep(2*ONE_SEC);

        //list-vms, find a running vm, dump a heap
        try
        {
            List<String> vms = thermostatListVms("client-tester", "heslo2");
            boolean foundRunning = false;
            int index = -1;
            for(String vm : vms)
            {
                if(vm.contains("RUNNING"))
                {
                    foundRunning = true;
                    index = vms.indexOf(vm);
                    break;
                }
            }
            
            Assert.assertTrue(foundRunning, "Problem finding a running vm!");
            
            String hostId = (vms.get(index).split(" "))[0];
            String vmId =  (vms.get(index).split(" "))[2];
            thermostatDumpHeap(hostId, vmId, "", "");
            
        }
        catch (IOException e1)
        {
            // TODO Auto-generated catch block
            e1.printStackTrace();
        }

        //run js test script, get output
        try
        {
            scriptOutput = runCommandsInMongoShell("check-collection-heap-dump.js");
        }
        catch (IOException e)
        {
            e.printStackTrace();
        }
        
        //stop the agent and storage
        try
        {
            //ADD END OF THE SITUATION HERE

            runHelperBashScript("stop_all_therm_agents.sh");
            stopStorage();
        }
        catch (IOException e)
        {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }

    public void testAgentConfig(){
        Assert.assertNotNull(scriptOutput, "problems running auxiliary script");
        checkPresenceOfPatternInTexts(scriptOutput, "schema for agent-config is OK");
    }
    public void testBackendInfo(){
        Assert.assertNotNull(scriptOutput, "problems running auxiliary script");
        checkPresenceOfPatternInTexts(scriptOutput, "schema for backend-info is OK");
    }
    public void testCpuStats(){
        Assert.assertNotNull(scriptOutput, "problems running auxiliary script");
        checkPresenceOfPatternInTexts(scriptOutput, "schema for cpu-stats is OK");
    }
    /*public void testFs.chunks(){
        Assert.assertNotNull(scriptOutput, "problems running auxiliary script");
        checkPresenceOfPatternInTexts(scriptOutput, "schema for fs.chunks is OK");
    }
    public void testFs.files(){
        Assert.assertNotNull(scriptOutput, "problems running auxiliary script");
        checkPresenceOfPatternInTexts(scriptOutput, "schema for fs.files is OK");
    }*/
    public void testHostInfo(){
        Assert.assertNotNull(scriptOutput, "problems running auxiliary script");
        checkPresenceOfPatternInTexts(scriptOutput, "schema for host-info is OK");
    }
    public void testMemoryStats(){
        Assert.assertNotNull(scriptOutput, "problems running auxiliary script");
        checkPresenceOfPatternInTexts(scriptOutput, "schema for memory-stats is OK");
    }
    public void testNetworkInfo(){
        Assert.assertNotNull(scriptOutput, "problems running auxiliary script");
        checkPresenceOfPatternInTexts(scriptOutput, "schema for network-info is OK");
    }
    public void testNumaHostInfo(){
        Assert.assertNotNull(scriptOutput, "problems running auxiliary script");
        checkPresenceOfPatternInTexts(scriptOutput, "schema for numa-host-info is OK");
    }
    public void testNumaStat(){
        Assert.assertNotNull(scriptOutput, "problems running auxiliary script");
        checkPresenceOfPatternInTexts(scriptOutput, "schema for numa-stat is OK");
    }
    public void testVmClassStats(){
        Assert.assertNotNull(scriptOutput, "problems running auxiliary script");
        checkPresenceOfPatternInTexts(scriptOutput, "schema for vm-class-stats is OK");
    }
    public void testVmCpuStats(){
        Assert.assertNotNull(scriptOutput, "problems running auxiliary script");
        checkPresenceOfPatternInTexts(scriptOutput, "schema for vm-cpu-stats is OK");
    }
    public void testVmGcStats(){
        Assert.assertNotNull(scriptOutput, "problems running auxiliary script");
        checkPresenceOfPatternInTexts(scriptOutput, "schema for vm-gc-stats is OK");
    }
    public void testVmHeapInfo(){
        Assert.assertNotNull(scriptOutput, "problems running auxiliary script");
        checkPresenceOfPatternInTexts(scriptOutput, "schema for vm-heap-info is OK");
    }
    public void testVmInfo(){
        Assert.assertNotNull(scriptOutput, "problems running auxiliary script");
        checkPresenceOfPatternInTexts(scriptOutput, "schema for vm-info is OK");
    }
    public void testVmMemoryStats(){
        Assert.assertNotNull(scriptOutput, "problems running auxiliary script");
        checkPresenceOfPatternInTexts(scriptOutput, "schema for vm-memory-stats is OK");
    }
    public void testVmThreadCapabilities(){
        Assert.assertNotNull(scriptOutput, "problems running auxiliary script");
        checkPresenceOfPatternInTexts(scriptOutput, "schema for vm-thread-capabilities is OK");
    }
    public void testVmThreadHarvesting(){
        Assert.assertNotNull(scriptOutput, "problems running auxiliary script");
        checkPresenceOfPatternInTexts(scriptOutput, "schema for vm-thread-harvesting is OK");
    }
    
    public static void main(String[] args) {
        new DBCommandsHeapDumpTest().doTests(args);
    }

}