[jboss-cvs] JBossAS SVN: r67624 - in trunk/testsuite/src/main/org/jboss/test/cluster: invokerha and 1 other directory.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Thu Nov 29 14:54:11 EST 2007
Author: galder.zamarreno at jboss.com
Date: 2007-11-29 14:54:10 -0500 (Thu, 29 Nov 2007)
New Revision: 67624
Added:
trunk/testsuite/src/main/org/jboss/test/cluster/defaultcfg/test/JRMPInvokerHaTransactionStickyUnitTestCase.java
trunk/testsuite/src/main/org/jboss/test/cluster/defaultcfg/test/UnifiedInvokerHaTransactionStickyUnitTestCase.java
trunk/testsuite/src/main/org/jboss/test/cluster/invokerha/AbstractInvokerHaTransactionSticky.java
trunk/testsuite/src/main/org/jboss/test/cluster/invokerha/InvokerHaFailureType.java
Modified:
trunk/testsuite/src/main/org/jboss/test/cluster/defaultcfg/test/JRMPInvokerHaUnitTestCase.java
trunk/testsuite/src/main/org/jboss/test/cluster/defaultcfg/test/UnifiedInvokerHaUnitTestCase.java
trunk/testsuite/src/main/org/jboss/test/cluster/invokerha/AbstractInvokerHa.java
trunk/testsuite/src/main/org/jboss/test/cluster/invokerha/InvokerHaInfrastructure.java
trunk/testsuite/src/main/org/jboss/test/cluster/invokerha/JRMPInvokerHaMockUtils.java
trunk/testsuite/src/main/org/jboss/test/cluster/invokerha/UnifiedInvokerHaMockUtils.java
Log:
[JBAS-4455] New test classes added to test the new transaction sticky lbps and the behaivour of the invoker ha proxies. These tests include both successfull and failure scenarios.
Added: trunk/testsuite/src/main/org/jboss/test/cluster/defaultcfg/test/JRMPInvokerHaTransactionStickyUnitTestCase.java
===================================================================
--- trunk/testsuite/src/main/org/jboss/test/cluster/defaultcfg/test/JRMPInvokerHaTransactionStickyUnitTestCase.java (rev 0)
+++ trunk/testsuite/src/main/org/jboss/test/cluster/defaultcfg/test/JRMPInvokerHaTransactionStickyUnitTestCase.java 2007-11-29 19:54:10 UTC (rev 67624)
@@ -0,0 +1,50 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2007, 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.cluster.defaultcfg.test;
+
+import org.jboss.test.cluster.defaultcfg.test.JRMPInvokerHaUnitTestCase.JRMPInvokerHaFactory;
+import org.jboss.test.cluster.invokerha.AbstractInvokerHaTransactionSticky;
+
+/**
+ * JRMPInvokerHaTransactionStickyUnitTestCase.
+ *
+ * @author <a href="mailto:galder.zamarreno at jboss.com">Galder Zamarreno</a>
+ */
+public class JRMPInvokerHaTransactionStickyUnitTestCase extends AbstractInvokerHaTransactionSticky
+{
+ @Override
+ protected void setUp() throws Exception
+ {
+ setUp(2, new JRMPInvokerHaTransactionStickyFactory());
+ }
+
+ @Override
+ protected void tearDown() throws Exception
+ {
+ super.tearDown();
+ }
+
+ public static class JRMPInvokerHaTransactionStickyFactory extends JRMPInvokerHaFactory
+ {
+ }
+
+}
Modified: trunk/testsuite/src/main/org/jboss/test/cluster/defaultcfg/test/JRMPInvokerHaUnitTestCase.java
===================================================================
--- trunk/testsuite/src/main/org/jboss/test/cluster/defaultcfg/test/JRMPInvokerHaUnitTestCase.java 2007-11-29 19:50:01 UTC (rev 67623)
+++ trunk/testsuite/src/main/org/jboss/test/cluster/defaultcfg/test/JRMPInvokerHaUnitTestCase.java 2007-11-29 19:54:10 UTC (rev 67624)
@@ -51,7 +51,7 @@
/** Classes **/
- public class JRMPInvokerHaFactory implements InvokerHaFactory
+ public static class JRMPInvokerHaFactory implements InvokerHaFactory
{
public String getInvokerTypeName()
{
Added: trunk/testsuite/src/main/org/jboss/test/cluster/defaultcfg/test/UnifiedInvokerHaTransactionStickyUnitTestCase.java
===================================================================
--- trunk/testsuite/src/main/org/jboss/test/cluster/defaultcfg/test/UnifiedInvokerHaTransactionStickyUnitTestCase.java (rev 0)
+++ trunk/testsuite/src/main/org/jboss/test/cluster/defaultcfg/test/UnifiedInvokerHaTransactionStickyUnitTestCase.java 2007-11-29 19:54:10 UTC (rev 67624)
@@ -0,0 +1,49 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2007, 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.cluster.defaultcfg.test;
+
+import org.jboss.test.cluster.defaultcfg.test.UnifiedInvokerHaUnitTestCase.UnifiedInvokerHaFactory;
+import org.jboss.test.cluster.invokerha.AbstractInvokerHaTransactionSticky;
+
+/**
+ * UnifiedInvokerHaTransactionStickyUnitTestCase.
+ *
+ * @author <a href="mailto:galder.zamarreno at jboss.com">Galder Zamarreno</a>
+ */
+public class UnifiedInvokerHaTransactionStickyUnitTestCase extends AbstractInvokerHaTransactionSticky
+{
+ @Override
+ protected void setUp() throws Exception
+ {
+ setUp(2, new UnifiedInvokerHaTransactionStickyFactory());
+ }
+
+ @Override
+ protected void tearDown() throws Exception
+ {
+ super.tearDown();
+ }
+
+ public static class UnifiedInvokerHaTransactionStickyFactory extends UnifiedInvokerHaFactory
+ {
+ }
+}
Modified: trunk/testsuite/src/main/org/jboss/test/cluster/defaultcfg/test/UnifiedInvokerHaUnitTestCase.java
===================================================================
--- trunk/testsuite/src/main/org/jboss/test/cluster/defaultcfg/test/UnifiedInvokerHaUnitTestCase.java 2007-11-29 19:50:01 UTC (rev 67623)
+++ trunk/testsuite/src/main/org/jboss/test/cluster/defaultcfg/test/UnifiedInvokerHaUnitTestCase.java 2007-11-29 19:54:10 UTC (rev 67624)
@@ -65,7 +65,7 @@
/**
* Unified invoker ha factory.
*/
- public class UnifiedInvokerHaFactory implements InvokerHaFactory
+ public static class UnifiedInvokerHaFactory implements InvokerHaFactory
{
public String getInvokerTypeName()
{
@@ -96,7 +96,7 @@
/**
* Unified invoker specific infrastructure class.
*/
- public class UnifiedInvokerHaInfrastructure extends InvokerHaInfrastructure
+ public static class UnifiedInvokerHaInfrastructure extends InvokerHaInfrastructure
{
public UnifiedInvokerHaInfrastructure(int serverCount, InvokerHaFactory invokerHaFactory)
{
Modified: trunk/testsuite/src/main/org/jboss/test/cluster/invokerha/AbstractInvokerHa.java
===================================================================
--- trunk/testsuite/src/main/org/jboss/test/cluster/invokerha/AbstractInvokerHa.java 2007-11-29 19:50:01 UTC (rev 67623)
+++ trunk/testsuite/src/main/org/jboss/test/cluster/invokerha/AbstractInvokerHa.java 2007-11-29 19:54:10 UTC (rev 67624)
@@ -22,7 +22,6 @@
package org.jboss.test.cluster.invokerha;
import java.rmi.server.UID;
-import java.util.WeakHashMap;
import javax.transaction.Transaction;
@@ -48,19 +47,19 @@
{
private static final Logger log = Logger.getLogger(AbstractInvokerHa.class);
- private InvokerHaInfrastructure infrastructure;
+ InvokerHaInfrastructure infrastructure;
- private InvokerHaTransactionalMockUtils transactionalMockUtils;
+ InvokerHaTransactionalMockUtils transactionalMockUtils;
- private InvokerHaFactory invokerHaFactory;
+ InvokerHaFactory invokerHaFactory;
- private Invoker timeTellerProxy;
+ Invoker timeTellerProxy;
- private Invoker systemTimeProxy;
+ Invoker systemTimeProxy;
- private Object prevChosenTargetDateTimeTeller;
+ Object prevChosenTargetDateTimeTeller;
- private Object prevChosenTargetSystemTimeTeller;
+ Object prevChosenTargetSystemTimeTeller;
protected void setUp(int serverCount, InvokerHaFactory factory) throws Exception
{
@@ -96,39 +95,39 @@
infrastructure.undeployServers();
}
- public void testSuccessfulCallsRoundRobin() throws Exception
+ public void testTransactionalSuccessfulCallsRoundRobin() throws Exception
{
/* same proxies used in simulated transactions */
- successfulCalls(TraceRoundRobin.class, false);
+ transactionalSuccessfulCalls(TraceRoundRobin.class, false);
/* different proxies in simulated transactions */
- successfulCalls(TraceRoundRobin.class, true);
+ transactionalSuccessfulCalls(TraceRoundRobin.class, true);
}
- public void testSuccessfulCallsFirstAvailable() throws Exception
+ public void testTransactionalSuccessfulCallsFirstAvailable() throws Exception
{
/* same proxies used in simulated transactions */
- successfulCalls(TraceFirstAvailable.class, false);
+ transactionalSuccessfulCalls(TraceFirstAvailable.class, false);
/* same proxies used in simulated transactions */
- successfulCalls(TraceFirstAvailable.class, true);
+ transactionalSuccessfulCalls(TraceFirstAvailable.class, true);
}
- public void testSuccessfulCallsFirstAvailableIndenticalAllProxies() throws Exception
+ public void testTransactionalSuccessfulCallsFirstAvailableIndenticalAllProxies() throws Exception
{
/* same proxies used in simulated transactions */
- successfulCalls(TraceFirstAvailableIdenticalAllProxies.class, false);
+ transactionalSuccessfulCalls(TraceFirstAvailableIdenticalAllProxies.class, false);
/* same proxies used in simulated transactions */
- successfulCalls(TraceFirstAvailableIdenticalAllProxies.class, true);
+ transactionalSuccessfulCalls(TraceFirstAvailableIdenticalAllProxies.class, true);
}
- public void testSuccessfulCallsRandomRobin() throws Exception
+ public void testTransactionalSuccessfulCallsRandomRobin() throws Exception
{
/* same proxies used in simulated transactions */
- successfulCalls(TraceRandomRobin.class, false);
+ transactionalSuccessfulCalls(TraceRandomRobin.class, false);
/* same proxies used in simulated transactions */
- successfulCalls(TraceRandomRobin.class, true);
+ transactionalSuccessfulCalls(TraceRandomRobin.class, true);
}
- protected void successfulCalls(Class<? extends LoadBalancePolicy> policyClass, boolean newProxiesInBetweenTransactions)
+ protected void transactionalSuccessfulCalls(Class<? extends LoadBalancePolicy> policyClass, boolean newProxiesInBetweenTransactions)
{
log.debug("successfull calls [policy=" + policyClass + ",newProxiesInBetweenTransactions=" + newProxiesInBetweenTransactions + "]");
@@ -141,7 +140,7 @@
/* Simulate client user transaction */
uid = new UID();
transactionalMockUtils.getTpcf().setUid(uid);
- callsWithinTransaction(3, null, policyClass, newProxiesInBetweenTransactions);
+ performCalls(3, null, policyClass, newProxiesInBetweenTransactions);
if (newProxiesInBetweenTransactions)
{
@@ -153,7 +152,7 @@
Transaction tx = new MockTransaction();
transactionalMockUtils.getTpcf().setUid(uid);
transactionalMockUtils.getTpci().setTransaction(tx);
- callsWithinTransaction(3, tx, policyClass, newProxiesInBetweenTransactions);
+ performCalls(3, tx, policyClass, newProxiesInBetweenTransactions);
}
catch(Exception e)
{
@@ -164,49 +163,43 @@
}
}
- protected void callsWithinTransaction(int numberPairCalls,
+ protected void performCalls(int numberPairCalls,
Transaction tx, Class<? extends LoadBalancePolicy> policyClass,
boolean newProxiesInBetweenTransactions) throws Exception
{
Invocation inv;
- Object chosenTarget;
- WeakHashMap txFailoverAuthorizations = invokerHaFactory.getTxFailoverAuthorizationsMap();
-
for (int i = 0; i < numberPairCalls; i++)
{
/* create invocation to date time teller */
- inv = infrastructure.createDateTimeTellerInvocation(tx);
+ inv = infrastructure.createDateTimeTellerInvocation(tx, null);
/* invoke on proxy passing the invocation */
log.debug(timeTellerProxy.invoke(inv));
-
- assertEquals(0, inv.getAsIsValue("FAILOVER_COUNTER"));
- chosenTarget = inv.getTransientValue("TEST_CHOSEN_TARGET");
- assertNotNull(chosenTarget);
- /* if tx was null, invocation's tx should be null after invocation. */
- assertEquals(tx, inv.getTransaction());
- /* check tx failover authorisations */
- assertTrue("transaction should have reached the server", txFailoverAuthorizations.containsKey(transactionalMockUtils.getTpcf().getUid()));
- /* check chosen target with previously chosen target, if there's any */
- prevChosenTargetDateTimeTeller = assertChosenTarget(policyClass, chosenTarget, prevChosenTargetDateTimeTeller);
+ /* assert post conditions after invocation */
+ prevChosenTargetDateTimeTeller = assertSuccessfulPostConditions(inv, prevChosenTargetDateTimeTeller, tx, policyClass);
/* create invocation to system time teller */
- inv = infrastructure.createSystemTimeTellerInvocation(tx);
+ inv = infrastructure.createSystemTimeTellerInvocation(tx, null);
/* invoke on proxy passing the invocation */
log.debug(systemTimeProxy.invoke(inv));
-
- assertEquals(0, inv.getAsIsValue("FAILOVER_COUNTER"));
- chosenTarget = inv.getTransientValue("TEST_CHOSEN_TARGET");
- assertNotNull(chosenTarget);
- /* if tx was null, invocation's tx should be null after invocation. */
- assertEquals(tx, inv.getTransaction());
- /* check tx failover authorisations */
- assertTrue("transaction should have reached the server", txFailoverAuthorizations.containsKey(transactionalMockUtils.getTpcf().getUid()));
- /* check chosen target with previously chosen target, if there's any */
- prevChosenTargetSystemTimeTeller = assertChosenTarget(policyClass, chosenTarget, prevChosenTargetSystemTimeTeller);
+ /* assert post conditions after invocation */
+ prevChosenTargetSystemTimeTeller = assertSuccessfulPostConditions(inv, prevChosenTargetSystemTimeTeller, tx, policyClass);
}
}
+ protected Object assertSuccessfulPostConditions(Invocation inv, Object prevChosenTarget, Transaction tx, Class<? extends LoadBalancePolicy> policyClass)
+ {
+ assertEquals(0, inv.getAsIsValue("FAILOVER_COUNTER"));
+ Object chosenTarget = inv.getTransientValue("TEST_CHOSEN_TARGET");
+ assertNotNull(chosenTarget);
+ /* if tx was null, invocation's tx should be null after invocation. */
+ assertEquals(tx, inv.getTransaction());
+ /* check tx failover authorisations */
+ assertTrue("transaction should have reached the server", invokerHaFactory.getTxFailoverAuthorizationsMap().containsKey(transactionalMockUtils.getTpcf().getUid()));
+ /* check chosen target with previously chosen target, if there's any */
+ return assertChosenTarget(policyClass, chosenTarget, prevChosenTarget);
+ }
+
protected void createNewProxies(int serverIndex, Class<? extends LoadBalancePolicy> policyClass, boolean isVery1st) throws Exception
{
/* Create a proxy instances retrieved from the first server */
Added: trunk/testsuite/src/main/org/jboss/test/cluster/invokerha/AbstractInvokerHaTransactionSticky.java
===================================================================
--- trunk/testsuite/src/main/org/jboss/test/cluster/invokerha/AbstractInvokerHaTransactionSticky.java (rev 0)
+++ trunk/testsuite/src/main/org/jboss/test/cluster/invokerha/AbstractInvokerHaTransactionSticky.java 2007-11-29 19:54:10 UTC (rev 67624)
@@ -0,0 +1,326 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2007, 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.cluster.invokerha;
+
+import java.rmi.server.UID;
+import java.util.HashSet;
+import java.util.Set;
+
+import javax.transaction.Transaction;
+
+import org.jboss.ha.framework.interfaces.LoadBalancePolicy;
+import org.jboss.ha.framework.interfaces.TransactionStickyFirstAvailable;
+import org.jboss.ha.framework.interfaces.TransactionStickyFirstAvailableIdenticalAllProxies;
+import org.jboss.ha.framework.interfaces.TransactionStickyRandomRobin;
+import org.jboss.ha.framework.interfaces.TransactionStickyRoundRobin;
+import org.jboss.invocation.Invocation;
+import org.jboss.logging.Logger;
+import org.jboss.test.cluster.invokerha.InvokerHaTransactionalMockUtils.MockTransaction;
+
+/**
+ * AbstractInvokerHaTransactionSticky.
+ *
+ * @author <a href="mailto:galder.zamarreno at jboss.com">Galder Zamarreno</a>
+ */
+public class AbstractInvokerHaTransactionSticky extends AbstractInvokerHa
+{
+ private static final Logger log = Logger.getLogger(AbstractInvokerHaTransactionSticky.class);
+
+ private Set<Object> chosenTargets;
+
+ @Override
+ public void testTransactionalSuccessfulCallsRoundRobin() throws Exception
+ {
+ /* same proxies used in simulated transactions */
+ transactionalSuccessfulCalls(TransactionStickyRoundRobin.class, false);
+ /* different proxies in simulated transactions */
+ transactionalSuccessfulCalls(TransactionStickyRoundRobin.class, true);
+ }
+
+ @Override
+ public void testTransactionalSuccessfulCallsFirstAvailable() throws Exception
+ {
+ /* same proxies used in simulated transactions */
+ transactionalSuccessfulCalls(TransactionStickyFirstAvailable.class, false);
+ /* different proxies in simulated transactions */
+ transactionalSuccessfulCalls(TransactionStickyFirstAvailable.class, true);
+ }
+
+ @Override
+ public void testTransactionalSuccessfulCallsFirstAvailableIndenticalAllProxies() throws Exception
+ {
+ /* same proxies used in simulated transactions */
+ transactionalSuccessfulCalls(TransactionStickyFirstAvailableIdenticalAllProxies.class, false);
+ /* different proxies in simulated transactions */
+ transactionalSuccessfulCalls(TransactionStickyFirstAvailableIdenticalAllProxies.class, true);
+ }
+
+ @Override
+ public void testTransactionalSuccessfulCallsRandomRobin() throws Exception
+ {
+ /* same proxies used in simulated transactions */
+ transactionalSuccessfulCalls(TransactionStickyRandomRobin.class, false);
+ /* different proxies in simulated transactions */
+ transactionalSuccessfulCalls(TransactionStickyRandomRobin.class, true);
+ }
+
+ /* TODO -> bunch of tests that test the new transaction sticky lbps under
+ * when no transactions run. They should behave exactly as the normal lbps */
+
+ public void testFailBeforeServer() throws Exception
+ {
+ /* if failure happens before reaching the server, regardless of whether
+ * the failure happened in the 1st or the Nth invocation, it's not
+ * recoverable */
+ transactionalFailureCalls(InvokerHaFailureType.BEFORE_SERVER, TransactionStickyRandomRobin.class, false);
+ }
+
+ public void testFailAfterServerNotCompletedButSuccessAfter() throws Exception
+ {
+ /* we use new proxies in between tests for 1st and Nth
+ * call so that results from Nth call don't get polluted with what
+ * happened in the 1st call test. */
+ transactionalFailureCalls(InvokerHaFailureType.AFTER_SERVER_NOT_COMPLETED_BUT_SUCCESS_AFTER, TransactionStickyRandomRobin.class, true);
+ }
+
+ public void testFailAfterServerNotCompletedBothServers() throws Exception
+ {
+ /* we use new proxies in between tests for 1st and Nth call
+ * so that results from Nth call don't get polluted with what happened in
+ * the 1st call test. */
+ transactionalFailureCalls(InvokerHaFailureType.AFTER_SERVER_NOT_COMPLETED_BOTH_SERVERS, TransactionStickyRandomRobin.class, true);
+ }
+
+ public void testFailAfterServerCompleted() throws Exception
+ {
+ /* We use new proxies in between tests for 1st and Nth call
+ * so that results from Nth call don't get polluted with what happened in
+ * the 1st call test. */
+ transactionalFailureCalls(InvokerHaFailureType.AFTER_SERVER_COMPLETED, TransactionStickyRandomRobin.class, true);
+ }
+
+ @Override
+ protected void transactionalSuccessfulCalls(Class<? extends LoadBalancePolicy> policyClass,
+ boolean newProxiesInBetweenTransactions)
+ {
+ log.debug("successfull calls [policy=" + policyClass + ",newProxiesInBetweenTransactions=" + newProxiesInBetweenTransactions + "]");
+
+ try
+ {
+ UID uid;
+
+ createNewProxies(0, policyClass, true);
+
+ /* Simulate client user transaction */
+ uid = new UID();
+ transactionalMockUtils.getTpcf().setUid(uid);
+ performTransactionalStickyCalls(3, null, policyClass, newProxiesInBetweenTransactions);
+ /* either set would do because they should be the same */
+ Set<Object> chosenTargetsTx1 = chosenTargets;
+
+ if (newProxiesInBetweenTransactions)
+ {
+ createNewProxies(0, policyClass, false);
+ }
+
+ /* Simulate transaction interceptor */
+ uid = new UID();
+ Transaction tx = new MockTransaction();
+ transactionalMockUtils.getTpcf().setUid(uid);
+ transactionalMockUtils.getTpci().setTransaction(tx);
+ performTransactionalStickyCalls(3, tx, policyClass, newProxiesInBetweenTransactions);
+ /* either set would do because they should be the same */
+ Set<Object> chosenTargetsTx2 = chosenTargets;
+
+ assertChosenTargetsInBetweenTx(policyClass, chosenTargetsTx1, chosenTargetsTx2, newProxiesInBetweenTransactions);
+ }
+ catch(Exception e)
+ {
+ /* catching to log the error properly (JUnit in eclipse does not show
+ * correctly exceptions from invokers) and fail */
+ log.error("error", e);
+ fail();
+ }
+
+ }
+
+ protected void performTransactionalStickyCalls(int numberPairCalls, Transaction tx,
+ Class<? extends LoadBalancePolicy> policyClass, boolean newProxiesInBetweenTransactions) throws Exception
+ {
+ Invocation inv;
+
+ Set<Object> chosenTargetsDateTimeTeller = new HashSet<Object>(1);
+ Set<Object> chosenTargetsSystemTimeTeller = new HashSet<Object>(1);
+
+ for (int i = 0; i < numberPairCalls; i++)
+ {
+ /* create invocation to date time teller */
+ inv = infrastructure.createDateTimeTellerInvocation(tx, null);
+ /* invoke on proxy passing the invocation */
+ log.debug(timeTellerProxy.invoke(inv));
+ /* assert post conditions after invocation */
+ chosenTargetsDateTimeTeller = assertSuccessfulPostConditions(inv, chosenTargetsDateTimeTeller, tx);
+
+ /* create invocation to system time teller */
+ inv = infrastructure.createSystemTimeTellerInvocation(tx, null);
+ /* invoke on proxy passing the invocation */
+ log.debug(systemTimeProxy.invoke(inv));
+ /* assert post conditions after invocation */
+ chosenTargetsSystemTimeTeller = assertSuccessfulPostConditions(inv, chosenTargetsSystemTimeTeller, tx);
+ }
+
+ /* for the duration of a transaction, all chosen targets should be the same */
+ assertEquals(chosenTargetsDateTimeTeller, chosenTargetsSystemTimeTeller);
+
+ chosenTargets = chosenTargetsDateTimeTeller;
+ }
+
+ protected Set<Object> assertSuccessfulPostConditions(Invocation inv, Set<Object> chosenTargets, Transaction tx)
+ {
+ assertEquals(0, inv.getAsIsValue("FAILOVER_COUNTER"));
+ Object chosenTarget = inv.getTransientValue("TX_STICKY_TARGET");
+ assertNotNull(chosenTarget);
+ /* if tx was null, invocation's tx should be null after invocation. */
+ assertEquals(tx, inv.getTransaction());
+ /* check tx failover authorisations */
+ assertTrue("transaction should have reached the server", invokerHaFactory.getTxFailoverAuthorizationsMap().containsKey(transactionalMockUtils.getTpcf().getUid()));
+ /* add target to singleton set, there must only be one different target within a transaction */
+ chosenTargets.add(chosenTarget);
+ assertEquals(1, chosenTargets.size());
+
+ return chosenTargets;
+ }
+
+ protected void assertChosenTargetsInBetweenTx(Class<? extends LoadBalancePolicy> policyClass, Set<?> chosenTargetsTx1, Set<?> chosenTargetsTx2, boolean newProxiesInBetweenTransactions)
+ {
+ if (policyClass.equals(TransactionStickyRoundRobin.class))
+ {
+ if (!newProxiesInBetweenTransactions)
+ {
+ /* If we're using sticky round robin and we didn't change proxies
+ * in between transactions, we can guarantee that the chosen targets
+ * were different between transactions.*/
+ assertNotSame(chosenTargetsTx1, chosenTargetsTx2);
+ }
+ }
+ else if (policyClass.equals(TransactionStickyFirstAvailable.class))
+ {
+ if (!newProxiesInBetweenTransactions)
+ {
+ /* If we're using sticky first available and we didn't change proxies
+ * in between transactions, we can guarantee that the chosen targets
+ * are equals between transactions.*/
+ assertEquals(chosenTargetsTx1, chosenTargetsTx2);
+ }
+ }
+ else if (policyClass.equals(TransactionStickyFirstAvailableIdenticalAllProxies.class))
+ {
+ /* If we're using sticky first available identical all proxies,
+ * regardless of whether we're using same proxies or not, we can
+ * guarantee that the chosen targets are the same between
+ * transactions.*/
+ assertEquals(chosenTargetsTx1, chosenTargetsTx2);
+ }
+ }
+
+ protected void transactionalFailureCalls(InvokerHaFailureType failureType, Class<? extends LoadBalancePolicy> policyClass, boolean newProxiesInBetweenFailures) throws Exception
+ {
+ createNewProxies(0, policyClass, true);
+
+ try
+ {
+ /* fail in 1st call */
+ failureCall(failureType, true, policyClass, newProxiesInBetweenFailures);
+
+ if (newProxiesInBetweenFailures)
+ {
+ createNewProxies(0, policyClass, false);
+ }
+
+ /* fail in Nth call */
+ failureCall(failureType, false, policyClass, newProxiesInBetweenFailures);
+ }
+ catch(Exception e)
+ {
+ /* catching to log the error properly (JUnit in eclipse does not show
+ * correctly exceptions from invokers) and fail */
+ log.error("error", e);
+ fail();
+ }
+ }
+
+ protected void failureCall(InvokerHaFailureType failureType, boolean injectFailureIn1stCall, Class<? extends LoadBalancePolicy> policyClass, boolean newProxiesInBetweenFailures) throws Exception
+ {
+ UID uid;
+ Invocation inv;
+
+ if (injectFailureIn1stCall)
+ {
+ uid = new UID();
+ transactionalMockUtils.getTpcf().setUid(uid);
+ /* When failure must happen in the very 1st call, we create a 1st
+ * invocation with the failure injected */
+ inv = infrastructure.createDateTimeTellerInvocation(null, failureType);
+ }
+ else
+ {
+ uid = new UID();
+ Transaction tx = new MockTransaction();
+ transactionalMockUtils.getTpcf().setUid(uid);
+ transactionalMockUtils.getTpci().setTransaction(tx);
+ /* When failure is not in first call, we do a call to each bean before
+ * injecting the faliure */
+ performTransactionalStickyCalls(1, tx, policyClass, newProxiesInBetweenFailures);
+ /* Now we create the invocation with the failure injected */
+ inv = infrastructure.createDateTimeTellerInvocation(null, failureType);
+ }
+
+ try
+ {
+ log.debug(timeTellerProxy.invoke(inv));
+ if (failureType.isRecoverable(injectFailureIn1stCall))
+ {
+ failureType.assertFailoverCounter(injectFailureIn1stCall, inv.getAsIsValue("FAILOVER_COUNTER"));
+ inv = infrastructure.createDateTimeTellerInvocation(null, null);
+ log.debug(timeTellerProxy.invoke(inv));
+ }
+ else
+ {
+ fail("should have failed, failover is not allowed for " + failureType);
+ }
+ }
+ catch (Exception e)
+ {
+ if (failureType.isRecoverable(injectFailureIn1stCall))
+ {
+ fail("should have failed, failover is not allowed for " + failureType);
+ }
+ else
+ {
+ assertNull("transaction on the client side should be null", inv.getTransaction());
+ failureType.assertFailoverCounter(injectFailureIn1stCall, inv.getAsIsValue("FAILOVER_COUNTER"));
+ failureType.assertException(e);
+ }
+ }
+ }
+
+}
Added: trunk/testsuite/src/main/org/jboss/test/cluster/invokerha/InvokerHaFailureType.java
===================================================================
--- trunk/testsuite/src/main/org/jboss/test/cluster/invokerha/InvokerHaFailureType.java (rev 0)
+++ trunk/testsuite/src/main/org/jboss/test/cluster/invokerha/InvokerHaFailureType.java 2007-11-29 19:54:10 UTC (rev 67624)
@@ -0,0 +1,169 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2007, 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.cluster.invokerha;
+
+import java.rmi.ServerException;
+
+import org.jboss.ha.framework.interfaces.GenericClusteringException;
+import org.jboss.invocation.ServiceUnavailableException;
+import org.jboss.logging.Logger;
+
+import junit.framework.TestCase;
+
+/**
+ * InvokerHaFailureType.
+ *
+ * @author <a href="mailto:galder.zamarreno at jboss.com">Galder Zamarreno</a>
+ */
+public enum InvokerHaFailureType
+{
+ BEFORE_SERVER,
+ AFTER_SERVER_NOT_COMPLETED_BUT_SUCCESS_AFTER,
+ AFTER_SERVER_NOT_COMPLETED_BOTH_SERVERS,
+ AFTER_SERVER_COMPLETED;
+
+ private static final Logger log = Logger.getLogger(InvokerHaFailureType.class);
+
+ public boolean isRecoverable(boolean injectFailureIn1stCall)
+ {
+ switch(this)
+ {
+ case BEFORE_SERVER:
+ /* a failure before even getting to the invocation call itself is
+ * never recoverable */
+ return false;
+
+ case AFTER_SERVER_NOT_COMPLETED_BUT_SUCCESS_AFTER:
+ /* - if failure happens after reaching the server but didn't complete, and
+ * it happens in the 1st transactional invocation, it's recoverable as
+ * long as the failover call succeeds, otherwise (Nth invocation) it's
+ * not recoverable. */
+ if (injectFailureIn1stCall)
+ {
+ return true;
+ }
+ return false;
+
+ case AFTER_SERVER_NOT_COMPLETED_BOTH_SERVERS:
+ /* if failure happens after reaching the server but didn't complete when
+ * trying to call either server, neither in the 1st or Nth call is
+ * recoverable.*/
+ return false;
+
+ case AFTER_SERVER_COMPLETED:
+ /* if failure happens after reaching the server and completed, neither
+ * 1st or Nth call are recoverable. */
+ return false;
+
+ default:
+ return false;
+ }
+ }
+
+ public void injectFailureIfExistsBeforeServer() throws IllegalStateException
+ {
+ switch(this)
+ {
+ case BEFORE_SERVER:
+ log.debug("failing because of " + this);
+ throw new IllegalStateException("see how you handle this!!");
+ }
+ }
+
+ public void injectFailureIfExistsAfterServer(Integer failoverCounter) throws GenericClusteringException
+ {
+ switch(this)
+ {
+ case AFTER_SERVER_NOT_COMPLETED_BUT_SUCCESS_AFTER:
+ if (failoverCounter.equals(new Integer(0)))
+ {
+ log.debug("failing because of " + this);
+ throw new GenericClusteringException(GenericClusteringException.COMPLETED_NO, this.toString());
+ }
+ break;
+
+ case AFTER_SERVER_NOT_COMPLETED_BOTH_SERVERS:
+ log.debug("failing because of " + this);
+ throw new GenericClusteringException(GenericClusteringException.COMPLETED_NO, this.toString());
+
+ case AFTER_SERVER_COMPLETED:
+ log.debug("failing because of " + this);
+ throw new GenericClusteringException(GenericClusteringException.COMPLETED_YES, this.toString());
+ }
+ }
+
+ public void assertFailoverCounter(boolean injectFailureIn1stCall, Object failoverCounter)
+ {
+ switch(this)
+ {
+ case BEFORE_SERVER:
+ TestCase.assertEquals(0, failoverCounter);
+ break;
+
+ case AFTER_SERVER_NOT_COMPLETED_BUT_SUCCESS_AFTER:
+ TestCase.assertEquals(1, failoverCounter);
+ break;
+
+ case AFTER_SERVER_NOT_COMPLETED_BOTH_SERVERS:
+ if (injectFailureIn1stCall)
+ {
+ /* Two failovers were attempted before finally giving up */
+ TestCase.assertEquals(2, failoverCounter);
+ }
+ else
+ {
+ /* It's 1 because after several calls, the transaction has
+ * already reached the server, so that's good enough not to
+ * succeed */
+ TestCase.assertEquals(1, failoverCounter);
+ }
+ break;
+
+ case AFTER_SERVER_COMPLETED:
+ /* failover counters are always 0 because there's no chance of
+ * calculating failover at all */
+ TestCase.assertEquals(0, failoverCounter);
+ break;
+ }
+ }
+
+ public void assertException(Exception e)
+ {
+ switch(this)
+ {
+ case BEFORE_SERVER:
+ TestCase.assertTrue(e instanceof IllegalStateException);
+ break;
+
+ case AFTER_SERVER_NOT_COMPLETED_BUT_SUCCESS_AFTER:
+ case AFTER_SERVER_NOT_COMPLETED_BOTH_SERVERS:
+ TestCase.assertTrue(e instanceof ServiceUnavailableException);
+ TestCase.assertTrue(e.getCause() instanceof GenericClusteringException);
+ break;
+
+ case AFTER_SERVER_COMPLETED:
+ TestCase.assertTrue(e instanceof ServerException);
+ TestCase.assertTrue(e.getCause() instanceof GenericClusteringException);
+ break;
+ }
+ }
+}
Modified: trunk/testsuite/src/main/org/jboss/test/cluster/invokerha/InvokerHaInfrastructure.java
===================================================================
--- trunk/testsuite/src/main/org/jboss/test/cluster/invokerha/InvokerHaInfrastructure.java 2007-11-29 19:50:01 UTC (rev 67623)
+++ trunk/testsuite/src/main/org/jboss/test/cluster/invokerha/InvokerHaInfrastructure.java 2007-11-29 19:54:10 UTC (rev 67624)
@@ -223,11 +223,13 @@
* @param tx instance of Transaction. If tx is null, transaction is not
* added to invocation, which is useful to replicate transactions starting
* in non managed environments.
+ * @param failureType type of failure to inject. If null, no failure is
+ * injected.
* @return
*/
- public Invocation createDateTimeTellerInvocation(Transaction tx)
+ public Invocation createDateTimeTellerInvocation(Transaction tx, InvokerHaFailureType failureType)
{
- return createInvocation(tx, dateTimeTellerONHashCode);
+ return createInvocation(tx, dateTimeTellerONHashCode, failureType);
}
/**
@@ -238,10 +240,10 @@
* in non managed environments.
* @return
*/
- public Invocation createSystemTimeTellerInvocation(Transaction tx)
+ public Invocation createSystemTimeTellerInvocation(Transaction tx, InvokerHaFailureType failureType)
{
- return createInvocation(tx, systemTimeTellerONHashCode);
- }
+ return createInvocation(tx, systemTimeTellerONHashCode, failureType);
+ }
/**
* Unbind mbean object name hashcodes from JMX registry.
@@ -327,7 +329,7 @@
* @param hashCode hashcode of object name of the mbean
* @return
*/
- private Invocation createInvocation(Transaction tx, Integer hashCode)
+ private Invocation createInvocation(Transaction tx, Integer hashCode, InvokerHaFailureType failureType)
{
Invocation inv = new Invocation();
inv.setObjectName(hashCode);
@@ -335,6 +337,10 @@
{
inv.setTransaction(tx);
}
+ if (failureType != null)
+ {
+ inv.setValue("FAILURE_TYPE", failureType);
+ }
return inv;
}
Modified: trunk/testsuite/src/main/org/jboss/test/cluster/invokerha/JRMPInvokerHaMockUtils.java
===================================================================
--- trunk/testsuite/src/main/org/jboss/test/cluster/invokerha/JRMPInvokerHaMockUtils.java 2007-11-29 19:50:01 UTC (rev 67623)
+++ trunk/testsuite/src/main/org/jboss/test/cluster/invokerha/JRMPInvokerHaMockUtils.java 2007-11-29 19:54:10 UTC (rev 67624)
@@ -92,27 +92,11 @@
@Override
public Object invoke(Invocation invocation) throws Exception
{
-// Object[] arguments = invocation.getArguments();
-// if (arguments != null && arguments.length != 0)
-// {
-// if (arguments[0].equals(FailureType.AFTER_SERVER_NOT_COMPLETED_BUT_SUCCESS_AFTER)
-// && invocation.getPayloadValue("MOCK_FAILOVER_COUNTER").equals(new Integer(0)))
-// {
-// log.debug("failing because of " + FailureType.AFTER_SERVER_NOT_COMPLETED_BUT_SUCCESS_AFTER);
-// throw new GenericClusteringException(GenericClusteringException.COMPLETED_NO, FailureType.AFTER_SERVER_NOT_COMPLETED_BUT_SUCCESS_AFTER.toString());
-// }
-//
-// if (arguments[0].equals(FailureType.AFTER_SERVER_NOT_COMPLETED_BOTH_SERVERS))
-// {
-// log.debug("failing because of " + FailureType.AFTER_SERVER_NOT_COMPLETED_BOTH_SERVERS);
-// throw new GenericClusteringException(GenericClusteringException.COMPLETED_NO, FailureType.AFTER_SERVER_NOT_COMPLETED_BOTH_SERVERS.toString());
-// }
-// if (arguments[0].equals(FailureType.AFTER_SERVER_COMPLETED))
-// {
-// log.debug("failing because of " + FailureType.AFTER_SERVER_COMPLETED);
-// throw new GenericClusteringException(GenericClusteringException.COMPLETED_YES, FailureType.AFTER_SERVER_COMPLETED.toString());
-// }
-// }
+ InvokerHaFailureType failureType = (InvokerHaFailureType)invocation.getValue("FAILURE_TYPE");
+ if (failureType != null)
+ {
+ failureType.injectFailureIfExistsAfterServer((Integer)invocation.getAsIsValue("FAILOVER_COUNTER"));
+ }
return super.invoke(invocation);
}
@@ -127,36 +111,30 @@
super(targets, policy, proxyFamilyName, viewId);
}
-// @Override
-// protected void putIfExistsTransactionTarget(Invocation invocation, Object tpc)
-// {
-// Object[] arguments = invocation.getArguments();
-// if (arguments != null && arguments.length != 0 && arguments[0].equals(FailureType.BEFORE_SERVER))
-// {
-// log.info("failing because of " + FailureType.BEFORE_SERVER);
-// throw new IllegalStateException("see how you handle this!!");
-// }
-//
-// super.putIfExistsTransactionTarget(invocation, tpc);
-// }
@Override
public boolean txContextAllowsFailover(Invocation invocation)
{
-// int failoverCount = ((Integer)invocation.getPayloadValue("MOCK_FAILOVER_COUNTER")).intValue();
-// failoverCount++;
-// invocation.setValue ("MOCK_FAILOVER_COUNTER", new Integer(failoverCount), PayloadKey.PAYLOAD);
-
return super.txContextAllowsFailover(invocation);
}
@Override
public Object invoke(Invocation invocation) throws Exception
{
-// invocation.setValue ("MOCK_FAILOVER_COUNTER", new Integer(0), PayloadKey.PAYLOAD);
-
return super.invoke(invocation);
- }
+ }
+
+ @Override
+ protected void putIfExistsTransactionTarget(Invocation invocation, Object tpc)
+ {
+ InvokerHaFailureType failureType = (InvokerHaFailureType)invocation.getValue("FAILURE_TYPE");
+ if (failureType != null)
+ {
+ failureType.injectFailureIfExistsBeforeServer();
+ }
+
+ super.putIfExistsTransactionTarget(invocation, tpc);
+ }
}
}
Modified: trunk/testsuite/src/main/org/jboss/test/cluster/invokerha/UnifiedInvokerHaMockUtils.java
===================================================================
--- trunk/testsuite/src/main/org/jboss/test/cluster/invokerha/UnifiedInvokerHaMockUtils.java 2007-11-29 19:50:01 UTC (rev 67623)
+++ trunk/testsuite/src/main/org/jboss/test/cluster/invokerha/UnifiedInvokerHaMockUtils.java 2007-11-29 19:54:10 UTC (rev 67624)
@@ -96,6 +96,19 @@
{
return ManagementFactory.getPlatformMBeanServer();
}
+
+ @Override
+ public Object invoke(InvocationRequest invocationReq) throws Throwable
+ {
+ Invocation invocation = (Invocation) invocationReq.getParameter();
+ InvokerHaFailureType failureType = (InvokerHaFailureType)invocation.getValue("FAILURE_TYPE");
+ if (failureType != null)
+ {
+ failureType.injectFailureIfExistsAfterServer((Integer)invocation.getAsIsValue("FAILOVER_COUNTER"));
+ }
+
+ return super.invoke(invocationReq);
+ }
}
public static class MockUnifiedInvokerHAProxy extends UnifiedInvokerHAProxy
@@ -113,6 +126,17 @@
return ((MockInvokerLocator)locator).getClient();
}
+ @Override
+ protected void putIfExistsTransactionTarget(Invocation invocation, Object tpc)
+ {
+ InvokerHaFailureType failureType = (InvokerHaFailureType)invocation.getValue("FAILURE_TYPE");
+ if (failureType != null)
+ {
+ failureType.injectFailureIfExistsBeforeServer();
+ }
+
+ super.putIfExistsTransactionTarget(invocation, tpc);
+ }
}
public static class MockInvokerLocator extends InvokerLocator
More information about the jboss-cvs-commits
mailing list