Пример #1
0
        public void TestRpcSpeedTimeoutSuccess()
        {
            Console.WriteLine("SpeedTimeoutSuccess");
            var def = new RpcDefinition(1, "myfunc1", new List <RpcParamDef> {
                new RpcParamDef("param1", Value.MakeDouble(0.0))
            }, new List <RpcResultsDef> {
                new RpcResultsDef("result1", NtType.Double)
            });

            RemoteProcedureCall.CreateRpc("func1", RemoteProcedureCall.PackRpcDefinition(def), Callback1);
            Stopwatch sw = new Stopwatch();

            sw.Start();
            for (int i = 0; i < 10000; ++i)
            {
                long   call1Uid    = RemoteProcedureCall.CallRpc("func1", RemoteProcedureCall.PackRpcValues(new [] { Value.MakeDouble(i) }));
                byte[] call1Result = null;
                RemoteProcedureCall.GetRpcResult(true, call1Uid, TimeSpan.FromSeconds(1), out call1Result);
                Assert.That(call1Result, Is.Not.Null);
                var res = RemoteProcedureCall.UnpackRpcValues(call1Result, new [] { NtType.Double });
                Assert.AreNotEqual(0, res.Count, "RPC Result empty");
            }
            sw.Stop();
            Console.WriteLine(sw.Elapsed);
        }
Пример #2
0
        public void TestRpcLocalTimeoutFailure()
        {
            Console.WriteLine("LocalTimeoutFailure");
            var def = new RpcDefinition(1, "myfunc1", new List <RpcParamDef> {
                new RpcParamDef("param1", Value.MakeDouble(0.0))
            }, new List <RpcResultsDef> {
                new RpcResultsDef("result1", NtType.Double)
            });

            RemoteProcedureCall.CreateRpc("func1", RemoteProcedureCall.PackRpcDefinition(def), Callback1);

            Console.WriteLine("Calling RPC");

            long call1Uid = 585;

            Console.WriteLine("Waiting for RPC Result");
            TimeSpan  timeoutTime = TimeSpan.FromSeconds(1);
            Stopwatch sw          = Stopwatch.StartNew();

            byte[] result  = null;
            bool   success = RemoteProcedureCall.GetRpcResult(true, call1Uid, timeoutTime, out result);

            sw.Stop();
            Assert.That(success, Is.False);
            Assert.That(result, Is.Null);
            TimeSpan tolerance = TimeSpan.FromSeconds(0.25);

            Assert.That(sw.Elapsed < timeoutTime + tolerance);
            Assert.That(sw.Elapsed > timeoutTime - tolerance);
        }
Пример #3
0
        public void TestRpcLocalTimeoutSuccess()
        {
            Console.WriteLine("LocalTimeoutSuccess");
            var def = new RpcDefinition(1, "myfunc1", new List <RpcParamDef> {
                new RpcParamDef("param1", Value.MakeDouble(0.0))
            }, new List <RpcResultsDef> {
                new RpcResultsDef("result1", NtType.Double)
            });

            RemoteProcedureCall.CreateRpc("func1", RemoteProcedureCall.PackRpcDefinition(def), Callback1);

            Console.WriteLine("Calling RPC");

            long call1Uid = RemoteProcedureCall.CallRpc("func1", RemoteProcedureCall.PackRpcValues(new [] { Value.MakeDouble(2.0) }));

            Console.WriteLine("Waiting for RPC Result");
            byte[] result = null;
            RemoteProcedureCall.GetRpcResult(true, call1Uid, TimeSpan.FromSeconds(1), out result);
            Assert.That(result, Is.Not.Null);
            var call1Result = RemoteProcedureCall.UnpackRpcValues(result, new [] { NtType.Double });

            Assert.AreNotEqual(0, call1Result.Count, "RPC Result empty");

            Console.WriteLine(call1Result[0].ToString());
        }
Пример #4
0
        public void TestPolledRpc()
        {
            Console.WriteLine("TestPolledRpc");
            var def = new RpcDefinition(1, "myfunc1", new List <RpcParamDef> {
                new RpcParamDef("param1", Value.MakeDouble(0.0))
            }, new List <RpcResultsDef> {
                new RpcResultsDef("result1", NtType.Double)
            });

            RemoteProcedureCall.CreatePolledRpc("func1", def);

            Console.WriteLine("Calling RPC");

            long call1Uid = RemoteProcedureCall.CallRpc("func1", RemoteProcedureCall.PackRpcValues(new [] { Value.MakeDouble(2.0) }));

            RpcCallInfo info;
            bool        polled = RemoteProcedureCall.PollRpc(true, TimeSpan.FromSeconds(1), out info);

            Assert.That(polled, Is.True);

            IList <byte> toSendBack = Callback1(info.Name, info.Params, new ConnectionInfo());

            Assert.That(toSendBack.Count, Is.Not.EqualTo(0));

            RemoteProcedureCall.PostRpcResponse(info.RpcId, info.CallUid, toSendBack);

            Console.WriteLine("Waiting for RPC Result");
            byte[] result = null;
            RemoteProcedureCall.GetRpcResult(true, call1Uid, out result);
            var call1Result = RemoteProcedureCall.UnpackRpcValues(result, new [] { NtType.Double });

            Assert.AreNotEqual(0, call1Result.Count, "RPC Result empty");

            Console.WriteLine(call1Result[0].ToString());
        }
Пример #5
0
        public void TestRpcSpeed()
        {
            CoreMethods.SetLogger((level, file, line, message) =>
            {
                //Console.Error.WriteLine(message);
            }, 0);

            var def = new NtRpcDefinition(1, "myfunc1", new[] { new NtRpcParamDef("param1", RpcValue.MakeDouble(0.0)) }, new[] { new NtRpcResultDef("result1", NtType.Double) });

            RemoteProcedureCall.CreateRpc("func1", def, Callback1);



            Stopwatch sw = new Stopwatch();

            sw.Start();

            for (int i = 0; i < 10000; ++i)
            {
                uint   call1Uid    = RemoteProcedureCall.CallRpc("func1", RpcValue.MakeDouble(i));
                byte[] call1Result = RemoteProcedureCall.GetRpcResult(true, call1Uid);
                var    res         = RemoteProcedureCall.UnpackRpcValues(call1Result, NtType.Double);
                Assert.AreNotEqual(0, res.Count, "RPC Result empty");
            }
            sw.Stop();
            Console.WriteLine(sw.Elapsed);
        }
Пример #6
0
        public void TestPolledRpcAsync()
        {
            Console.WriteLine("TestPolledRpcAsync");
            var def = new RpcDefinition(1, "myfunc1", new List <RpcParamDef> {
                new RpcParamDef("param1", Value.MakeDouble(0.0))
            }, new List <RpcResultsDef> {
                new RpcResultsDef("result1", NtType.Double)
            });

            RemoteProcedureCall.CreatePolledRpc("func1", def);

            Console.WriteLine("Calling RPC");

            long call1Uid = RemoteProcedureCall.CallRpc("func1", RemoteProcedureCall.PackRpcValues(new [] { Value.MakeDouble(2.0) }));

            CancellationTokenSource source = new CancellationTokenSource();
            var  task      = RemoteProcedureCall.PollRpcAsync(source.Token);
            bool completed = task.Wait(TimeSpan.FromSeconds(1));

            if (!completed)
            {
                source.Cancel();
            }
            Assert.That(completed, Is.True);
            Assert.That(task.IsCompleted, Is.True);
            Assert.That(task.Result, Is.Not.Null);
            Assert.That(task.Result.HasValue);

            IList <byte> toSendBack = Callback1(task.Result.Value.Name, task.Result.Value.Params, new ConnectionInfo());

            Assert.That(toSendBack.Count, Is.Not.EqualTo(0));

            RemoteProcedureCall.PostRpcResponse(task.Result.Value.RpcId, task.Result.Value.CallUid, toSendBack);

            Console.WriteLine("Waiting for RPC Result");
            byte[] result = null;
            RemoteProcedureCall.GetRpcResult(true, call1Uid, out result);
            var call1Result = RemoteProcedureCall.UnpackRpcValues(result, new [] { NtType.Double });

            Assert.AreNotEqual(0, call1Result.Count, "RPC Result empty");

            Console.WriteLine(call1Result[0].ToString());
        }
Пример #7
0
        public void TestRpcAllTypes()
        {
            CoreMethods.SetLogger((level, file, line, message) =>
            {
                //Console.Error.WriteLine(message);
            }, 0);

            var def = new NtRpcDefinition(1, "myfunc1", new[]
            {
                new NtRpcParamDef("param1", RpcValue.MakeBoolean(true)),
                new NtRpcParamDef("param2", RpcValue.MakeBooleanArray(new[] { true, false })),
                new NtRpcParamDef("param3", RpcValue.MakeDouble(0.0)),
                new NtRpcParamDef("param4", RpcValue.MakeDoubleArray(new[] { 2.8, 6.87 })),
                new NtRpcParamDef("param5", RpcValue.MakeRaw(new byte[] { 52, 0, 89, 0, 0, 98 })),
                new NtRpcParamDef("param6", RpcValue.MakeString("NewString")),
                new NtRpcParamDef("param7", RpcValue.MakeStringArray(new[] { "String1", "String2" })),
            }, new[]
            {
                new NtRpcResultDef("result1", NtType.Boolean),
                new NtRpcResultDef("result2", NtType.BooleanArray),
                new NtRpcResultDef("result3", NtType.Double),
                new NtRpcResultDef("result4", NtType.DoubleArray),
                new NtRpcResultDef("result5", NtType.Raw),
                new NtRpcResultDef("result6", NtType.String),
                new NtRpcResultDef("result7", NtType.StringArray),
            });

            RemoteProcedureCall.CreateRpc("func1", def, Callback2);

            Console.WriteLine("Calling RPC");

            uint call1Uid = RemoteProcedureCall.CallRpc("func1", RpcValue.MakeBoolean(true), RpcValue.MakeBooleanArray(new[] { true, false }), RpcValue.MakeDouble(2.2), RpcValue.MakeDoubleArray(new[] { 2.8, 6.87 }),
                                                        RpcValue.MakeRaw(new byte[] { 52, 0, 89, 0, 0, 98 }), RpcValue.MakeString("NewString"), RpcValue.MakeStringArray(new[] { "String1", "String2" }));

            Console.WriteLine("Waiting for RPC Result");
            byte[] result      = RemoteProcedureCall.GetRpcResult(true, call1Uid);
            var    call1Result = RemoteProcedureCall.UnpackRpcValues(result, NtType.Boolean, NtType.BooleanArray, NtType.Double, NtType.DoubleArray, NtType.Raw, NtType.String, NtType.StringArray);

            Assert.AreNotEqual(0, call1Result.Count, "RPC Result empty");

            Console.WriteLine(call1Result[0].ToString());
        }
Пример #8
0
        public void TestRpcAllTypes()
        {
            Console.WriteLine("AllTypes");
            var def = new RpcDefinition(1, "myfunc1", new List <RpcParamDef>
            {
                new RpcParamDef("param1", Value.MakeBoolean(true)),
                new RpcParamDef("param2", Value.MakeBooleanArray(new[] { true, false })),
                new RpcParamDef("param3", Value.MakeDouble(0.0)),
                new RpcParamDef("param4", Value.MakeDoubleArray(new[] { 2.8, 6.87 })),
                new RpcParamDef("param5", Value.MakeRaw(new byte[] { 52, 0, 89, 0, 0, 98 })),
                new RpcParamDef("param6", Value.MakeString("NewString")),
                new RpcParamDef("param7", Value.MakeStringArray(new[] { "String1", "String2" })),
            }, new List <RpcResultsDef>
            {
                new RpcResultsDef("result1", NtType.Boolean),
                new RpcResultsDef("result2", NtType.BooleanArray),
                new RpcResultsDef("result3", NtType.Double),
                new RpcResultsDef("result4", NtType.DoubleArray),
                new RpcResultsDef("result5", NtType.Raw),
                new RpcResultsDef("result6", NtType.String),
                new RpcResultsDef("result7", NtType.StringArray),
            });

            RemoteProcedureCall.CreateRpc("func1", RemoteProcedureCall.PackRpcDefinition(def), Callback2);

            Console.WriteLine("Calling RPC");

            long call1Uid = RemoteProcedureCall.CallRpc("func1", RemoteProcedureCall.PackRpcValues(Value.MakeBoolean(true), Value.MakeBooleanArray(new[] { true, false }), Value.MakeDouble(2.2), Value.MakeDoubleArray(new[] { 2.8, 6.87 }),
                                                                                                   Value.MakeRaw(new byte[] { 52, 0, 89, 0, 0, 98 }), Value.MakeString("NewString"), Value.MakeStringArray(new[] { "String1", "String2" })));

            Console.WriteLine("Waiting for RPC Result");
            byte[] result = null;
            RemoteProcedureCall.GetRpcResult(true, call1Uid, out result);
            var call1Result = RemoteProcedureCall.UnpackRpcValues(result, NtType.Boolean, NtType.BooleanArray, NtType.Double, NtType.DoubleArray, NtType.Raw, NtType.String, NtType.StringArray);

            Assert.AreNotEqual(0, call1Result.Count, "RPC Result empty");

            Console.WriteLine(call1Result[0].ToString());
        }
Пример #9
0
        public void TestRpcLocalNonBlockingWithTimeout()
        {
            Console.WriteLine("LocalNonBlockingWithTimeout");
            var def = new RpcDefinition(1, "myfunc1", new List <RpcParamDef> {
                new RpcParamDef("param1", Value.MakeDouble(0.0))
            }, new List <RpcResultsDef> {
                new RpcResultsDef("result1", NtType.Double)
            });

            RemoteProcedureCall.CreateRpc("func1", RemoteProcedureCall.PackRpcDefinition(def), Callback1);

            Console.WriteLine("Calling RPC");

            long call1Uid = 585;

            Console.WriteLine("Waiting for RPC Result");
            byte[] result  = null;
            bool   success = RemoteProcedureCall.GetRpcResult(false, call1Uid, TimeSpan.FromSeconds(1), out result);

            Assert.That(success, Is.False);
            Assert.That(result, Is.Null);
        }
Пример #10
0
        public void TestRpcLocal()
        {
            CoreMethods.SetLogger((level, file, line, message) =>
            {
                //Console.Error.WriteLine(message);
            }, 0);

            var def = new NtRpcDefinition(1, "myfunc1", new[] { new NtRpcParamDef("param1", RpcValue.MakeDouble(0.0)) }, new[] { new NtRpcResultDef("result1", NtType.Double) });

            RemoteProcedureCall.CreateRpc("func1", def, Callback1);

            Console.WriteLine("Calling RPC");

            uint call1Uid = RemoteProcedureCall.CallRpc("func1", RpcValue.MakeDouble(2.0));

            Console.WriteLine("Waiting for RPC Result");
            byte[] result      = RemoteProcedureCall.GetRpcResult(true, call1Uid);
            var    call1Result = RemoteProcedureCall.UnpackRpcValues(result, NtType.Double);

            Assert.AreNotEqual(0, call1Result.Count, "RPC Result empty");

            Console.WriteLine(call1Result[0].ToString());
        }