01: /*
02: * All content copyright (c) 2003-2006 Terracotta, Inc., except as may otherwise be noted in a separate copyright
03: * notice. All rights reserved.
04: */
05: package com.tc.objectserver.lockmanager.api;
06:
07: import com.tc.net.groups.ClientID;
08: import com.tc.net.protocol.tcm.ChannelID;
09: import com.tc.object.lockmanager.api.LockContext;
10: import com.tc.object.lockmanager.api.LockID;
11: import com.tc.object.lockmanager.api.ThreadID;
12:
13: import java.util.HashSet;
14: import java.util.Set;
15:
16: import junit.framework.TestCase;
17:
18: public class NotifiedWaitersTest extends TestCase {
19:
20: public void testBasics() throws Exception {
21: ClientID clientID1 = new ClientID(new ChannelID(1));
22: ClientID clientID2 = new ClientID(new ChannelID(2));
23:
24: Set forChannel1 = new HashSet();
25: Set forChannel2 = new HashSet();
26:
27: LockID lockID = new LockID("me");
28: ThreadID txID1 = new ThreadID(1);
29: ThreadID txID2 = new ThreadID(2);
30: ThreadID txID3 = new ThreadID(3);
31:
32: NotifiedWaiters ns = new NotifiedWaiters();
33:
34: LockContext lr1 = new LockContext(lockID, clientID1, txID1, 0);
35: forChannel1.add(lr1);
36: ns.addNotification(lr1);
37:
38: LockContext lr2 = new LockContext(lockID, clientID1, txID2, 0);
39: forChannel1.add(lr2);
40: ns.addNotification(lr2);
41:
42: LockContext lr3 = new LockContext(lockID, clientID2, txID3, 0);
43: forChannel2.add(lr3);
44: ns.addNotification(lr3);
45:
46: assertEquals(forChannel1, ns.getNotifiedFor(clientID1));
47: assertEquals(forChannel2, ns.getNotifiedFor(clientID2));
48:
49: ns = new NotifiedWaiters();
50: assertTrue(ns.isEmpty());
51: ns.getNotifiedFor(new ClientID(new ChannelID(1)));
52: assertTrue(ns.isEmpty());
53: }
54:
55: }
|