private ObjectIDSet makeRemovedSet(int num) { ObjectIDSet rv = new BitSetObjectIDSet(); for (int i = 0; i < num; i++) { rv.add(new ObjectID(i)); } return rv; }
public void testValidations() throws Exception { // Valid object ids ObjectIDSet validOids = new BitSetObjectIDSet(); for (int i = 0; i < 10; i++) { for (int j = 0; j < 50; j++) { long longOid = 100 * i + j; validOids.add(new ObjectID(longOid)); } } ClientID[] cids = new ClientID[10]; for (int i = 0; i < 10; i++) { cids[i] = new ClientID(i); } for (int i = 0; i < 10; i++) { ObjectIDSet validate = new BitSetObjectIDSet(); for (int j = 0; j < 100; j++) { long longOid = 100 * i + j; validate.add(new ObjectID(longOid)); } invalidateObjectManager.addObjectsToValidateFor(cids[i], validate); } invalidateObjectManager.start(); invalidateObjectManager.validateObjects(validOids); ArrayList list = inValidateSink.getList(); Assert.assertEquals(10, list.size()); for (int i = 0; i < 10; i++) { InvalidateObjectsForClientContext clientContext = (InvalidateObjectsForClientContext) list.get(i); ClientID cid = clientContext.getClientID(); int k = (int) cid.toLong(); Invalidations invalidationsGot = invalidateObjectManager.getObjectsIDsToInvalidate(cid); Invalidations expected = new Invalidations(); ObjectID mapID = ObjectID.NULL_ID; for (int j = 50; j < 100; j++) { long longOid = 100 * k + j; expected.add(mapID, new ObjectID(longOid)); } Assert.assertEquals(expected, invalidationsGot); } }
@Override public Set getObjectReferences() { ObjectIDSet set = new ObjectIDSet(); if (componentObjects != null) { for (Object obj : componentObjects) { if (obj instanceof ObjectID) { ObjectID oid = (ObjectID) obj; if (!oid.isNull()) { set.add(oid); } } } } return set; }
public void testObjectRequestCounter() { Counter channelReqCounter = new CounterImpl(666L); Counter requestCounter = new CounterImpl(0L); TestChannelStats channelStats = new TestChannelStats(channelReqCounter); TestObjectManager objectManager = new TestObjectManager(); TestDSOChannelManager channelManager = new TestDSOChannelManager(); TestClientStateManager clientStateManager = new TestClientStateManager(); TestSink requestSink = new TestSink(); TestSink respondSink = new TestSink(); ObjectRequestManagerImpl objectRequestManager = new ObjectRequestManagerImpl( objectManager, channelManager, clientStateManager, requestSink, respondSink, new ObjectStatsRecorder()); TestServerConfigurationContext context = new TestServerConfigurationContext(); context.setObjectRequestManager(objectRequestManager); context.clientStateManager = new TestClientStateManager(); context.addStage( ServerConfigurationContext.RESPOND_TO_OBJECT_REQUEST_STAGE, new MockStage("yo")); context.channelStats = channelStats; ManagedObjectRequestHandler handler = new ManagedObjectRequestHandler(requestCounter); handler.initializeContext(context); TestRequestManagedObjectMessage msg = new TestRequestManagedObjectMessage(); ObjectIDSet s = new BitSetObjectIDSet(); s.add(new ObjectID(1)); msg.setObjectIDs(s); ObjectIDSet removed = makeRemovedSet(31); msg.setRemoved(removed); assertEquals(0, requestCounter.getValue()); assertEquals(666, channelReqCounter.getValue()); handler.handleEvent(msg); assertEquals(1, requestCounter.getValue()); assertEquals(667, channelReqCounter.getValue()); }