Пример #1
0
        public void AddAndRemoveObject()
        {
            ObjectRepository objRepo = new ObjectRepository();

            // Create a distributed object to play with
            DistributedObjectId   doId = new DistributedObjectId(100);
            DistributedTestObject obj  = new DistributedTestObject(doId);

            // Object should not be present
            Assert.IsFalse(objRepo.ContainsObject(obj));
            Assert.IsFalse(objRepo.ContainsObject(doId));
            Assert.IsTrue(objRepo.GetObject(doId) == null);

            // Add obj
            objRepo.AddObject(obj);
            Assert.IsTrue(objRepo.ContainsObject(obj));
            Assert.IsTrue(objRepo.ContainsObject(doId));
            Assert.AreEqual((IDistributedObject)objRepo.GetObject(doId), (IDistributedObject)obj);

            // Remove obj
            objRepo.RemoveObject(obj);
            Assert.IsFalse(objRepo.ContainsObject(obj));

            // Try to remove an object already removed
            objRepo.RemoveObject(obj);
        }
        public void ZoneHandling()
        {
            ServerStateMachine     serverStateMachine = new TestServerStateMachine();
            ServerObjectRepository objRepo            = new ServerObjectRepository(serverStateMachine);

            // Create a distributed object to play with
            DistributedObjectId   doId = new DistributedObjectId(100);
            DistributedTestObject obj  = new DistributedTestObject(doId);

            ZoneId zoneId1 = new ZoneId(100);
            ZoneId zoneId2 = new ZoneId(200);

            objRepo.AddObject(obj);

            // No zone set yet
            Assert.IsTrue(objRepo.GetZone(obj) == null);
            Assert.IsTrue(objRepo.GetZone(doId) == null);
            Assert.IsTrue(objRepo.GetObjectsInZone(zoneId1).Count == 0);

            // Set the first zone
            objRepo.SetObjectZone(obj, zoneId1);
            Assert.IsTrue(objRepo.GetZone(obj) == zoneId1);
            Assert.IsTrue(objRepo.GetZone(doId) == zoneId1);
            Assert.IsTrue(objRepo.GetObjectsInZone(zoneId1).Count == 1);

            // Now change to the second zone
            objRepo.SetObjectZone(obj, zoneId2);
            Assert.IsTrue(objRepo.GetZone(obj) == zoneId2);
            Assert.IsTrue(objRepo.GetZone(doId) == zoneId2);
            // Should no longer be in the first zone
            Assert.IsTrue(objRepo.GetObjectsInZone(zoneId1).Count == 0);
            // Should be in the second zone
            Assert.IsTrue(objRepo.GetObjectsInZone(zoneId2).Count == 1);

            // Try setting the same zone again
            objRepo.SetObjectZone(obj, zoneId2);
            Assert.IsTrue(objRepo.GetZone(obj) == zoneId2);
            Assert.IsTrue(objRepo.GetZone(doId) == zoneId2);
            // Should be in the second zone, only once
            Assert.IsTrue(objRepo.GetObjectsInZone(zoneId2).Count == 1);

            // Remove obj
            objRepo.RemoveObject(obj);
            Assert.IsFalse(objRepo.ContainsObject(obj));
            // Should not be in either zone
            Assert.IsTrue(objRepo.GetObjectsInZone(zoneId1).Count == 0);
            Assert.IsTrue(objRepo.GetObjectsInZone(zoneId2).Count == 0);
        }
Пример #3
0
        public void ObjectZoneChangingWithNobodyListening()
        {
            // Setup the server engine and its required dependencies
            ServerStateMachine     serverStateMachine = new TestServerStateMachine();
            SessionManager         sessionManager     = new SessionManager();
            ServerObjectRepository objectRepo         = new ServerObjectRepository(serverStateMachine);
            ServerEngine           serverEngine       = new ServerEngine(sessionManager, objectRepo, MockSendMessageToReflector);

            // Create a distributed object to play with
            DistributedObjectId   doId = new DistributedObjectId(100);
            DistributedTestObject obj  = new DistributedTestObject(doId);

            ZoneId zoneId1 = new ZoneId(100);
            ZoneId zoneId2 = new ZoneId(200);

            // Start by putting the object in the first zone
            serverEngine.ProcessZoneChange(obj, zoneId1);
            Assert.IsTrue(objectRepo.GetZone(obj) == zoneId1);

            // Test changing to the zone the object is already in
            serverEngine.ProcessZoneChange(obj, zoneId1);
            Assert.IsTrue(objectRepo.GetZone(obj) == zoneId1);

            // Now change to a new zone
            serverEngine.ProcessZoneChange(obj, zoneId2);
            Assert.IsTrue(objectRepo.GetZone(obj) == zoneId2);

            // Now remove the object from the zone
            Assert.IsTrue(serverEngine.RemoveObjectFromZone(obj) == zoneId2);
            Assert.IsTrue(objectRepo.GetZone(obj) == null);

            // Try a duplicate removal - should be safe to do
            Assert.IsTrue(serverEngine.RemoveObjectFromZone(obj) == null);
            Assert.IsTrue(objectRepo.GetZone(obj) == null);

            // Now put the object back in the first zone
            serverEngine.ProcessZoneChange(obj, zoneId1);
            Assert.IsTrue(objectRepo.GetZone(obj) == zoneId1);
        }
Пример #4
0
        public void DisconnectSession()
        {
            // Setup the server engine and its required dependencies
            ServerStateMachine     serverStateMachine = new TestServerStateMachine();
            SessionManager         sessionManager     = new SessionManager();
            ServerObjectRepository objectRepo         = new ServerObjectRepository(serverStateMachine);
            ServerEngine           serverEngine       = new ServerEngine(sessionManager, objectRepo, MockSendMessageToReflector);

            // Create a distributed object to play with
            DistributedObjectId   doId = new DistributedObjectId(100);
            DistributedTestObject obj  = new DistributedTestObject(doId);

            ZoneId zoneId    = new ZoneId(200);
            Guid   sessionId = new Guid();

            Assert.IsTrue(sessionManager.AddSession(sessionId, new ServerAccount(new AccountId(0), 0, "0", "0", "schmear", "mein", "schmeer", null)));
            objectRepo.AddObjectToSessionId(sessionId, obj);

            serverEngine.ProcessOpenZoneInterest(sessionId, zoneId);
            serverEngine.ProcessZoneChange(obj, zoneId);

            serverEngine.ProcessDisconnectSession(sessionId);

            // See if the object repo got cleaned up
            // Object repo should no longer have the object
            Assert.IsFalse(objectRepo.ContainsObject(obj));
            Assert.IsTrue(objectRepo.GetObject(doId) == null);
            // Object should not be in the zone
            Assert.IsFalse(objectRepo.GetObjectsInZone(zoneId).Contains(obj));
            Assert.IsTrue(objectRepo.GetDistributedObjectIdsOwnedBySessionId(sessionId).Count == 0);

            // See if the session manager got cleaned up
            // Session manager should no longer have the session
            Assert.IsFalse(sessionManager.ContainsSession(sessionId));
            // Zone interest should be cleaned up
            Assert.IsFalse(sessionManager.SessionIdHasInterest(sessionId, zoneId));
            Assert.IsFalse(sessionManager.GetSessionIdsInterestedInZoneId(zoneId).Contains(sessionId));
            Assert.IsFalse(sessionManager.GetZoneIdsFromInterestedSessionId(sessionId).Contains(zoneId));
        }