KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > cache > tests > eviction > RegionTest


1 package org.jboss.cache.tests.eviction;
2
3 import junit.framework.Test;
4 import junit.framework.TestCase;
5 import junit.framework.TestSuite;
6 import org.jboss.cache.Fqn;
7 import org.jboss.cache.eviction.EvictedEventNode;
8 import org.jboss.cache.eviction.Region;
9 import org.jboss.cache.eviction.RegionManager;
10
11 /**
12  * @author Ben Wang, Feb 11, 2004
13  */

14 public class RegionTest extends TestCase
15 {
16    RegionManager regionManager_;
17    public RegionTest(String JavaDoc s)
18    {
19       super(s);
20    }
21
22    public void setUp() throws Exception JavaDoc
23    {
24       super.setUp();
25       regionManager_ = new RegionManager(null);
26       regionManager_.createRegion("/a/b", null);
27    }
28
29    public void tearDown() throws Exception JavaDoc
30    {
31       super.tearDown();
32    }
33
34    public void testAddedQueue() {
35       Fqn fqn1 = Fqn.fromString("/a/b/c");
36       Fqn fqn2 = Fqn.fromString("/a/b/d");
37       Fqn fqn3 = Fqn.fromString("/a/b/e");
38
39       Region region = regionManager_.getRegion("/a/b");
40       region.setAddedNode(fqn1);
41       region.setAddedNode(fqn2);
42       region.setAddedNode(fqn3);
43
44       assertEquals("AddedNode queue size ", 3, region.nodeEventQueueSize());
45       EvictedEventNode node = (EvictedEventNode)region.takeLastEventNode();
46       Fqn fqn = node.getFqn();
47       assertEquals("Node retrieved should be FILO ", fqn, fqn1);
48       assertEquals("AddedNode queue size ", 2, region.nodeEventQueueSize());
49       fqn = ((EvictedEventNode)region.takeLastEventNode()).getFqn();
50       fqn = ((EvictedEventNode)region.takeLastEventNode()).getFqn();
51       node = ((EvictedEventNode)region.takeLastEventNode());
52       assertNull("Node should be null", node);
53    }
54
55    public void testEventQueue() {
56       Fqn fqn1 = Fqn.fromString("/a/b/c");
57       Fqn fqn2 = Fqn.fromString("/a/b/d");
58       Fqn fqn3 = Fqn.fromString("/a/b/e");
59
60       Region region = regionManager_.getRegion("/a/b");
61       region.setRemovedNode(fqn1);
62       region.setAddedNode(fqn2);
63       region.setVisitedNode(fqn3);
64
65       assertEquals("RemovedNode queue size ", 3, region.nodeEventQueueSize());
66       Integer JavaDoc event = ((EvictedEventNode)region.takeLastEventNode()).getEvent();
67       assertEquals("Node retrieved should be: ", EvictedEventNode.REMOVE_EVENT, event);
68       Fqn fqn = ((EvictedEventNode)region.takeLastEventNode()).getFqn();
69       fqn = ((EvictedEventNode)region.takeLastEventNode()).getFqn();
70       EvictedEventNode node = ((EvictedEventNode)region.takeLastEventNode());
71       assertNull("Node should be null", node);
72    }
73
74    void log(String JavaDoc msg)
75    {
76       System.out.println("-- " + msg);
77    }
78
79    public static Test suite()
80    {
81       return new TestSuite(RegionTest.class);
82    }
83
84    public static void main(String JavaDoc[] args)
85    {
86       junit.textui.TestRunner.run(suite());
87    }
88
89 }
90
Popular Tags