Exemplo n.º 1
0
        public async Task DelayedDictionaryTest()
        {
            var dict   = new KeyedProducerConsumer <string, int>();
            var ignore = AsynchronousAddition(dict);
            var s1     = dict.GetItem("World");
            var s2     = dict.GetItem("Foo");
            var s3     = dict.GetItem("Bar");

            Assert.AreEqual(await s1, "World".GetHashCode());
            Assert.AreEqual(await s3, "Bar".GetHashCode());
            Assert.AreEqual(await s2, "Foo".GetHashCode());
        }
Exemplo n.º 2
0
        public async Task RaceTest()
        {
            for (var i = 0; i < 5000000; i++)
            {
                var dict   = new KeyedProducerConsumer <string, int>();
                var ignore = AsynchronousAddition2(dict);
                var s1     = dict.GetItem("World");
                var s2     = dict.GetItem("Foo");
                var s3     = dict.GetItem("Bar");

                Assert.AreEqual(await s1, "World".GetHashCode());
                Assert.AreEqual(await s3, "Bar".GetHashCode());
                Assert.AreEqual(await s2, "Foo".GetHashCode());
            }
        }
Exemplo n.º 3
0
        public async Task ImmediateDictionaryTest()
        {
            var dict = new KeyedProducerConsumer <string, int>();

            dict.AddOrReplace("Hello", "Hello".GetHashCode());
            var s = await dict.GetItem("Hello");

            Assert.AreEqual(s, "Hello".GetHashCode());
        }