Permalink
Browse files

Added tests on resize() and move()

  • Loading branch information...
1 parent 3a108b1 commit 57594fce934daf762fef60c6b3c5c299f383930b @belaban committed Jan 23, 2012
Showing with 28 additions and 2 deletions.
  1. +1 −1 src/org/jgroups/util/Table.java
  2. +27 −1 tests/junit-functional/org/jgroups/tests/TableTest.java
View
2 src/org/jgroups/util/Table.java
@@ -396,7 +396,7 @@ public void forEach(long from, long to, Visitor<T> visitor) {
@SuppressWarnings("unchecked")
@GuardedBy("lock")
protected void resize(long seqno) {
- int num_rows_to_purge=(int)((low - offset) / elements_per_row);
+ int num_rows_to_purge=computeRow(low);
int row_index=computeRow(seqno) - num_rows_to_purge;
if(row_index < 0)
return;
View
28 tests/junit-functional/org/jgroups/tests/TableTest.java
@@ -824,6 +824,32 @@ public static void testMove() {
assert table.capacity() == 50;
}
+ public static void testMove2() {
+ Table<Integer> table=new Table<Integer>(3, 10, 0);
+ for(int i=1; i < 30; i++)
+ table.add(i, i);
+ table.removeMany(true, 23);
+ System.out.println("table = " + table);
+ table.add(35, 35); // triggers a resize() --> move()
+ for(int i=1; i <= 23; i++)
+ assert table._get(i) == null;
+ for(int i=24; i < 30; i++)
+ assert table._get(i) != null;
+ }
+
+ public static void testMove3() {
+ Table<Integer> table=new Table<Integer>(3, 10, 0);
+ for(int i=1; i < 30; i++)
+ table.add(i, i);
+ table.removeMany(true, 23);
+ System.out.println("table = " + table);
+ table.add(30, 30); // triggers a resize() --> move()
+ for(int i=1; i <= 23; i++)
+ assert table._get(i) == null;
+ for(int i=24; i < 30; i++)
+ assert table._get(i) != null;
+ }
+
public static void testPurge() {
Table<Integer> table=new Table<Integer>(5, 10, 0);
@@ -955,7 +981,7 @@ public void testCompact() {
}
- public void testCompactWithAutomaticPurging() {
+ public void testCompact2() {
Table<Integer> table=new Table<Integer>(3, 10, 0);
for(int i=1; i <= 80; i++)
addAndGet(table, i);

0 comments on commit 57594fc

Please sign in to comment.