KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > tc > objectserver > l1 > api > ClientStateManagerTest


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.l1.api;
6
7 import com.tc.logging.TCLogging;
8 import com.tc.net.protocol.tcm.ChannelID;
9 import com.tc.object.ObjectID;
10 import com.tc.objectserver.core.api.TestDNA;
11 import com.tc.objectserver.l1.impl.ClientStateManagerImpl;
12 import com.tc.objectserver.managedobject.BackReferences;
13
14 import java.util.HashSet JavaDoc;
15 import java.util.Iterator JavaDoc;
16 import java.util.LinkedList JavaDoc;
17 import java.util.List JavaDoc;
18 import java.util.Set JavaDoc;
19
20 import junit.framework.TestCase;
21
22 /**
23  * @author steve
24  */

25 public class ClientStateManagerTest extends TestCase {
26
27   public void test() throws Exception JavaDoc {
28     Set JavaDoc clients = new HashSet JavaDoc();
29     ClientStateManager stateManager = new ClientStateManagerImpl(TCLogging.getLogger(ClientStateManager.class));
30
31     Set JavaDoc toGC = new HashSet JavaDoc();
32     toGC.add(new ObjectID(0));
33     toGC.add(new ObjectID(1));
34     toGC.add(new ObjectID(2));
35     toGC.add(new ObjectID(3));
36
37     List JavaDoc changes = new LinkedList JavaDoc();
38     for (Iterator JavaDoc i = toGC.iterator(); i.hasNext();) {
39       ObjectID id = (ObjectID) i.next();
40       changes.add(new TestDNA(id, id.toLong() % 2 == 0));
41     }
42     Set JavaDoc testSet = new HashSet JavaDoc();
43     Set JavaDoc lookupObjectIDs = new HashSet JavaDoc();
44
45     clients.add(new ChannelID(50));
46     assertTrue(stateManager.createPrunedChangesAndAddObjectIDTo(changes, new BackReferences(), new ChannelID(50),
47                                                                 lookupObjectIDs).size() == 0);
48     assertEquals(0, lookupObjectIDs.size());
49
50     clients.add(new ChannelID(0));
51     stateManager.addReference(new ChannelID(0), new ObjectID(4));
52     stateManager.addAllReferencedIdsTo(testSet);
53     assertEquals(0, stateManager.createPrunedChangesAndAddObjectIDTo(changes, new BackReferences(), new ChannelID(50),
54                                                                      lookupObjectIDs).size());
55     assertEquals(0, lookupObjectIDs.size());
56     assertEquals(1, testSet.size());
57
58     testSet = new HashSet JavaDoc();
59     stateManager.addReference(new ChannelID(0), new ObjectID(1));
60     stateManager.addAllReferencedIdsTo(testSet);
61     assertEquals(2, testSet.size());
62
63     assertEquals(0, stateManager.createPrunedChangesAndAddObjectIDTo(changes, new BackReferences(), new ChannelID(50),
64                                                                      lookupObjectIDs).size());
65     assertEquals(0, lookupObjectIDs.size());
66     assertEquals(0, stateManager.createPrunedChangesAndAddObjectIDTo(changes, new BackReferences(), new ChannelID(0),
67                                                                      lookupObjectIDs).size());
68     assertEquals(0, lookupObjectIDs.size());
69
70     stateManager.addReference(new ChannelID(0), new ObjectID(0));
71     stateManager.addAllReferencedIdsTo(testSet);
72     assertEquals(3, testSet.size());
73
74     assertEquals(1, stateManager.createPrunedChangesAndAddObjectIDTo(changes, new BackReferences(), new ChannelID(0),
75                                                                      lookupObjectIDs).size());
76     assertEquals(0, lookupObjectIDs.size());
77
78     BackReferences backReferences = new BackReferences();
79     backReferences.addBackReference(new ObjectID(2), new ObjectID(0));
80     backReferences.addBackReference(new ObjectID(3), new ObjectID(0));
81
82     assertEquals(1, stateManager.createPrunedChangesAndAddObjectIDTo(changes, backReferences, new ChannelID(0),
83                                                                      lookupObjectIDs).size());
84     assertEquals(2, lookupObjectIDs.size());
85
86     clients.remove(new ChannelID(50));
87     stateManager.shutdownClient(new ChannelID(50));
88
89   }
90 }
91
Popular Tags