Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion performancetest-demo-framework/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.8.2</version>
<version>4.10</version>
</dependency>
</dependencies>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
* @author Erich Eichinger
* @since 25/01/12
*/
public abstract class AbstractPerformanceTestRunner {
public abstract class AbstractPerformanceTestRunner<T extends Runnable> {

final Logger log = LoggerFactory.getLogger(getClass());

Expand Down Expand Up @@ -63,25 +63,25 @@ public void run(String[] args) throws Exception {
}

protected void run() throws Exception {
List<BrowserSessionFactory> browserProfiles = createBrowserProfiles();
List<BrowserSessionFactory<T>> browserProfiles = createBrowserProfiles();

usersMax = Math.max(users, usersMax);

log.info(String.format("PerformanceTestBegin{users=%s,sessions=%s,usersMax=%s,usersIncr=%s}", users, sessions,usersMax, usersIncr));
log.info(String.format("PerformanceTestBegin{users=%s,sessions=%s,usersMax=%s,usersIncr=%s}", users, sessions, usersMax, usersIncr));

boolean hasErrors = false;

for(int usersForIteration=users;usersForIteration<=usersMax;usersForIteration+=usersIncr){
for(int usersForIteration=users; usersForIteration <= usersMax; usersForIteration += usersIncr){
log.info(String.format("IterationBegin{usersForIteration=%s}", usersForIteration));
hasErrors = hasErrors || runIteration(browserProfiles, usersForIteration);
}

Assert.assertFalse("Performance Tests had errors", hasErrors);
}

abstract protected List<BrowserSessionFactory> createBrowserProfiles();
abstract protected List<BrowserSessionFactory<T>> createBrowserProfiles();

private boolean runIteration(List<BrowserSessionFactory> browserProfiles, int usersForIteration) throws Exception {
private boolean runIteration(List<BrowserSessionFactory<T>> browserProfiles, int usersForIteration) throws Exception {
int totalSessions = usersForIteration * sessions;

ExecutorService executor = Executors.newFixedThreadPool(usersForIteration);
Expand All @@ -90,7 +90,7 @@ private boolean runIteration(List<BrowserSessionFactory> browserProfiles, int us

for(int i=0;i<totalSessions;i++) {
// TODO: in case we have more than 1 profile, select them based on probability/distribution
BrowserSessionFactory profile = browserProfiles.get(0);
BrowserSessionFactory<T> profile = browserProfiles.get(0);
Callable<Exception> session = new SessionResultReporter(profile.getProfileClass(), profile.newRunnable());
sessions.add(session);
}
Expand All @@ -107,10 +107,10 @@ private boolean runIteration(List<BrowserSessionFactory> browserProfiles, int us
}

public class SessionResultReporter implements Callable<Exception> {
private final Class profileClass;
private final Class<T> profileClass;
final Runnable inner;

public SessionResultReporter(Class profileClass, Runnable inner) {
public SessionResultReporter(Class<T> profileClass, Runnable inner) {
this.profileClass = profileClass;
this.inner = inner;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
package org.eeichinger.testing.web;

import org.junit.Rule;
import org.junit.rules.MethodRule;
import org.junit.rules.RuleChain;
import org.junit.rules.TestRule;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand All @@ -12,10 +13,14 @@
* @author Neale Upstone/OpenCredo
*/
public class BaseWebDriverTest {
// note that rules are executed bottom up - hence DriverLifecycle must be last!
@Rule public final TestTracerRule loggerRule = new TestTracerRule();
@Rule public final MethodRule screenshotRule = new ScreenshotCaptureRule();
@Rule public final MethodRule driverLifecycle = new DriverLifecycleRule();
private final TestTracerRule loggerRule = new TestTracerRule();
private final TestRule screenshotRule = new ScreenshotCaptureRule();
private final TestRule driverLifecycle = new DriverLifecycleRule();

@Rule public final RuleChain chain = RuleChain
.outerRule(driverLifecycle)
.around(screenshotRule)
.around(loggerRule);

protected final Logger log = LoggerFactory.getLogger(getClass());
}
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
package org.eeichinger.testing.web;
import org.junit.rules.TestWatchman;
import org.junit.runners.model.FrameworkMethod;
/**
* Manages the WebDriver lifecycle for plain unit tests
*
* @author Erich Eichinger
* @since 26/01/12
*/
public class DriverLifecycleRule extends TestWatchman {
@Override
public void starting(FrameworkMethod method) {
WebDriverFactory.getInstance().initializeWebDriver();
}
@Override
public void finished(FrameworkMethod method) {
WebDriverFactory.getInstance().getCurrentWebDriver().quit();
}
}
package org.eeichinger.testing.web;

import org.junit.rules.TestWatcher;
import org.junit.runner.Description;

/**
* Manages the WebDriver lifecycle for plain unit tests
*
* @author Erich Eichinger
* @since 26/01/12
*/
public class DriverLifecycleRule extends TestWatcher {

@Override
protected void starting(Description description) {
WebDriverFactory.getInstance().initializeWebDriver();
}

@Override
protected void finished(Description description) {
WebDriverFactory.getInstance().getCurrentWebDriver().quit();
}
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package org.eeichinger.testing.web;

import org.apache.commons.io.FileUtils;
import org.junit.rules.TestWatchman;
import org.junit.runners.model.FrameworkMethod;
import org.junit.rules.TestWatcher;
import org.junit.runner.Description;
import org.openqa.selenium.OutputType;
import org.openqa.selenium.TakesScreenshot;
import org.openqa.selenium.WebDriver;
Expand All @@ -19,7 +19,7 @@
* @author Neale Upstone/OpenCredo
* @author Erich Eichinger/OpenCredo
*/
public final class ScreenshotCaptureRule extends TestWatchman {
public final class ScreenshotCaptureRule extends TestWatcher {

protected final Logger log = LoggerFactory.getLogger(getClass());

Expand All @@ -33,9 +33,10 @@ public ScreenshotCaptureRule(String screenshotPath) {
this.screenshotPath = screenshotPath;
}

public void failed(Throwable e, FrameworkMethod method) {
String methodName = method.getMethod().getName();
log.error(String.format("Failure in %s.%s", method.getMethod().getDeclaringClass().getName(), methodName), e);
@Override
public void failed(Throwable e, Description description) {
String methodName = description.getMethodName();
log.error(String.format("Failure in %s.%s", description.getClassName(), methodName), e);
if (Settings.TAKE_ERROR_SCREENSHOTS) {
captureScreen(screenshotPath, methodName);
}
Expand All @@ -50,6 +51,11 @@ public void captureEntirePageScreenshot(String fileName) {
return;

WebDriver driver = WebDriverFactory.getInstance().getCurrentWebDriver();
if (!(driver instanceof TakesScreenshot)) {
log.warn("Driver {} doesn't support screenshots - page source was:\n {}", driver.getClass().getName(), driver.getPageSource());
return;
}

File screenshotAs;
try {
screenshotAs = ((TakesScreenshot) driver).getScreenshotAs(OutputType.FILE);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package org.eeichinger.testing.web;

import org.junit.rules.TestWatchman;
import org.junit.runners.model.FrameworkMethod;
import org.junit.rules.TestWatcher;
import org.junit.runner.Description;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand All @@ -10,22 +10,22 @@
*
* @author Neale Upstone/OpenCredo
*/
public class TestTracerRule extends TestWatchman {
public class TestTracerRule extends TestWatcher {

protected final Logger log = LoggerFactory.getLogger(getClass());

@Override
public void starting(FrameworkMethod method) {
log.info("Starting: {}", method.getName());
public void starting(Description description) {
log.info("Starting: {}", description.getMethodName());
}

@Override
public void failed(Throwable e, FrameworkMethod method) {
log.error("Failed: {}", method.getName(), e);
public void failed(Throwable e, Description description) {
log.error("Failed: {}", description.getMethodName(), e);
}

@Override
public void succeeded(FrameworkMethod method) {
log.info("Success: {}", method.getName());
public void succeeded(Description description) {
log.info("Success: {}", description.getMethodName());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@
*/
public class TimeoutThresholdException extends RuntimeException {

public TimeoutThresholdException(String msg) {
private static final long serialVersionUID = 1L;

public TimeoutThresholdException(String msg) {
super(msg);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,15 @@
* @author: Erich Eichinger/OpenCredo
* @date: 26/01/12
*/
public class PerformanceTestRunner extends AbstractPerformanceTestRunner {
public class PerformanceTestRunner extends AbstractPerformanceTestRunner<StandardUserSession> {

public static void main(String[] args) throws Exception {
new PerformanceTestRunner().run(args);
}

@Override
protected List<BrowserSessionFactory> createBrowserProfiles() {
List<BrowserSessionFactory> browserProfiles = new ArrayList<BrowserSessionFactory>();
protected List<BrowserSessionFactory<StandardUserSession>> createBrowserProfiles() {
List<BrowserSessionFactory<StandardUserSession>> browserProfiles = new ArrayList<BrowserSessionFactory<StandardUserSession>>();
browserProfiles.add(new BrowserSessionFactory<StandardUserSession>(StandardUserSession.class, 100, 20000));
return browserProfiles;
}
Expand Down
17 changes: 17 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,21 @@
<module>performancetest-demo-web</module>
<module>performancetest-demo-tests</module>
</modules>


<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.3.2</version>
<configuration>
<source>1.6</source>
<target>1.6</target>
</configuration>
</plugin>
</plugins>
</pluginManagement>
</build>
</project>