Esempio n. 1
0
        public void HostCreateBeforeConnection()
        {
            var testWorkQueue = new WorkQueue();

            // the first host under test
            using DistributedHost host = CreateHost(testWorkQueue, true);

            // create object
            var distributedThing = new DistributedThing(host, new LocalThing());

            // construct second host
            using DistributedHost host2 = CreateHost(testWorkQueue, false);

            // consume one owner ID so second object has ID 2 instead of (matching first object) ID 1
            host2.NextOwnerId();

            // now create an owner object on the other host
            var distributedThing2 = new DistributedThing(host2, new LocalThing());

            // host could start announcing also, but host2 isn't listening so it wouldn't be detectable
            host2.Announce();

            // wait until the proxy for the new object makes it to the other host
            WaitUtils.WaitUntil(new[] { host, host2 }, () =>
                                host2.NetPeers.Count() == 1 &&
                                ProxiesForFirstPeer(host2).Count == 1 &&
                                host.NetPeers.Count() == 1 &&
                                host.ProxiesForPeer(new SerializedSocketAddress(host.NetPeers.First())).Count == 1);

            IDistributedObject host2Proxy = ProxiesForFirstPeer(host2).Values.First();

            Assert.AreEqual(new DistributedId(1), host2Proxy.Id);
            Assert.False(host2Proxy.IsOwner);

            IDistributedObject hostProxy = ProxiesForFirstPeer(host).Values.First();

            Assert.AreEqual(new DistributedId(2), hostProxy.Id);
            Assert.False(hostProxy.IsOwner);
        }
Esempio n. 2
0
 private static IReadOnlyDictionary <DistributedId, IDistributedObject> ProxiesForFirstPeer(DistributedHost host)
 {
     return(host.ProxiesForPeer(new SerializedSocketAddress(host.NetPeers.First())));
 }