[jboss-cvs] JBossAS SVN: r72592 - in projects/cluster/ha-client/trunk/src: test/java/org/jboss/test and 2 other directories.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Tue Apr 22 22:14:17 EDT 2008
Author: bstansberry at jboss.com
Date: 2008-04-22 22:14:17 -0400 (Tue, 22 Apr 2008)
New Revision: 72592
Added:
projects/cluster/ha-client/trunk/src/test/java/org/jboss/test/aspects/
projects/cluster/ha-client/trunk/src/test/java/org/jboss/test/aspects/remoting/
projects/cluster/ha-client/trunk/src/test/java/org/jboss/test/aspects/remoting/ClusterChooserInterceptorUnitTestCase.java
projects/cluster/ha-client/trunk/src/test/java/org/jboss/test/aspects/remoting/MockAopLoadBalancePolicy.java
projects/cluster/ha-client/trunk/src/test/java/org/jboss/test/aspects/remoting/MockInvocation.java
projects/cluster/ha-client/trunk/src/test/java/org/jboss/test/aspects/remoting/MockNextInterceptor.java
Modified:
projects/cluster/ha-client/trunk/src/main/java/org/jboss/aspects/remoting/ClusterChooserInterceptor.java
Log:
[JBCLUSTER-196] ClusterChooserInterceptor should pass invocation to AopLoadBalancePolicy
Modified: projects/cluster/ha-client/trunk/src/main/java/org/jboss/aspects/remoting/ClusterChooserInterceptor.java
===================================================================
--- projects/cluster/ha-client/trunk/src/main/java/org/jboss/aspects/remoting/ClusterChooserInterceptor.java 2008-04-22 23:25:58 UTC (rev 72591)
+++ projects/cluster/ha-client/trunk/src/main/java/org/jboss/aspects/remoting/ClusterChooserInterceptor.java 2008-04-23 02:14:17 UTC (rev 72592)
@@ -23,6 +23,7 @@
import org.jboss.aop.DispatcherConnectException;
import org.jboss.aop.util.PayloadKey;
+import org.jboss.ha.client.loadbalance.AopLoadBalancePolicy;
import org.jboss.ha.client.loadbalance.LoadBalancePolicy;
import org.jboss.ha.framework.interfaces.GenericClusteringException;
import org.jboss.remoting.CannotConnectException;
@@ -59,7 +60,16 @@
int failoverCounter = 0;
String familyName = family.get().getFamilyName();
invocation.getMetaData().addMetaData(CLUSTERED_REMOTING, CLUSTER_FAMILY, familyName, PayloadKey.AS_IS);
- InvokerLocator target = (InvokerLocator) lb.chooseTarget(family.get());
+ InvokerLocator target = null;
+ if (lb instanceof AopLoadBalancePolicy)
+ {
+ target = (InvokerLocator) ((AopLoadBalancePolicy) lb).chooseTarget(family.get(), invocation);
+ }
+ else
+ {
+ target = (InvokerLocator) lb.chooseTarget(family.get());
+ }
+
Throwable lastException = null;
while (target != null)
{
@@ -71,9 +81,6 @@
lastException = null;
try
{
-
-
-
Object rsp = invocation.invokeNext();
ArrayList newReplicants = (ArrayList) invocation.getResponseAttachment("replicants");
if (newReplicants != null)
Added: projects/cluster/ha-client/trunk/src/test/java/org/jboss/test/aspects/remoting/ClusterChooserInterceptorUnitTestCase.java
===================================================================
--- projects/cluster/ha-client/trunk/src/test/java/org/jboss/test/aspects/remoting/ClusterChooserInterceptorUnitTestCase.java (rev 0)
+++ projects/cluster/ha-client/trunk/src/test/java/org/jboss/test/aspects/remoting/ClusterChooserInterceptorUnitTestCase.java 2008-04-23 02:14:17 UTC (rev 72592)
@@ -0,0 +1,97 @@
+/*
+ * 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.aspects.remoting;
+
+import java.net.MalformedURLException;
+import java.util.ArrayList;
+import java.util.List;
+
+import junit.framework.TestCase;
+
+import org.jboss.aop.advice.Interceptor;
+import org.jboss.aspects.remoting.ClusterChooserInterceptor;
+import org.jboss.aspects.remoting.ClusterConstants;
+import org.jboss.aspects.remoting.FamilyWrapper;
+import org.jboss.aspects.remoting.InvokeRemoteInterceptor;
+import org.jboss.ha.client.loadbalance.LoadBalancePolicy;
+import org.jboss.remoting.InvokerLocator;
+
+/**
+ * @author Brian Stansberry
+ *
+ */
+public class ClusterChooserInterceptorUnitTestCase extends TestCase
+{
+ private static int testCount;
+
+ /**
+ * Create a new ClusterChooserInterceptorUnitTestCase.
+ *
+ * @param name
+ */
+ public ClusterChooserInterceptorUnitTestCase(String name)
+ {
+ super(name);
+ }
+
+ public void testUseAopLoadBalancePolicy() throws Throwable
+ {
+ testCount++;
+
+ MockAopLoadBalancePolicy lb = new MockAopLoadBalancePolicy();
+ FamilyWrapper fw = createFamilyWrapper("test" + testCount, 1);
+ MockInvocation invocation = setupInvocation(lb, fw);
+ MockNextInterceptor next = (MockNextInterceptor) invocation.getNextInterceptor();
+ next.setReturnValue("a");
+
+ assertEquals("a", invocation.invokeNext());
+
+ // This assertion is the real thing this method is testing
+ assertEquals(1, lb.getOverloadedInvocationCount());
+ assertEquals(getInvokerLocator(0), next.getInvocationHistory().get(0).getMetaData(InvokeRemoteInterceptor.REMOTING, InvokeRemoteInterceptor.INVOKER_LOCATOR));
+ }
+
+ private MockInvocation setupInvocation(LoadBalancePolicy lb, FamilyWrapper fw)
+ {
+ ClusterChooserInterceptor cci = new ClusterChooserInterceptor();
+ MockNextInterceptor next = new MockNextInterceptor();
+ MockInvocation mi = new MockInvocation(new Interceptor[]{cci, next});
+ mi.getMetaData().addMetaData(ClusterConstants.CLUSTERED_REMOTING, ClusterConstants.LOADBALANCE_POLICY, lb);
+ mi.getMetaData().addMetaData(ClusterConstants.CLUSTERED_REMOTING, ClusterConstants.CLUSTER_FAMILY_WRAPPER, fw);
+ return mi;
+ }
+
+ private FamilyWrapper createFamilyWrapper(String familyName, int numTargets) throws Exception
+ {
+ List<InvokerLocator> targets = new ArrayList<InvokerLocator>(numTargets);
+ for (int i = 0; i < numTargets; i++)
+ targets.add(getInvokerLocator(i));
+ return new FamilyWrapper(familyName, targets);
+ }
+
+ private static InvokerLocator getInvokerLocator(int targetNum) throws MalformedURLException
+ {
+ return new InvokerLocator("http://host" + String.valueOf(targetNum));
+ }
+
+}
Added: projects/cluster/ha-client/trunk/src/test/java/org/jboss/test/aspects/remoting/MockAopLoadBalancePolicy.java
===================================================================
--- projects/cluster/ha-client/trunk/src/test/java/org/jboss/test/aspects/remoting/MockAopLoadBalancePolicy.java (rev 0)
+++ projects/cluster/ha-client/trunk/src/test/java/org/jboss/test/aspects/remoting/MockAopLoadBalancePolicy.java 2008-04-23 02:14:17 UTC (rev 72592)
@@ -0,0 +1,62 @@
+/*
+ * 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.aspects.remoting;
+
+import org.jboss.aop.joinpoint.Invocation;
+import org.jboss.ha.client.loadbalance.AopLoadBalancePolicy;
+import org.jboss.ha.client.loadbalance.RoundRobin;
+import org.jboss.ha.framework.interfaces.FamilyClusterInfo;
+
+/**
+ * @author Brian Stansberry
+ *
+ */
+public class MockAopLoadBalancePolicy
+ extends RoundRobin
+ implements AopLoadBalancePolicy
+{
+ /** The serialVersionUID */
+ private static final long serialVersionUID = -4356989928555975360L;
+
+ private int overloadedInvocationCount;
+ /**
+ * Create a new MockAopLoadBalancePolicy.
+ *
+ *
+ */
+ public MockAopLoadBalancePolicy()
+ {
+ }
+
+ public Object chooseTarget(FamilyClusterInfo clusterFamily, Invocation routingDecision)
+ {
+ overloadedInvocationCount++;
+ return chooseTarget(clusterFamily);
+ }
+
+ public int getOverloadedInvocationCount()
+ {
+ return overloadedInvocationCount;
+ }
+
+}
Added: projects/cluster/ha-client/trunk/src/test/java/org/jboss/test/aspects/remoting/MockInvocation.java
===================================================================
--- projects/cluster/ha-client/trunk/src/test/java/org/jboss/test/aspects/remoting/MockInvocation.java (rev 0)
+++ projects/cluster/ha-client/trunk/src/test/java/org/jboss/test/aspects/remoting/MockInvocation.java 2008-04-23 02:14:17 UTC (rev 72592)
@@ -0,0 +1,97 @@
+/*
+ * 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.aspects.remoting;
+
+import org.jboss.aop.advice.Interceptor;
+import org.jboss.aop.joinpoint.Invocation;
+import org.jboss.aop.joinpoint.InvocationBase;
+import org.jboss.aop.metadata.SimpleMetaData;
+import org.jboss.aspects.remoting.ClusterChooserInterceptor;
+
+/**
+ * @author Brian Stansberry
+ *
+ */
+public class MockInvocation extends InvocationBase
+{
+
+ /** The serialVersionUID */
+ private static final long serialVersionUID = -8025564256411866981L;
+
+ /**
+ * Create a new MockInvocation.
+ *
+ * @param interceptors
+ */
+ public MockInvocation(Interceptor[] interceptors)
+ {
+ super(interceptors);
+ // TODO Auto-generated constructor stub
+ }
+
+ /**
+ * Create a new MockInvocation.
+ *
+ * @param interceptors
+ * @param meta
+ */
+ public MockInvocation(Interceptor[] interceptors, SimpleMetaData meta)
+ {
+ super(interceptors, meta);
+ }
+
+ public Invocation copy()
+ {
+ return null;
+ }
+
+ public Invocation getWrapper(Interceptor[] ainterceptor)
+ {
+ return null;
+ }
+
+ public ClusterChooserInterceptor getClusterChooserInterceptor()
+ {
+ for (Interceptor i : getInterceptors())
+ {
+ if (i instanceof ClusterChooserInterceptor)
+ return (ClusterChooserInterceptor) i;
+ }
+
+ return null;
+ }
+
+ public Interceptor getNextInterceptor()
+ {
+ boolean found = false;
+ for (Interceptor i : getInterceptors())
+ {
+ if (found)
+ return i;
+ else if (i instanceof ClusterChooserInterceptor)
+ found = true;
+ }
+
+ return null;
+ }
+}
Added: projects/cluster/ha-client/trunk/src/test/java/org/jboss/test/aspects/remoting/MockNextInterceptor.java
===================================================================
--- projects/cluster/ha-client/trunk/src/test/java/org/jboss/test/aspects/remoting/MockNextInterceptor.java (rev 0)
+++ projects/cluster/ha-client/trunk/src/test/java/org/jboss/test/aspects/remoting/MockNextInterceptor.java 2008-04-23 02:14:17 UTC (rev 72592)
@@ -0,0 +1,105 @@
+/*
+ * 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.aspects.remoting;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.jboss.aop.advice.Interceptor;
+import org.jboss.aop.joinpoint.Invocation;
+import org.jboss.aop.metadata.SimpleMetaData;
+
+/**
+ * An interceptor that comes next in the chain after ClusterChooserInterceptor.
+ *
+ * @author Brian Stansberry
+ */
+public class MockNextInterceptor implements Interceptor
+{
+ private List<SimpleMetaData> invocationMetaData = new ArrayList<SimpleMetaData>();
+ private Object[] returnValues;
+ private int idx;
+
+ public String getName()
+ {
+ return "MockNextInterceptor";
+ }
+
+ public Object invoke(Invocation invocation) throws Throwable
+ {
+ SimpleMetaData latest = new SimpleMetaData();
+ latest.mergeIn(invocation.getMetaData());
+ invocationMetaData.add(latest);
+ Object result = null;
+ if (returnValues != null)
+ {
+ try
+ {
+ if (returnValues[idx] instanceof Throwable)
+ {
+ throw (Throwable) returnValues[idx];
+ }
+ result = returnValues[idx];
+ }
+ finally
+ {
+ idx++;
+ }
+ }
+ return result;
+ }
+
+ /**
+ * Gets a list containing copies of the SimpleMetaData that has been
+ * passed to each invocation of invoke().
+ *
+ * @return
+ */
+ public List<SimpleMetaData> getInvocationHistory()
+ {
+ return invocationMetaData;
+ }
+
+ /**
+ * Sets a sequence of return values that should be returned from invoke().
+ * Typically this would be one per expected invocation during a series
+ * of failover attempts.
+ */
+ public void setReturnValues(Object[] returnValues)
+ {
+ this.returnValues = returnValues;
+ }
+
+ /** Convenience method to set a single return value for a non-failover test */
+ public void setReturnValue(Object returnValue)
+ {
+ if (returnValue != null)
+ {
+ returnValues = new Object[] { returnValue };
+ }
+ else
+ {
+ returnValues = null;
+ }
+ }
+}
More information about the jboss-cvs-commits
mailing list