summaryrefslogtreecommitdiff
path: root/qpid/java/common/src/test
diff options
context:
space:
mode:
authorRafael H. Schloming <rhs@apache.org>2008-05-22 21:43:13 +0000
committerRafael H. Schloming <rhs@apache.org>2008-05-22 21:43:13 +0000
commit7db4a1119ade3a1e882602c2fc2b689da2497ae7 (patch)
treeb64bb049e7daec15c86867cbbe087f3992907340 /qpid/java/common/src/test
parent411d8ab04176a9608548244cb86894eb2760ba4c (diff)
downloadqpid-python-7db4a1119ade3a1e882602c2fc2b689da2497ae7.tar.gz
Made Range, RangeSet, and Session all use proper RFC1982 comparisons per QPID-861. Also switched command ids from long -> int, and added a mutex to channel to prevent multi-frame commands from interleaving when invoked from separate threads.
git-svn-id: https://svn.apache.org/repos/asf/incubator/qpid/trunk@659271 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'qpid/java/common/src/test')
-rw-r--r--qpid/java/common/src/test/java/org/apache/qpid/util/SerialTest.java124
1 files changed, 25 insertions, 99 deletions
diff --git a/qpid/java/common/src/test/java/org/apache/qpid/util/SerialTest.java b/qpid/java/common/src/test/java/org/apache/qpid/util/SerialTest.java
index 312b1ab9ce..d3ab817b5d 100644
--- a/qpid/java/common/src/test/java/org/apache/qpid/util/SerialTest.java
+++ b/qpid/java/common/src/test/java/org/apache/qpid/util/SerialTest.java
@@ -13,84 +13,18 @@ public class SerialTest extends TestCase
{
/**
- * The simplest meaningful serial number space has SERIAL_BITS == 2. In
- * this space, the integers that make up the serial number space are 0,
- * 1, 2, and 3. That is, 3 == 2^SERIAL_BITS - 1.
- *
- * In this space, the largest integer that it is meaningful to add to a
- * sequence number is 2^(SERIAL_BITS - 1) - 1, or 1.
- *
- * Then, as defined 0+1 == 1, 1+1 == 2, 2+1 == 3, and 3+1 == 0.
- * Further, 1 > 0, 2 > 1, 3 > 2, and 0 > 3. It is undefined whether
- * 2 > 0 or 0 > 2, and whether 1 > 3 or 3 > 1.
+ * Test the key boundaries where wraparound occurs.
*/
- public void testTrivialSample()
+ public void testBoundaries()
{
- Serial serial = new Serial(2);
- assertEquals( serial.increment(0, 1), 1);
- assertEquals( serial.increment(1, 1), 2);
- assertEquals( serial.increment(2, 1), 3);
- assertEquals( serial.increment(3, 1), 0);
- try
- {
- serial.increment(4, 1);
- fail("IllegalArgumentException was not trhown");
- }
- catch (IllegalArgumentException e)
- {
- // expected
- }
- try
- {
- assertTrue( serial.compare(1, 0) > 0);
- assertTrue( serial.compare(2, 1) > 0);
- assertTrue( serial.compare(3, 2) > 0);
- assertTrue( serial.compare(0, 3) > 0);
- assertTrue( serial.compare(0, 1) < 0);
- assertTrue( serial.compare(1, 2) < 0);
- assertTrue( serial.compare(2, 3) < 0);
- assertTrue( serial.compare(3, 0) < 0);
- }
- catch (SerialException e)
- {
- fail("Unexpected exception " + e);
- }
- try
- {
- serial.compare(2, 0);
- fail("AMQSerialException not thrown as expected");
- }
- catch (SerialException e)
- {
- // expected
- }
- try
- {
- serial.compare(0, 2);
- fail("AMQSerialException not thrown as expected");
- }
- catch (SerialException e)
- {
- // expected
- }
- try
- {
- serial.compare(3, 1);
- fail("AMQSerialException not thrown as expected");
- }
- catch (SerialException e)
- {
- // expected
- }
- try
- {
- serial.compare(3, 1);
- fail("AMQSerialException not thrown as expected");
- }
- catch (SerialException e)
- {
- // expected
- }
+ assertTrue(Serial.gt(1, 0));
+ assertTrue(Serial.lt(0, 1));
+
+ assertTrue(Serial.gt(Integer.MAX_VALUE+1, Integer.MAX_VALUE));
+ assertTrue(Serial.lt(Integer.MAX_VALUE, Integer.MAX_VALUE+1));
+
+ assertTrue(Serial.gt(0xFFFFFFFF + 1, 0xFFFFFFFF));
+ assertTrue(Serial.lt(0xFFFFFFFF, 0xFFFFFFFF + 1));
}
/**
@@ -98,38 +32,30 @@ public class SerialTest extends TestCase
* For any sequence number s and any integer n such that addition of n
* to s is well defined, (s + n) >= s. Further (s + n) == s only when
* n == 0, in all other defined cases, (s + n) > s.
- * strategy:
- * Create a serial number with 32 bits and check in a loop that adding integers
- * respect the corollary
*/
public void testCorollary1()
{
- Serial serial = new Serial(32);
- Random random = new Random();
- long number = random.nextInt((int) Math.pow(2.0 , 32.0) - 1);
- for(int i = 1; i<= 10000; i++ )
+ int wrapcount = 0;
+
+ int s = 0;
+
+ for (int i = 0; i < 67108664; i++)
{
- long nextInt = random.nextInt((int) Math.pow(2.0 , 32.0) - 1);
- long inc = serial.increment(number, nextInt);
- int res =0;
- try
- {
- res=serial.compare(inc, number);
- }
- catch (SerialException e)
- {
- fail("un-expected exception " + e);
- }
- if( res < 1 )
+ for (int n = 1; n < 4096; n += 512)
{
- fail("Corollary 1 violated " + number + " + " + nextInt + " < " + number);
+ assertTrue(Serial.gt(s+n, s));
+ assertTrue(Serial.lt(s, s+n));
}
- else if( res == 0 && nextInt > 0)
+
+ s += 1024;
+
+ if (s == 0)
{
- fail("Corollary 1 violated " + number + " + " + nextInt + " = " + number);
+ wrapcount += 1;
}
}
+
+ assertTrue(wrapcount > 0);
}
-
}