More testing, coverage setup and aa try-catch to avoid exits on errors

This commit is contained in:
Mark Nellemann 2020-08-17 14:23:15 +02:00
parent e805d25143
commit 5004a30331
7 changed files with 128 additions and 14 deletions

View File

@ -5,6 +5,9 @@ plugins {
// Apply the application plugin to add support for building a CLI application.
id 'application'
// Code coverage of tests
id 'jacoco'
id "com.github.johnrengelman.shadow" version "6.0.0"
id "nebula.ospackage" version "8.4.1"
}
@ -68,3 +71,29 @@ buildDeb {
dependsOn startShadowScripts
requires('default-jre-headless')
}
jacoco {
toolVersion = "0.8.5"
}
jacocoTestReport {
group = "verification"
reports {
xml.enabled false
csv.enabled false
html.destination file("${buildDir}/reports/coverage")
}
}
test.finalizedBy jacocoTestReport
jacocoTestCoverageVerification {
violationRules {
rule {
limit {
minimum = 0.3 // FIXME: Raise when more tests are implemented
}
}
}
}
check.dependsOn jacocoTestCoverageVerification

View File

@ -1,2 +1,2 @@
group = biz.nellemann.hmci
version = 1.0.3
version = 1.0.4

View File

@ -104,7 +104,6 @@ class App implements Runnable {
} catch(Exception e) {
log.error(e.message)
hmc = null
}
}
@ -129,7 +128,6 @@ class App implements Runnable {
} catch(Exception e) {
log.error(e.message)
hmc = null
}
}
@ -196,17 +194,21 @@ class App implements Runnable {
while(keepRunning) {
getMetricsForSystems()
getMetricsForPartitions()
try {
getMetricsForSystems()
getMetricsForPartitions()
writeMetricsForManagedSystems()
writeMetricsForLogicalPartitions()
influxClient.writeBatchPoints()
writeMetricsForManagedSystems()
writeMetricsForLogicalPartitions()
influxClient.writeBatchPoints()
// Refresh HMC's
if(executions > rescanHmcEvery) {
executions = 0
discover()
// Refresh HMC's
if(executions > rescanHmcEvery) {
executions = 0
discover()
}
} catch(Exception e) {
log.error(e.message, e)
}
executions++

View File

@ -82,4 +82,9 @@ class HmcClientTest extends Specification {
}
// getPcmDataForManagedSystem
// getPcmDataForLogicalPartition
}

View File

@ -17,7 +17,7 @@ class InfluxClientTest extends Specification {
influxClient.logoff()
}
@Ignore
void "write ManagedSystem data to influx"() {
setup:
@ -34,7 +34,7 @@ class InfluxClientTest extends Specification {
}
@Ignore
void "write LogicalPartition data to influx"() {
setup:

View File

@ -23,6 +23,45 @@ class LogicalPartitionTest extends Specification {
}
void "test getMemoryMetrics"() {
setup:
def testFile = new File(getClass().getResource('/pcm-data-logical-partition.json').toURI())
def testJson = testFile.getText('UTF-8')
ManagedSystem system = new ManagedSystem("site1", "e09834d1-c930-3883-bdad-405d8e26e166", "Test Name","Test Type", "Test Model", "Test S/N")
LogicalPartition lpar = new LogicalPartition("2DE05DB6-8AD5-448F-8327-0F488D287E82", "9Flash01", "OS400", system)
when:
lpar.processMetrics(testJson)
List<Map> listOfMaps = lpar.getMemoryMetrics()
then:
listOfMaps.size() == 1
listOfMaps.first().get("fields")['logicalMem'] == 8192.000
listOfMaps.first().get("tags")['partition'] == '9Flash01'
}
void "test getProcessorMetrics"() {
setup:
def testFile = new File(getClass().getResource('/pcm-data-logical-partition.json').toURI())
def testJson = testFile.getText('UTF-8')
ManagedSystem system = new ManagedSystem("site1", "e09834d1-c930-3883-bdad-405d8e26e166", "Test Name","Test Type", "Test Model", "Test S/N")
LogicalPartition lpar = new LogicalPartition("2DE05DB6-8AD5-448F-8327-0F488D287E82", "9Flash01", "OS400", system)
when:
lpar.processMetrics(testJson)
List<Map> listOfMaps = lpar.getProcessorMetrics()
then:
listOfMaps.size() == 1
listOfMaps.first().get("fields")['utilizedProcUnits'] == 0.001
listOfMaps.first().get("tags")['partition'] == '9Flash01'
}
void "test getVirtualEthernetAdapterMetrics"() {
setup:
@ -41,7 +80,23 @@ class LogicalPartitionTest extends Specification {
listOfMaps.first().get("tags")['sea'] == 'ent5'
}
void "test getVirtualFiberChannelAdaptersMetrics"() {
setup:
def testFile = new File(getClass().getResource('/pcm-data-logical-partition.json').toURI())
def testJson = testFile.getText('UTF-8')
ManagedSystem system = new ManagedSystem("site1", "e09834d1-c930-3883-bdad-405d8e26e166", "Test Name","Test Type", "Test Model", "Test S/N")
LogicalPartition lpar = new LogicalPartition("2DE05DB6-8AD5-448F-8327-0F488D287E82", "9Flash01", "OS400", system)
when:
lpar.processMetrics(testJson)
List<Map> listOfMaps = lpar.getVirtualFiberChannelAdaptersMetrics()
then:
listOfMaps.size() == 4
listOfMaps.first().get("fields")['writeBytes'] == 546.133
listOfMaps.first().get("tags")['viosId'] == '2'
}
}

View File

@ -0,0 +1,23 @@
package biz.nellemann.hmci
import spock.lang.Specification
import java.time.Instant
class MetaSystemTest extends Specification {
void "test timestamp retrieval from xml"() {
setup:
def testFile = new File(getClass().getResource('/pcm-data-managed-system.json').toURI())
def testJson = testFile.getText('UTF-8')
when:
ManagedSystem system = new ManagedSystem("site1", "e09834d1-c930-3883-bdad-405d8e26e166", "Test Name","Test Type", "Test Model", "Test S/N")
system.processMetrics(testJson)
Instant instant = system.getTimestamp()
then:
instant.getEpochSecond() == 1597086630
}
}