You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@labs.apache.org by ry...@apache.org on 2008/10/08 19:58:00 UTC
svn commit: r702941 - in /labs/droids/branch/LABS-144/src:
core/java/org/apache/droids/delay/ core/test/ core/test/org/
core/test/org/apache/ core/test/org/apache/droids/
core/test/org/apache/droids/delay/ examples/java/org/apache/droids/examples/
Author: ryan
Date: Wed Oct 8 10:58:00 2008
New Revision: 702941
URL: http://svn.apache.org/viewvc?rev=702941&view=rev
Log:
adding test folder and simple test to have 100% coverage on DelayTimers
Added:
labs/droids/branch/LABS-144/src/core/test/
labs/droids/branch/LABS-144/src/core/test/org/
labs/droids/branch/LABS-144/src/core/test/org/apache/
labs/droids/branch/LABS-144/src/core/test/org/apache/droids/
labs/droids/branch/LABS-144/src/core/test/org/apache/droids/delay/
labs/droids/branch/LABS-144/src/core/test/org/apache/droids/delay/TestDelay.java
Modified:
labs/droids/branch/LABS-144/src/core/java/org/apache/droids/delay/GaussianRandomDelayTimer.java
labs/droids/branch/LABS-144/src/core/java/org/apache/droids/delay/RandomDelayTimer.java
labs/droids/branch/LABS-144/src/core/java/org/apache/droids/delay/SimpleDelayTimer.java
labs/droids/branch/LABS-144/src/examples/java/org/apache/droids/examples/SimpleRuntime.java
Modified: labs/droids/branch/LABS-144/src/core/java/org/apache/droids/delay/GaussianRandomDelayTimer.java
URL: http://svn.apache.org/viewvc/labs/droids/branch/LABS-144/src/core/java/org/apache/droids/delay/GaussianRandomDelayTimer.java?rev=702941&r1=702940&r2=702941&view=diff
==============================================================================
--- labs/droids/branch/LABS-144/src/core/java/org/apache/droids/delay/GaussianRandomDelayTimer.java (original)
+++ labs/droids/branch/LABS-144/src/core/java/org/apache/droids/delay/GaussianRandomDelayTimer.java Wed Oct 8 10:58:00 2008
@@ -20,23 +20,17 @@
public class GaussianRandomDelayTimer extends RandomDelayTimer implements DelayTimer
{
- private long fixedDelay;
-
- public GaussianRandomDelayTimer(){
- super();
- fixedDelay = 0;
- }
-
- @Override
- public long getDelayMillis() {
- return (long) Math.abs((this.random.nextGaussian() * getDelay()) + fixedDelay);
+ public GaussianRandomDelayTimer()
+ {
+ super( 0, 0 );
}
- public long getFixedDelay() {
- return fixedDelay;
+ public GaussianRandomDelayTimer( int min, int range )
+ {
+ super( min, range );
}
- public void setFixedDelay(long fixedDelay) {
- this.fixedDelay = fixedDelay;
+ public long getDelayMillis() {
+ return (Math.abs((long)(random.nextGaussian() * delaySpread))) + minimumDelay;
}
}
Modified: labs/droids/branch/LABS-144/src/core/java/org/apache/droids/delay/RandomDelayTimer.java
URL: http://svn.apache.org/viewvc/labs/droids/branch/LABS-144/src/core/java/org/apache/droids/delay/RandomDelayTimer.java?rev=702941&r1=702940&r2=702941&view=diff
==============================================================================
--- labs/droids/branch/LABS-144/src/core/java/org/apache/droids/delay/RandomDelayTimer.java (original)
+++ labs/droids/branch/LABS-144/src/core/java/org/apache/droids/delay/RandomDelayTimer.java Wed Oct 8 10:58:00 2008
@@ -20,17 +20,44 @@
import org.apache.droids.api.DelayTimer;
-public class RandomDelayTimer extends SimpleDelayTimer implements DelayTimer
+public class RandomDelayTimer implements DelayTimer
{
- protected Random random;
+ protected final Random random;
+ protected int minimumDelay;
+ protected int delaySpread;
public RandomDelayTimer()
{
- this.random = new Random();
+ this( 0, 0 );
}
- @Override
+ public RandomDelayTimer( int min, int range )
+ {
+ random = new Random();
+ minimumDelay = min;
+ delaySpread = range;
+ }
+
public long getDelayMillis() {
- return (long) Math.abs(this.random.nextDouble() * getDelay());
+ if( delaySpread > 0 ) {
+ return (long) this.random.nextInt( delaySpread ) + minimumDelay;
+ }
+ return 0;
+ }
+
+ public int getMinimumDelay() {
+ return minimumDelay;
+ }
+
+ public void setMinimumDelay(int minimumDelay) {
+ this.minimumDelay = minimumDelay;
+ }
+
+ public int getDelaySpread() {
+ return delaySpread;
+ }
+
+ public void setDelaySpread(int delayRange) {
+ this.delaySpread = delayRange;
}
}
Modified: labs/droids/branch/LABS-144/src/core/java/org/apache/droids/delay/SimpleDelayTimer.java
URL: http://svn.apache.org/viewvc/labs/droids/branch/LABS-144/src/core/java/org/apache/droids/delay/SimpleDelayTimer.java?rev=702941&r1=702940&r2=702941&view=diff
==============================================================================
--- labs/droids/branch/LABS-144/src/core/java/org/apache/droids/delay/SimpleDelayTimer.java (original)
+++ labs/droids/branch/LABS-144/src/core/java/org/apache/droids/delay/SimpleDelayTimer.java Wed Oct 8 10:58:00 2008
@@ -23,25 +23,31 @@
/**
* The fixed value of the delay.
*/
- private long delay = 0;
+ private long delayMillis = 0;
- public long getDelayMillis() {
- return delay;
+ public SimpleDelayTimer()
+ {
+
+ }
+
+ public SimpleDelayTimer( long delay )
+ {
+ this.delayMillis = delay;
}
/**
- * Returns the delay time.
- * @return long
+ * Gets the delay time.
+ * @param delay long
*/
- public long getDelay() {
- return delay;
+ public long getDelayMillis() {
+ return this.delayMillis;
}
-
+
/**
* Sets the delay time.
* @param delay long
*/
- public void setDelay(long delay) {
- this.delay = delay;
+ public void setDelayMillis(long delay) {
+ this.delayMillis = delay;
}
}
Added: labs/droids/branch/LABS-144/src/core/test/org/apache/droids/delay/TestDelay.java
URL: http://svn.apache.org/viewvc/labs/droids/branch/LABS-144/src/core/test/org/apache/droids/delay/TestDelay.java?rev=702941&view=auto
==============================================================================
--- labs/droids/branch/LABS-144/src/core/test/org/apache/droids/delay/TestDelay.java (added)
+++ labs/droids/branch/LABS-144/src/core/test/org/apache/droids/delay/TestDelay.java Wed Oct 8 10:58:00 2008
@@ -0,0 +1,71 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.
+ */
+package org.apache.droids.delay;
+
+import org.apache.droids.api.DelayTimer;
+
+import junit.framework.TestCase;
+
+
+public class TestDelay extends TestCase
+{
+ @Override
+ protected void setUp() throws Exception {
+ super.setUp();
+ }
+
+ @Override
+ protected void tearDown() throws Exception {
+ super.tearDown();
+ }
+
+ public void testTimers()
+ {
+ int i=0;
+ int min = 10;
+ int spread = 100;
+ RandomDelayTimer timer = new RandomDelayTimer( min, spread );
+ for( i=0; i<100; i++ ) {
+ long delay = timer.getDelayMillis();
+ assertTrue( delay >= min );
+ assertTrue( delay < (min+spread) );
+ }
+ min = 300; spread = 20;
+ timer.setDelaySpread( spread );
+ timer.setMinimumDelay( min );
+ for( i=0; i<100; i++ ) {
+ long delay = timer.getDelayMillis();
+ assertTrue( delay >= min );
+ assertTrue( delay < (min+spread) );
+ }
+
+ timer = new GaussianRandomDelayTimer( min, spread );
+ for( i=0; i<100; i++ ) {
+ long delay = timer.getDelayMillis();
+ assertTrue( "DELAY:"+delay, delay >= min );
+ assertTrue( "DELAY:"+delay, delay < (min+(spread*4)) );
+ }
+
+ DelayTimer t = new SimpleDelayTimer( 1000 );
+ assertTrue( 1000 == t.getDelayMillis() );
+
+ // default timers all have time zero
+ assertEquals( 0, new SimpleDelayTimer().getDelayMillis() );
+ assertEquals( 0, new RandomDelayTimer().getDelayMillis() );
+ assertEquals( 0, new GaussianRandomDelayTimer().getDelayMillis() );
+ }
+}
Modified: labs/droids/branch/LABS-144/src/examples/java/org/apache/droids/examples/SimpleRuntime.java
URL: http://svn.apache.org/viewvc/labs/droids/branch/LABS-144/src/examples/java/org/apache/droids/examples/SimpleRuntime.java?rev=702941&r1=702940&r2=702941&view=diff
==============================================================================
--- labs/droids/branch/LABS-144/src/examples/java/org/apache/droids/examples/SimpleRuntime.java (original)
+++ labs/droids/branch/LABS-144/src/examples/java/org/apache/droids/examples/SimpleRuntime.java Wed Oct 8 10:58:00 2008
@@ -89,7 +89,7 @@
// Create default droid
SimpleDelayTimer simpleDelayTimer = new SimpleDelayTimer();
- simpleDelayTimer.setDelay(100);
+ simpleDelayTimer.setDelayMillis(100);
SimpleTaskQueue simpleQueue = new SimpleTaskQueue();
// simpleQueue.setMaxDepth(3);
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@labs.apache.org
For additional commands, e-mail: commits-help@labs.apache.org