KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > tc > objectserver > lockmanager > api > NotifiedWaitersTest


1 /*
2  * All content copyright (c) 2003-2006 Terracotta, Inc., except as may otherwise be noted in a separate copyright
3  * notice. All rights reserved.
4  */

5 package com.tc.objectserver.lockmanager.api;
6
7 import com.tc.net.protocol.tcm.ChannelID;
8 import com.tc.object.lockmanager.api.LockContext;
9 import com.tc.object.lockmanager.api.LockID;
10 import com.tc.object.lockmanager.api.ThreadID;
11
12 import java.util.HashSet JavaDoc;
13 import java.util.Set JavaDoc;
14
15 import junit.framework.TestCase;
16
17 public class NotifiedWaitersTest extends TestCase {
18
19   public void testBasics() throws Exception JavaDoc {
20     ChannelID channel1 = new ChannelID(1);
21     ChannelID channel2 = new ChannelID(2);
22
23     Set JavaDoc forChannel1 = new HashSet JavaDoc();
24     Set JavaDoc forChannel2 = new HashSet JavaDoc();
25
26     LockID lockID = new LockID("me");
27     ThreadID txID1 = new ThreadID(1);
28     ThreadID txID2 = new ThreadID(2);
29     ThreadID txID3 = new ThreadID(3);
30
31     NotifiedWaiters ns = new NotifiedWaiters();
32
33     LockContext lr1 = new LockContext(lockID, channel1, txID1, 0);
34     forChannel1.add(lr1);
35     ns.addNotification(lr1);
36
37     LockContext lr2 = new LockContext(lockID, channel1, txID2, 0);
38     forChannel1.add(lr2);
39     ns.addNotification(lr2);
40
41     LockContext lr3 = new LockContext(lockID, channel2, txID3, 0);
42     forChannel2.add(lr3);
43     ns.addNotification(lr3);
44
45     assertEquals(forChannel1, ns.getNotifiedFor(channel1));
46     assertEquals(forChannel2, ns.getNotifiedFor(channel2));
47
48     ns = new NotifiedWaiters();
49     assertTrue(ns.isEmpty());
50     ns.getNotifiedFor(new ChannelID(1));
51     assertTrue(ns.isEmpty());
52   }
53
54 }
55
Popular Tags