예제 #1
0
        public void new及びstart_stop_disposeの繰り返し_負荷テスト()
        {
            var ip = new Ip(IpKind.V4Localhost);
            var oneBind = new OneBind(ip, ProtocolKind.Tcp);
            Conf conf = TestUtil.CreateConf("OptionSample");
            conf.Set("port", 88);
            conf.Set("multiple", 10);
            conf.Set("acl", new Dat(new CtrlType[0]));
            conf.Set("enableAcl", 1);
            conf.Set("timeOut", 3);

            for (var i = 0; i < 5; i++){
                var myServer = new MyServer(conf, oneBind);

                myServer.Start();
                Assert.That(myServer.ThreadBaseKind, Is.EqualTo(ThreadBaseKind.Running));
                Assert.That(myServer.SockState(),  Is.EqualTo(SockState.Bind));

                myServer.Stop();
                Assert.That(myServer.ThreadBaseKind,  Is.EqualTo(ThreadBaseKind.After));
                Assert.That(myServer.SockState(), Is.EqualTo(SockState.Error));

                myServer.Dispose();
            }
        }
예제 #2
0
        public void new及びstart_stop_disposeの繰り返し_負荷テスト_UDP()
        {
            var  ip      = new Ip(IpKind.V4Localhost);
            var  oneBind = new OneBind(ip, ProtocolKind.Udp);
            Conf conf    = TestUtil.CreateConf("OptionSample");

            conf.Set("port", 88);
            conf.Set("multiple", 10);
            conf.Set("acl", new Dat(new CtrlType[0]));
            conf.Set("enableAcl", 1);
            conf.Set("timeOut", 3);

            for (var i = 0; i < 5; i++)
            {
                var myServer = new MyServer(conf, oneBind);

                myServer.Start();
                Assert.That(myServer.ThreadBaseKind, Is.EqualTo(ThreadBaseKind.Running));
                Assert.That(myServer.SockState(), Is.EqualTo(SockState.Bind));

                myServer.Stop();
                Assert.That(myServer.ThreadBaseKind, Is.EqualTo(ThreadBaseKind.After));
                Assert.That(myServer.SockState(), Is.EqualTo(SockState.Error));

                myServer.Dispose();
            }
        }
예제 #3
0
        public async Task <object> GetInvoker(IDictionary <string, object> input)
        {
            var service   = (string)input["service"];
            var callbacks = (IDictionary <string, object>)input["callbacks"];
            var server    = new MyServer(service, callbacks);

            return((Func <object, Task <object> >)(async(i) =>
            {
                var opts = (IDictionary <string, object>)i;
                var method = (string)opts["method"];
                var topic = opts.ContainsKey("topic") ? (string)opts["topic"] : null;
                var item = opts.ContainsKey("item") ? (string)opts["item"] : null;

                switch (method)
                {
                case "Register":
                    server.Register();
                    break;

                case "Unregister":
                    server.Unregister();
                    break;

                case "Advise":
                    await Task.Run(() => server.Advise(topic, item));
                    break;

                case "Disconnect":
                    server.Disconnect();
                    break;

                case "Pause":
                    server.Pause();
                    break;

                case "Resume":
                    server.Resume();
                    break;

                case "Dispose":
                    server.Dispose();
                    break;

                case "Service":
                    return server.Service;

                case "IsRegistered":
                    return server.IsRegistered;
                }

                return null;
            }));
        }
예제 #4
0
        public void DisposeShouldBeOverrideable()
        {
            // Arrange
            var sut = new MyServer() as TcpServer;

            // Pre-assert
            // Act
            sut.Dispose();
            // Assert
            var upcast = sut as MyServer;

            Expect(upcast.Disposed).To.Be.True();
        }
예제 #5
0
파일: server.cs 프로젝트: catataw/node-dde
        public async Task<object> GetInvoker(IDictionary<string, object> input)
        {
            var service = (string)input["service"];
            var callbacks = (IDictionary<string, object>)input["callbacks"];
            var server = new MyServer(service, callbacks);

            return (Func<object, Task<object>>)(async (i) =>
            {
                var opts = (IDictionary<string, object>)i;
                var method = (string)opts["method"];
                var topic = opts.ContainsKey("topic") ? (string)opts["topic"] : null;
                var item = opts.ContainsKey("item") ? (string)opts["item"] : null;

                switch (method)
                {
                    case "Register":
                        server.Register();
                        break;
                    case "Unregister":
                        server.Unregister();
                        break;
                    case "Advise":
                        await Task.Run(() => server.Advise(topic, item));
                        break;
                    case "Disconnect":
                        server.Disconnect();
                        break;
                    case "Pause":
                        server.Pause();
                        break;
                    case "Resume":
                        server.Resume();
                        break;
                    case "Dispose":
                        server.Dispose();
                        break;
                    case "Service":
                        return server.Service;
                    case "IsRegistered":
                        return server.IsRegistered;
                }

                return null;
            });
        }
예제 #6
0
        public void A001()
        {
            var ip = new Ip(IpKind.V4Localhost);
            var oneBind = new OneBind(ip, ProtocolKind.Tcp);
            var conf = TestUtil.CreateConf("OptionSample");
            conf.Set("protocolKind", (int) ProtocolKind.Tcp);
            conf.Set("port", 8888);
            conf.Set("multiple", 10);
            conf.Set("acl", new Dat(new CtrlType[0]));
            conf.Set("enableAcl", 1);
            conf.Set("timeOut", 3);

            var myServer = new MyServer(conf, oneBind);
            myServer.Start();
            for (var i = 10; i > 0; i--){
                Thread.Sleep(1);
            }
            myServer.Dispose();
        }
예제 #7
0
        public void multipleを超えたリクエストは破棄される事をcountで確認する()
        {
            const int    multiple = 5;
            const int    port     = 8889;
            const string address  = "127.0.0.1";
            var          ip       = new Ip(address);
            var          oneBind  = new OneBind(ip, ProtocolKind.Tcp);
            Conf         conf     = TestUtil.CreateConf("OptionSample");

            conf.Set("port", port);
            conf.Set("multiple", multiple);
            conf.Set("acl", new Dat(new CtrlType[0]));
            conf.Set("enableAcl", 1);
            conf.Set("timeOut", 3);

            var myServer = new MyServer(conf, oneBind);

            myServer.Start();

            var ar = new List <MyClient>();

            for (int i = 0; i < 20; i++)
            {
                var myClient = new MyClient(address, port);
                myClient.Connet();
                ar.Add(myClient);
            }
            Thread.Sleep(100);

            //multiple以上は接続できない
            Assert.That(myServer.Count(), Is.EqualTo(multiple));

            myServer.Stop();
            myServer.Dispose();

            foreach (var c in ar)
            {
                c.Dispose();
            }
        }
예제 #8
0
        public void A001()
        {
            var ip      = new Ip(IpKind.V4Localhost);
            var oneBind = new OneBind(ip, ProtocolKind.Tcp);
            var conf    = TestUtil.CreateConf("OptionSample");

            conf.Set("protocolKind", (int)ProtocolKind.Tcp);
            conf.Set("port", 8888);
            conf.Set("multiple", 10);
            conf.Set("acl", new Dat(new CtrlType[0]));
            conf.Set("enableAcl", 1);
            conf.Set("timeOut", 3);

            var myServer = new MyServer(conf, oneBind);

            myServer.Start();
            for (var i = 10; i > 0; i--)
            {
                Thread.Sleep(1);
            }
            myServer.Dispose();
        }
예제 #9
0
        public void multipleを超えたリクエストは破棄される事をcountで確認する()
        {
            const int multiple = 5;
            const int port = 8889;
            const string address = "127.0.0.1";
            var ip = new Ip(address);
            var oneBind = new OneBind(ip, ProtocolKind.Tcp);
            Conf conf = TestUtil.CreateConf("OptionSample");
            conf.Set("port", port);
            conf.Set("multiple", multiple);
            conf.Set("acl", new Dat(new CtrlType[0]));
            conf.Set("enableAcl", 1);
            conf.Set("timeOut", 3);

            var myServer = new MyServer(conf, oneBind);
            myServer.Start();

            var ar = new List<MyClient>();

            for (int i = 0; i < 20; i++){
                var myClient = new MyClient(address, port);
                myClient.Connet();
                ar.Add(myClient);
            }
            Thread.Sleep(100);

            //multiple以上は接続できない
            Assert.That(myServer.Count(), Is.EqualTo(multiple));

            myServer.Stop();
            myServer.Dispose();

            foreach (var c in ar){
                c.Dispose();
            }
        }