[jboss-svn-commits] JBL Code SVN: r37443 - in labs/jbosstm/workspace/mlittle/STM-Arjuna/src: test/java/org/jboss/stm and 1 other directory.
jboss-svn-commits at lists.jboss.org
jboss-svn-commits at lists.jboss.org
Fri Aug 26 09:26:27 EDT 2011
Author: mark.little at jboss.com
Date: 2011-08-26 09:26:27 -0400 (Fri, 26 Aug 2011)
New Revision: 37443
Added:
labs/jbosstm/workspace/mlittle/STM-Arjuna/src/main/java/org/jboss/stm/annotations/NotState.java
labs/jbosstm/workspace/mlittle/STM-Arjuna/src/test/java/org/jboss/stm/BasicIntUnitTest.java
labs/jbosstm/workspace/mlittle/STM-Arjuna/src/test/java/org/jboss/stm/TransactionalTypesUnitTest.java
Log:
Changed default behaviour to save state unless marked as NotState.
Added: labs/jbosstm/workspace/mlittle/STM-Arjuna/src/main/java/org/jboss/stm/annotations/NotState.java
===================================================================
--- labs/jbosstm/workspace/mlittle/STM-Arjuna/src/main/java/org/jboss/stm/annotations/NotState.java (rev 0)
+++ labs/jbosstm/workspace/mlittle/STM-Arjuna/src/main/java/org/jboss/stm/annotations/NotState.java 2011-08-26 13:26:27 UTC (rev 37443)
@@ -0,0 +1,36 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2006, JBoss Inc., and others contributors as indicated
+ * by the @authors tag. All rights reserved.
+ * 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 mark.little at jboss.com
+ */
+
+package org.jboss.stm.annotations;
+
+import java.lang.annotation.*;
+
+/**
+ * Marks member variables that should not be saved/restored during a transaction.
+ *
+ * @author marklittle
+ */
+
+ at Retention(RetentionPolicy.RUNTIME)
+ at Target({ ElementType.FIELD })
+public @interface NotState
+{
+}
\ No newline at end of file
Added: labs/jbosstm/workspace/mlittle/STM-Arjuna/src/test/java/org/jboss/stm/BasicIntUnitTest.java
===================================================================
--- labs/jbosstm/workspace/mlittle/STM-Arjuna/src/test/java/org/jboss/stm/BasicIntUnitTest.java (rev 0)
+++ labs/jbosstm/workspace/mlittle/STM-Arjuna/src/test/java/org/jboss/stm/BasicIntUnitTest.java 2011-08-26 13:26:27 UTC (rev 37443)
@@ -0,0 +1,126 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2006, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt 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.stm;
+
+import java.io.IOException;
+
+import org.jboss.stm.annotations.State;
+import org.jboss.stm.annotations.Transactional;
+import org.jboss.stm.annotations.ReadLock;
+import org.jboss.stm.annotations.WriteLock;
+
+import com.arjuna.ats.arjuna.AtomicAction;
+import com.arjuna.ats.arjuna.ObjectType;
+import com.arjuna.ats.arjuna.common.Uid;
+import com.arjuna.ats.arjuna.coordinator.ActionStatus;
+import com.arjuna.ats.arjuna.coordinator.BasicAction;
+import com.arjuna.ats.arjuna.state.InputObjectState;
+import com.arjuna.ats.arjuna.state.OutputObjectState;
+import com.arjuna.ats.txoj.Lock;
+import com.arjuna.ats.txoj.LockManager;
+import com.arjuna.ats.txoj.LockMode;
+import com.arjuna.ats.txoj.LockResult;
+
+import junit.framework.TestCase;
+
+/**
+ * @author Mark Little
+ */
+
+public class BasicIntUnitTest extends TestCase
+{
+ @Transactional
+ public interface Atomic
+ {
+ public void change (int value) throws Exception;
+
+ public void set (int value) throws Exception;
+
+ public int get () throws Exception;
+ }
+
+ @Transactional
+ public class ExampleSTM implements Atomic
+ {
+ @ReadLock
+ public int get () throws Exception
+ {
+ return state;
+ }
+
+ @WriteLock
+ public void set (int value) throws Exception
+ {
+ state = value;
+ }
+
+ @WriteLock
+ public void change (int value) throws Exception
+ {
+ state += value;
+ }
+
+ private int state;
+ }
+
+ public void testExampleSTM () throws Exception
+ {
+ RecoverableContainer<Atomic> theContainer = new RecoverableContainer<Atomic>();
+ ExampleSTM basic = new ExampleSTM();
+ boolean success = true;
+ Atomic obj = null;
+
+ try
+ {
+ obj = theContainer.enlist(basic);
+ }
+ catch (final Throwable ex)
+ {
+ ex.printStackTrace();
+
+ success = false;
+ }
+
+ assertTrue(success);
+
+ AtomicAction a = new AtomicAction();
+
+ a.begin();
+
+ obj.set(1234);
+
+ a.commit();
+
+ assertEquals(obj.get(), 1234);
+
+ a = new AtomicAction();
+
+ a.begin();
+
+ obj.change(1);
+
+ a.abort();
+
+ assertEquals(obj.get(), 1234);
+ }
+}
Added: labs/jbosstm/workspace/mlittle/STM-Arjuna/src/test/java/org/jboss/stm/TransactionalTypesUnitTest.java
===================================================================
--- labs/jbosstm/workspace/mlittle/STM-Arjuna/src/test/java/org/jboss/stm/TransactionalTypesUnitTest.java (rev 0)
+++ labs/jbosstm/workspace/mlittle/STM-Arjuna/src/test/java/org/jboss/stm/TransactionalTypesUnitTest.java 2011-08-26 13:26:27 UTC (rev 37443)
@@ -0,0 +1,177 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2006, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt 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.stm;
+
+import java.io.IOException;
+import java.util.Hashtable;
+
+import org.jboss.stm.RecoverableContainer;
+import org.jboss.stm.annotations.RestoreState;
+import org.jboss.stm.annotations.SaveState;
+import org.jboss.stm.annotations.State;
+import org.jboss.stm.annotations.Transactional;
+import org.jboss.stm.annotations.ReadLock;
+import org.jboss.stm.annotations.WriteLock;
+
+import com.arjuna.ats.arjuna.AtomicAction;
+import com.arjuna.ats.arjuna.ObjectType;
+import com.arjuna.ats.arjuna.common.Uid;
+import com.arjuna.ats.arjuna.coordinator.ActionStatus;
+import com.arjuna.ats.arjuna.coordinator.BasicAction;
+import com.arjuna.ats.arjuna.state.InputObjectState;
+import com.arjuna.ats.arjuna.state.OutputObjectState;
+import com.arjuna.ats.txoj.Lock;
+import com.arjuna.ats.txoj.LockManager;
+import com.arjuna.ats.txoj.LockMode;
+import com.arjuna.ats.txoj.LockResult;
+
+import junit.framework.TestCase;
+
+/**
+ * Unit tests for the Class class.
+ *
+ * @author Mark Little
+ */
+
+public class TransactionalTypesUnitTest extends TestCase
+{
+ @Transactional
+ public interface Identifier
+ {
+ @ReadLock
+ public String name ();
+ }
+
+ @Transactional
+ public interface Counter
+ {
+ @WriteLock
+ public void increment ();
+
+ @ReadLock
+ public int count ();
+ }
+
+ @Transactional
+ public interface NamedCounter
+ {
+ @WriteLock
+ public void setCounter (Counter c);
+
+ @ReadLock
+ public Counter getCounter ();
+
+ @WriteLock
+ public void setName (Identifier n);
+
+ @ReadLock
+ public Identifier getName ();
+ }
+
+ public class IdentifierImple implements Identifier
+ {
+ public IdentifierImple (final String n)
+ {
+ _name = n;
+ }
+
+ @ReadLock
+ public String name ()
+ {
+ return _name;
+ }
+
+ private final String _name;
+ }
+
+ public class CounterImple implements Counter
+ {
+ @ReadLock
+ public int count ()
+ {
+ return _count;
+ }
+
+ @WriteLock
+ public void increment ()
+ {
+ _count++;
+ }
+
+ private int _count = 0;
+ }
+
+ public class NamedCounterImple implements NamedCounter
+ {
+ @ReadLock
+ public Counter getCounter ()
+ {
+ return _count;
+ }
+
+ @ReadLock
+ public Identifier getName ()
+ {
+ return _name;
+ }
+
+ @WriteLock
+ public void setCounter (Counter c)
+ {
+ _count = c;
+ }
+
+ @WriteLock
+ public void setName (Identifier n)
+ {
+ _name = n;
+ }
+
+ @State
+ private Identifier _name;
+
+ @State
+ private Counter _count;
+ }
+
+ public void testBasicAssignment () throws Exception
+ {
+ Identifier dt1 = new RecoverableContainer<Identifier>().enlist(new IdentifierImple("hello"));
+ Counter dt2 = new RecoverableContainer<Counter>().enlist(new CounterImple());
+ NamedCounter dt3 = new RecoverableContainer<NamedCounter>().enlist(new NamedCounterImple());
+ AtomicAction A = new AtomicAction();
+
+ A.begin();
+
+ dt3.setCounter(dt2);
+ dt3.setName(dt1);
+
+ assertTrue(dt3.getCounter() == dt2);
+ assertTrue(dt3.getName() == dt1);
+
+ A.abort();
+
+ assertTrue(dt3.getCounter() == null);
+ assertTrue(dt3.getName() == null);
+ }
+}
More information about the jboss-svn-commits
mailing list