Пример #1
0
 string FindLeaks()
 {
     using (var visitor = new FindUnusedKeysVisitor())
     {
         using (var tr = _db.StartReadOnlyTransaction())
         {
             visitor.ImportAllKeys(tr);
             visitor.Iterate(tr);
             return(DumpUnseenKeys(visitor, " "));
         }
     }
 }
Пример #2
0
        public static void DumpLeaksCode(this IObjectDB db)
        {
            var leakedObjects      = new Dictionary <ulong, bool>();
            var leakedDictionaries = new Dictionary <ulong, bool>();

            using var tr      = db.StartReadOnlyTransaction();
            using var visitor = new FindUnusedKeysVisitor();
            visitor.ImportAllKeys(tr);
            visitor.Iterate(tr);
            foreach (var unseenKey in visitor.UnseenKeys())
            {
                var isDict   = unseenKey.Key[0] == 2;
                var isObject = unseenKey.Key[0] == 1;

                var r = new ByteArrayReader(unseenKey.Key);
                r.SkipUInt8();
                var oid = r.ReadVUInt64();

                if (isDict)
                {
                    leakedDictionaries.TryAdd(oid, false);
                }
                else if (isObject)
                {
                    leakedObjects.TryAdd(oid, false);
                }
            }

            WriteSplitIdList(leakedDictionaries.Keys, "dicts", 1000);
            WriteSplitIdList(leakedObjects.Keys, "objs", 1000);
        }
Пример #3
0
        public void CanInsertAndEnumerate()
        {
            var personBoris = new PersonSimple {
                TenantId = 1, Email = "*****@*****.**", Name = "Boris"
            };
            var personLubos = new PersonSimple {
                TenantId = 2, Email = "*****@*****.**", Name = "Lubos"
            };

            Func <IObjectDBTransaction, ISimplePersonTable> creator;

            using (var tr = _db.StartTransaction())
            {
                creator = tr.InitRelation <ISimplePersonTable>("Person");
                var personSimpleTable = creator(tr);
                personSimpleTable.Insert(personBoris);
                personSimpleTable.Insert(personLubos);
                tr.Commit();
            }
            using (var tr = _db.StartReadOnlyTransaction())
            {
                var personSimpleTable = creator(tr);
                var enumerator        = personSimpleTable.GetEnumerator();
                Assert.True(enumerator.MoveNext());
                var person = enumerator.Current;
                Assert.Equal(personBoris, person);
                Assert.True(enumerator.MoveNext());
                person = enumerator.Current;
                Assert.Equal(personLubos, person);
                Assert.False(enumerator.MoveNext(), "Only one Person should be evaluated");
            }
        }
Пример #4
0
 void AssertNoLeaksInDb()
 {
     using (var visitor = new FindUnusedKeysVisitor())
     {
         using (var tr = _db.StartReadOnlyTransaction())
         {
             visitor.ImportAllKeys(tr);
             visitor.Iterate(tr);
             Assert.Empty(visitor.UnseenKeys());
         }
     }
 }
Пример #5
0
        public void MaterializesInlineObjectProperty()
        {
            ulong oid;

            using (var tr = _db.StartTransaction())
            {
                oid = tr.Store(new Parent {
                    Child = new DerivedChild {
                        Id = 1
                    }
                });
                tr.Commit();
            }
            ReopenDb();
            _db.RegisterType(typeof(ParentNewVersion), "Parent");
            _db.RegisterType(typeof(DerivedChild));
            _db.RegisterType(typeof(Child));
            using (var tr = _db.StartReadOnlyTransaction())
            {
                var parent = (ParentNewVersion)tr.Get(oid);
                Assert.NotNull(parent.Child);
                Assert.Equal(1ul, parent.Child.Id);
            }
        }
Пример #6
0
        public static void DumpLeaks(this IObjectDB db)
        {
            using (var tr = db.StartReadOnlyTransaction())
                using (var visitor = new FindUnusedKeysVisitor())
                {
                    visitor.ImportAllKeys(tr);
                    var iterator = visitor.Iterate(tr);
                    visitor.DumpUnseenKeys();
                    var leakedObjects = new List <ulong>();
                    foreach (var unseenKey in visitor.UnseenKeys())
                    {
                        if (unseenKey.Key[0] == 1)
                        {
                            try
                            {
                                var r = new ByteArrayReader(unseenKey.Key);
                                r.SkipUInt8();
                                var oid = r.ReadVUInt64();
                                leakedObjects.Add(oid);
                            }
                            catch (Exception ex)
                            {
                                Console.WriteLine($"Leak found but error has occured while reading: {ex.Message}");
                            }
                        }
                    }

                    if (leakedObjects.Count > 0)
                    {
                        Console.WriteLine("--- OBJECTS ---");
                        var consoleVisitor = new ToConsoleVisitorNice();
                        foreach (var oid in leakedObjects)
                        {
                            iterator.IterateUnseenOid(oid, consoleVisitor);
                            Console.WriteLine("------");
                        }
                    }
                }
        }