[Jboss-cvs] JBossAS SVN: r54948 - trunk/testsuite/src/main/org/jboss/test/cluster/test
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Mon Jul 31 17:48:39 EDT 2006
Author: bstansberry at jboss.com
Date: 2006-07-31 17:48:38 -0400 (Mon, 31 Jul 2006)
New Revision: 54948
Modified:
trunk/testsuite/src/main/org/jboss/test/cluster/test/FamilyClusterInfoUnitTestCase.java
Log:
[JBAS-2225] Test target list is immutable
Modified: trunk/testsuite/src/main/org/jboss/test/cluster/test/FamilyClusterInfoUnitTestCase.java
===================================================================
--- trunk/testsuite/src/main/org/jboss/test/cluster/test/FamilyClusterInfoUnitTestCase.java 2006-07-31 21:48:14 UTC (rev 54947)
+++ trunk/testsuite/src/main/org/jboss/test/cluster/test/FamilyClusterInfoUnitTestCase.java 2006-07-31 21:48:38 UTC (rev 54948)
@@ -1,7 +1,9 @@
package org.jboss.test.cluster.test;
import java.util.ArrayList;
+import java.util.Iterator;
import java.util.List;
+import java.util.ListIterator;
import org.jboss.ha.framework.interfaces.ClusteringTargetsRepository;
import org.jboss.ha.framework.interfaces.FamilyClusterInfo;
@@ -174,26 +176,178 @@
assertNull("Resetter had no exceptions", resetter.getThrowable());
}
+
+ public void testTargetListImmutability() throws Exception
+ {
+ ArrayList targets = new ArrayList();
+ targets.add("ONE");
+ targets.add("TWO");
+ ClusteringTargetsRepository.initTarget("testSynchronization", targets, 0);
+ FamilyClusterInfo fci = ClusteringTargetsRepository.getFamilyClusterInfo("testSynchronization");
- private void checkFCIConsistency(FamilyClusterInfo fci, int checks, boolean allowOutOfSync)
+ ArrayList fciTargets = fci.getTargets();
+
+ try
+ {
+ fciTargets.add("FAIL");
+ fail("add call did not fail");
+ }
+ catch (UnsupportedOperationException good) {}
+
+ try
+ {
+ fciTargets.addAll(targets);
+ fail("addAll call did not fail");
+ }
+ catch (UnsupportedOperationException good) {}
+
+ try
+ {
+ fciTargets.clear();
+ fail("clear call did not fail");
+ }
+ catch (UnsupportedOperationException good) {}
+
+ try
+ {
+ fciTargets.ensureCapacity(5);
+ fail("ensureCapacity call did not fail");
+ }
+ catch (UnsupportedOperationException good) {}
+
+ try
+ {
+ fciTargets.remove(0);
+ fail("remove call did not fail");
+ }
+ catch (UnsupportedOperationException good) {}
+
+ try
+ {
+ fciTargets.set(0, "FAIL");
+ fail("set call did not fail");
+ }
+ catch (UnsupportedOperationException good) {}
+
+ try
+ {
+ fciTargets.trimToSize();
+ fail("trimToSize call did not fail");
+ }
+ catch (UnsupportedOperationException good) {}
+
+ try
+ {
+ fciTargets.removeAll(targets);
+ fail("removeAll call did not fail");
+ }
+ catch (UnsupportedOperationException good) {}
+
+ try
+ {
+ fciTargets.retainAll(targets);
+ fail("retainAll call did not fail");
+ }
+ catch (UnsupportedOperationException good) {}
+
+ Iterator iter = fciTargets.iterator();
+ int count = 0;
+ while (iter.hasNext())
{
-
- for (int i = 0; i < checks; i++)
+ iter.next();
+ count++;
+ }
+ assertEquals("Correct count", 2, count);
+ try
+ {
+ iter.remove();
+ fail("Iterator.remove call did not fail");
+ }
+ catch (UnsupportedOperationException good) {}
+
+ ListIterator listIter = fciTargets.listIterator();
+ count = 0;
+ while (listIter.hasNext())
+ {
+ listIter.next();
+ count++;
+ }
+ assertEquals("Correct count", 2, count);
+ try
+ {
+ listIter.remove();
+ fail("Iterator.remove call did not fail");
+ }
+ catch (UnsupportedOperationException good) {}
+
+ while (listIter.hasPrevious())
+ {
+ listIter.previous();
+ count--;
+ }
+ assertEquals("Correct count", 0, count);
+
+ listIter = fciTargets.listIterator(1);
+ while (listIter.hasNext())
+ {
+ listIter.next();
+ count++;
+ }
+ assertEquals("Correct count", 1, count);
+ try
+ {
+ listIter.remove();
+ fail("Iterator.remove call did not fail");
+ }
+ catch (UnsupportedOperationException good) {}
+
+ while (listIter.hasPrevious())
+ {
+ listIter.previous();
+ count--;
+ }
+ assertEquals("Correct count", -1, count);
+
+ // Check the lists returned by other methods
+ fciTargets = fci.updateClusterInfo(targets, 0);
+
+ try
+ {
+ fciTargets.add("FAIL");
+ fail("add call did not fail");
+ }
+ catch (UnsupportedOperationException good) {}
+
+ fciTargets = fci.removeDeadTarget(targets.get(0));
+
+ try
+ {
+ fciTargets.add("FAIL");
+ fail("add call did not fail");
+ }
+ catch (UnsupportedOperationException good) {}
+
+ }
+
+ private void checkFCIConsistency(FamilyClusterInfo fci, int checks, boolean allowOutOfSync)
+ {
+
+ for (int i = 0; i < checks; i++)
+ {
+ synchronized (fci)
{
- synchronized (fci)
+ if (fci.currentMembershipInSyncWithViewId())
{
- if (fci.currentMembershipInSyncWithViewId())
- {
- List targets = fci.getTargets();
- long vid = fci.getCurrentViewId();
- assertEquals("targets and vid match", vid, targets.size());
- }
- else
- {
- assertTrue("OK for FCI view to be out of sync", allowOutOfSync);
- }
+ List targets = fci.getTargets();
+ long vid = fci.getCurrentViewId();
+ assertEquals("targets and vid match", vid, targets.size());
}
+ else
+ {
+ assertTrue("OK for FCI view to be out of sync", allowOutOfSync);
+ }
}
-
}
+
+ }
}
More information about the jboss-cvs-commits
mailing list