KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > cache > optimistic > ValidationFailureTest


1 /*
2  * JBoss, Home of Professional Open Source
3  *
4  * Distributable under LGPL license.
5  * See terms of license at gnu.org.
6  */

7 package org.jboss.cache.optimistic;
8
9 import org.jboss.cache.CacheImpl;
10
11 import javax.transaction.Transaction JavaDoc;
12 import javax.transaction.TransactionManager JavaDoc;
13
14 /**
15  * Tests a failure in validating a concurrently updated node
16  *
17  * @author <a HREF="mailto:manik@jboss.org">Manik Surtani (manik@jboss.org)</a>
18  */

19 public class ValidationFailureTest extends AbstractOptimisticTestCase
20 {
21    public ValidationFailureTest(String JavaDoc name)
22    {
23       super(name);
24    }
25
26    public void testValidationFailureLockRelease() throws Exception JavaDoc
27    {
28       CacheImpl cache = createCache();
29
30       TransactionManager JavaDoc mgr = cache.getTransactionManager();
31
32       mgr.begin();
33       cache.put("/a", "key", "value");
34       mgr.commit();
35
36       // should succeed, 0 locks left over
37
assertEquals("value", cache.get("/a", "key"));
38       assertEquals(0, cache.getNumberOfLocksHeld());
39
40       mgr.begin();
41       cache.put("/b", "key", "value");
42       Transaction JavaDoc tx1 = mgr.suspend();
43
44       mgr.begin();
45       cache.put("/b", "key", "value2");
46       mgr.commit();
47
48       mgr.resume(tx1);
49       try
50       {
51          mgr.commit();
52          assertTrue("Should have failed", false);
53       }
54       catch (Exception JavaDoc e)
55       {
56          assertTrue("Expecting this to fail", true);
57       }
58
59       // nothing should have been locked.
60
assertEquals(0, cache.getNumberOfLocksHeld());
61
62       destroyCache(cache);
63    }
64 }
65
Popular Tags