Exemple #1
0
        public async Task TestCancelInOffering()
        {
            var iterator    = new TestIterator(3);
            var cts         = new CancellationTokenSource(50);
            var testBlock   = iterator.AsSourceBlock(cts.Token);
            var targetBlock = new BufferBlock <int>(new DataflowBlockOptions()
            {
                BoundedCapacity = 1
            });

            testBlock.LinkTo(targetBlock);

            // When link is added, call MoveNext once and buffer the result.
            // The task is not completed until the buffered value is consumed.
            await testBlock.Completion.NeverComplete();

            // targetBlock received 1 soon after linking
            (await targetBlock.ReceiveAsync(TestUtils.SometimeSoon)).Is(1);

            // 2 was buffered and targetBlock received it soon after the previous line
            (await targetBlock.ReceiveAsync(TestUtils.SometimeSoon)).Is(2);

            // The cancel is requested and no buffer in testBlock
            await testBlock.Completion.CanceledSoon();

            // targetBlock never receives 3
            await Assert.ThrowsAnyAsync <TimeoutException>(() => targetBlock.ReceiveAsync(TestUtils.SometimeSoon));
        }
Exemple #2
0
        public async Task TestCancelBeforeLink()
        {
            var iterator  = new TestIterator(3);
            var cts       = new CancellationTokenSource();
            var testBlock = iterator.AsSourceBlock(cts.Token);

            cts.Cancel();
            await testBlock.Completion.CanceledSoon();
        }
Exemple #3
0
        public async Task TestRange()
        {
            var iterator    = new TestIterator(3);
            var testBlock   = iterator.AsSourceBlock();
            var targetBlock = new BufferBlock <int>();

            testBlock.LinkTo(targetBlock);
            await testBlock.Completion.CompleteSoon();

            iterator.Disposed.IsTrue();

            targetBlock.TryReceiveAll(out var values).IsTrue();
            values.Is(1, 2, 3);
        }
Exemple #4
0
        public void TestReceive()
        {
            var iterator  = new TestIterator(3);
            var testBlock = iterator.AsSourceBlock().IsInstanceOf <IReceivableSourceBlock <int> >();

            // Cannot receive item before link
            testBlock.TryReceive(null, out _).IsFalse();
            iterator.Enumerating.IsFalse();

            // Can receive with link
            testBlock.Receive(TestUtils.SometimeSoon).Is(1);
            iterator.Enumerating.IsTrue();

            // Does not MoveNext after unlink
            testBlock.TryReceive(null, out _).IsFalse();
        }
        public async Task TestDisposeEnumerator(int receiveCount)
        {
            var iterator  = new TestIterator(2);
            var cts       = new CancellationTokenSource();
            var testBlock = iterator.AsSourceBlock(cts.Token);

            for (var i = 1; i <= receiveCount; i++)
            {
                (await testBlock.ReceiveAsync(TestUtils.SometimeSoon)).Is(i);
            }

            cts.Cancel();

            await testBlock.Completion.CanceledSoon();

            iterator.Disposed.IsTrue();
        }
Exemple #6
0
        public async Task TestCancelInOffering()
        {
            var iterator    = new TestIterator(3);
            var cts         = new CancellationTokenSource();
            var testBlock   = iterator.AsSourceBlock(cts.Token);
            var targetBlock = new TransformWithoutBufferBlock <int, int>(x => x);

            testBlock.LinkTo(targetBlock);
            cts.Cancel();

            // When link is added, call MoveNext once and buffer the result.
            // The task is not completed until the buffered value is consumed.
            await testBlock.Completion.NeverComplete();

            (await targetBlock.ReceiveAsync(TestUtils.SometimeSoon)).Is(1);

            await testBlock.Completion.CanceledSoon();
        }
Exemple #7
0
        static void Main(string[] args)
        {
            try
            {
                Console.WriteLine("Making a single call to service to check availability...");
                //Manual call to log service to test plain performance
                DateTime d1 = DateTime.Now;
                WebTarget.DoRequest("Http://localhost:55044/api/log", JsonConvert.SerializeObject(new NLog.WebLog.WebTarget.LogMessage()
                {
                    Message        = "TEST MANUAL MESSAGE" + DateTime.Now,
                    SourceDate     = DateTime.Now,
                    Level          = "Error",
                    ApplicationKey = "{FF99EE02-1E88-44FF-B0A4-8DF8D2F3B742}"
                }));

                double ms = DateTime.Now.Subtract(d1).TotalMilliseconds;
                Console.WriteLine("Service call done in ms:" + ms);

                TestIterator it = new TestIterator();
                it.Instances.Add(new WlogTest());
                it.Instances.Add(new WLogBulkTest());
                it.Instances.Add(new FileTest());

                int[] iterationSize = new int[] { 1, 10, 100, 1000, 10000 };
                Console.WriteLine("#;Wlog;Wlog (bulk);File;");
                for (int i = 0; i < iterationSize.Length; i++)
                {
                    it.RepeatCount = iterationSize[i];
                    //Console.WriteLine("=> Starting benchmark with iterationSize " + it.RepeatCount);

                    it.DoTest();

                    Console.WriteLine("{0};{1};{2};{3}", it.RepeatCount, it.Instances[0].Avg, it.Instances[1].Avg, it.Instances[2].Avg);
                }
            }
            catch (Exception er)
            {
                Console.WriteLine(er.StackTrace);
            }


            Console.ReadKey();
        }
        static void Main(string[] args)
        {
            ITestEnumerator<TestClass> enumerator = new TestEnumerator<TestClass>();
            enumerator.HasMoreItems();
            enumerator.Next();

            Console.WriteLine("-----------------------------------");

            ITestIterator<TestClass> iterator = new TestIterator<TestClass>();
            iterator.HasNext();
            iterator.Next();

            Console.WriteLine("-----------------------------------");

            ITestEnumerator<TestClass> adapter = new IteratorEnumeratorAdapter<TestClass>(iterator);
            adapter.HasMoreItems();
            adapter.Next();

        }
        static void Main(string[] args)
        {
            TestBridge cls1 = new TestBridge();

            cls1.Execute();

            TestFactory cls5 = new TestFactory();

            cls5.Execute();

            TestBuilder cls15 = new TestBuilder();

            cls15.Execute();

            TestPrototype cls9 = new TestPrototype();

            cls9.Execute();

            TestObserver cls7 = new TestObserver();

            cls7.Execute();

            TestAdaptor cls = new TestAdaptor();

            cls.Execute();

            TestDecorater cls4 = new TestDecorater();

            cls4.Execute();

            TestComposite cls3 = new TestComposite();

            cls3.Execute();

            TestProxy cls10 = new TestProxy();

            cls10.Execute();

            TestIterator cls6 = new TestIterator();

            cls6.Execute();

            TestState cls14 = new TestState();

            cls14.Execute();

            TestCommand cls2 = new TestCommand();

            cls2.Execute();

            // ************
            TestProducerConsumer cls8 = new TestProducerConsumer();

            cls8.Execute();

            TestReaderWriter cls11 = new TestReaderWriter();

            cls11.Execute();

            TestSimpleThread cls12 = new TestSimpleThread();

            cls12.Execute();

            TestSingleton cls13 = new TestSingleton();

            cls13.Execute();
        }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void runTest()
            public virtual void RunTest()
            {
                Graph.makeEdge("start", "a", "cost", ( double )1);
                Graph.makeEdge("a", "x", "cost", ( double )9);
                Graph.makeEdge("a", "b", "cost", ( float )1);
                Graph.makeEdge("b", "x", "cost", ( double )7);
                Graph.makeEdge("b", "c", "cost", ( long )1);
                Graph.makeEdge("c", "x", "cost", 5);
                Graph.makeEdge("c", "d", "cost", ( sbyte )1);
                Graph.makeEdge("d", "x", "cost", ( short )3);
                Graph.makeEdge("d", "e", "cost", ( double )1);
                Graph.makeEdge("e", "x", "cost", ( double )1);
                Dictionary <Node, double> seen1  = new Dictionary <Node, double>();
                Dictionary <Node, double> seen2  = new Dictionary <Node, double>();
                Dictionary <Node, double> dists1 = new Dictionary <Node, double>();
                Dictionary <Node, double> dists2 = new Dictionary <Node, double>();
                DijkstraIterator          iter1  = new TestIterator(this, Graph.getNode("start"), Predecessors1, seen1, seen2, dists1, dists2, false);

                // while ( iter1.hasNext() && !limitReached() && !iter1.isDone() )
//JAVA TO C# CONVERTER TODO TASK: Java iterators are only converted within the context of 'while' and 'for' loops:
                assertEquals(iter1.Next(), Graph.getNode("start"));
//JAVA TO C# CONVERTER TODO TASK: Java iterators are only converted within the context of 'while' and 'for' loops:
                assertEquals(iter1.Next(), Graph.getNode("a"));
                assertEquals(10.0, seen1[Graph.getNode("x")], 0.0);
//JAVA TO C# CONVERTER TODO TASK: Java iterators are only converted within the context of 'while' and 'for' loops:
                assertEquals(iter1.Next(), Graph.getNode("b"));
                assertEquals(9.0, seen1[Graph.getNode("x")], 0.0);
//JAVA TO C# CONVERTER TODO TASK: Java iterators are only converted within the context of 'while' and 'for' loops:
                assertEquals(iter1.Next(), Graph.getNode("c"));
                assertEquals(8.0, seen1[Graph.getNode("x")], 0.0);
//JAVA TO C# CONVERTER TODO TASK: Java iterators are only converted within the context of 'while' and 'for' loops:
                assertEquals(iter1.Next(), Graph.getNode("d"));
                assertEquals(7.0, seen1[Graph.getNode("x")], 0.0);
//JAVA TO C# CONVERTER TODO TASK: Java iterators are only converted within the context of 'while' and 'for' loops:
                assertEquals(iter1.Next(), Graph.getNode("e"));
                assertEquals(6.0, seen1[Graph.getNode("x")], 0.0);
//JAVA TO C# CONVERTER TODO TASK: Java iterators are only converted within the context of 'while' and 'for' loops:
                assertEquals(iter1.Next(), Graph.getNode("x"));
                assertEquals(6.0, seen1[Graph.getNode("x")], 0.0);
//JAVA TO C# CONVERTER TODO TASK: Java iterators are only converted within the context of 'while' and 'for' loops:
                assertFalse(iter1.HasNext());
                int count = 0;

                // This code below is correct for the alternative priority queue
                // while ( iter1.hasNext() )
                // {
                // iter1.next();
                // ++count;
                // }
                // assertTrue( count == 4 );
                // assertTrue( seen1.get( graph.getNode( "x" ) ) == 6.0 );
                // Now test node limit
                seen1  = new Dictionary <Node, double>();
                seen2  = new Dictionary <Node, double>();
                dists1 = new Dictionary <Node, double>();
                dists2 = new Dictionary <Node, double>();
                iter1  = new TestIterator(this, Graph.getNode("start"), Predecessors1, seen1, seen2, dists1, dists2, false);
                this.NumberOfNodesTraversed = 0;
                this.LimitMaxNodesToTraverse(3);
                count = 0;
                while (iter1.MoveNext())
                {
                    iter1.Current;
                    ++count;
                }
                assertEquals(3, count);
            }
Exemple #11
0
 private void button6_Click(object sender, EventArgs e)
 {
     TestIterator.Testar();
 }