Mercurial > hg > ThermostatQA
view scripts/check-collections-smoke.js @ 171:1d7ab9111fd2
- added tests ported to the new framework (package org.thermostat.qa2.tests)
- added/updated required targets in Makefile
- new info about dependecies added to README.md
- authorization and error checking code added to mongo js scripts
- done necessary changes to reporter, so it can be used with new framework
- updated keyrings
- added required pattern (for gui tests)
author | Zdenek Zambersky <zzambers@redhat.com> |
---|---|
date | Tue, 10 Mar 2015 13:48:12 +0100 |
parents | 80e28ec6a244 |
children |
line wrap: on
line source
debug = false; verbose = true; //function for running the tests var runTests = function() { // get the thermostat db db = db.getMongo().getDB( "thermostat" ); db.auth("mongodevuser","mongodevpassword"); // initialize the arrays of collection field names + types fity = { "agent-config" : [ ["agentId","string"], ["alive","boolean"], ["configListenAddress","string"], ["startTime","NumberLong"], ["stopTime","NumberLong"] ], "backend-info" : [ ["agentId","string"], ["name","string"], ["description","string"], ["observeNewJvm","boolean"], ["pids",["empty array","array of number"]], ["active","boolean"], ["orderValue","number"] ], "cpu-stats" : [ ["agentId","string"], ["perProcessorUsage","array of number"], ["timeStamp","NumberLong"] ], "host-info" : [ ["agentId","string"], ["hostname","string"], ["osName","string"], ["osKernel","string"], ["cpuModel","string"], ["cpuCount","number"], ["totalMemory","NumberLong"] ], "memory-stats" : [ ["agentId","string"], ["timeStamp","NumberLong"], ["total","NumberLong"], ["free","NumberLong"], ["buffers","NumberLong"], ["cached","NumberLong"], ["swapTotal","NumberLong"], ["swapFree","NumberLong"], ["commitLimit","NumberLong"] ], "network-info" : [ ["agentId","string"], ["interfaceName","string"], ["ip4Addr","string"], ["ip6Addr","string"] ], "numa-host-info" : [ ["agentId","string"], ["numNumaNodes","number"] ], "numa-stat" : [ ["agentId","string"], ["timeStamp", "NumberLong"], ["nodeStats","array of object"] ], "system.indexes" : [ ["v","number"], ["key","object"], ["ns","string"], ["name","string"] ], "vm-class-stats" : [ ["agentId","string"], ["vmId","string"], ["timeStamp","NumberLong"], ["loadedClasses","NumberLong"] ], "vm-cpu-stats" : [ ["agentId","string"], ["vmId","string"], ["timeStamp","NumberLong"], ["cpuLoad","number"] ], "vm-deadlock-data" : [], "vm-gc-stats" : [ ["agentId","string"], ["vmId","string"], ["timeStamp","NumberLong"], ["collectorName","string"], ["runCount","NumberLong"], ["wallTime","NumberLong"] ], "vm-heap-info" : [], "vm-info" : [ ["agentId","string"], ["vmId","string"], ["vmPid","number"], ["startTimeStamp","NumberLong"], ["stopTimeStamp","NumberLong"], ["javaVersion","string"], ["javaHome","string"], ["mainClass","string"], ["javaCommandLine","string"], ["vmName","string"], ["vmArguments","string"], ["vmInfo","string"], ["vmVersion","string"], ["propertiesAsArray",["empty array","array of object"]], //???TODO what type? ["environmentAsArray","array of object"], ["loadedNativeLibraries",["empty array","array of object"]],//???TODO what type? ["uid","NumberLong"], ["username","string"] ], "vm-jmx-notification" : [], "vm-jmx-notification-status" : [], "vm-memory-stats" : [ ["agentId","string"], ["vmId","string"], ["timeStamp","NumberLong"], ["generations","array of object"] ], "vm-thread-capabilities" : [ ["agentId","string"], ["vmId","string"], ["supportedFeaturesList","array of string"] ], "vm-thread-harvesting" : [ ["agentId","string"], ["vmId","string"], ["timeStamp","NumberLong"], ["harvesting","boolean"] ], "vm-thread-info" : [], "vm-thread-summary": [] } //check the schemes of all collections c = db.getCollectionNames(); c.forEach(getSchemaAnalysis); } // get collection from db var mappedCollection = function(x) { return db[x]; } // function for inspecting the types in each collection var getSchemaAnalysis = function(y) { if( fity[y] != null && fity[y].length >0) { var wholeSchemaPass = true; var schemaPass; if(debug || verbose) { print("---------------------------------------------------------------"); print("checking collection: " + y); } // deal with agent config schema // it is expected to have agentId, alive, configListenAddress // startTime, etc. keys // Ideally it would analyze the type of the field as well. // // example: // record.startTime.tojson() == 'NumberLong("1391084711073")' var record = mappedCollection(y).findOne(); try { var fieldsTypes = fity[y]; if(debug) printjson(fieldsTypes); for(var i=0; i<fieldsTypes.length; i++) { //checking not null + the right type of one field schemaPass = true; schemaPass = checkOneField(record, fieldsTypes[i][0], fieldsTypes[i][1]); wholeSchemaPass = wholeSchemaPass && schemaPass; } } catch(err) { wholeSchemaPass = false; } var isPass = wholeSchemaPass ? "OK" : "BAD"; print("schema for " + y + " is " + isPass ); return wholeSchemaPass; }else{ print("schema for "+ y + " is UNKNOWN by this test script"); return false; } } // special type=arrays, // for objects (not arrays) the realType will be parsed from json representation: var typeOrObjectTypeOf = function(x) { if(x == null) { if(Array.isArray(x)) return "array null" else if(typeof x == "object") return "object null" else return "null"; } var type = typeof x; if( Array.isArray(x) ) { if(x.length > 0) { type = "array of "+typeOrObjectTypeOf(x[0]); }else{ type = "empty array"; } } if( type == "object" ) { if("tojson" in x) { var jsonRep = x.tojson(); var endOfObjName = jsonRep.indexOf('('); type = jsonRep.substring(0,endOfObjName); } } return type; } // returns boolean if the given field is ok in given record var checkOneField = function(record,field,expectedType) { if(debug || verbose) { print("-checking field "+field+":"); } var notNull = (record[field] != null); var realType = typeOrObjectTypeOf(record[field]); var ofExpectedType = false; if((typeof expectedType) == "string")//one expected type { ofExpectedType = (realType == expectedType) }else{ //more admissible expected types = an array of them for(var i=0; i<expectedType.length; i++) { ofExpectedType = ofExpectedType || (expectedType[i] == realType); } } var OKString = (notNull && ofExpectedType)? "OK":"BAD" if(debug || verbose) { print(" not-null?"+notNull+", type="+realType+" (expected="+expectedType+") ... "+OKString); } return notNull && ofExpectedType } /******************RUN******************/ runTests();