You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@commons.apache.org by oz...@apache.org on 2004/06/04 13:20:14 UTC
cvs commit: jakarta-commons-sandbox/transaction/src/test/org/apache/commons/transaction/memory MapWrapperTest.java OptimisticMapWrapperTest.java
ozeigermann 2004/06/04 04:20:13
Modified: transaction/src/test/org/apache/commons/transaction/memory
MapWrapperTest.java OptimisticMapWrapperTest.java
Log:
Added more tests and resue others
Revision Changes Path
1.5 +101 -7 jakarta-commons-sandbox/transaction/src/test/org/apache/commons/transaction/memory/MapWrapperTest.java
Index: MapWrapperTest.java
===================================================================
RCS file: /home/cvs/jakarta-commons-sandbox/transaction/src/test/org/apache/commons/transaction/memory/MapWrapperTest.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- MapWrapperTest.java 3 Jun 2004 14:04:31 -0000 1.4
+++ MapWrapperTest.java 4 Jun 2004 11:20:13 -0000 1.5
@@ -27,6 +27,7 @@
import java.util.HashMap;
import java.util.Map;
+import java.util.Set;
import java.util.logging.*;
import org.apache.commons.transaction.util.Jdk14Logger;
@@ -71,21 +72,28 @@
super(testName);
}
+ protected TransactionalMapWrapper getNewWrapper(Map map) {
+ return new TransactionalMapWrapper(map);
+ }
+
public void testBasic() throws Throwable {
logger.info("Checking basic transaction features");
final Map map1 = new HashMap();
- final TransactionalMapWrapper txMap1 =
- new TransactionalMapWrapper(map1);
+ final TransactionalMapWrapper txMap1 = getNewWrapper(map1);
+
+ assertTrue(txMap1.isEmpty());
// make sure changes are propagated to wrapped map outside tx
txMap1.put("key1", "value1");
report("value1", (String) map1.get("key1"));
+ assertFalse(txMap1.isEmpty());
// make sure changes are progated to wrapped map only after commit
txMap1.startTransaction();
+ assertFalse(txMap1.isEmpty());
txMap1.put("key1", "value2");
report("value1", (String) map1.get("key1"));
report("value2", (String) txMap1.get("key1"));
@@ -101,13 +109,95 @@
report("value2", (String) txMap1.get("key1"));
}
+ public void testComplex() throws Throwable {
+
+ logger.info("Checking advanced and complex transaction features");
+
+ final Map map1 = new HashMap();
+
+ final TransactionalMapWrapper txMap1 = getNewWrapper(map1);
+
+ // first fill in some global values:
+ txMap1.put("key1", "value1");
+ txMap1.put("key2", "value2");
+
+ // let's see if we have all values:
+ logger.info("Checking if global values are present");
+
+ assertTrue(txMap1.containsValue("value1"));
+ assertTrue(txMap1.containsValue("value2"));
+ assertFalse(txMap1.containsValue("novalue"));
+
+ // ... and all keys
+ logger.info("Checking if global keys are present");
+ assertTrue(txMap1.containsKey("key1"));
+ assertTrue(txMap1.containsKey("key2"));
+ assertFalse(txMap1.containsKey("nokey"));
+
+ // and now some inside a transaction
+ txMap1.startTransaction();
+ txMap1.put("key3", "value3");
+ txMap1.put("key4", "value4");
+
+ // let's see if we have all values:
+ logger.info("Checking if values inside transactions are present");
+ assertTrue(txMap1.containsValue("value1"));
+ assertTrue(txMap1.containsValue("value2"));
+ assertTrue(txMap1.containsValue("value3"));
+ assertTrue(txMap1.containsValue("value4"));
+ assertFalse(txMap1.containsValue("novalue"));
+
+ // ... and all keys
+ logger.info("Checking if keys inside transactions are present");
+ assertTrue(txMap1.containsKey("key1"));
+ assertTrue(txMap1.containsKey("key2"));
+ assertTrue(txMap1.containsKey("key3"));
+ assertTrue(txMap1.containsKey("key4"));
+ assertFalse(txMap1.containsKey("nokey"));
+
+ // now let's delete some old stuff
+ logger.info("Checking remove inside transactions");
+ txMap1.remove("key1");
+ assertFalse(txMap1.containsKey("key1"));
+ assertFalse(txMap1.containsValue("value1"));
+ assertNull(txMap1.get("key1"));
+ assertEquals(3, txMap1.size());
+
+ // and some newly created
+ txMap1.remove("key3");
+ assertFalse(txMap1.containsKey("key3"));
+ assertFalse(txMap1.containsValue("value3"));
+ assertNull(txMap1.get("key3"));
+ assertEquals(2, txMap1.size());
+
+ logger.info("Checking remove and propagation after commit");
+ txMap1.commitTransaction();
+
+ txMap1.remove("key1");
+ assertFalse(txMap1.containsKey("key1"));
+ assertFalse(txMap1.containsValue("value1"));
+ assertNull(txMap1.get("key1"));
+ assertFalse(txMap1.containsKey("key3"));
+ assertFalse(txMap1.containsValue("value3"));
+ assertNull(txMap1.get("key3"));
+ assertEquals(2, txMap1.size());
+ }
+
+ public void testSets() throws Throwable {
+
+ logger.info("Checking set opertaions");
+
+ final Map map1 = new HashMap();
+
+ final TransactionalMapWrapper txMap1 = getNewWrapper(map1);
+ }
+
public void testMulti() throws Throwable {
logger.info("Checking concurrent transaction features");
final Map map1 = new HashMap();
- final TransactionalMapWrapper txMap1 =
- new TransactionalMapWrapper(map1);
+ final TransactionalMapWrapper txMap1 = getNewWrapper(map1);
final RendezvousBarrier beforeCommitBarrier =
new RendezvousBarrier("Before Commit", 2, BARRIER_TIMEOUT, sLogger);
@@ -155,6 +245,10 @@
public void testTxControl() throws Throwable {
logger.info("Checking advanced transaction control (heavily used in JCA implementation)");
+ final Map map1 = new HashMap();
+
+ final TransactionalMapWrapper txMap1 = getNewWrapper(map1);
+
}
}
1.4 +17 -34 jakarta-commons-sandbox/transaction/src/test/org/apache/commons/transaction/memory/OptimisticMapWrapperTest.java
Index: OptimisticMapWrapperTest.java
===================================================================
RCS file: /home/cvs/jakarta-commons-sandbox/transaction/src/test/org/apache/commons/transaction/memory/OptimisticMapWrapperTest.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- OptimisticMapWrapperTest.java 3 Jun 2004 21:07:54 -0000 1.3
+++ OptimisticMapWrapperTest.java 4 Jun 2004 11:20:13 -0000 1.4
@@ -38,7 +38,7 @@
*
* @author <a href="mailto:ozeigermann@apache.org">Oliver Zeigermann</a>
*/
-public class OptimisticMapWrapperTest extends TestCase {
+public class OptimisticMapWrapperTest extends MapWrapperTest {
private static final Logger logger = Logger.getLogger(OptimisticMapWrapperTest.class.getName());
private static final LoggerFacade sLogger = new Jdk14Logger(logger);
@@ -65,41 +65,25 @@
super(testName);
}
- public void testBasic() throws Throwable {
-
- logger.info("Checking basic transaction features");
-
- final Map map1 = new HashMap();
-
- final OptimisticMapWrapper txMap1 = new OptimisticMapWrapper(map1);
-
- // make sure changes are propagated to wrapped map outside tx
- txMap1.put("key1", "value1");
- report("value1", (String) map1.get("key1"));
-
- // make sure changes are progated to wrapped map only after commit
- txMap1.startTransaction();
- txMap1.put("key1", "value2");
- report("value1", (String) map1.get("key1"));
- report("value2", (String) txMap1.get("key1"));
- txMap1.commitTransaction();
- report("value2", (String) map1.get("key1"));
- report("value2", (String) txMap1.get("key1"));
+ protected TransactionalMapWrapper getNewWrapper(Map map) {
+ return new OptimisticMapWrapper(map);
+ }
- // make sure changes are reverted after rollback
- txMap1.startTransaction();
- txMap1.put("key1", "value3");
- txMap1.rollbackTransaction();
- report("value2", (String) map1.get("key1"));
- report("value2", (String) txMap1.get("key1"));
+ // XXX no need for this code, just to make clear those tests are run as well
+ public void testBasic() throws Throwable {
+ super.testBasic();
}
+ public void testComplex() throws Throwable {
+ super.testComplex();
+ }
+
public void testMulti() throws Throwable {
logger.info("Checking concurrent transaction features");
final Map map1 = new HashMap();
- final OptimisticMapWrapper txMap1 = new OptimisticMapWrapper(map1);
+ final OptimisticMapWrapper txMap1 = (OptimisticMapWrapper) getNewWrapper(map1);
final RendezvousBarrier beforeCommitBarrier =
new RendezvousBarrier("Before Commit", 2, BARRIER_TIMEOUT, sLogger);
@@ -147,7 +131,7 @@
final Map map1 = new HashMap();
- final OptimisticMapWrapper txMap1 = new OptimisticMapWrapper(map1);
+ final OptimisticMapWrapper txMap1 = (OptimisticMapWrapper) getNewWrapper(map1);
final RendezvousBarrier beforeCommitBarrier =
new RendezvousBarrier("Before Commit", 2, BARRIER_TIMEOUT, sLogger);
@@ -204,8 +188,7 @@
}
public void testTxControl() throws Throwable {
- logger.info("Checking advanced transaction control (heavily used in JCA implementation)");
-
+ super.testTxControl();
}
}
---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org