Exemplo n.º 1
0
        public void CanProxiseByAppid()
        {
            var aconfig1 = new HostConfig();
            aconfig1.AddQorpentBinding(98);
            var aconfig2 = new HostConfig();
            aconfig2.AddQorpentBinding(99);
            aconfig2.Proxize["/call1"] = "appid=98";
            var h1 = new HostServer(aconfig1);
            var h2 = new HostServer(aconfig2);
            h1.On("/call1", "hello!");
            var result = "";
            try
            {
                h1.Start();
                h2.Start(); 
                Thread.Sleep(100);
                result = new HttpClient().GetString("http://127.0.0.1:14990/call1");
            }
            finally
            {
                h1.Stop();
                h2.Stop();

            }
            Assert.AreEqual("hello!", result);
        }
Exemplo n.º 2
0
        public void CanProxiseByAppid()
        {
            var aconfig1 = new HostConfig();

            aconfig1.AddQorpentBinding(98);
            var aconfig2 = new HostConfig();

            aconfig2.AddQorpentBinding(99);
            aconfig2.Proxize["/call1"] = "appid=98";
            var h1 = new HostServer(aconfig1);
            var h2 = new HostServer(aconfig2);

            h1.On("/call1", "hello!");
            var result = "";

            try
            {
                h1.Start();
                h2.Start();
                Thread.Sleep(100);
                result = new HttpClient().GetString("http://127.0.0.1:14990/call1");
            }
            finally
            {
                h1.Stop();
                h2.Stop();
            }
            Assert.AreEqual("hello!", result);
        }
Exemplo n.º 3
0
        public void CanProxisePost()
        {
            var aconfig1 = new HostConfig();

            aconfig1.AddQorpentBinding(98);
            var aconfig2 = new HostConfig();

            aconfig2.AddQorpentBinding(99);
            aconfig2.Proxize["/call1"] = "appid=98";
            var h1 = new HostServer(aconfig1);
            var h2 = new HostServer(aconfig2);

            h1.OnContext("/call1", _ => {
                if (_.Method == "POST")
                {
                    _.Finish(new StreamReader(_.Request.Stream).ReadToEnd());
                }
                else
                {
                    _.Finish("hello!");
                }
            });
            var result       = "";
            var resultDirect = "";

            try
            {
                h1.Start();
                h2.Start();
                Thread.Sleep(1000);
                resultDirect = new HttpClient().GetString("http://127.0.0.1:14980/call1", "hello2");
                result       = new HttpClient().GetString("http://127.0.0.1:14990/call1", "hello2");
            }
            finally
            {
                h1.Stop();
                h2.Stop();
            }
            Console.WriteLine(result);

            Assert.AreEqual("hello2", resultDirect);
            Assert.AreEqual("hello2", result);
        }
Exemplo n.º 4
0
        public void CanProxisePost()
        {
            var aconfig1 = new HostConfig();
            aconfig1.AddQorpentBinding(98);
            var aconfig2 = new HostConfig();
            aconfig2.AddQorpentBinding(99);
            aconfig2.Proxize["/call1"] = "appid=98";
            var h1 = new HostServer(aconfig1);
            var h2 = new HostServer(aconfig2);
            h1.OnContext("/call1", _ => {
                if (_.Method == "POST") {
                    _.Finish(new StreamReader(_.Request.Stream).ReadToEnd());
                }
                else {
                    _.Finish("hello!");    
                }
                
            });
            var result = "";
            var resultDirect = "";

            try
            {
                h1.Start();
                h2.Start();
                Thread.Sleep(1000);
                resultDirect = new HttpClient().GetString("http://127.0.0.1:14980/call1", "hello2");
                result = new HttpClient().GetString("http://127.0.0.1:14990/call1", "hello2");
            }
            finally
            {
                h1.Stop();
                h2.Stop();

            }
            Console.WriteLine(result);

            Assert.AreEqual("hello2", resultDirect);
            Assert.AreEqual("hello2", result);
        }
Exemplo n.º 5
0
        public void HttpCacheTest()
        {
            var conf = new HostConfig();

            conf.AddQorpentBinding(99);
            conf.StaticContentMap["/files/"] = new StaticFolderDescriptor {
                Path = web
            };
            var qh = new HostServer(conf);

            qh.Start();
            try {
                Thread.Sleep(200);
                Assert.AreEqual("41", new HttpClient().GetString("http://127.0.0.1:14990/files/a.txt"));
                cache.Sources.Add(new FileCacheSource("http://127.0.0.1:14990/files/"));
                CheckFile("b/e/j.txt", 48);
                Assert.Null(cache.Resolve("b/e/k.txt")); //check that 404 doesn't cause error
            }
            finally {
                qh.Stop();
            }
        }