Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Created a testing project to house testing related infrastructure.
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
1 parent
62eafc3
commit a3bace8
Showing
8 changed files
with
250 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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
39
testing/src/main/java/io/atomix/atomix/testing/TestCaseLogger.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters