[jboss-svn-commits] JBL Code SVN: r32161 - in labs/jbosstm/trunk/ArjunaCore/txoj: classes/com/arjuna/ats/txoj and 7 other directories.
jboss-svn-commits at lists.jboss.org
jboss-svn-commits at lists.jboss.org
Sat Mar 20 15:45:30 EDT 2010
Author: mark.little at jboss.com
Date: 2010-03-20 15:45:28 -0400 (Sat, 20 Mar 2010)
New Revision: 32161
Added:
labs/jbosstm/trunk/ArjunaCore/txoj/tests/classes/com/arjuna/
labs/jbosstm/trunk/ArjunaCore/txoj/tests/classes/com/arjuna/ats/
labs/jbosstm/trunk/ArjunaCore/txoj/tests/classes/com/arjuna/ats/txoj/
labs/jbosstm/trunk/ArjunaCore/txoj/tests/classes/com/arjuna/ats/txoj/LockConflictUnitTest.java
labs/jbosstm/trunk/ArjunaCore/txoj/tests/classes/com/hp/mwtests/ts/txoj/concurrencycontrol/LockConflictUnitTest.java
labs/jbosstm/trunk/ArjunaCore/txoj/tests/classes/com/hp/mwtests/ts/txoj/concurrencycontrol/LockListIteratorUnitTest.java
labs/jbosstm/trunk/ArjunaCore/txoj/tests/classes/com/hp/mwtests/ts/txoj/concurrencycontrol/LockManagerUnitTest.java
labs/jbosstm/trunk/ArjunaCore/txoj/tests/classes/com/hp/mwtests/ts/txoj/concurrencycontrol/LockUnitTest.java
Modified:
labs/jbosstm/trunk/ArjunaCore/txoj/classes/com/arjuna/ats/internal/txoj/LockFriend.java
labs/jbosstm/trunk/ArjunaCore/txoj/classes/com/arjuna/ats/txoj/LockConflictManager.java
labs/jbosstm/trunk/ArjunaCore/txoj/classes/com/arjuna/ats/txoj/LockManager.java
labs/jbosstm/trunk/ArjunaCore/txoj/tests/classes/com/hp/mwtests/ts/txoj/common/resources/AtomicObject.java
labs/jbosstm/trunk/ArjunaCore/txoj/tests/classes/com/hp/mwtests/ts/txoj/recovery/RecoveryModuleUnitTest.java
Log:
https://jira.jboss.org/jira/browse/JBTM-709
Modified: labs/jbosstm/trunk/ArjunaCore/txoj/classes/com/arjuna/ats/internal/txoj/LockFriend.java
===================================================================
--- labs/jbosstm/trunk/ArjunaCore/txoj/classes/com/arjuna/ats/internal/txoj/LockFriend.java 2010-03-20 13:38:54 UTC (rev 32160)
+++ labs/jbosstm/trunk/ArjunaCore/txoj/classes/com/arjuna/ats/internal/txoj/LockFriend.java 2010-03-20 19:45:28 UTC (rev 32161)
@@ -94,8 +94,4 @@
}
}
}
-
- private LockFriend ()
- {
- }
}
Modified: labs/jbosstm/trunk/ArjunaCore/txoj/classes/com/arjuna/ats/txoj/LockConflictManager.java
===================================================================
--- labs/jbosstm/trunk/ArjunaCore/txoj/classes/com/arjuna/ats/txoj/LockConflictManager.java 2010-03-20 13:38:54 UTC (rev 32160)
+++ labs/jbosstm/trunk/ArjunaCore/txoj/classes/com/arjuna/ats/txoj/LockConflictManager.java 2010-03-20 19:45:28 UTC (rev 32161)
@@ -41,17 +41,15 @@
* lock conflict for a given object. If the timeout and retry values are >=0
* then we use them to sleep the thread which tried to get the lock. If the
* retry value is -100 (LockManager.waitTotalTimeout) then the thread will block
- * for up to the total timeout and be signalled either when the timeout occurs,
+ * for up to the total timeout and be signaled either when the timeout occurs,
* or when the lock is actually released.
*/
class LockConflictManager
{
-
LockConflictManager()
{
_lock = new Object();
- _signals = 0;
}
/**
@@ -61,63 +59,35 @@
int wait (int retry, int waitTime)
{
- /*
- * If the retry is -1 then we wait on the object as if it were a lock.
- * Otherwise we do the usual sleep call.
- */
-
- if (retry < 0)
+ Date d1 = Calendar.getInstance().getTime();
+
+ if (retry == LockManager.waitTotalTimeout)
{
- /*
- * Wait for the lock object to be signalled.
- */
-
- Date d1 = Calendar.getInstance().getTime();
-
+ try
+ {
+ Thread.sleep(waitTime);
+ }
+ catch (final Throwable ex)
+ {
+ }
+ }
+ else
+ {
synchronized (_lock)
{
try
{
- /*
- * Consume an old signal. May cause us to go round the loop
- * quicker than we should, but its better than synchronizing
- * signal and wait.
- */
-
- if (_signals == 0)
- {
- _lock.wait(waitTime);
- }
- else
- {
- _signals--;
-
- return waitTime;
- }
+ _lock.wait(waitTime);
}
catch (InterruptedException e)
{
}
}
-
- Date d2 = Calendar.getInstance().getTime();
-
- return (int) (d2.getTime() - d1.getTime());
}
- else
- {
- try
- {
- /* hope things happen in time */
- Thread.sleep(waitTime);
- }
- catch (InterruptedException e)
- {
- }
+ Date d2 = Calendar.getInstance().getTime();
- return 0;
- }
+ return (int) (d2.getTime() - d1.getTime());
}
/**
@@ -129,16 +99,8 @@
synchronized (_lock)
{
_lock.notifyAll();
-
- _signals++;
-
- if (_signals < 0) // check for overflow
- _signals = 1;
}
}
private Object _lock;
-
- private int _signals;
-
}
Modified: labs/jbosstm/trunk/ArjunaCore/txoj/classes/com/arjuna/ats/txoj/LockManager.java
===================================================================
--- labs/jbosstm/trunk/ArjunaCore/txoj/classes/com/arjuna/ats/txoj/LockManager.java 2010-03-20 13:38:54 UTC (rev 32160)
+++ labs/jbosstm/trunk/ArjunaCore/txoj/classes/com/arjuna/ats/txoj/LockManager.java 2010-03-20 19:45:28 UTC (rev 32161)
@@ -413,7 +413,7 @@
super.setupStore();
while ((conflict == ConflictType.CONFLICT)
- && ((retry >= 0) || (retry == LockManager.waitTotalTimeout)))
+ && ((retry >= 0) || ((retry == LockManager.waitTotalTimeout) && (sleepTime > 0))))
{
Object syncObject = ((currAct == null) ? getMutex() : currAct);
@@ -549,22 +549,22 @@
if (conflict == ConflictType.CONFLICT)
freeState();
}
-
- if (conflict == ConflictType.CONFLICT)
+ }
+
+ if (conflict == ConflictType.CONFLICT)
+ {
+ if (retry != 0)
{
- if (retry != 0)
+ if (sleepTime > 0)
{
- if (sleepTime > 0)
- {
- sleepTime -= conflictManager.wait(retry, sleepTime);
- }
- else
- retry = 0;
+ sleepTime -= conflictManager.wait(retry, sleepTime);
}
-
- if (retry != LockManager.waitTotalTimeout)
- retry--;
+ else
+ retry = 0;
}
+
+ if (retry != LockManager.waitTotalTimeout)
+ retry--;
}
}
Added: labs/jbosstm/trunk/ArjunaCore/txoj/tests/classes/com/arjuna/ats/txoj/LockConflictUnitTest.java
===================================================================
--- labs/jbosstm/trunk/ArjunaCore/txoj/tests/classes/com/arjuna/ats/txoj/LockConflictUnitTest.java (rev 0)
+++ labs/jbosstm/trunk/ArjunaCore/txoj/tests/classes/com/arjuna/ats/txoj/LockConflictUnitTest.java 2010-03-20 19:45:28 UTC (rev 32161)
@@ -0,0 +1,52 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2006, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags.
+ * See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ * This copyrighted material is made available to anyone wishing to use,
+ * modify, copy, or redistribute it subject to the terms and conditions
+ * of the GNU Lesser General Public License, v. 2.1.
+ * This program is distributed in the hope that it will be useful, but WITHOUT A
+ * 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,
+ * v.2.1 along with this distribution; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
+ * MA 02110-1301, USA.
+ *
+ * (C) 2005-2006,
+ * @author JBoss Inc.
+ */
+/*
+ * Copyright (C) 1998, 1999, 2000,
+ *
+ * Arjuna Solutions Limited,
+ * Newcastle upon Tyne,
+ * Tyne and Wear,
+ * UK.
+ *
+ * $Id: RecoveryTest.java 2342 2006-03-30 13:06:17Z $
+ */
+
+package com.arjuna.ats.txoj;
+
+import org.junit.Test;
+
+import com.arjuna.ats.txoj.LockConflictManager;
+
+import static org.junit.Assert.*;
+
+public class LockConflictUnitTest
+{
+ @Test
+ public void test () throws Exception
+ {
+ LockConflictManager manager = new LockConflictManager();
+
+ assertTrue(manager.wait(1, 100) != -1);
+ assertTrue(manager.wait(LockManager.waitTotalTimeout, 100) != -1);
+
+ manager.signal();
+ }
+}
Modified: labs/jbosstm/trunk/ArjunaCore/txoj/tests/classes/com/hp/mwtests/ts/txoj/common/resources/AtomicObject.java
===================================================================
--- labs/jbosstm/trunk/ArjunaCore/txoj/tests/classes/com/hp/mwtests/ts/txoj/common/resources/AtomicObject.java 2010-03-20 13:38:54 UTC (rev 32160)
+++ labs/jbosstm/trunk/ArjunaCore/txoj/tests/classes/com/hp/mwtests/ts/txoj/common/resources/AtomicObject.java 2010-03-20 19:45:28 UTC (rev 32161)
@@ -109,6 +109,16 @@
printDebug = true;
}
+ public int getRetry ()
+ {
+ return retry;
+ }
+
+ public void setRetry (int t)
+ {
+ retry = t;
+ }
+
public void terminate ()
{
super.terminate();
@@ -120,7 +130,7 @@
A.begin();
- if (setlock(new Lock(LockMode.WRITE), 0) == LockResult.GRANTED)
+ if (setlock(new Lock(LockMode.WRITE), retry) == LockResult.GRANTED)
{
state += value;
@@ -146,7 +156,7 @@
A.begin();
- if (setlock(new Lock(LockMode.WRITE), 0) == LockResult.GRANTED)
+ if (setlock(new Lock(LockMode.WRITE), retry) == LockResult.GRANTED)
{
state = value;
@@ -173,7 +183,7 @@
A.begin();
- if (setlock(new Lock(LockMode.READ), 0) == LockResult.GRANTED)
+ if (setlock(new Lock(LockMode.READ), retry) == LockResult.GRANTED)
{
value = state;
@@ -239,5 +249,5 @@
private int state;
private boolean printDebug;
-
+ private int retry = 0;
};
Added: labs/jbosstm/trunk/ArjunaCore/txoj/tests/classes/com/hp/mwtests/ts/txoj/concurrencycontrol/LockConflictUnitTest.java
===================================================================
--- labs/jbosstm/trunk/ArjunaCore/txoj/tests/classes/com/hp/mwtests/ts/txoj/concurrencycontrol/LockConflictUnitTest.java (rev 0)
+++ labs/jbosstm/trunk/ArjunaCore/txoj/tests/classes/com/hp/mwtests/ts/txoj/concurrencycontrol/LockConflictUnitTest.java 2010-03-20 19:45:28 UTC (rev 32161)
@@ -0,0 +1,64 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2006, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags.
+ * See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ * This copyrighted material is made available to anyone wishing to use,
+ * modify, copy, or redistribute it subject to the terms and conditions
+ * of the GNU Lesser General Public License, v. 2.1.
+ * This program is distributed in the hope that it will be useful, but WITHOUT A
+ * 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,
+ * v.2.1 along with this distribution; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
+ * MA 02110-1301, USA.
+ *
+ * (C) 2005-2006,
+ * @author JBoss Inc.
+ */
+/*
+ * Copyright (C) 1998, 1999, 2000,
+ *
+ * Arjuna Solutions Limited,
+ * Newcastle upon Tyne,
+ * Tyne and Wear,
+ * UK.
+ *
+ * $Id: RecoveryTest.java 2342 2006-03-30 13:06:17Z $
+ */
+
+package com.hp.mwtests.ts.txoj.concurrencycontrol;
+
+import org.junit.Test;
+
+import com.hp.mwtests.ts.txoj.common.resources.AtomicObject;
+import com.hp.mwtests.ts.txoj.common.resources.HammerThreadedObject;
+
+import static org.junit.Assert.*;
+
+public class LockConflictUnitTest
+{
+ @Test
+ public void testAtomicObject () throws Exception
+ {
+ HammerThreadedObject.object = new AtomicObject();
+ HammerThreadedObject object1 = new HammerThreadedObject(2);
+ HammerThreadedObject object2 = new HammerThreadedObject(-2);
+
+ HammerThreadedObject.object.setRetry(2);
+
+ object1.start();
+ object2.start();
+
+ try
+ {
+ object1.join();
+ object2.join();
+ }
+ catch (InterruptedException e)
+ {
+ }
+ }
+}
Added: labs/jbosstm/trunk/ArjunaCore/txoj/tests/classes/com/hp/mwtests/ts/txoj/concurrencycontrol/LockListIteratorUnitTest.java
===================================================================
--- labs/jbosstm/trunk/ArjunaCore/txoj/tests/classes/com/hp/mwtests/ts/txoj/concurrencycontrol/LockListIteratorUnitTest.java (rev 0)
+++ labs/jbosstm/trunk/ArjunaCore/txoj/tests/classes/com/hp/mwtests/ts/txoj/concurrencycontrol/LockListIteratorUnitTest.java 2010-03-20 19:45:28 UTC (rev 32161)
@@ -0,0 +1,53 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2006, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags.
+ * See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ * This copyrighted material is made available to anyone wishing to use,
+ * modify, copy, or redistribute it subject to the terms and conditions
+ * of the GNU Lesser General Public License, v. 2.1.
+ * This program is distributed in the hope that it will be useful, but WITHOUT A
+ * 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,
+ * v.2.1 along with this distribution; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
+ * MA 02110-1301, USA.
+ *
+ * (C) 2005-2006,
+ * @author JBoss Inc.
+ */
+/*
+ * Copyright (C) 1998, 1999, 2000,
+ *
+ * Arjuna Solutions Limited,
+ * Newcastle upon Tyne,
+ * Tyne and Wear,
+ * UK.
+ *
+ * $Id: RecoveryTest.java 2342 2006-03-30 13:06:17Z $
+ */
+
+package com.hp.mwtests.ts.txoj.concurrencycontrol;
+
+import org.junit.Test;
+
+import com.arjuna.ats.internal.txoj.LockList;
+import com.arjuna.ats.internal.txoj.LockListIterator;
+
+import static org.junit.Assert.*;
+
+public class LockListIteratorUnitTest
+{
+ @Test
+ public void test () throws Exception
+ {
+ LockList list = new LockList();
+ LockListIterator iter = new LockListIterator(list);
+
+ assertEquals(iter.iterate(), null);
+
+ iter.reset();
+ }
+}
Added: labs/jbosstm/trunk/ArjunaCore/txoj/tests/classes/com/hp/mwtests/ts/txoj/concurrencycontrol/LockManagerUnitTest.java
===================================================================
--- labs/jbosstm/trunk/ArjunaCore/txoj/tests/classes/com/hp/mwtests/ts/txoj/concurrencycontrol/LockManagerUnitTest.java (rev 0)
+++ labs/jbosstm/trunk/ArjunaCore/txoj/tests/classes/com/hp/mwtests/ts/txoj/concurrencycontrol/LockManagerUnitTest.java 2010-03-20 19:45:28 UTC (rev 32161)
@@ -0,0 +1,75 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2006, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags.
+ * See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ * This copyrighted material is made available to anyone wishing to use,
+ * modify, copy, or redistribute it subject to the terms and conditions
+ * of the GNU Lesser General Public License, v. 2.1.
+ * This program is distributed in the hope that it will be useful, but WITHOUT A
+ * 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,
+ * v.2.1 along with this distribution; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
+ * MA 02110-1301, USA.
+ *
+ * (C) 2005-2006,
+ * @author JBoss Inc.
+ */
+/*
+ * Copyright (C) 1998, 1999, 2000,
+ *
+ * Arjuna Solutions Limited,
+ * Newcastle upon Tyne,
+ * Tyne and Wear,
+ * UK.
+ *
+ * $Id: RecoveryTest.java 2342 2006-03-30 13:06:17Z $
+ */
+
+package com.hp.mwtests.ts.txoj.concurrencycontrol;
+
+import java.io.ByteArrayOutputStream;
+import java.io.PrintWriter;
+
+import org.junit.Test;
+
+import com.arjuna.ats.arjuna.ObjectType;
+import com.arjuna.ats.arjuna.common.Uid;
+import com.arjuna.ats.txoj.LockManager;
+import com.arjuna.ats.txoj.LockResult;
+import com.hp.mwtests.ts.txoj.common.resources.AtomicObject;
+
+import static org.junit.Assert.*;
+
+class DummyLockManager extends LockManager
+{
+ public DummyLockManager ()
+ {
+ super(new Uid(), ObjectType.ANDPERSISTENT);
+ }
+}
+
+
+public class LockManagerUnitTest
+{
+ @Test
+ public void test () throws Throwable
+ {
+ AtomicObject obj = new AtomicObject();
+
+ obj.finalize();
+
+ obj = new AtomicObject();
+
+ assertTrue(obj.releaselock(new Uid()));
+ assertEquals(obj.setlock(null), LockResult.REFUSED);
+
+ obj.print(new PrintWriter(new ByteArrayOutputStream()));
+ obj.printState(new PrintWriter(new ByteArrayOutputStream()));
+
+ assertEquals(new DummyLockManager().type(), "StateManager/LockManager");
+ }
+}
Added: labs/jbosstm/trunk/ArjunaCore/txoj/tests/classes/com/hp/mwtests/ts/txoj/concurrencycontrol/LockUnitTest.java
===================================================================
--- labs/jbosstm/trunk/ArjunaCore/txoj/tests/classes/com/hp/mwtests/ts/txoj/concurrencycontrol/LockUnitTest.java (rev 0)
+++ labs/jbosstm/trunk/ArjunaCore/txoj/tests/classes/com/hp/mwtests/ts/txoj/concurrencycontrol/LockUnitTest.java 2010-03-20 19:45:28 UTC (rev 32161)
@@ -0,0 +1,67 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2006, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags.
+ * See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ * This copyrighted material is made available to anyone wishing to use,
+ * modify, copy, or redistribute it subject to the terms and conditions
+ * of the GNU Lesser General Public License, v. 2.1.
+ * This program is distributed in the hope that it will be useful, but WITHOUT A
+ * 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,
+ * v.2.1 along with this distribution; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
+ * MA 02110-1301, USA.
+ *
+ * (C) 2005-2006,
+ * @author JBoss Inc.
+ */
+/*
+ * Copyright (C) 1998, 1999, 2000,
+ *
+ * Arjuna Solutions Limited,
+ * Newcastle upon Tyne,
+ * Tyne and Wear,
+ * UK.
+ *
+ * $Id: RecoveryTest.java 2342 2006-03-30 13:06:17Z $
+ */
+
+package com.hp.mwtests.ts.txoj.concurrencycontrol;
+
+import java.io.ByteArrayOutputStream;
+import java.io.PrintWriter;
+
+import org.junit.Test;
+
+import com.arjuna.ats.txoj.Lock;
+import com.arjuna.ats.txoj.LockMode;
+import com.arjuna.ats.txoj.LockStatus;
+
+import static org.junit.Assert.*;
+
+public class LockUnitTest
+{
+ @Test
+ public void test () throws Exception
+ {
+ Lock lock = new Lock();
+
+ lock = new Lock(LockMode.WRITE);
+
+ assertTrue(lock.getAllOwners() != null);
+ assertEquals(lock.getCurrentStatus(), LockStatus.LOCKFREE);
+
+ assertFalse(lock.equals(new Object()));
+ assertFalse(lock.equals((Object) new Lock()));
+ assertTrue(lock.equals(lock));
+
+ assertTrue(lock.toString() != null);
+
+ assertEquals(lock.type(), "/StateManager/Lock");
+
+ lock.print(new PrintWriter(new ByteArrayOutputStream()));
+ }
+}
Modified: labs/jbosstm/trunk/ArjunaCore/txoj/tests/classes/com/hp/mwtests/ts/txoj/recovery/RecoveryModuleUnitTest.java
===================================================================
--- labs/jbosstm/trunk/ArjunaCore/txoj/tests/classes/com/hp/mwtests/ts/txoj/recovery/RecoveryModuleUnitTest.java 2010-03-20 13:38:54 UTC (rev 32160)
+++ labs/jbosstm/trunk/ArjunaCore/txoj/tests/classes/com/hp/mwtests/ts/txoj/recovery/RecoveryModuleUnitTest.java 2010-03-20 19:45:28 UTC (rev 32161)
@@ -44,14 +44,24 @@
import static org.junit.Assert.*;
+class DummyTOModule extends TORecoveryModule
+{
+ public void intialise ()
+ {
+ super.initialise();
+ }
+}
+
public class RecoveryModuleUnitTest
{
@Test
public void test () throws Exception
{
- TORecoveryModule trm = new TORecoveryModule();
+ DummyTOModule trm = new DummyTOModule();
AtomicAction A = new AtomicAction();
+ trm.intialise();
+
A.begin();
AtomicObject obj = new AtomicObject();
More information about the jboss-svn-commits
mailing list