KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > cache > lock > LockMapTest


1 /*
2  * JBoss, the OpenSource J2EE webOS
3  *
4  * Distributable under LGPL license.
5  * See terms of license at gnu.org.
6  */

7 package org.jboss.cache.lock;
8
9 import junit.framework.TestCase;
10
11 /**
12  * @author Ben Wang
13  */

14 public class LockMapTest extends TestCase
15 {
16    private LockMap map_;
17
18    /**
19     * Constructor for LockMapTest.
20     *
21     * @param arg0
22     */

23    public LockMapTest(String JavaDoc arg0)
24    {
25       super(arg0);
26    }
27
28    public static void main(String JavaDoc[] args)
29    {
30       junit.textui.TestRunner.run(LockMapTest.class);
31    }
32
33    /*
34     * @see TestCase#setUp()
35     */

36    protected void setUp() throws Exception JavaDoc
37    {
38       super.setUp();
39       map_ = new LockMap();
40    }
41
42    /*
43     * @see TestCase#tearDown()
44     */

45    protected void tearDown() throws Exception JavaDoc
46    {
47       super.tearDown();
48       map_.removeAll();
49    }
50
51    final public void testIsOwner()
52    {
53       map_.addReader(this);
54       assertTrue(map_.isOwner(this, LockMap.OWNER_READ));
55       map_.setWriterIfNotNull(this);
56       assertTrue(map_.isOwner(this, LockMap.OWNER_WRITE));
57       assertTrue(map_.isOwner(this, LockMap.OWNER_ANY));
58       map_.removeAll();
59    }
60
61    final public void testAddReader()
62    {
63       map_.addReader(this);
64       assertTrue(map_.isOwner(this, LockMap.OWNER_READ));
65       map_.removeReader(this);
66    }
67
68    final public void testAddWriter()
69    {
70       map_.setWriterIfNotNull(this);
71       assertTrue(map_.writerOwner().equals(this));
72       map_.removeWriter();
73    }
74
75 }
76
Popular Tags