Skip to content

Commit

Permalink
Created a testing project to house testing related infrastructure.
Browse files Browse the repository at this point in the history
Add a test case logger to log the beginning and end of test methods to better help us ascertain what is going on in the logs. AFTER is only logged if the test runs for > 1 second.
  • Loading branch information
jhalterman committed Dec 11, 2015
1 parent 62eafc3 commit a3bace8
Show file tree
Hide file tree
Showing 8 changed files with 250 additions and 16 deletions.
47 changes: 31 additions & 16 deletions all/pom.xml
@@ -1,19 +1,11 @@
<!--
~ Copyright 2015 the original author or authors.
~
~ Licensed under the Apache License, Version 2.0 (the "License");
~ you may not use this file except in compliance with the License.
~ You may obtain a copy of the License at
~
~ http://www.apache.org/licenses/LICENSE-2.0
~
~ Unless required by applicable law or agreed to in writing, software
~ distributed under the License is distributed on an "AS IS" BASIS,
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
~ See the License for the specific language governing permissions and
~ limitations under the License.
-->
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<!-- ~ Copyright 2015 the original author or authors. ~ ~ Licensed under the Apache License, Version
2.0 (the "License"); ~ you may not use this file except in compliance with the License. ~ You may obtain
a copy of the License at ~ ~ http://www.apache.org/licenses/LICENSE-2.0 ~ ~ Unless required by applicable
law or agreed to in writing, software ~ distributed under the License is distributed on an "AS IS" BASIS,
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. ~ See the License for the
specific language governing permissions and ~ limitations under the License. -->
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<parent>
Expand Down Expand Up @@ -51,5 +43,28 @@
<artifactId>catalyst-netty</artifactId>
<version>${catalyst.version}</version>
</dependency>
<dependency>
<groupId>io.atomix</groupId>
<artifactId>atomix-testing</artifactId>
<version>${project.version}</version>
<scope>test</scope>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<properties>
<property>
<name>listener</name>
<value>io.atomix.atomix.testing.TestCaseLogger</value>
</property>
</properties>
</configuration>
</plugin>
</plugins>
</build>
</project>
23 changes: 23 additions & 0 deletions collections/pom.xml
Expand Up @@ -37,5 +37,28 @@
<version>${catalyst.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.atomix</groupId>
<artifactId>atomix-testing</artifactId>
<version>${project.version}</version>
<scope>test</scope>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<properties>
<property>
<name>listener</name>
<value>io.atomix.atomix.testing.TestCaseLogger</value>
</property>
</properties>
</configuration>
</plugin>
</plugins>
</build>
</project>
23 changes: 23 additions & 0 deletions coordination/pom.xml
Expand Up @@ -37,5 +37,28 @@
<version>${catalyst.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.atomix</groupId>
<artifactId>atomix-testing</artifactId>
<version>${project.version}</version>
<scope>test</scope>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<properties>
<property>
<name>listener</name>
<value>io.atomix.atomix.testing.TestCaseLogger</value>
</property>
</properties>
</configuration>
</plugin>
</plugins>
</build>
</project>
23 changes: 23 additions & 0 deletions manager/pom.xml
Expand Up @@ -21,5 +21,28 @@
<artifactId>atomix-resource</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>io.atomix</groupId>
<artifactId>atomix-testing</artifactId>
<version>${project.version}</version>
<scope>test</scope>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<properties>
<property>
<name>listener</name>
<value>io.atomix.atomix.testing.TestCaseLogger</value>
</property>
</properties>
</configuration>
</plugin>
</plugins>
</build>
</project>
1 change: 1 addition & 0 deletions pom.xml
Expand Up @@ -68,6 +68,7 @@
<module>coordination</module>
<module>variables</module>
<module>examples</module>
<module>testing</module>
<module>all</module>
</modules>

Expand Down
87 changes: 87 additions & 0 deletions testing/pom.xml
@@ -0,0 +1,87 @@
<!--
~ Copyright 2015 the original author or authors.
~
~ Licensed under the Apache License, Version 2.0 (the "License");
~ you may not use this file except in compliance with the License.
~ You may obtain a copy of the License at
~
~ http://www.apache.org/licenses/LICENSE-2.0
~
~ Unless required by applicable law or agreed to in writing, software
~ distributed under the License is distributed on an "AS IS" BASIS,
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
~ See the License for the specific language governing permissions and
~ limitations under the License
-->
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<parent>
<groupId>io.atomix</groupId>
<artifactId>atomix-parent</artifactId>
<version>0.1.0-SNAPSHOT</version>
</parent>

<artifactId>atomix-testing</artifactId>
<name>Atomix Testing Support</name>

<properties>
<logback.version>1.1.2</logback.version>
</properties>

<dependencies>
<dependency>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
<version>6.8.8</version>
</dependency>
<dependency>
<groupId>net.jodah</groupId>
<artifactId>concurrentunit</artifactId>
<version>0.4.2</version>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
<version>1.10.19</version>
</dependency>
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
<version>${logback.version}</version>
</dependency>
</dependencies>

<build>
<plugins>
<!-- Skip deployment -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-deploy-plugin</artifactId>
<version>2.8.2</version>
<configuration>
<skip>true</skip>
</configuration>
</plugin>

<!-- Skip site / docs creation -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-site-plugin</artifactId>
<version>3.4</version>
<configuration>
<skip>true</skip>
<skipDeploy>true</skipDeploy>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<version>2.10.3</version>
<configuration>
<skip>true</skip>
</configuration>
</plugin>
</plugins>
</build>
</project>
39 changes: 39 additions & 0 deletions testing/src/main/java/io/atomix/atomix/testing/TestCaseLogger.java
@@ -0,0 +1,39 @@
package io.atomix.atomix.testing;

import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

import org.slf4j.LoggerFactory;
import org.testng.IClass;
import org.testng.IInvokedMethod;
import org.testng.IInvokedMethodListener;
import org.testng.ITestNGMethod;
import org.testng.ITestResult;

public class TestCaseLogger implements IInvokedMethodListener {
private static final Map<ITestNGMethod, Long> START_TIMES = new ConcurrentHashMap<>();

public void beforeInvocation(IInvokedMethod method, ITestResult testResult) {
if (!method.isTestMethod())
return;

ITestNGMethod testMethod = method.getTestMethod();
IClass clazz = testMethod.getTestClass();

START_TIMES.put(testMethod, System.currentTimeMillis());
LoggerFactory.getLogger("BEFORE").info("{}.{}", clazz.getRealClass().getName(), testMethod.getMethodName());
}

public void afterInvocation(IInvokedMethod method, ITestResult testResult) {
if (!method.isTestMethod())
return;

ITestNGMethod testMethod = method.getTestMethod();
IClass clazz = testMethod.getTestClass();
double elapsed = (System.currentTimeMillis() - START_TIMES.remove(testMethod)) / 1000.0;

if (elapsed > 1)
LoggerFactory.getLogger("AFTER").info("{}.{} Ran for {} seconds", clazz.getRealClass().getName(),
testMethod.getMethodName(), elapsed);
}
}
23 changes: 23 additions & 0 deletions variables/pom.xml
Expand Up @@ -37,5 +37,28 @@
<version>${catalyst.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.atomix</groupId>
<artifactId>atomix-testing</artifactId>
<version>${project.version}</version>
<scope>test</scope>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<properties>
<property>
<name>listener</name>
<value>io.atomix.atomix.testing.TestCaseLogger</value>
</property>
</properties>
</configuration>
</plugin>
</plugins>
</build>
</project>

0 comments on commit a3bace8

Please sign in to comment.