Пример #1
0
        public void T_03_Update()
        {
            var BIN = new byte[] { 0x00, 0x79, 0x14 };

            using (var client = new MongoClient("My Test"))
            {
                var db = client.DefaultLocalServer["db1"];

                db["t1"].Drop();

                var t1 = db["t1"];

                var row = new TestRow()
                {
                    _id = 1,

                    String1 = "Mudaker",
                };

                var rc  = new NFX.Serialization.BSON.RowConverter();
                var doc = rc.RowToBSONDocument(row, "A");
                Aver.AreEqual(1, t1.Insert(doc).TotalDocumentsAffected);

                var updateResult = t1.Update
                                   (
                    new NFX.DataAccess.MongoDB.Connector.UpdateEntry
                    (
                        Query.ID_EQ_Int32(1),
                        new Update("{'String1': '$$VAL'}", true, new TemplateArg("VAL", BSONElementType.String, "makaka")),
                        false,
                        false
                    )
                                   );

                var got = db["t1"].FindOne(Query.ID_EQ_Int32(1));
                Aver.IsNotNull(got);

                var row1 = new TestRow();
                rc.BSONDocumentToRow(got, row1, "A");

                Aver.AreEqual("makaka", row1.String1);
            }
        }
Пример #2
0
        public void T_01_Insert()
        {
            var BIN = new byte[] { 0x00, 0x79, 0x14 };

            using (var client = new MongoClient("My Test"))
            {
                var db = client.DefaultLocalServer["db1"];

                db["t1"].Drop();

                var t1 = db["t1"];

                var row = new TestRow()
                {
                    _id = 1,

                    String1  = "Mudaker",
                    String2  = null,
                    Date1    = new DateTime(1980, 07, 12, 10, 13, 27, DateTimeKind.Utc),
                    Date2    = null,
                    Bool1    = true,
                    Bool2    = null,
                    Guid1    = new Guid("{9195F7DB-FE21-4BB2-B006-2496F4E24D14}"),
                    Guid2    = null,
                    Gdid1    = new NFX.DataAccess.Distributed.GDID(0, 12345),
                    Gdid2    = null,
                    Float1   = 127.0123f,
                    Float2   = null,
                    Double1  = 122345.012d,
                    Double2  = null,
                    Decimal1 = 1234567.098M,
                    Decimal2 = null,
                    Amount1  = new Amount("din", 123.11M),
                    Amount2  = null,
                    Bytes1   = BIN,
                    Bytes2   = null,

                    Byte1   = 23,
                    SByte1  = -3,
                    Short1  = -32761,
                    UShort1 = 65535,
                    Int1    = 4324,
                    Uint1   = 42345,
                    Long1   = 993,
                    ULong1  = 8829383762,
                    ETest1  = ETest.Two,
                    EFlags1 = EFlags.First | EFlags.Third,

                    Byte2   = null,
                    SByte2  = null,
                    Short2  = null,
                    UShort2 = null,
                    Int2    = null,
                    Uint2   = null,
                    Long2   = null,
                    ULong2  = null,
                    ETest2  = null,
                    EFlags2 = null
                };

                var rc  = new NFX.Serialization.BSON.RowConverter();
                var doc = rc.RowToBSONDocument(row, "A");
                Aver.AreEqual(1, t1.Insert(doc).TotalDocumentsAffected);

                var got = db["t1"].FindOne(Query.ID_EQ_Int32(1));
                Aver.IsNotNull(got);

                var row1 = new TestRow();
                rc.BSONDocumentToRow(got, row1, "A");

                Aver.AreObjectsEqual(row, row1);
            }
        }
Пример #3
0
        public void T_02_Update_Parallel()
        {
            const int CNT = 11973;
            var       BIN = new byte[] { 0x00, 0x79, 0x14 };

            using (var client = new MongoClient("My Test"))
            {
                var db = client.DefaultLocalServer["db1"];

                db["t1"].Drop();

                var t1 = db["t1"];

                var rows = new TestRow[CNT];

                var rc = new NFX.Serialization.BSON.RowConverter();

                var sw = new Stopwatch();

                sw.Start();

                Parallel.For(0, CNT, i =>
                {
                    var row = new TestRow()
                    {
                        _id = i,

                        String1  = "Mudaker",
                        String2  = null,
                        Date1    = new DateTime(1980, 07, 12, 10, 13, 27, DateTimeKind.Utc),
                        Date2    = null,
                        Bool1    = true,
                        Bool2    = null,
                        Guid1    = new Guid("{9195F7DB-FE21-4BB2-B006-2496F4E24D14}"),
                        Guid2    = null,
                        Gdid1    = new NFX.DataAccess.Distributed.GDID(0, 12345),
                        Gdid2    = null,
                        Float1   = 127.0123f,
                        Float2   = null,
                        Double1  = 122345.012d,
                        Double2  = null,
                        Decimal1 = 1234567.098M,
                        Decimal2 = null,
                        Amount1  = new Amount("din", 123.11M),
                        Amount2  = null,
                        Bytes1   = BIN,
                        Bytes2   = null,

                        Byte1   = 23,
                        SByte1  = -3,
                        Short1  = -32761,
                        UShort1 = 65535,
                        Int1    = 4324,
                        Uint1   = 42345,
                        Long1   = 993,
                        ULong1  = 8829383762,
                        ETest1  = ETest.Two,
                        EFlags1 = EFlags.First | EFlags.Third,

                        Byte2   = null,
                        SByte2  = null,
                        Short2  = null,
                        UShort2 = null,
                        Int2    = null,
                        Uint2   = null,
                        Long2   = null,
                        ULong2  = null,
                        ETest2  = null,
                        EFlags2 = null
                    };

                    rows[i] = row;

                    var doc = rc.RowToBSONDocument(row, "A");
                    Aver.AreEqual(1, t1.Insert(doc).TotalDocumentsAffected);
                });
                sw.Stop();
                Console.WriteLine("{0:N0} row inserted in {1:N3} sec on {2:N0} ops/sec", CNT, sw.Elapsed.TotalSeconds, CNT / sw.Elapsed.TotalSeconds);

                sw.Restart();
                Parallel.For(0, CNT, i => {
                    var row     = rows[i];
                    row.String1 = "makaka" + i.ToString();
                    row.Int1    = 9789 + (i * 100);

                    var doc = rc.RowToBSONDocument(row, "A");

                    var r = t1.Save(doc);
                    Aver.AreEqual(1, r.TotalDocumentsAffected);
                    Aver.AreEqual(1, r.TotalDocumentsUpdatedAffected);
                    Aver.IsNull(r.WriteErrors);
                });
                sw.Stop();
                Console.WriteLine("{0:N0} row updated in {1:N3} sec on {2:N0} ops/sec", CNT, sw.Elapsed.TotalSeconds, CNT / sw.Elapsed.TotalSeconds);

                sw.Restart();
                var RCNT = CNT * 3;
                Parallel.For(0, RCNT, i => {
                    var j   = i % CNT;
                    var got = db["t1"].FindOne(Query.ID_EQ_Int32(j));
                    Aver.IsNotNull(got);

                    var row1 = new TestRow();
                    rc.BSONDocumentToRow(got, row1, "A");

                    Aver.AreObjectsEqual(rows[j], row1);
                });
                sw.Stop();
                Console.WriteLine("{0:N0} row red in {1:N3} sec on {2:N0} ops/sec", RCNT, sw.Elapsed.TotalSeconds, RCNT / sw.Elapsed.TotalSeconds);
            }
        }