001: /*
002: * All content copyright (c) 2003-2006 Terracotta, Inc., except as may otherwise be noted in a separate copyright
003: * notice. All rights reserved.
004: */
005: package com.tc.objectserver.l1.api;
006:
007: import com.tc.logging.TCLogging;
008: import com.tc.net.groups.ClientID;
009: import com.tc.net.protocol.tcm.ChannelID;
010: import com.tc.object.ObjectID;
011: import com.tc.objectserver.core.api.TestDNA;
012: import com.tc.objectserver.l1.impl.ClientStateManagerImpl;
013: import com.tc.objectserver.managedobject.BackReferences;
014:
015: import java.util.HashSet;
016: import java.util.Iterator;
017: import java.util.LinkedList;
018: import java.util.List;
019: import java.util.Set;
020:
021: import junit.framework.TestCase;
022:
023: /**
024: * @author steve
025: */
026: public class ClientStateManagerTest extends TestCase {
027:
028: public void test() throws Exception {
029: ClientStateManager stateManager = new ClientStateManagerImpl(
030: TCLogging.getLogger(ClientStateManager.class));
031:
032: Set toGC = new HashSet();
033: toGC.add(new ObjectID(0));
034: toGC.add(new ObjectID(1));
035: toGC.add(new ObjectID(2));
036: toGC.add(new ObjectID(3));
037:
038: List changes = new LinkedList();
039: for (Iterator i = toGC.iterator(); i.hasNext();) {
040: ObjectID id = (ObjectID) i.next();
041: changes.add(new TestDNA(id, id.toLong() % 2 == 0));
042: }
043: Set testSet = new HashSet();
044: Set lookupObjectIDs = new HashSet();
045:
046: ClientID cid0 = new ClientID(new ChannelID(0));
047: ClientID cid1 = new ClientID(new ChannelID(1));
048: stateManager.startupNode(cid1);
049: assertTrue(stateManager.createPrunedChangesAndAddObjectIDTo(
050: changes, new BackReferences(), cid1, lookupObjectIDs)
051: .size() == 0);
052: assertEquals(0, lookupObjectIDs.size());
053:
054: stateManager.startupNode(cid0);
055: stateManager.addReference(cid0, new ObjectID(4));
056: stateManager.addAllReferencedIdsTo(testSet);
057: assertEquals(0, stateManager
058: .createPrunedChangesAndAddObjectIDTo(changes,
059: new BackReferences(), cid1, lookupObjectIDs)
060: .size());
061: assertEquals(0, lookupObjectIDs.size());
062: assertEquals(1, testSet.size());
063:
064: testSet = new HashSet();
065: stateManager.addReference(cid0, new ObjectID(1));
066: stateManager.addAllReferencedIdsTo(testSet);
067: assertEquals(2, testSet.size());
068:
069: assertEquals(0, stateManager
070: .createPrunedChangesAndAddObjectIDTo(changes,
071: new BackReferences(), cid1, lookupObjectIDs)
072: .size());
073: assertEquals(0, lookupObjectIDs.size());
074: assertEquals(0, stateManager
075: .createPrunedChangesAndAddObjectIDTo(changes,
076: new BackReferences(), cid0, lookupObjectIDs)
077: .size());
078: assertEquals(0, lookupObjectIDs.size());
079:
080: stateManager.addReference(cid0, new ObjectID(0));
081: stateManager.addAllReferencedIdsTo(testSet);
082: assertEquals(3, testSet.size());
083:
084: assertEquals(1, stateManager
085: .createPrunedChangesAndAddObjectIDTo(changes,
086: new BackReferences(), cid0, lookupObjectIDs)
087: .size());
088: assertEquals(0, lookupObjectIDs.size());
089:
090: BackReferences backReferences = new BackReferences();
091: backReferences.addBackReference(new ObjectID(2),
092: new ObjectID(0));
093: backReferences.addBackReference(new ObjectID(3),
094: new ObjectID(0));
095:
096: assertEquals(1, stateManager
097: .createPrunedChangesAndAddObjectIDTo(changes,
098: backReferences, cid0, lookupObjectIDs).size());
099: assertEquals(2, lookupObjectIDs.size());
100:
101: stateManager.shutdownNode(cid1);
102:
103: }
104: }
|