コード例 #1
0
        public void Glue_SerializeDeserialize_WithHeadersWithChineseText()
        {
            var hdr = "<a><remote name='久有归天愿'/></a>";

            var frm1 = new WireFrame(123, false, FID.Generate(), hdr);


            var utfLen = WireFrame.HEADERS_ENCODING.GetByteCount(hdr);

            Aver.IsTrue(utfLen > hdr.Length);
            Console.WriteLine("{0} has {1} byte len and {2} char len".Args(hdr, utfLen, hdr.Length));

            Aver.AreEqual(WireFrame.FRAME_LENGTH + utfLen, frm1.Length);

            var ms = new MemoryStream();

            Aver.AreEqual(WireFrame.FRAME_LENGTH + utfLen, frm1.Serialize(ms));

            ms.Position = 0;

            var frm2 = new WireFrame(ms);

            Aver.IsTrue(frm1.Type == frm2.Type);
            Aver.AreEqual(frm1.RequestID, frm2.RequestID);
            Aver.AreEqual(frm1.OneWay, frm2.OneWay);

            Aver.AreEqual(frm1.Length, frm2.Length);
            Aver.AreEqual(frm1.Format, frm2.Format);
            Aver.AreEqual(frm1.HeadersContent, frm2.HeadersContent);

            Aver.IsFalse(frm2.OneWay);

            Aver.AreEqual("久有归天愿", frm2.Headers["remote"].AttrByName("name").Value);
        }
コード例 #2
0
ファイル: Sink.cs プロジェクト: wangchengqun/azos
 protected Sink(ISinkOwner owner, string name, int order) : base(owner)
 {
     m_Levels = new Filters.LevelsList();
     Name     = name.IsNullOrWhiteSpace() ? "{0}.{1}".Args(GetType().Name, FID.Generate().ID.ToString("X")) : name;
     m_Order  = order;
     ((ISinkOwnerRegistration)owner).Register(this);
 }
コード例 #3
0
        public void HeartBeat_SerializeDeserialize()
        {
            var frm1 = new WireFrame(FrameType.Heartbeat, 123, false, FID.Generate());

            Aver.IsTrue(frm1.OneWay);
            Aver.AreEqual(WireFrame.FRAME_LENGTH, frm1.Length);

            var ms = new MemoryStream();

            Aver.AreEqual(WireFrame.FRAME_LENGTH, frm1.Serialize(ms));

            ms.Position = 0;

            var frm2 = new WireFrame(ms);

            Aver.IsTrue(frm1.Type == frm2.Type);
            Aver.AreEqual(frm1.RequestID, frm2.RequestID);
            Aver.AreEqual(frm1.OneWay, frm2.OneWay);

            Aver.AreEqual(frm1.Length, frm2.Length);
            Aver.AreEqual(frm1.Format, frm2.Format);
            Aver.AreEqual(frm1.HeadersContent, frm2.HeadersContent);

            Aver.IsTrue(frm2.OneWay);
        }
コード例 #4
0
        public void Glue_SerializeDeserialize_WithHeadersWithLatinText()
        {
            var hdr = "<a><remote name='zzz'/></a>";//Latin only chars

            var frm1 = new WireFrame(123, false, FID.Generate(), hdr);


            var utfLen = WireFrame.HEADERS_ENCODING.GetByteCount(hdr);

            Aver.IsTrue(utfLen == hdr.Length);

            Aver.AreEqual(WireFrame.FRAME_LENGTH + hdr.Length, frm1.Length);

            var ms = new MemoryStream();

            Aver.AreEqual(WireFrame.FRAME_LENGTH + hdr.Length, frm1.Serialize(ms));

            ms.Position = 0;

            var frm2 = new WireFrame(ms);

            Aver.IsTrue(frm1.Type == frm2.Type);
            Aver.AreEqual(frm1.RequestID, frm2.RequestID);
            Aver.AreEqual(frm1.OneWay, frm2.OneWay);

            Aver.AreEqual(frm1.Length, frm2.Length);
            Aver.AreEqual(frm1.Format, frm2.Format);
            Aver.AreEqual(frm1.HeadersContent, frm2.HeadersContent);

            Aver.IsFalse(frm2.OneWay);

            Aver.AreEqual("zzz", frm2.Headers["remote"].AttrByName("name").Value);
        }
コード例 #5
0
ファイル: FIDTests.cs プロジェクト: ame89/nfx
        public void FID4()
        {
            var CNT = 100000;

            var tasks = new List <Task>();
            var sets  = new List <FID>();

            for (var c = 0; c < 100; c++)
            {
                tasks.Add(Task.Factory.StartNew(() =>
                {
                    var set = new FID[CNT];
                    for (var i = 0; i < CNT; i++)
                    {
                        set[i] = FID.Generate();
                    }

                    lock (sets)
                        sets.AddRange(set);
                }));
            }

            Task.WaitAll(tasks.ToArray());
            Console.WriteLine("Analyzing {0:n} FIDs", sets.Count);
            Assert.IsTrue(sets.Distinct().Count() == sets.Count());
        }
コード例 #6
0
        public void Echo_SerializeDeserialize()
        {
            var frm1 = new WireFrame(FrameType.Echo, 123, true, FID.Generate());

            Assert.IsFalse(frm1.OneWay);
            Assert.AreEqual(WireFrame.FRAME_LENGTH, frm1.Length);

            var ms = new MemoryStream();

            Assert.AreEqual(WireFrame.FRAME_LENGTH, frm1.Serialize(ms));

            ms.Position = 0;

            var frm2 = new WireFrame(ms);

            Assert.AreEqual(frm1.Type, frm2.Type);
            Assert.AreEqual(frm1.RequestID, frm2.RequestID);
            Assert.AreEqual(frm1.OneWay, frm2.OneWay);

            Assert.AreEqual(frm1.Length, frm2.Length);
            Assert.AreEqual(frm1.Format, frm2.Format);
            Assert.AreEqual(frm1.HeadersContent, frm2.HeadersContent);

            Assert.IsFalse(frm2.OneWay);
        }
コード例 #7
0
        public void FID4(int CNT, int tCNT)
        {
            var tasks = new List <Task>();
            var sets  = new List <FID>();
            var bag   = new ConcurrentBag <FID[]>();

            for (var c = 0; c < tCNT; c++)
            {
                tasks.Add(Task.Factory.StartNew(() =>
                {
                    var set = new FID[CNT];

                    for (var i = 0; i < CNT; i++)
                    {
                        set[i] = FID.Generate();
                    }

                    bag.Add(set);
                }));
            }

            Task.WaitAll(tasks.ToArray());

            foreach (var set in bag)
            {
                sets.AddRange(set);
            }


            Console.WriteLine("Analyzing {0:n} FIDs", sets.Count);
            Assert.IsTrue(sets.AsParallel().Distinct().Count() == sets.Count());
            Console.WriteLine("Done. All ok");
        }
コード例 #8
0
        private void btnFID_Click(object sender, EventArgs e)
        {
            var cnt = tbCount.Text.AsInt();

            var w = Stopwatch.StartNew();

            if (chkParallel.Checked)
            {
                Parallel.For(0, cnt, (i) =>
                {
                    FID.Generate();
                });
            }
            else
            {
                for (var i = 0; i < cnt; i++)
                {
                    FID.Generate();
                }
            }

            w.Stop();


            Text = "FID {0:n2} gened in {1:n2} msec at {2:n2} ops/sec".Args(cnt, w.ElapsedMilliseconds, cnt / (w.ElapsedMilliseconds / 1000d));
        }
コード例 #9
0
 protected AspectBase(IConfigSectionNode config)
 {
     ConfigAttribute.Apply(this, config);
     if (m_Name.IsNullOrWhiteSpace())
     {
         m_Name = "{0}-{1}".Args(GetType().Name, FID.Generate());
     }
 }
コード例 #10
0
ファイル: Connection.cs プロジェクト: azist/azos
 internal Connection(ServerNode server)
 {
     m_Server       = server;
     m_Id           = FID.Generate();
     m_StartDateUTC = server.App.TimeSource.UTCNow;
     connectSocket();
     Thread.MemoryBarrier();
 }
コード例 #11
0
        private void button1_Click(object sender, EventArgs e)
        {
            var cnt = tbCount.Text.AsInt();

            var bag = new ConcurrentBag <FID>();

            if (chkParallel.Checked)
            {
                Parallel.For(0, cnt, (i) =>
                {
                    bag.Add(FID.Generate());
                });
            }
            else
            {
                for (var i = 0; i < cnt; i++)
                {
                    bag.Add(FID.Generate());
                }
            }


            var sb = new StringBuilder();
            var c  = 0;

            foreach (var id in bag)
            {
                sb.AppendLine("{0}:    {1}  ->  {2}".Args(c, id.ID, id));
                c++;
                if (c > 10000)
                {
                    sb.AppendLine("......more......");
                    break;
                }
            }

            //Uncomment to cause duplicates
            //var v =bag.FirstOrDefault();
            //bag.Add(v);
            //bag.Add(v);//duplicate


            if (bag.Count == bag.Distinct().Count())
            {
                sb.Insert(0, "No Duplicates in the set of {0:n2}\r\n".Args(bag.Count));
            }
            else
            {
                sb.Insert(0, "DUPLICATES!!!!!!!!!!!!! in the set of {0:n2}\r\n\r\n\r\n".Args(bag.Count));
            }

            tbDump.Text = sb.ToString();
        }
コード例 #12
0
ファイル: FIDTests.cs プロジェクト: azist/azos
        public void FID3()
        {
            var CNT = 0xffff * 2;

            for (var c = 0; c < 37; c++)
            {
                var set1 = new FID[CNT];
                var set2 = new FID[CNT];
                for (var i = 0; i < CNT; i++)
                {
                    set1[i] = FID.Generate();
                    set2[i] = FID.Generate();
                }

                Aver.IsFalse(set1.Intersect(set2).Any());
                "{0}: Set of {1} FIDs no intersection".SeeArgs(c, CNT);
            }
        }
コード例 #13
0
        public void FID3()
        {
            var CNT = 500000;

            for (var c = 0; c < 100; c++)
            {
                var set1 = new FID[CNT];
                var set2 = new FID[CNT];
                for (var i = 0; i < CNT; i++)
                {
                    set1[i] = FID.Generate();
                    set2[i] = FID.Generate();
                }

                Assert.IsFalse(set1.Intersect(set2).Any());
                Console.WriteLine("{0}: Set of {1} FIDs no intersection", c, CNT);
            }
        }
コード例 #14
0
 public void getKeyValuePairsTest(int count)
 {
     using (var test = new PrefixTree <int>(m_Pile))
     {
         Console.WriteLine(DateTime.Now);
         for (int i = 0; i < count; i++)
         {
             test[FID.Generate().ToString()] = i;
         }
         Console.WriteLine(DateTime.Now);
         List <KeyValuePair <string, int> > keyValuePairs = new List <KeyValuePair <string, int> >(test.getKeyValuePairs());
         Console.WriteLine(keyValuePairs.Count);
         Console.WriteLine(DateTime.Now);
         Console.WriteLine(new List <String>(test.Keys).Count);
         Console.WriteLine(DateTime.Now);
     }
     Console.WriteLine(m_Pile.ObjectCount);
     Console.WriteLine(DateTime.Now);
 }
コード例 #15
0
 public static ulong GenerateId() => FID.Generate().ID;
コード例 #16
0
        public void PutValueSimpleTest(int count)
        {
            string[] keys = new string[count];
            var      rnd  = new Random();
            DateTime start;
            DateTime end;

            using (var test = new PrefixTree <int>(m_Pile))
            {
                start = DateTime.Now;
                Console.WriteLine(start);
                for (int i = 0; i < count; i++)
                {
                    keys[i] = FID.Generate().ToString();
                    test.Put(keys[i], i);
                }
                end = DateTime.Now;
                Console.WriteLine(end);
                Console.WriteLine(end.Subtract(start));
                if (count < 11)
                {
                    foreach (string key in test.Keys)
                    {
                        Console.Write(key);
                        Console.Write(" = ");
                        Console.WriteLine(test[key]);
                    }
                    Console.WriteLine(DateTime.Now);
                    Console.WriteLine(test[keys[rnd.Next(count)]]);
                    Console.WriteLine(DateTime.Now);
                }
            }
            using (var test1 = new PrefixTree <int>(m_Pile))
            {
                start = DateTime.Now;
                Console.WriteLine(start);
                for (int i = 0; i < count; i++)
                {
                    try
                    {
                        test1[keys[i]] = i;
                    }
                    catch (Exception ex)
                    {
                        Console.Write("Error: ");
                        Console.WriteLine(keys[i]);
                        Console.WriteLine(test1.Count);
                    }
                }
                end = DateTime.Now;
                Console.WriteLine(end);
                Console.WriteLine(end.Subtract(start));
                Console.WriteLine(test1[keys[rnd.Next(count)]]);
                Console.WriteLine(DateTime.Now);
            }
            start = DateTime.Now;
            Console.WriteLine(start);
            Dictionary <string, int> test2 = new Dictionary <string, int>();

            for (int i = 0; i < count; i++)
            {
                try
                {
                    test2[keys[i]] = i;
                }
                catch (Exception ex)
                {
                    Console.Write("Error: ");
                    Console.WriteLine(keys[i]);
                    Console.WriteLine(test2.Count);
                }
            }
            end = DateTime.Now;
            Console.WriteLine(end);
            Console.WriteLine(end.Subtract(start));
            Console.WriteLine(DateTime.Now);
            Console.WriteLine(test2[keys[rnd.Next(count)]]);
            Console.WriteLine(DateTime.Now);
            start = DateTime.Now;
            Console.WriteLine(start);
            var test3 = new SortedDictionary <string, int>(test2);

            end = DateTime.Now;
            Console.WriteLine(end);
            Console.WriteLine(test3[keys[rnd.Next(count)]]);
            Console.WriteLine(end.Subtract(start));
        }
コード例 #17
0
ファイル: CacheTest.cs プロジェクト: mjaric/nfx
        public void T190_FID_PutGetCorrectness(int cnt, int tbls)
        {
            var sw    = new System.Diagnostics.Stopwatch();
            var dicts = new ConcurrentDictionary <FID, string> [tbls];

            for (var i = 0; i < dicts.Length; i++)
            {
                dicts[i] = new ConcurrentDictionary <FID, string>();
            }
            var notInserted = 0;

            using (var cache = makeCache())
            {
                sw.Start();
                Parallel.For(0, cnt, (i) =>
                {
                    var t   = i % tbls;
                    var tbl = cache.GetOrCreateTable <FID>(t.ToString());

                    var key  = FID.Generate();
                    var data = NFX.Parsing.NaturalTextGenerator.Generate(0);

                    var pr = tbl.Put(key, data);
                    dicts[t].TryAdd(key, data);
                    if (pr != PutResult.Inserted)
                    {
                        Interlocked.Increment(ref notInserted);
                    }
                });


                var elapsed  = sw.ElapsedMilliseconds;
                var inserted = cnt - notInserted;
                Console.WriteLine("Population of {0:n0} in {1:n0} msec at {2:n0}ops/sec", cnt, elapsed, cnt / (elapsed / 1000d));
                Console.WriteLine("  inserted: {0:n0} ({1:n0}%)", inserted, (int)(100 * (inserted / (double)cnt)));
                Console.WriteLine("  not-inserted: {0:n0} ({1:n0}%)", notInserted, (int)(100 * (notInserted) / (double)cnt));
                sw.Restart();

                var found    = 0;
                var notfound = 0;

                for (var i = 0; i < tbls; i++)
                {
                    var tbl  = cache.GetOrCreateTable <FID>(i.ToString());
                    var dict = dicts[i];

                    Parallel.ForEach(dict, (kvp) =>
                    {
                        var data = tbl.Get(kvp.Key);
                        if (data != null)
                        {
                            Assert.AreEqual(data, kvp.Value);
                            Interlocked.Increment(ref found);
                        }
                        else
                        {
                            Interlocked.Increment(ref notfound);
                        }
                    });
                }

                elapsed = sw.ElapsedMilliseconds;
                var totalGot = found + notfound;
                Console.WriteLine("Got of {0:n0} in {1:n0} msec at {2:n0}ops/sec", totalGot, elapsed, totalGot / (elapsed / 1000d));
                Console.WriteLine("  found: {0:n0} ({1:n0}%)", found, (int)(100 * (found / (double)totalGot)));
                Console.WriteLine("  not-found: {0:n0} ({1:n0}%)", notfound, (int)(100 * (notfound) / (double)totalGot));

                Assert.IsTrue((found / (double)inserted) > 0.9d);
            }//using cache
        }
コード例 #18
0
 /// <summary>
 /// Constructs new message and allocates unique ID
 /// </summary>
 protected Msg()
 {
     m_ID = FID.Generate();
 }