Ejemplo n.º 1
0
        public void HostCreateThenUpdate()
        {
            var testWorkQueue = new WorkQueue();

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

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

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

            // should generate announce response and then connection
            WaitUtils.WaitUntil(new[] { host, host2 }, () => host.PeerCount == 1 && host2.PeerCount == 1);

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

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

            // change the state of the owner
            distributedThing.Enqueue(new[] { 1, 2 });

            // verify the proxy gets updated
            WaitUtils.WaitUntil(
                new[] { host, host2 },
                () => FirstProxyLocalThing(host2).LocalValues.Count() == 2);

            Assert.IsTrue(Enumerable.SequenceEqual(new[] { 1, 2 }, FirstProxyLocalThing(host2).LocalValues.ToList()));
        }
Ejemplo n.º 2
0
        public void HostCreateThenProxyUpdate()
        {
            var testWorkQueue = new WorkQueue();

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

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

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

            // should generate announce response and then connection
            WaitUtils.WaitUntil(new[] { host, host2 }, () => host.PeerCount == 1 && host2.PeerCount == 1);

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

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

            // this time update the state of the *proxy* -- or more precisely, send a request to the proxy
            // to update the owner's state (which will, in turn, update the proxy's state)
            DistributedThing host2DistributedThing = (DistributedThing)ProxiesForFirstPeer(host2).First().Value;

            host2DistributedThing.Enqueue(new[] { 1, 2 });

            // make sure we didn't actually update the local thing yet; only messages from the owner can do that
            Assert.AreEqual(0, host2DistributedThing.TypedLocalObject.LocalValues.Count());

            // wait until owner gets the proxy's memo
            WaitUtils.WaitUntil(
                new[] { host, host2 },
                () => distributedThing.TypedLocalObject.LocalValues.Count() == 2);

            // and now wait until proxy gets the owner's memo
            WaitUtils.WaitUntil(
                new[] { host, host2 },
                () => host2DistributedThing.TypedLocalObject.LocalValues.Count() == 2);

            Assert.IsTrue(Enumerable.SequenceEqual(new[] { 1, 2 }, distributedThing.TypedLocalObject.LocalValues.ToList()));
            Assert.IsTrue(Enumerable.SequenceEqual(new[] { 1, 2 }, host2DistributedThing.TypedLocalObject.LocalValues.ToList()));
        }