1 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 ; 15 import java.util.Iterator ; 16 import java.util.LinkedList ; 17 import java.util.List ; 18 import java.util.Set ; 19 20 import junit.framework.TestCase; 21 22 25 public class ClientStateManagerTest extends TestCase { 26 27 public void test() throws Exception { 28 Set clients = new HashSet (); 29 ClientStateManager stateManager = new ClientStateManagerImpl(TCLogging.getLogger(ClientStateManager.class)); 30 31 Set toGC = new HashSet (); 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 changes = new LinkedList (); 38 for (Iterator i = toGC.iterator(); i.hasNext();) { 39 ObjectID id = (ObjectID) i.next(); 40 changes.add(new TestDNA(id, id.toLong() % 2 == 0)); 41 } 42 Set testSet = new HashSet (); 43 Set lookupObjectIDs = new HashSet (); 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 (); 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 |