Exemple #1
0
        public static void TestContractB_4_Async(string CONF_SRC)
        {
            var conf = LaconicConfiguration.CreateFromString(CONF_SRC);

            using (var app = new ServiceBaseApplication(null, conf.Root))
            {
                var cl = new TestContractBClient(App.ConfigRoot.AttrByName("cs").Value);

                Assert.AreEqual("Felix", cl.GetName()); //alloc first

                //Testing overloaded calls via CallSlot
                Assert.AreEqual("Felix", cl.Async_GetName().GetValue <string>());
                Assert.AreEqual("Felix23", cl.Async_GetName(23).GetValue <string>());
                Assert.AreEqual("Felix42", cl.Async_GetName(42).GetValue <string>());
                Assert.AreEqual("Felix", cl.Async_GetName().GetValue <string>());

                dumpBindingTransports(cl.Binding);
            }
        }
Exemple #2
0
        public static void TestContractB_4_AsyncReactor(string CONF_SRC)
        {
            var conf = LaconicConfiguration.CreateFromString(CONF_SRC);

            using (var app = new ServiceBaseApplication(null, conf.Root))
            {
                var cl = new TestContractBClient(App.ConfigRoot.AttrByName("cs").Value);

                var reactor = new CallReactor(
                    new Call(cl.Async_GetName(), (r, c) => Assert.AreEqual("Felix", c.CallSlot.GetValue <string>())),
                    new Call(cl.Async_GetName(23), (r, c) => Assert.AreEqual("Felix23", c.CallSlot.GetValue <string>())),
                    new Call(cl.Async_GetName(42), (r, c) => Assert.AreEqual("Felix42", c.CallSlot.GetValue <string>())),
                    new Call(cl.Async_GetName(2, DateTime.Now), (r, c) => Assert.IsTrue(c.CallSlot.GetValue <string>().StartsWith("Felix2")))
                    );

                reactor.Wait();

                dumpBindingTransports(cl.Binding);
                Assert.IsTrue(reactor.Finished);
            }
        }
Exemple #3
0
        public static void TASK_TestContractB_4_Parallel(string CONF_SRC, bool threadSafe)
        {
            const int CNT = 10000;


            var conf = LaconicConfiguration.CreateFromString(CONF_SRC);

            using (var app = new ServiceBaseApplication(null, conf.Root))
            {
                //Use the same client.....
                var cl = new TestContractBClient(App.ConfigRoot.AttrByName(threadSafe?"cs":"cs2").Value);

                Assert.AreEqual("Felix1223", cl.GetName(1223)); //alloc server

                var set   = new HashSet <int>();
                var watch = System.Diagnostics.Stopwatch.StartNew();

                //.....for making many parallel calls
                System.Threading.Tasks.Parallel.For(0, CNT,
                                                    (i, loop) =>
                {
                    var id = System.Threading.Thread.CurrentThread.ManagedThreadId;

                    lock (set)
                        set.Add(id);

                    //Testing overloaded calls USING asTASK property
                    var result = cl.Async_GetName(i).AsTask.Result.GetValue <string>();
                    Assert.AreEqual("Felix{0}".Args(i), result);
                });
                var elps = watch.ElapsedMilliseconds;

                Console.WriteLine("Parallel Glue Test made {0} calls in {1} ms at {2} call/sec and was done by these threads:".Args(CNT, elps, CNT / (elps / 1000d)));
                dumpBindingTransports(cl.Binding);
                var cnt = 0;
                foreach (var id in set)
                {
                    Console.Write(id + ", ");
                    cnt++;
                }
                Console.WriteLine(cnt + " total");
            }
        }
Exemple #4
0
        public static void TestContractB_4_AsyncReactor(string CONF_SRC)
        {
            var conf = LaconicConfiguration.CreateFromString(CONF_SRC);
            using( var app = new ServiceBaseApplication(null, conf.Root))
            {
                var cl = new TestContractBClient(App.ConfigRoot.AttrByName("cs").Value);

                var reactor = new CallReactor(
                                new Call( cl.Async_GetName(),   (r,c)=> Assert.AreEqual( "Felix", c.CallSlot.GetValue<string>()   ) ),
                                new Call( cl.Async_GetName(23), (r,c)=> Assert.AreEqual( "Felix23", c.CallSlot.GetValue<string>() ) ),
                                new Call( cl.Async_GetName(42), (r,c)=> Assert.AreEqual( "Felix42", c.CallSlot.GetValue<string>() ) ),
                                new Call( cl.Async_GetName(2, DateTime.Now), (r,c)=> Assert.IsTrue( c.CallSlot.GetValue<string>().StartsWith("Felix2") ) )
                              );

                reactor.Wait();

                dumpBindingTransports( cl.Binding );
                Assert.IsTrue(reactor.Finished);
            }
        }
Exemple #5
0
        public static void TestContractB_4_Async(string CONF_SRC)
        {
            var conf = LaconicConfiguration.CreateFromString(CONF_SRC);
            using( var app = new ServiceBaseApplication(null, conf.Root))
            {
                var cl = new TestContractBClient(App.ConfigRoot.AttrByName("cs").Value);

                Assert.AreEqual( "Felix", cl.GetName());//alloc first

                //Testing overloaded calls via CallSlot
                Assert.AreEqual( "Felix",   cl.Async_GetName()  .GetValue<string>());
                Assert.AreEqual( "Felix23", cl.Async_GetName(23).GetValue<string>());
                Assert.AreEqual( "Felix42", cl.Async_GetName(42).GetValue<string>());
                Assert.AreEqual( "Felix",   cl.Async_GetName()  .GetValue<string>());

                dumpBindingTransports( cl.Binding );
            }
        }
Exemple #6
0
        public static void TASK_TestContractB_4_Parallel(string CONF_SRC, bool threadSafe)
        {
            const int CNT = 10000;

            var conf = LaconicConfiguration.CreateFromString(CONF_SRC);
            using( var app = new ServiceBaseApplication(null, conf.Root))
            {
                //Use the same client.....
                var cl = new TestContractBClient(App.ConfigRoot.AttrByName(threadSafe?"cs":"cs2").Value);

                Assert.AreEqual( "Felix1223", cl.GetName(1223));//alloc server

                var set = new HashSet<int>();
                var watch = System.Diagnostics.Stopwatch.StartNew();

                //.....for making many parallel calls
                System.Threading.Tasks.Parallel.For(0, CNT,
                                              (i, loop)=>
                                              {
                                                var id = System.Threading.Thread.CurrentThread.ManagedThreadId;

                                                lock(set)
                                                 set.Add( id );

                                                //Testing overloaded calls USING asTASK property
                                                var result = cl.Async_GetName(i).AsTask.Result.GetValue<string>();
                                                Assert.AreEqual( "Felix{0}".Args(i), result);
                                              });
                var elps = watch.ElapsedMilliseconds;

                Console.WriteLine("Parallel Glue Test made {0} calls in {1} ms at {2} call/sec and was done by these threads:".Args(CNT, elps, CNT / (elps / 1000d)) );
                dumpBindingTransports( cl.Binding );
                var cnt = 0;
                foreach(var id in set)
                {
                   Console.Write( id+", " );
                   cnt++;
                }
                Console.WriteLine( cnt + " total");

            }
        }