Author: cziegeler
Date: Tue Apr 10 14:38:07 2012
New Revision: 1311760
URL: http://svn.apache.org/viewvc?rev=1311760&view=rev
Log:
Add a simple stress test for event admin
Modified:
felix/sandbox/cziegeler/eventadmin-tests/src/test/java/org/apache/felix/eventadmin/tests/AbstractTest.java
felix/sandbox/cziegeler/eventadmin-tests/src/test/java/org/apache/felix/eventadmin/tests/StressTestIT.java
Modified:
felix/sandbox/cziegeler/eventadmin-tests/src/test/java/org/apache/felix/eventadmin/tests/AbstractTest.java
URL:
http://svn.apache.org/viewvc/felix/sandbox/cziegeler/eventadmin-tests/src/test/java/org/apache/felix/eventadmin/tests/AbstractTest.java?rev=1311760&r1=1311759&r2=1311760&view=diff
==============================================================================
---
felix/sandbox/cziegeler/eventadmin-tests/src/test/java/org/apache/felix/eventadmin/tests/AbstractTest.java
(original)
+++
felix/sandbox/cziegeler/eventadmin-tests/src/test/java/org/apache/felix/eventadmin/tests/AbstractTest.java
Tue Apr 10 14:38:07 2012
@@ -71,19 +71,30 @@ public abstract class AbstractTest imple
private volatile String prefix;
+ private volatile long startTime;
+
/** Wait lock for syncing. */
private final Object waitLock = new Object();
/**
+ * Handle an event from the listener.
* @param event
* @param payload
*/
public void handleEvent(final Event event, final Object payload) {
- if ( prefix == null || event.getTopic().startsWith(prefix) ) {
- incCount();
+ if ( this.running ) {
+ if ( prefix == null || event.getTopic().startsWith(prefix) ) {
+ incCount();
+ }
}
}
+ /**
+ * Send an event
+ * @param topic
+ * @param properties
+ * @param sync
+ */
protected void send(String topic, Dictionary<String, Object> properties,
boolean sync) {
final Event event = new Event(topic, properties);
if ( sync ) {
@@ -96,20 +107,24 @@ public abstract class AbstractTest imple
private synchronized void incCount() {
eventCount++;
if ( eventCount >= finishEventCount) {
- logger.info("Finished tests, received {} events", eventCount);
+ final long duration = this.startTime == -1 ? -1 :
System.currentTimeMillis() - this.startTime;
+ logger.info("Finished tests, received {} events in {}ms",
eventCount, duration);
}
}
- public synchronized int getCount() {
+ private synchronized int getCount() {
return eventCount;
}
protected void start(final String prefix, final int nrThreads, final int
nrEvents, final int finishCount) {
+ logger.info("Starting eventing test {}",
this.getClass().getSimpleName());
+
+ this.startTime = -1;
this.prefix = prefix;
this.nrEvents = nrEvents;
finishEventCount = finishCount;
eventCount = 0;
- logger.info("Preparing test with {} threads and {} events.",
nrThreads, nrEvents);
+ logger.info("Preparing test with {} threads and {} events per
thread.", nrThreads, nrEvents);
logger.info("Expecting {} events.", finishCount);
this.running = true;
final Thread[] threads = new Thread[nrThreads];
@@ -125,9 +140,8 @@ public abstract class AbstractTest imple
logger.info("Received {} events so far.", getCount());
try {
Thread.sleep(1000 * 5);
- } catch (InterruptedException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
+ } catch (final InterruptedException ignore) {
+ // ignore
}
if ( getCount() >= finishCount) {
running = false;
@@ -140,6 +154,7 @@ public abstract class AbstractTest imple
});
infoT.start();
logger.info("Started test with {} threads and {} events.", nrThreads,
nrEvents);
+ this.execute();
}
private void waitForFinish() {
@@ -156,17 +171,19 @@ public abstract class AbstractTest imple
protected abstract void sendEvent(final int index);
- public abstract void start();
-
/**
* @see java.lang.Runnable#run()
*/
public void run() {
try {
Thread.sleep(1000 * 10);
- } catch (InterruptedException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
+ } catch (final InterruptedException ignore) {
+ // ignore
+ }
+ synchronized ( this ) {
+ if ( this.startTime == -1 ) {
+ this.startTime = System.currentTimeMillis();
+ }
}
logger.info("Started thread");
int index = 0;
@@ -235,21 +252,10 @@ public abstract class AbstractTest imple
}
/**
- * Start the test.
- */
- public void startTest() {
- logger.info("Starting eventing tests....");
- this.execute();
- logger.info("Finished with eventing tests....");
- }
-
- /**
* Execute a single test.
* @param test
*/
private void execute() {
- logger.info("Starting eventing test {}",
this.getClass().getSimpleName());
- this.start();
this.waitForFinish();
this.stop();
logger.info("Finished eventing test {}",
this.getClass().getSimpleName());
Modified:
felix/sandbox/cziegeler/eventadmin-tests/src/test/java/org/apache/felix/eventadmin/tests/StressTestIT.java
URL:
http://svn.apache.org/viewvc/felix/sandbox/cziegeler/eventadmin-tests/src/test/java/org/apache/felix/eventadmin/tests/StressTestIT.java?rev=1311760&r1=1311759&r2=1311760&view=diff
==============================================================================
---
felix/sandbox/cziegeler/eventadmin-tests/src/test/java/org/apache/felix/eventadmin/tests/StressTestIT.java
(original)
+++
felix/sandbox/cziegeler/eventadmin-tests/src/test/java/org/apache/felix/eventadmin/tests/StressTestIT.java
Tue Apr 10 14:38:07 2012
@@ -24,7 +24,15 @@ public class StressTestIT extends Abstra
private static final int THREADS = 15;
private static final int EVENTS_PER_THREAD = 10000;
- public void start() {
+ @Override
+ protected void sendEvent(int index) {
+ final String postFix = String.valueOf(index % 10);
+ final String topic = PREFIX + '/' + postFix;
+ this.send(topic, null, true);
+ }
+
+ @Test
+ public void testEventing() throws Exception {
this.addListener(PREFIX + "/0", null);
this.addListener(PREFIX + "/1", null);
this.addListener(PREFIX + "/2", null);
@@ -41,18 +49,7 @@ public class StressTestIT extends Abstra
this.addListener("org/apache/*", null);
this.addListener("org/*", null);
this.addListener("*", null);
- super.start(PREFIX, THREADS, EVENTS_PER_THREAD, THREADS *
EVENTS_PER_THREAD * (1 + 6));
- }
- @Override
- protected void sendEvent(int index) {
- final String postFix = String.valueOf(index % 10);
- final String topic = PREFIX + '/' + postFix;
- this.send(topic, null, true);
- }
-
- @Test
- public void testEventing() throws Exception {
- this.startTest();
+ this.start(PREFIX, THREADS, EVENTS_PER_THREAD, THREADS *
EVENTS_PER_THREAD * (1 + 6));
}
}