Inheritance: IHttpController
Esempio n. 1
0
        public void of_http_requests_routing()
        {
            const int iterations = 100000;

            IPublisher inputBus           = new NoopPublisher();
            var        bus                = InMemoryBus.CreateTest();
            var        queue              = new QueuedHandlerThreadPool(bus, "Test", true, TimeSpan.FromMilliseconds(50));
            var        multiQueuedHandler = new MultiQueuedHandler(new IQueuedHandler[] { queue }, null);
            var        providers          = new HttpAuthenticationProvider[] { new AnonymousHttpAuthenticationProvider() };
            var        httpService        = new HttpService(ServiceAccessibility.Public, inputBus,
                                                            new TrieUriRouter(), multiQueuedHandler, false, "http://localhost:12345/");

            HttpService.CreateAndSubscribePipeline(bus, providers);

            var fakeController = new FakeController(iterations, null);

            httpService.SetupController(fakeController);

            httpService.Handle(new SystemMessage.SystemInit());

            var rnd = new Random();
            var sw  = Stopwatch.StartNew();

            var httpClient = new HttpAsyncClient();

            for (int i = 0; i < iterations; ++i)
            {
                var route = fakeController.BoundRoutes[rnd.Next(0, fakeController.BoundRoutes.Count)];

                switch (route.Item2)
                {
                case HttpMethod.Get:
                    httpClient.Get(route.Item1, TimeSpan.FromMilliseconds(10000), x => { }, x => { throw new Exception(); });
                    break;

                case HttpMethod.Post:
                    httpClient.Post(route.Item1, "abracadabra", ContentType.Json, TimeSpan.FromMilliseconds(10000), x => { }, x => { throw new Exception(); });
                    break;

                case HttpMethod.Delete:
                    httpClient.Delete(route.Item1, TimeSpan.FromMilliseconds(10000), x => { }, x => { throw new Exception(); });
                    break;

                case HttpMethod.Put:
                    httpClient.Put(route.Item1, "abracadabra", ContentType.Json, TimeSpan.FromMilliseconds(10000), x => { }, x => { throw new Exception(); });
                    break;

                default:
                    throw new Exception();
                }
            }

            fakeController.CountdownEvent.Wait();
            sw.Stop();

            Console.WriteLine("{0} request done in {1} ({2:0.00} per sec)", iterations, sw.Elapsed, 1000.0 * iterations / sw.ElapsedMilliseconds);

            httpService.Shutdown();
            multiQueuedHandler.Stop();
        }
        public void of_uri_router()
        {
            const int iterations = 100000;

            IUriRouter router         = new TrieUriRouter();
            var        fakeController = new FakeController(iterations, router);

            fakeController.Subscribe(null);

            var rnd = new Random();
            var sw  = Stopwatch.StartNew();

            for (int i = 0; i < iterations; ++i)
            {
                var route = fakeController.BoundRoutes[rnd.Next(0, fakeController.BoundRoutes.Count)];
                router.GetAllUriMatches(new Uri(route.Item1));
            }
            sw.Stop();

            Console.WriteLine("{0} request done in {1} ({2:0.00} per sec)", iterations, sw.Elapsed, 1000.0 * iterations / sw.ElapsedMilliseconds);
        }
Esempio n. 3
0
        public void of_uri_router()
        {
            const int iterations = 100000;

            IUriRouter router = new TrieUriRouter();
            var fakeController = new FakeController(iterations, router);
            fakeController.Subscribe(null);

            var rnd = new Random();
            var sw = Stopwatch.StartNew();

            for (int i = 0; i < iterations; ++i)
            {
                var route = fakeController.BoundRoutes[rnd.Next(0, fakeController.BoundRoutes.Count)];
                router.GetAllUriMatches(new Uri(route.Item1));
            }
            sw.Stop();

            Console.WriteLine("{0} request done in {1} ({2:0.00} per sec)", iterations, sw.Elapsed, 1000.0 * iterations / sw.ElapsedMilliseconds);
        }
Esempio n. 4
0
        public void of_http_requests_routing()
        {
            const int iterations = 100000;

            IPublisher inputBus = new NoopPublisher();
            var bus = InMemoryBus.CreateTest();
            var queue = new QueuedHandlerThreadPool(bus, "Test", true, TimeSpan.FromMilliseconds(50));
            var multiQueuedHandler = new MultiQueuedHandler(new IQueuedHandler[]{queue}, null);
            var providers = new AuthenticationProvider[] {new AnonymousAuthenticationProvider()};
            var httpService = new HttpService(ServiceAccessibility.Public, inputBus, 
                                              new TrieUriRouter(), multiQueuedHandler, "http://localhost:12345/");
            HttpService.CreateAndSubscribePipeline(bus, providers);

            var fakeController = new FakeController(iterations, null);
            httpService.SetupController(fakeController);

            httpService.Handle(new SystemMessage.SystemInit());

            var rnd = new Random();
            var sw = Stopwatch.StartNew();

            var httpClient = new HttpAsyncClient();
            for (int i = 0; i < iterations; ++i)
            {
                var route = fakeController.BoundRoutes[rnd.Next(0, fakeController.BoundRoutes.Count)];

                switch (route.Item2)
                {
                    case HttpMethod.Get:
                        httpClient.Get(route.Item1,TimeSpan.FromMilliseconds(10000),  x => { }, x => { throw new Exception();});
                        break;
                    case HttpMethod.Post:
                        httpClient.Post(route.Item1, "abracadabra", ContentType.Json, TimeSpan.FromMilliseconds(10000), x => { }, x => { throw new Exception(); });
                        break;
                    case HttpMethod.Delete:
                        httpClient.Delete(route.Item1, TimeSpan.FromMilliseconds(10000), x => { }, x => { throw new Exception(); });
                        break;
                    case HttpMethod.Put:
                        httpClient.Put(route.Item1, "abracadabra", ContentType.Json, TimeSpan.FromMilliseconds(10000), x => { }, x => { throw new Exception(); });
                        break;
                    default:
                        throw new Exception();
                }
            }

            fakeController.CountdownEvent.Wait();
            sw.Stop();

            Console.WriteLine("{0} request done in {1} ({2:0.00} per sec)", iterations, sw.Elapsed, 1000.0 * iterations / sw.ElapsedMilliseconds);

            httpService.Shutdown();
            multiQueuedHandler.Stop();
        }