Author: lfryc(a)redhat.com
Date: 2010-07-30 11:36:47 -0400 (Fri, 30 Jul 2010)
New Revision: 18301
Modified:
root/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/a4jPush/TestInterval.java
Log:
tweaked a4jPush/testInterval to be more stable
Modified:
root/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/a4jPush/TestInterval.java
===================================================================
---
root/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/a4jPush/TestInterval.java 2010-07-30
15:36:03 UTC (rev 18300)
+++
root/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/a4jPush/TestInterval.java 2010-07-30
15:36:47 UTC (rev 18301)
@@ -31,6 +31,9 @@
import org.apache.commons.httpclient.HttpException;
import org.jboss.test.selenium.locator.Attribute;
import org.jboss.test.selenium.locator.AttributeLocator;
+import org.richfaces.tests.metamer.ftest.annotations.Inject;
+import org.richfaces.tests.metamer.ftest.annotations.Templates;
+import org.richfaces.tests.metamer.ftest.annotations.Use;
import org.testng.annotations.Test;
/**
@@ -42,9 +45,6 @@
public class TestInterval extends AbstractPushTest {
private static final Attribute ATTRIBUTE_TITLE = new Attribute("title");
- private static final int[] INTERVAL_VALUES = new int[]{1000, 5000, 500};
- private static final long MAX_DEVIATION = 100;
- private static final long MAX_AVERAGE_DEVIATION = 75;
private static final int DEFAULT_COUNTER_STEP = 2;
private static final int ITERATION_COUNT = 3;
private static final int MULTIPLE_PUSH_COUNT = 5;
@@ -58,10 +58,13 @@
private long deviationTotal = 0;
private long deviationCount = 0;
+ @Inject
+ private int interval;
+
/**
* <p>
- * For 3 different intervals, test that the interval between push event triggered and
event observered by client
- * haven't greater deviation than the specified interval.
+ * For interval 1000, test that the interval between push event triggered and event
observered by client haven't
+ * greater deviation than the one interval.
* </p>
*
* <p>
@@ -73,31 +76,69 @@
* </p>
*
* <p>
- * Then repeat push and wait 6 times with 1 event triggered and 5 events triggered in
sequence.
+ * Then repeat push and wait 6 times with 1 event triggered and 5 fast events
triggered in sequence.
* </p>
*/
@Test
- public void testIntervalFromClientPerspective() throws HttpException, IOException {
- for (int interval : INTERVAL_VALUES) {
- counterStep = DEFAULT_COUNTER_STEP;
- pushAttributes.setInterval(interval);
+ @Use(field = "interval", ints = { 1000 })
+ public void testClientAllTemplates() throws HttpException, IOException {
+ counterStep = DEFAULT_COUNTER_STEP;
+ pushAttributes.setInterval(interval);
+ pushAndWait(1);
+ for (int i = 0; i < ITERATION_COUNT; i++) {
+ startIntervalAndCounter();
pushAndWait(1);
- for (int i = 0; i < ITERATION_COUNT; i++) {
- startIntervalAndCounter();
- pushAndWait(1);
- validateIntervalAndCounter(interval);
+ validateIntervalAndCounter(interval);
- startIntervalAndCounter();
- pushAndWait(MULTIPLE_PUSH_COUNT);
- validateIntervalAndCounter(interval);
- }
+ startIntervalAndCounter();
+ pushAndWait(MULTIPLE_PUSH_COUNT);
+ validateIntervalAndCounter(interval);
}
validateAverageDeviation();
}
/**
+ * <p>
+ * For interval two different values (small and big), test that the interval between
push event triggered and event
+ * observered by client haven't greater deviation than the one interval.
+ * </p>
+ *
+ * <p>
+ * First set the given interval into the interval attribute.
+ * </p>
+ *
+ * <p>
+ * Then push and wait for result of update triggered by observation of push event.
+ * </p>
+ *
+ * <p>
+ * Then repeat push and wait 6 times with 1 event triggered and 5 fast events
triggered in sequence.
+ * </p>
+ */
+ @Test
+ @Use(field = "interval", ints = { 500, 5000 })
+ @Templates(value = "plain")
+ public void testClientDifferentIntervals() throws HttpException, IOException {
+ counterStep = DEFAULT_COUNTER_STEP;
+ pushAttributes.setInterval(interval);
+
+ pushAndWait(1);
+ for (int i = 0; i < ITERATION_COUNT; i++) {
+ startIntervalAndCounter();
+ pushAndWait(1);
+ validateIntervalAndCounter(interval);
+
+ startIntervalAndCounter();
+ pushAndWait(MULTIPLE_PUSH_COUNT);
+ validateIntervalAndCounter(interval);
+ }
+
+ validateAverageDeviation();
+ }
+
+ /**
* Remembers start of the time frame and current value of counter.
*/
private void startIntervalAndCounter() {
@@ -125,13 +166,14 @@
private void validateIntervalAndCounter(int interval) {
long runTime = getClientTime() - startTime;
long deviation = Math.abs(interval - runTime);
- assertTrue(deviation <= MAX_DEVIATION, format("Deviation ({0}) is greater
than defined maximum {1}", deviation,
- MAX_DEVIATION));
if (seleniumDebug) {
System.out.println(format("deviation for interval {0}: {1}",
interval, deviation));
}
+ assertTrue(deviation <= interval,
+ format("Deviation ({0}) is greater than one interval {1}",
deviation, interval));
+
deviationTotal += deviation;
deviationCount += 1;
@@ -145,13 +187,15 @@
* Validates the average deviations from intervals.
*/
private void validateAverageDeviation() {
+ long maximumAvgDeviation = Math.min(interval / 4, 1000);
long averageDeviation = deviationTotal / deviationCount;
if (seleniumDebug) {
System.out.println("averageDeviation: " + averageDeviation);
}
- assertTrue(averageDeviation <= MAX_AVERAGE_DEVIATION, format(
- "Average deviation for all the intervals ({0}) should not be greater
than defined maximum {1}",
- averageDeviation, MAX_AVERAGE_DEVIATION));
+ assertTrue(
+ averageDeviation <= maximumAvgDeviation,
+ format("Average deviation for all the intervals ({0}) should not be
greater than defined maximum {1}",
+ averageDeviation, maximumAvgDeviation));
}
/**