public void MetricPublisherFactory_SingleInitializePerKey()
        {
            TestHystrixMetricsPublisher publisher = new TestHystrixMetricsPublisher();
            HystrixMetricsPublisherFactory factory = new HystrixMetricsPublisherFactory(publisher);
            List<Thread> threads = new List<Thread>();
            for (int i = 0; i < 20; i++)
            {
                threads.Add(new Thread(() =>
                {
                    factory.GetPublisherForCommand(CommandKeyForUnitTest.KeyOne, null, null, null, null);
                    factory.GetPublisherForCommand(CommandKeyForUnitTest.KeyTwo, null, null, null, null);
                    factory.GetPublisherForThreadPool(ThreadPoolKeyForUnitTest.ThreadPoolOne, null, null);
                }));
            }

            // start them
            foreach (Thread t in threads)
            {
                t.Start();
            }

            // wait for them to finish
            foreach (Thread t in threads)
            {
                t.Join();
            }

            // we should see 2 commands and 1 threadPool publisher created
            Assert.AreEqual(2, publisher.CommandCounter);
            Assert.AreEqual(1, publisher.ThreadCounter);
        }
Ejemplo n.º 2
0
        public void TestSingleInitializePerKey()
        {
            TestHystrixMetricsPublisher publisher = new TestHystrixMetricsPublisher();

            HystrixPlugins.RegisterMetricsPublisher(publisher);
            HystrixMetricsPublisherFactory factory = new HystrixMetricsPublisherFactory();
            List <Task> threads = new List <Task>();

            for (int i = 0; i < 20; i++)
            {
                threads.Add(new Task(() =>
                {
                    factory.GetPublisherForCommand(TestCommandKey.TEST_A, null, null, null, null);
                    factory.GetPublisherForCommand(TestCommandKey.TEST_B, null, null, null, null);
                    factory.GetPublisherForThreadPool(TestThreadPoolKey.TEST_A, null, null);
                }, CancellationToken.None, TaskCreationOptions.LongRunning));
            }

            // start them
            foreach (Task t in threads)
            {
                t.Start();
            }

            // wait for them to finish
            Task.WaitAll(threads.ToArray());

            Assert.Equal(2, factory.commandPublishers.Count);
            Assert.Equal(1, factory.threadPoolPublishers.Count);

            // we should see 2 commands and 1 threadPool publisher created
            Assert.Equal(2, publisher.commandCounter.Value);
            Assert.Equal(1, publisher.threadCounter.Value);
        }
        public void MetricPublisherFactory_SingleInitializePerKey()
        {
            TestHystrixMetricsPublisher    publisher = new TestHystrixMetricsPublisher();
            HystrixMetricsPublisherFactory factory   = new HystrixMetricsPublisherFactory(publisher);
            List <Thread> threads = new List <Thread>();

            for (int i = 0; i < 20; i++)
            {
                threads.Add(new Thread(() =>
                {
                    factory.GetPublisherForCommand(CommandKeyForUnitTest.KeyOne, null, null, null, null);
                    factory.GetPublisherForCommand(CommandKeyForUnitTest.KeyTwo, null, null, null, null);
                    factory.GetPublisherForThreadPool(ThreadPoolKeyForUnitTest.ThreadPoolOne, null, null);
                }));
            }

            // start them
            foreach (Thread t in threads)
            {
                t.Start();
            }

            // wait for them to finish
            foreach (Thread t in threads)
            {
                t.Join();
            }

            // we should see 2 commands and 1 threadPool publisher created
            Assert.AreEqual(2, publisher.CommandCounter);
            Assert.AreEqual(1, publisher.ThreadCounter);
        }