[jboss-cvs] JBossAS SVN: r83531 - projects/cluster/ha-client/trunk/src/test/java/org/jboss/test/ha/client/loadbalance.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Tue Jan 27 21:31:37 EST 2009
Author: bstansberry at jboss.com
Date: 2009-01-27 21:31:36 -0500 (Tue, 27 Jan 2009)
New Revision: 83531
Added:
projects/cluster/ha-client/trunk/src/test/java/org/jboss/test/ha/client/loadbalance/RoundRobinUnitTestCase.java
Log:
Add a test of RoundRobin
Added: projects/cluster/ha-client/trunk/src/test/java/org/jboss/test/ha/client/loadbalance/RoundRobinUnitTestCase.java
===================================================================
--- projects/cluster/ha-client/trunk/src/test/java/org/jboss/test/ha/client/loadbalance/RoundRobinUnitTestCase.java (rev 0)
+++ projects/cluster/ha-client/trunk/src/test/java/org/jboss/test/ha/client/loadbalance/RoundRobinUnitTestCase.java 2009-01-28 02:31:36 UTC (rev 83531)
@@ -0,0 +1,140 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+
+package org.jboss.test.ha.client.loadbalance;
+
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+
+import org.jboss.ha.client.loadbalance.LoadBalancePolicy;
+import org.jboss.ha.client.loadbalance.RoundRobin;
+import org.jboss.ha.framework.interfaces.ClusteringTargetsRepository;
+import org.jboss.ha.framework.interfaces.FamilyClusterInfo;
+
+/**
+ * Unit tests for {@link RoundRobin}.
+ *
+ * @author Brian Stansberry
+ *
+ */
+public class RoundRobinUnitTestCase extends AbstractLoadBalancePolicyTestCase<RoundRobin>
+{
+
+ /**
+ * Create a new RoundRobinUnitTestCase.
+ *
+ */
+ public RoundRobinUnitTestCase()
+ {
+
+ }
+
+ /**
+ * Create a new RoundRobinUnitTestCase.
+ *
+ * @param name
+ */
+ public RoundRobinUnitTestCase(String name)
+ {
+ super(name);
+ }
+
+ protected RoundRobin getLoadBalancePolicy()
+ {
+ return new RoundRobin();
+ }
+
+ public void testBasicCycle()
+ {
+ testCount++;
+ FamilyClusterInfo fci = ClusteringTargetsRepository.initTarget(FAMILY_BASE + testCount, Arrays.asList(TARGETS));
+ LoadBalancePolicy lbp = getLoadBalancePolicy();
+ int expectedCursor = -1;
+ for (int i = 0; i < 100; i++)
+ {
+ Object target = lbp.chooseTarget(fci);
+ if (expectedCursor < 0)
+ {
+ expectedCursor = fci.getCursor();
+ }
+ else
+ {
+ expectedCursor = ++expectedCursor % TARGETS.length;
+ assertEquals(expectedCursor, fci.getCursor());
+ }
+
+ assertEquals(TARGETS[expectedCursor], target);
+
+ }
+ }
+
+ public void testFailover()
+ {
+ testCount++;
+ List<String> targets = new ArrayList<String>(Arrays.asList(TARGETS));
+ FamilyClusterInfo fci = ClusteringTargetsRepository.initTarget(FAMILY_BASE + testCount, targets);
+ LoadBalancePolicy lbp = getLoadBalancePolicy();
+
+ String target = (String) lbp.chooseTarget(fci);
+ int cursor = fci.getCursor();
+ assertEquals(target, fci.getTargets().get(cursor));
+
+ while (targets.size() > 1)
+ {
+ fci.removeDeadTarget(target);
+ targets.remove(target);
+ assertEquals(targets, fci.getTargets());
+
+ int expectedCursor = ++cursor % targets.size();
+
+ target = (String) lbp.chooseTarget(fci);
+ cursor = fci.getCursor();
+ assertEquals(expectedCursor, cursor);
+ assertEquals(target, fci.getTargets().get(cursor));
+ }
+ }
+
+ public void testTopologyChange()
+ {
+ testCount++;
+ List<String> targets = Arrays.asList(TARGETS);
+ FamilyClusterInfo fci = ClusteringTargetsRepository.initTarget(FAMILY_BASE + testCount, targets);
+ LoadBalancePolicy lbp = getLoadBalancePolicy();
+
+ String target = (String) lbp.chooseTarget(fci);
+ int cursor = fci.getCursor();
+ assertEquals(target, fci.getTargets().get(cursor));
+
+ targets = Arrays.asList(new String[]{"W", "X", "Y", "Z"});
+ fci.updateClusterInfo(targets, 1);
+
+ int expectedCursor = ++cursor % targets.size();
+
+ target = (String) lbp.chooseTarget(fci);
+ cursor = fci.getCursor();
+ assertEquals(expectedCursor, cursor);
+ assertEquals(target, targets.get(cursor));
+ }
+
+}
Property changes on: projects/cluster/ha-client/trunk/src/test/java/org/jboss/test/ha/client/loadbalance/RoundRobinUnitTestCase.java
___________________________________________________________________
Name: svn:keywords
+
More information about the jboss-cvs-commits
mailing list