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.object.msg;
06:
07: import com.tc.exception.ImplementMe;
08: import com.tc.io.TCByteBufferOutputStream;
09: import com.tc.net.groups.ClientID;
10: import com.tc.net.protocol.tcm.NullMessageMonitor;
11: import com.tc.net.protocol.tcm.TCMessageHeader;
12: import com.tc.net.protocol.tcm.TCMessageType;
13: import com.tc.net.protocol.tcm.TestMessageChannel;
14: import com.tc.object.ObjectID;
15: import com.tc.object.ObjectRequestContext;
16: import com.tc.object.ObjectRequestID;
17: import com.tc.object.session.SessionID;
18: import com.tc.test.TCTestCase;
19:
20: import java.util.HashSet;
21: import java.util.Set;
22:
23: public class RequestManagedObjectMessageImplTest extends TCTestCase {
24:
25: public void testBasics() throws Exception {
26: TestMessageChannel channel = new TestMessageChannel();
27: TCMessageType type = TCMessageType.REQUEST_MANAGED_OBJECT_MESSAGE;
28:
29: TestObjectRequestContext ctxt = new TestObjectRequestContext();
30: ObjectID id = new ObjectID(1);
31: Set removedIDs = new HashSet();
32: for (int i = 3; i < 100; i++) {
33: removedIDs.add(new ObjectID(i));
34: }
35:
36: RequestManagedObjectMessageImpl msg = new RequestManagedObjectMessageImpl(
37: new SessionID(0), new NullMessageMonitor(),
38: new TCByteBufferOutputStream(4, 4096, false), channel,
39: type);
40: Set oids = new HashSet();
41: oids.add(id);
42: msg.initialize(ctxt, oids, removedIDs);
43:
44: msg.dehydrate();
45:
46: RequestManagedObjectMessageImpl msg2 = new RequestManagedObjectMessageImpl(
47: SessionID.NULL_ID, new NullMessageMonitor(), channel,
48: (TCMessageHeader) msg.getHeader(), msg.getPayload());
49: msg2.hydrate();
50:
51: Set ids = new HashSet();
52: ids.add(id);
53:
54: checkMessageValues(ctxt, removedIDs, ids, msg2);
55: }
56:
57: private void checkMessageValues(TestObjectRequestContext ctxt,
58: Set removedIDs, Set ids, RequestManagedObjectMessageImpl msg) {
59: assertEquals(ids, new HashSet(msg.getObjectIDs()));
60: assertEquals(ctxt.getRequestID(), msg.getRequestID());
61: assertEquals(removedIDs, msg.getRemoved());
62: }
63:
64: private static class TestObjectRequestContext implements
65: ObjectRequestContext {
66:
67: public ObjectRequestID getRequestID() {
68: return new ObjectRequestID(1);
69: }
70:
71: public ClientID getClientID() {
72: throw new ImplementMe();
73: }
74:
75: public Set getObjectIDs() {
76: throw new ImplementMe();
77: }
78:
79: public int getRequestDepth() {
80: return 10;
81: }
82: }
83: }
|