Ejemplo n.º 1
0
        public void SubscriberInititializes()
        {
            _testName = System.Reflection.MethodInfo.GetCurrentMethod().Name.GetHashCode().ToString();

            using (var fLock = new ManagedFileLock(_testName))
            {
                Cleanup();

                using (var pdb = new Database<int, MockClassA>(_testName + ".publisher" + ".database", "Id")
                    .WithPublishing("Test", new FilePublisher<int, MockClassA>(Path.Combine(Environment.CurrentDirectory, _testName))))
                {
                    pdb.Load();

                    Assert.IsTrue(Directory.Exists(Path.Combine(Environment.CurrentDirectory, _testName)));

                    using (var sdb = new Database<int, MockClassA>(_testName + ".subscriber" + ".database", "Id")
                        .WithSubscription("Test", new FileSubscriber<int, MockClassA>(Path.Combine(Environment.CurrentDirectory, _testName), new TimeSpan(0, 0, 0, 0, 500))))
                    {
                        sdb.Load();

                        Assert.IsTrue(Directory.Exists(Path.Combine(Environment.CurrentDirectory, _testName)));

                        sdb.Flush();
                    }

                    pdb.Flush();
                }
            }
        }
        public void RSelectTest()
        {
            _testName = System.Reflection.MethodInfo.GetCurrentMethod().Name.GetHashCode().ToString();

            using (var fLock = new ManagedFileLock(_testName))
            {
                Cleanup();
                using (var db = new Relational.RelationalDatabase<int, MockClassD>(_testName + ".database", "Id"))
                {
                    db.Load();

                    var objs = TestResourceFactory.GetMockClassDObjects(3, db).ToList();

                    using (var t = db.BeginTransaction())
                    {
                        objs.ToList().ForEach(o => o.Id = db.Add(o));

                        t.Commit();
                    }
                }

                using (var db = new Relational.RelationalDatabase<int, MockClassD>(_testName + ".database", "Id"))
                {
                    db.Load();

                    var all = db.Select(s => s.Value<int>("Id") > 0);

                    Assert.AreEqual(15, all.Count);
                }
            }
        }
Ejemplo n.º 3
0
        public void SingleRelationshipSavesAndDeletes()
        {
            _testName = System.Reflection.MethodInfo.GetCurrentMethod().Name.GetHashCode().ToString();

            var seed = new Seed32();
            List<MockClassE> objs = null;
            var ids = new List<int>();

            using (var fLock = new ManagedFileLock(_testName))
            {
                Cleanup();

                using (var db = new RelationalDatabase<int, MockClassD>(_testName + ".database", "Id"))
                {
                    db.Load();

                    using (var t = db.BeginTransaction())
                    {
                        objs = TestResourceFactory.GetMockClassDObjects(3, db).ToList();

                        objs.ToList().ForEach(o => o.Id = db.Add(o));

                        t.Commit();
                    }
                }

                using (var db = new RelationalDatabase<int, MockClassD>(_testName + ".database"))
                {
                    db.Load();

                    var first = db.Fetch(objs[0].Id);

                    using (var t = db.BeginTransaction())
                    {
                        first.LowBall = new List<MockClassD>();

                        db.Update(first, first.Id);

                        t.Commit();
                    }

                    first = db.Fetch(objs[0].Id);

                    Assert.AreEqual(0, first.LowBall.Count());
                }

                using (var db = new RelationalDatabase<int, MockClassD>(_testName + ".database"))
                {
                    db.Load();

                    var first = db.Fetch(objs.First().Id);

                    Assert.AreEqual(0, first.LowBall.Count());
                }
            }
        }
Ejemplo n.º 4
0
        public void DatabaseDeletesFirstLastWithActiveTransactions()
        {
            _testName = MethodInfo.GetCurrentMethod().Name.GetHashCode().ToString();

            var objs = TestResourceFactory.GetMockClassAObjects(100).ToList();
            var ids = new List<int>();

            using (var fLock = new ManagedFileLock(_testName))
            {
                Cleanup();

                using (var db = new Database<int, MockClassA>(_testName + ".database", "Id", new FileCore<int, long>(), new BinConverter32(), new JSONFormatter()))
                {
                    db.Load();

                    var t = db.BeginTransaction();

                    objs.ToList().ForEach(o => ids.Add(db.Add(o)));

                    var last = db.SelectLast(s => true, 1).LastOrDefault();

                    Assert.IsNotNull(last);

                    var count = db.Update(s => s.Value<string>("Name") == last.Name
                        , new System.Action<MockClassA>(a => a.Name = "last"));

                    Assert.AreEqual(1, count);

                    var selected = db.Select(s => true);

                    Assert.AreEqual(100, selected.Count);

                    count = db.DeleteFirst(s => true, 10);

                    Assert.AreEqual(10, count);

                    selected = db.Select(s => true);

                    Assert.AreEqual(90, selected.Count);

                    count = db.DeleteLast(s => true, 10);

                    Assert.AreEqual(10, count);

                    selected = db.Select(s => true);

                    Assert.AreEqual(80, selected.Count);

                    t.Rollback();

                }
            }
        }
Ejemplo n.º 5
0
        public void TcpListenerSendsAuthError()
        {
            _testName = System.Reflection.MethodInfo.GetCurrentMethod().Name.GetHashCode().ToString();

            var random = new Random((int)(DateTime.Now.Ticks / 65782));

            var port = random.Next(8355, 10000);

            using (var fLock = new ManagedFileLock(_testName))
            {
                Cleanup();

                using (var testSub = new MockTcpSubscriber<int, MockClassA>(port))
                {
                    testSub.ThrowAuthError = true;

                    using (var pdb = new Database<int, MockClassA>(_testName + ".database", "Id")
                        .WithPublishing("Test", new TcpTransactionPublisher<int, MockClassA>(IPAddress.Parse("127.0.0.1"), port, 1)))
                    {
                        pdb.Load();

                        using (var sdb = new Database<int, MockClassA>(_testName + ".subscriber" + ".database", "Id")
                            .WithSubscription("Test", testSub))
                        {
                            sdb.Load();

                            var obj = TestResourceFactory.CreateRandom();

                            using (var t = pdb.BeginTransaction())
                            {
                                obj.Id = pdb.Add(obj);

                                t.Commit();
                            }

                            var sw = new Stopwatch();
                            sw.Start();

                            while (sdb.Fetch(obj.Id) == null && sw.ElapsedMilliseconds < 2000)
                                Thread.Sleep(100);

                            Assert.IsNull(sdb.Fetch(obj.Id));

                            sdb.Flush();
                        }

                        pdb.Flush();
                    }
                }
            }
        }
Ejemplo n.º 6
0
        public void PublisherQueuesTransactionsOnPause()
        {
            _testName = System.Reflection.MethodInfo.GetCurrentMethod().Name.GetHashCode().ToString();

            using (var fLock = new ManagedFileLock(_testName))
            {
                Cleanup();

                using (var db = new Database<int, MockClassA>(_testName + ".database", "Id"))
                {
                    db.Load();

                    db.Add(TestResourceFactory.CreateRandom());

                    db.FlushAll();
                }

                using (var db = new Database<int, MockClassA>(_testName + ".database")
                    .WithPublishing("Test", new FilePublisher<int, MockClassA>(_testName)))
                {
                    db.Load();

                    Assert.IsTrue(Directory.Exists(Path.Combine(Environment.CurrentDirectory, _testName)));

                    using (var fs = File.Create(Path.Combine(Environment.CurrentDirectory, _testName, "test.pause")))
                    {
                        fs.Flush();
                    }

                    using (var tran = db.BeginTransaction())
                    {
                        TestResourceFactory.GetMockClassAObjects(25).ToList().ForEach(m => db.Add(m));

                        tran.Commit();
                    }

                    Thread.Sleep(100);

                    Assert.AreEqual(0, Directory.GetFiles(Path.Combine(Environment.CurrentDirectory, _testName), "*.trans").Count());

                    File.Delete(Path.Combine(Environment.CurrentDirectory, _testName, "test.pause"));

                    Thread.Sleep(3000);

                    Assert.Greater(Directory.GetFiles(Path.Combine(Environment.CurrentDirectory, _testName), "*.trans").Count(), 0);

                    db.FlushAll();
                }
            }
        }
        public void CascadeIndexClosesWithCorrectLength()
        {
            _testName = MethodInfo.GetCurrentMethod().Name.GetHashCode().ToString();

            var formatter = TestResourceFactory.CreateJsonFormatterWithoutArrayFormatting();
            var core = new FileCore<string, long>() { IdSeed = new SeedString(2048), SegmentSeed = new Seed64(), Stride = 512 };

            using (var fLock = new ManagedFileLock(_testName))
            {
                Cleanup();
                using (var db = new Relational.RelationalDatabase<int, MockClassD>(_testName + ".database", "Id"))
                {
                    db.Load();

                    using (var t = db.BeginTransaction())
                    {
                        var objs = TestResourceFactory.GetMockClassDObjects(300, db).ToList();

                        objs.ToList().ForEach(o => o.Id = db.Add(o));

                        t.Commit();
                    }

                    var dbx = DynamicMemberManager.GetManager(db);
                    var pt = DynamicMemberManager.GetManager(dbx._cascadeIndex);

                    Assert.AreEqual(2, pt.Length);
                }

                using (var db = new Relational.RelationalDatabase<int, MockClassD>(_testName + ".database", "Id"))
                {
                    db.Load();

                    using (var t = db.BeginTransaction())
                    {
                        var additions = TestResourceFactory.GetMockClassDObjects(200, db).ToList();

                        additions.ToList().ForEach(o => o.Id = db.Add(o));

                        t.Commit();
                    }

                    var dbx = DynamicMemberManager.GetManager(db);
                    var pt = DynamicMemberManager.GetManager(dbx._cascadeIndex);

                    Assert.AreEqual(3, pt.Length);
                }
            }
        }
Ejemplo n.º 8
0
        public void AddOrUpdateWithoutIdAddsWithIdZeroAndUpdatesWithNonZeroId()
        {
            _testName = MethodInfo.GetCurrentMethod().Name.GetHashCode().ToString();

            var objs = TestResourceFactory.GetMockClassAObjects(100).ToList();

            using (var fLock = new ManagedFileLock(_testName))
            {
                Cleanup();
                using (var db = new Database<int, MockClassA>(_testName + ".database", "Id"))
                {
                    db.Load();

                    objs.ToList().ForEach(o => o.Id = db.AddOrUpdate(o));

                    db.FlushAll();
                }

                using (var db = new Database<int, MockClassA>(_testName + ".database"))
                {
                    db.Load();

                    var last = db.Fetch(objs.Last().Id);

                    Assert.IsNotNull(last);

                    last.Name = "last";

                    db.AddOrUpdate(last);

                    db.FlushAll();
                }

                using (var db = new Database<int, MockClassA>(_testName + ".database", "Id"))
                {
                    db.Load();

                    var last = db.Fetch(objs.Last().Id);

                    Assert.IsNotNull(last);
                    Assert.AreEqual("last", last.Name);

                    Assert.IsNotNull(db.Fetch(objs.First().Id));

                    db.FlushAll();
                }
            }
        }
Ejemplo n.º 9
0
        public void SubscriberPicksUpTransaction()
        {
            _testName = System.Reflection.MethodInfo.GetCurrentMethod().Name.GetHashCode().ToString();

            using (var fLock = new ManagedFileLock(_testName))
            {
                Cleanup();

                using (var pdb = new Database<Guid, MockClassA>(_testName + ".publisher" + ".database", "ReplicationID")
                    .WithPublishing("Test", new FilePublisher<Guid, MockClassA>(Path.Combine(Environment.CurrentDirectory, _testName))))
                {
                    pdb.Load();

                    Assert.IsTrue(Directory.Exists(Path.Combine(Environment.CurrentDirectory, _testName)));

                    using (var sdb = new Database<Guid, MockClassA>(_testName + ".subscriber" + ".database", "ReplicationID")
                        .WithSubscription("Test", new FileSubscriber<Guid, MockClassA>(Path.Combine(Environment.CurrentDirectory, _testName), new TimeSpan(0, 0, 0, 0, 500))))
                    {
                        sdb.Load();

                        Assert.IsTrue(Directory.Exists(Path.Combine(Environment.CurrentDirectory, _testName)));

                        var objects = TestResourceFactory.GetMockClassAObjects(25).OfType<MockClassC>().ToList();
                        //objects.ForEach(o => o.ReplicationID = Guid.Empty);

                        using (var tran = pdb.BeginTransaction())
                        {
                            objects.ForEach(o => o.ReplicationID = pdb.Add(o));

                            tran.Commit();
                        }

                        var sw = new Stopwatch();
                        sw.Start();

                        while (sdb.Fetch(objects.First().ReplicationID) == null && sw.ElapsedMilliseconds < 6000)
                            Thread.Sleep(750);

                        Assert.IsNotNull(sdb.Fetch(objects.First().ReplicationID));

                        sdb.Flush();
                    }

                    pdb.Flush();
                }
            }
        }
Ejemplo n.º 10
0
        public void SingleRelationshipSaves()
        {
            _testName = System.Reflection.MethodInfo.GetCurrentMethod().Name.GetHashCode().ToString();

            var seed = new Seed32();
            IList<MockClassE> objs = null;
            var ids = new List<int>();

            using (var fLock = new ManagedFileLock(_testName))
            {
                Cleanup();

                using (var db = new RelationalDatabase<int, MockClassD>(_testName + ".database", "Id"))
                {
                    db.Load();

                    using (var t = db.BeginTransaction())
                    {
                        objs = TestResourceFactory.GetMockClassDObjects(3, db).ToList();

                        objs.ToList().ForEach(o => o.Id = db.Add(o));

                        t.Commit();
                    }
                }

                using (var db = new RelationalDatabase<int, MockClassD>(_testName + ".database"))
                {
                    db.Load();

                    foreach (var obj in objs)
                    {
                        var orig = obj as MockClassE;
                        var item = db.Fetch(obj.Id) as MockClassE;

                        AssertMockClassE(item, orig, db);
                    }
                }
            }
        }
Ejemplo n.º 11
0
        public void FormatterCompressesAndUnCompressesManyRandomObjects()
        {
            _testName = MethodInfo.GetCurrentMethod().Name.GetHashCode().ToString();

            var objs = TestResourceFactory.GetMockClassAObjects(257);

            using (var fLock = new ManagedFileLock(_testName))
            {
                Cleanup();

                using (var db = new Database<int, MockClassA>
                    (_testName + ".database", "Id",
                    new FileCore<int, long>() { MinimumCoreStride = 4096, InitialDbSize = 256 },
                     new LZ4ZipFormatter(new BSONFormatter())))
                {
                    db.Load();

                    using (var t = db.BeginTransaction())
                    {
                        foreach (var o in objs)
                            o.Id = db.Add(o);

                        t.Commit();
                    }
                }
                using (var db = new Database<int, MockClassA>
                    (_testName + ".database", new LZ4ZipFormatter(new BSONFormatter())))
                {
                    db.Load();

                    foreach (var o in objs)
                    {
                        var test = db.Fetch(o.Id);

                        Assert.IsNotNull(test, "object could not be decompressed or fetched {0}", o.Id);
                        Validation.ValidateC(o as MockClassC, test as MockClassC);
                    }
                }
            }
        }
Ejemplo n.º 12
0
        public void DatabaseUpdatesJObject()
        {
            _testName = MethodInfo.GetCurrentMethod().Name.GetHashCode().ToString();

            var core = new FileCore<int, long>(new Seed32(999));
            var formatter = TestResourceFactory.CreateJsonFormatterWithoutArrayFormatting();

            var stopWatch = new Stopwatch();

            using (var fLock = new ManagedFileLock(_testName))
            {
                Cleanup();

                using (var db = new Database<int, MockClassA>(_testName + ".database", "Id", core))
                {
                    db.Load();

                    using (var t = db.BeginTransaction())
                    {
                        TestResourceFactory.GetMockClassAObjects(5000).ToList().ForEach(a => db.AddOrUpdateJObj(JObject.FromObject(a, formatter.Serializer), a.Id));

                        t.Commit();
                    }
                    var dmm = DynamicMemberManager.GetManager(db);
                    Assert.AreEqual(5000, dmm._primaryIndex.Length);
                }

                using (var db = new Database<int, MockClassA>(_testName + ".database"))
                {
                    var len = db.Load();

                    using (var t = db.BeginTransaction())
                    {
                        var old = db.FetchJObj(2000);

                        var eVal = old.SelectToken("LittleId") as JValue;
                        var sVal = JToken.FromObject(10, db.Formatter.Serializer);

                        eVal.Replace(sVal);

                        db.AddOrUpdateJObj(old, old.Value<int>("Id"));

                        t.Commit();
                    }

                    stopWatch.Reset();
                    stopWatch.Start();
                    var gets = db.SelectLast(o => o.Value<int>("Id") > 4000, 10);
                    stopWatch.Stop();

                    Console.WriteLine("query with 10 last records retreived in {0} seconds", stopWatch.ElapsedMilliseconds / 1000m);

                    Assert.AreEqual(10, gets.Count());

                    foreach (var item in gets)
                        Assert.Greater(item.Id, 4000);

                    var obj = db.FetchJObj(4000);

                    Assert.AreEqual(obj.Value<int>("Id"), 4000);

                    var updated = db.Fetch(2000) as MockClassC;

                    Assert.AreEqual(10, updated.LittleId);
                }
            }
        }
Ejemplo n.º 13
0
        public void PublisherUnInititializes()
        {
            _testName = System.Reflection.MethodInfo.GetCurrentMethod().Name.GetHashCode().ToString();

            using (var fLock = new ManagedFileLock(_testName))
            {
                Cleanup();
                using (var db = new Database<int, MockClassA>(_testName + ".database", "Id")
                    .WithPublishing("Test", new FilePublisher<int, MockClassA>(_testName)))
                {
                    db.Load();

                    Assert.IsTrue(Directory.Exists(Path.Combine(Environment.CurrentDirectory, _testName)));

                    db.Flush();
                }

                using (var db = new Database<int, MockClassA>(_testName + ".database")
                    .WithPublishing("Test", new FilePublisher<int, MockClassA>(_testName)))
                {
                    db.Load();
                    db.WithoutPublishing("Test");

                    Assert.IsTrue(Directory.Exists(Path.Combine(Environment.CurrentDirectory, _testName)));

                    using (var tran = db.BeginTransaction())
                    {
                        TestResourceFactory.GetMockClassAObjects(25).ToList().ForEach(m => db.Add(m));

                        tran.Commit();
                    }

                    Thread.Sleep(100);

                    Assert.AreEqual(0, Directory.GetFiles(Path.Combine(Environment.CurrentDirectory, _testName), "*.tLock").Count());
                }
            }
        }
Ejemplo n.º 14
0
        public void FormatterParsesAndUnparsesStream()
        {
            _testName = MethodInfo.GetCurrentMethod().Name.GetHashCode().ToString();

            var test1 = new Mocks.MockImageContainer(testRes.Luna_DIFF) { Name = "Luna_DIFF" };
            var test2 = new Mocks.MockImageContainer(testRes.IronAsteroid_NRM) { Name = "IronAsteroid_NRM" };

            using (var fLock = new ManagedFileLock(_testName))
            {
                Cleanup();
                using (var db = new Database<string, MockImageContainer>
                    (_testName + ".database", "Name",
                    new FileCore<string, long>(new SeedString(255)) { MinimumCoreStride = 4096, InitialDbSize = 256 },
                     new LZ4ZipFormatter(new BSONFormatter())))
                {
                    db.Load();

                    using (var t = db.BeginTransaction())
                    {
                        db.Add(test1);
                        db.Add(test2);

                        t.Commit();
                    }
                }

                using (var db = new Database<string, MockImageContainer>
                    (_testName + ".database", new LZ4ZipFormatter(new BSONFormatter())))
                {
                    db.Load();

                    var fetched = db.Fetch("Luna_DIFF");

                    Assert.IsNotNull(fetched);
                    Assert.AreEqual(fetched.Name, test1.Name);
                    Assert.AreEqual(fetched.GetResource<Bitmap>().Size.Height, test1.GetResource<Bitmap>().Size.Height);
                }
            }
        }
        public void AfmUpdatesAndDeletesExistingObjects()
        {
            _testName = MethodInfo.GetCurrentMethod().Name.GetHashCode().ToString();

            var formatter = TestResourceFactory.CreateJsonFormatterWithoutArrayFormatting();
            var core = new FileCore<int, long>() { IdSeed = new Seed32(999), SegmentSeed = new Seed64(), MinimumCoreStride = 512 };

            var entity1 = TestResourceFactory.CreateRandom() as MockClassC;
            var entity2 = TestResourceFactory.CreateRandom() as MockClassC;
            long seg = -1;

            using (var fLock = new ManagedFileLock(_testName))
            {
                Cleanup();
                using (var afm = new AtomicFileManager<MockClassA>(_testName + ".database", core, formatter))
                {
                    afm.Load<int>();

                    seg = AtomicFileManagerHelper.SaveSegment(afm, entity1, entity1.Id);
                }

                using (var afm = new AtomicFileManager<MockClassA>(_testName + ".database", formatter))
                {
                    afm.Load<int>();

                    AtomicFileManagerHelper.SaveSegment(afm, entity2, entity2.Id, seg);
                }

                using (var afm = new AtomicFileManager<MockClassA>(_testName + ".database", formatter))
                {
                    afm.Load<int>();

                    Assert.Less(512, afm.Stride);
                    Assert.Greater(1024, afm.CorePosition);

                    var obj = afm.LoadSegmentFrom(seg) as MockClassC;

                    Assert.IsNotNull(obj);
                    Assert.AreEqual(entity2.Id, obj.Id);
                    Assert.AreEqual(entity2.Name, obj.Name);
                    Assert.AreEqual(entity2.GetSomeCheckSum, obj.GetSomeCheckSum);
                    Assert.AreEqual(entity2.Location.X, obj.Location.X);
                    Assert.AreEqual(entity2.Location.Y, obj.Location.Y);
                    Assert.AreEqual(entity2.Location.Z, obj.Location.Z);
                    Assert.AreEqual(entity2.Location.W, obj.Location.W);
                    Assert.AreEqual(entity2.ReferenceCode, obj.ReferenceCode);
                    Assert.AreEqual(entity2.ReplicationID, obj.ReplicationID);

                    AtomicFileManagerHelper.DeleteSegment(afm, obj.Id, seg);

                    obj = afm.LoadSegmentFrom(seg) as MockClassC;

                    Assert.IsNull(obj);
                }

                using (var afm = new AtomicFileManager<MockClassA>(_testName + ".database", formatter))
                {
                    afm.Load<int>();

                    var obj = afm.LoadSegmentFrom(seg) as MockClassC;

                    Assert.IsNull(obj);
                }
            }
        }
        public void AfmSavesNewObjects()
        {
            _testName = MethodInfo.GetCurrentMethod().Name.GetHashCode().ToString();

            var formatter = TestResourceFactory.CreateJsonFormatterWithoutArrayFormatting();
            var core = new FileCore<int, long>() { IdSeed = new Seed32(999), SegmentSeed = new Seed64(), MinimumCoreStride = 512 };

            var entity = TestResourceFactory.CreateRandom() as MockClassC;
            long seg = -1;

            using (var fLock = new ManagedFileLock(_testName))
            {
                Cleanup();
                using (var afm = new AtomicFileManager<MockClassA>(_testName + ".database", core))
                {
                    afm.Load<int>();

                    entity.Id = core.IdSeed.Increment();

                    afm.Rebuilt += new Rebuild<MockClassA>(delegate(Guid transactionId, int newStride, long newLength, int newSeedStride)
                    {
                        afm.SaveCore<int>();
                    });

                    seg = AtomicFileManagerHelper.SaveSegment(afm, entity, entity.Id);

                    afm.SaveCore<int>();
                }

                using (var afm = new AtomicFileManager<MockClassA>(_testName + ".database"))
                {
                    afm.Load<int>();

                    Assert.AreEqual(512, afm.Stride);
                    Assert.AreEqual(1024, afm.CorePosition);

                    var obj = afm.LoadSegmentFrom(seg) as MockClassC;

                    Assert.IsNotNull(obj);
                    Assert.AreEqual(entity.Id, obj.Id);
                    Assert.AreEqual(entity.Name, obj.Name);
                    Assert.AreEqual(entity.GetSomeCheckSum, obj.GetSomeCheckSum);
                    Assert.AreEqual(entity.Location.X, obj.Location.X);
                    Assert.AreEqual(entity.Location.Y, obj.Location.Y);
                    Assert.AreEqual(entity.Location.Z, obj.Location.Z);
                    Assert.AreEqual(entity.Location.W, obj.Location.W);
                    Assert.AreEqual(entity.ReferenceCode, obj.ReferenceCode);
                    Assert.AreEqual(entity.ReplicationID, obj.ReplicationID);
                }
            }
        }
Ejemplo n.º 17
0
        public void DatabaseKeepsInitializedTypes()
        {
            _testName = MethodInfo.GetCurrentMethod().Name.GetHashCode().ToString();

            using (var fLock = new ManagedFileLock(_testName))
            {
                Cleanup();

                using (var db = new Database<int, MockClassA>
                    (_testName + ".database", "Id",
                    new FileCore<int, long>(new MockSeed32() { LastSeed = 1024 }, new Seed64(15)),
                    new BinConverter32(), new BSONFormatter(),
                    new TransactionManager<int, MockClassA>() { Source = new BinConverterGuid().Max },
                    new AtomicFileManagerFactory(), new DatabaseCacheFactory(), new IndexFileFactory(), new IndexFactory()))
                {
                    db.Load();
                }

                using (var db = new Database<int, MockClassA>(_testName + ".database"))
                {
                    db.Load();

                    Assert.AreEqual(1024, db.Seed.LastSeed);
                }
            }
        }
Ejemplo n.º 18
0
        public void DatabaseSavesLargeFile()
        {
            _testName = MethodInfo.GetCurrentMethod().Name.GetHashCode().ToString();

            using (var fLock = new ManagedFileLock(_testName))
            {
                Cleanup();

                using (var db = new Database<string, ResourceContainer>(_testName + ".database", "Name"))
                {
                    db.Load();

                    using (var tran = db.BeginTransaction())
                    {
                        db.Add(new MockImageContainer(testRes.Luna_DIFF) { Name = "Luna_DIFF" });
                        db.Add(new MockImageContainer(testRes.Luna_MAT) { Name = "Luna_MAT" });
                        db.Add(new MockImageContainer(testRes.Luna_NRM) { Name = "Luna_NRM" });

                        tran.Commit();
                    }
                }

                using (var db = new Database<string, ResourceContainer>(_testName + ".database"))
                {
                    var len = db.Load();

                    Assert.AreEqual(3, len);

                    Assert.AreEqual(db.Fetch("Luna_DIFF").GetResource<Bitmap>().Width, testRes.Luna_DIFF.Width);
                    Assert.AreEqual(db.Fetch("Luna_MAT").GetResource<Bitmap>().Width, testRes.Luna_MAT.Width);
                    Assert.AreEqual(db.Fetch("Luna_NRM").GetResource<Bitmap>().Width, testRes.Luna_NRM.Width);
                }
            }
        }
Ejemplo n.º 19
0
        public void FullEnlistmentScopeRollsBackOnExceptionTest()
        {
            _testName = MethodInfo.GetCurrentMethod().Name.GetHashCode().ToString();

            var objects = TestResourceFactory.GetMockClassAObjects(12);

            ITransaction trans = null;

            using (var fLock = new ManagedFileLock(_testName))
            {
                Cleanup();

                using (var db = new Database<int, MockClassA>(_testName + ".database", "Id", new FileCore<int, long>(), new BinConverter32(), new BSONFormatter(),
                    new TransactionManager<int, MockClassA>() { DistributedScopeEnlistment = TransactionEnlistmentType.FullEnlistmentNotification }))
                {
                    db.Load();

                    try
                    {
                        using (var scope = new System.Transactions.TransactionScope(TransactionScopeOption.RequiresNew))
                        {
                            using (trans = db.BeginTransaction())
                            {

                                foreach (var obj in objects)
                                    obj.Id = db.AddOrUpdate(obj, 0);

                                var update = db.Fetch(3);

                                update.Name = "Updated " + update.Id;

                                db.AddOrUpdate(update, update.Id);

                                db.Delete(objects.Last().Id);

                                throw new Exception();
                            }
                        }
                    }
                    catch (Exception) { }
                }

                using (var db = new Database<int, MockClassA>(_testName + ".database", "Id", new FileCore<int, long>(), new BinConverter32(), new BSONFormatter(),
                    new TransactionManager<int, MockClassA>() { DistributedScopeEnlistment = TransactionEnlistmentType.FullEnlistmentNotification }))
                {
                    db.Load();

                    Assert.AreEqual(0, db.Length);
                }
            }
        }
Ejemplo n.º 20
0
        public void DatabaseSavesTenThousandRecords()
        {
            _testName = MethodInfo.GetCurrentMethod().Name.GetHashCode().ToString();
            Cleanup();

            var objs = TestResourceFactory.GetMockClassAObjects(10000).ToList();

            using (var fLock = new ManagedFileLock(_testName + ".database"))
            {
                using (var db = new Database<int, MockClassA>(_testName + ".database", "Id", new FileCore<int, long>(new Seed32(999))))
                {
                    db.Load();

                    objs.ToList().ForEach(o => db.Add(o));
                }

                using (var db = new Database<int, MockClassA>(_testName + ".database"))
                {
                    var len = db.Load();

                    Assert.AreEqual(objs.Count(), len);
                }
            }
        }
Ejemplo n.º 21
0
        public void DatabaseFetchesSavedValues()
        {
            _testName = MethodInfo.GetCurrentMethod().Name.GetHashCode().ToString();

            var objs= TestResourceFactory.GetMockClassAObjects(3).ToList();
            var ids = new List<int>();

            using (var fLock = new ManagedFileLock(_testName))
            {
                Cleanup();

                using (var db = new Database<int, MockClassA>(_testName + ".database", "Id"))
                {
                    db.Load();

                    objs.ToList().ForEach(o => ids.Add(db.Add(o)));

                    db.FlushAll();
                }

                using (var db = new Database<int, MockClassA>(_testName + ".database"))
                {
                    db.Load();

                    foreach (var obj in objs)
                    {
                        var orig = obj as MockClassC;
                        var item = db.Fetch(obj.Id) as MockClassC;

                        Assert.AreEqual(item.Id, orig.Id);
                        Assert.AreEqual(item.Name, orig.Name);
                        Assert.AreEqual(item.GetSomeCheckSum[0], orig.GetSomeCheckSum[0]);
                        Assert.AreEqual(item.Location.X, orig.Location.X);
                        Assert.AreEqual(item.Location.Y, orig.Location.Y);
                        Assert.AreEqual(item.Location.Z, orig.Location.Z);
                        Assert.AreEqual(item.Location.W, orig.Location.W);
                        Assert.AreEqual(item.ReferenceCode, orig.ReferenceCode);
                        Assert.AreEqual(item.ReplicationID, orig.ReplicationID);
                    }
                }
            }
        }
Ejemplo n.º 22
0
        public void DatabaseSelectsScalarWithActiveTransactions()
        {
            _testName = MethodInfo.GetCurrentMethod().Name.GetHashCode().ToString();

            using (var fLock = new ManagedFileLock(_testName + ".database"))
            {
                Cleanup();

                var objs = TestResourceFactory.GetMockClassAObjects(100).ToList();
                var ids = new List<int>();

                using (var db = new JObjectDatabase<int>(_testName + ".database", "Id", new FileCore<int, long>(), new BinConverter32(), new JSONFormatter()))
                {
                    db.Load();

                    var t = db.BeginTransaction();

                    objs.ToList().ForEach(o => ids.Add(db.Add(db.Formatter.AsQueryableObj(o))));

                    var last = db.SelectLast(s => true, 1).LastOrDefault();

                    Assert.IsNotNull(last);

                    var count = db.Update(s => s.Value<string>("Name") == last.Value<string>("Name")
                        , new System.Action<JObject>(a => a.SetValue("Name", "last", db.Formatter.Serializer)));

                    Assert.AreEqual(1, count);

                    var selected = db.Select(s => true);

                    Assert.AreEqual(100, selected.Count);

                    var names = db.SelectScalar(s => s.Value<int>("Id") <= 15, "Name");

                    Assert.AreEqual(15, names.Count);

                    names = db.SelectScalarFirst(s => s.Value<int>("Id") <= 15, 10, "Name");

                    Assert.AreEqual(10, names.Count);

                    names = db.SelectScalarLast(s => s.Value<int>("Id") <= 15, 8, "Name");

                    Assert.AreEqual(8, names.Count);

                    t.Rollback();

                }
            }
        }
Ejemplo n.º 23
0
        public void DatabaseFetchesUpdatesAndDeletesWithQueries()
        {
            _testName = MethodInfo.GetCurrentMethod().Name.GetHashCode().ToString();

            using (var fLock = new ManagedFileLock(_testName))
            {
                Cleanup();

                var objs = TestResourceFactory.GetMockClassAObjects(100).ToList();
                var ids = new List<int>();

                using (var db = new JObjectDatabase<int>(_testName + ".database", "Id", new FileCore<int, long>(), new BinConverter32(), new JSONFormatter()))
                {
                    db.Load();

                    objs.ToList().ForEach(o => ids.Add(db.Add(db.Formatter.AsQueryableObj(o))));

                    db.FlushAll();
                }

                using (var db = new Database<int, MockClassA>(_testName + ".database", new JSONFormatter()))
                {
                    db.Load();

                    using (var t = db.BeginTransaction())
                    {
                        var last = db.SelectLast(s => true, 1).LastOrDefault();

                        Assert.IsNotNull(last);

                        db.Update(s => s.Value<string>("Name") == last.Name
                            , new System.Action<MockClassA>(a => a.Name = "last"));

                        db.Delete(s => true);

                        t.Commit();
                    }

                    var selected = db.Select(s => true);

                    Assert.AreEqual(0, selected.Count);
                }

                using (var db = new Database<int, MockClassA>(_testName + ".database", new JSONFormatter()))
                {
                    db.Load();

                    var selected = db.Select(s => true);

                    Assert.AreEqual(0, selected.Count);
                }
            }
        }
Ejemplo n.º 24
0
        public void SelectLastQuerySelectsLast10Matches()
        {
            _testName = MethodInfo.GetCurrentMethod().Name.GetHashCode().ToString();

            var core = new FileCore<int, long>(new Seed32(999));
            var formatter = TestResourceFactory.CreateJsonFormatterWithoutArrayFormatting();

            var stopWatch = new Stopwatch();

            using (var fLock = new ManagedFileLock(_testName))
            {
                Cleanup();

                using (var db = new Database<int, MockClassA>(_testName + ".database", "Id", core))
                {
                    db.Load();

                    using (var t = db.BeginTransaction())
                    {
                        TestResourceFactory.GetMockClassAObjects(25000).ToList().ForEach(a => db.Add(a));

                        t.Commit();
                    }

                    stopWatch.Reset();
                    stopWatch.Start();
                    var gets = db.SelectLast(o => o.Value<int>("Id") > 24000, 10);
                    stopWatch.Stop();

                    Console.WriteLine("query with 10 last records retreived in {0} seconds", stopWatch.ElapsedMilliseconds / 1000m);

                    Assert.AreEqual(10, gets.Count());

                    foreach (var item in gets)
                        Assert.Greater(item.Id, 24989);
                }

                using (var db = new Database<int, MockClassA>(_testName + ".database"))
                {
                    var len = db.Load();

                    stopWatch.Reset();
                    stopWatch.Start();
                    var gets = db.SelectLast(o => o.Value<int>("Id") > 24000, 10);
                    stopWatch.Stop();

                    Console.WriteLine("query with 10 last records retreived in {0} seconds", stopWatch.ElapsedMilliseconds / 1000m);

                    Assert.AreEqual(10, gets.Count());

                    foreach (var item in gets)
                        Assert.Greater(item.Id, 24000);
                }
            }
        }
Ejemplo n.º 25
0
        public void SinglePhaseScopeRollsBackTest()
        {
            _testName = MethodInfo.GetCurrentMethod().Name.GetHashCode().ToString();

            var objects = TestResourceFactory.GetMockClassAObjects(12);

            ITransaction trans = null;

            using (var fLock = new ManagedFileLock(_testName))
            {
                Cleanup();

                using (var db = new Database<int, MockClassA>(_testName + ".database", "Id", new FileCore<int, long>(), new BinConverter32(), new BSONFormatter(),
                    new TransactionManager<int, MockClassA>() { DistributedScopeEnlistment = TransactionEnlistmentType.SinglePhasePromotable }))
                {
                    db.Load();

                    using (var scope = new System.Transactions.TransactionScope(TransactionScopeOption.RequiresNew))
                    {
                        trans = db.BeginTransaction();

                        foreach (var obj in objects)
                            obj.Id = db.AddOrUpdate(obj, 0);

                        var update = db.Fetch(3);

                        update.Name = "Updated " + update.Id;

                        db.AddOrUpdate(update, update.Id);

                        db.Delete(objects.Last().Id);
                    }

                    while (!trans.IsComplete)
                        Thread.Sleep(100);
                }

                using (var db = new Database<int, MockClassA>(_testName + ".database", "Id", new FileCore<int, long>(), new BinConverter32(), new BSONFormatter(),
                    new TransactionManager<int, MockClassA>() { DistributedScopeEnlistment = TransactionEnlistmentType.SinglePhasePromotable }))
                {
                    db.Load();

                    Assert.AreEqual(0, db.Length);
                }

            }
        }
Ejemplo n.º 26
0
        public void FullEnlistmentScopeCommitsTest()
        {
            _testName = MethodInfo.GetCurrentMethod().Name.GetHashCode().ToString();

            var objects = TestResourceFactory.GetMockClassAObjects(12);

            ITransaction trans = null;

            using (var fLock = new ManagedFileLock(_testName))
            {
                Cleanup();

                using (var db = new Database<int, MockClassA>(_testName + ".database", "Id", new FileCore<int, long>(), new BinConverter32(), new BSONFormatter(),
                    new TransactionManager<int, MockClassA>() { DistributedScopeEnlistment = TransactionEnlistmentType.FullEnlistmentNotification }))
                {
                    db.Load();

                    using (var scope = new System.Transactions.TransactionScope(TransactionScopeOption.RequiresNew))
                    {
                        trans = db.BeginTransaction();

                        foreach (var obj in objects)
                            obj.Id = db.AddOrUpdate(obj, 0);

                        var update = db.Fetch(3);

                        update.Name = "Updated " + update.Id;

                        db.AddOrUpdate(update, update.Id);

                        db.Delete(objects.Last().Id);

                        scope.Complete();
                    }

                    while (!trans.IsComplete)
                        Thread.Sleep(100);
                }

                using (var db = new Database<int, MockClassA>(_testName + ".database", "Id", new FileCore<int, long>(), new BinConverter32(), new BSONFormatter(),
                    new TransactionManager<int, MockClassA>() { DistributedScopeEnlistment = TransactionEnlistmentType.FullEnlistmentNotification }))
                {
                    db.Load();

                    using (var scope = new System.Transactions.TransactionScope(TransactionScopeOption.RequiresNew))
                    {
                        trans = db.BeginTransaction();

                        db.Update<MockClassA>(u => !u.Value<string>("Name").Contains("Updated"), m => m.Name = "batch " + m.Id);

                        var old = db.Select(s => s.Value<string>("Name").Contains("Updated"));

                        Assert.AreEqual(1, old.Count);
                        Assert.AreEqual("Updated 3", old.Single().Name);

                        var updates = db.SelectFirst(s => s.Value<string>("Name").Contains("batch"), 11);

                        Assert.AreEqual(10, updates.Count);
                        Assert.AreEqual(1, updates.First().Id);
                        Assert.AreEqual(11, updates.Last().Id);

                        scope.Complete();
                    }

                    while (!trans.IsComplete)
                        Thread.Sleep(100);
                }
            }
        }
Ejemplo n.º 27
0
        public void DatabaseSavesOneHundredThousandRecords()
        {
            _testName = MethodInfo.GetCurrentMethod().Name.GetHashCode().ToString();

            decimal avgTime = 0;
            var stopWatch = new Stopwatch();

            using (var fLock = new ManagedFileLock(_testName))
            {
                Cleanup();

                using (var db = new Database<int, MockClassA>(_testName + ".database", "Id"))
                {
                    db.Load();

                    stopWatch.Start();
                    using (var t = db.BeginTransaction())
                    {
                        TestResourceFactory.GetMockClassAObjects(25000).ToList().ForEach(a => db.Add(a));

                        t.Commit();
                    }
                    stopWatch.Stop();
                    avgTime = (avgTime + stopWatch.ElapsedMilliseconds);

                    Console.WriteLine("Transaction with 25000 entities committed in {0} seconds", stopWatch.ElapsedMilliseconds / 1000m);

                    stopWatch.Reset();
                    stopWatch.Start();
                    using (var t = db.BeginTransaction())
                    {
                        TestResourceFactory.GetMockClassAObjects(25000).ToList().ForEach(a => db.Add(a));

                        t.Commit();
                    }
                    stopWatch.Stop();
                    avgTime = (avgTime + stopWatch.ElapsedMilliseconds) / 2;

                    Console.WriteLine("Transaction with 25000 entities committed in {0} seconds", stopWatch.ElapsedMilliseconds / 1000m);

                    stopWatch.Reset();
                    stopWatch.Start();
                    using (var t = db.BeginTransaction())
                    {
                        TestResourceFactory.GetMockClassAObjects(25000).ToList().ForEach(a => db.Add(a));

                        t.Commit();
                    }
                    stopWatch.Stop();
                    avgTime = (avgTime + stopWatch.ElapsedMilliseconds) / 2;

                    Console.WriteLine("Transaction with 25000 entities committed in {0} seconds", stopWatch.ElapsedMilliseconds / 1000m);

                    stopWatch.Reset();
                    stopWatch.Start();
                    using (var t = db.BeginTransaction())
                    {
                        TestResourceFactory.GetMockClassAObjects(25000).ToList().ForEach(a => db.Add(a));

                        t.Commit();
                    }
                    stopWatch.Stop();
                    avgTime = (avgTime + stopWatch.ElapsedMilliseconds) / 2;

                    Console.WriteLine("Transaction with 25000 entities committed in {0} seconds", stopWatch.ElapsedMilliseconds / 1000m);

                    Console.WriteLine("Avg Commit time for trans with 25000 entities {0} seconds", avgTime / 1000m);

                    stopWatch.Reset();
                    stopWatch.Start();
                    Assert.AreEqual(20000, db.Select(o => o.Value<int>("Id") > 80000).Count());
                    stopWatch.Stop();

                    Console.WriteLine("query with 20000 records retreived in {0} seconds", stopWatch.ElapsedMilliseconds / 1000m);

                    db.Flush();
                }

                using (var db = new Database<int, MockClassA>(_testName + ".database"))
                {
                    var len = db.Load();

                    Assert.AreEqual(100000, len);

                    stopWatch.Reset();
                    stopWatch.Start();
                    Assert.AreEqual(20000, db.Select(o => o.Value<int>("Id") > 80000).Count());
                    stopWatch.Stop();

                    Console.WriteLine("query with 20000 records retreived in {0} seconds", stopWatch.ElapsedMilliseconds / 1000m);

                    db.Clear();
                }
            }
        }
Ejemplo n.º 28
0
        public void DatabaseUpdatesIdFieldAndIndexes()
        {
            _testName = MethodInfo.GetCurrentMethod().Name.GetHashCode().ToString();

            var objs = TestResourceFactory.GetMockClassAObjects(100).ToList();
            var ids = new List<int>();

            using (var fLock = new ManagedFileLock(_testName))
            {
                Cleanup();
                using (var db = new Database<int, MockClassA>(_testName + ".database", "Id"))
                {
                    db.Load();

                    objs.ToList().ForEach(o => ids.Add(db.Add(o)));

                    db.FlushAll();
                }

                using (var db = new Database<int, MockClassA>(_testName + ".database"))
                {
                    db.Load();

                    var last = db.Fetch(objs.Last().Id);

                    Assert.IsNotNull(last);

                    var oldId = last.Id;
                    last.Name = "last";
                    last.Id = 1024;

                    db.Update(last, oldId);

                    last = db.Fetch(last.Id);

                    Assert.AreEqual(1024, last.Id);

                    var old = db.Fetch(oldId);

                    Assert.IsNull(old);

                    db.FlushAll();
                }

                using (var db = new Database<int, MockClassA>(_testName + ".database", "Id"))
                {
                    db.Load();

                    var last = db.Fetch(objs.Last().Id);
                    Assert.IsNull(last);

                    last = db.Fetch(1024);
                    Assert.IsNotNull(last);

                    Assert.AreEqual("last", last.Name);

                    Assert.IsNotNull(db.Fetch(objs.First().Id));

                    db.Delete(new int[] { objs.First().Id, objs.Last().Id });

                    Assert.IsNull(db.Fetch(objs.First().Id));
                    Assert.IsNull(db.Fetch(objs.Last().Id));

                    db.FlushAll();
                }

                using (var db = new Database<int, MockClassA>(_testName + ".database", "Id"))
                {
                    db.Load();

                    Assert.IsNull(db.Fetch(objs.First().Id));

                    db.Clear();
                }
            }
        }
Ejemplo n.º 29
0
        public void DatabaseRebuildsWithLargeFile()
        {
            _testName = MethodInfo.GetCurrentMethod().Name.GetHashCode().ToString();

            using (var fLock = new ManagedFileLock(_testName + ".database"))
            {
                Cleanup();

                using (var db = new Database<string, ResourceContainer>(_testName + ".database", "Name",
                    new FileCore<string, long>(new SeedString(50)) { InitialDbSize = 8 }))
                {
                    db.Load();

                    using (var tran = db.BeginTransaction())
                    {
                        db.Add(new MockImageContainer(testRes.Luna_DIFF) { Name = "Luna_DIFF" });
                        db.Add(new MockImageContainer(testRes.Luna_DIFF) { Name = "Luna_DIFF1" });
                        db.Add(new MockImageContainer(testRes.Luna_DIFF) { Name = "Luna_DIFF2" });
                        db.Add(new MockImageContainer(testRes.Luna_DIFF) { Name = "Luna_DIFF3" });
                        tran.Commit();
                    }

                    using (var tran = db.BeginTransaction())
                    {
                        db.Add(new MockImageContainer(testRes.Luna_MAT) { Name = "Luna_MAT" });
                        db.Add(new MockImageContainer(testRes.Luna_MAT) { Name = "Luna_MAT1" });
                        db.Add(new MockImageContainer(testRes.Luna_MAT) { Name = "Luna_MAT2" });
                        db.Add(new MockImageContainer(testRes.Luna_MAT) { Name = "Luna_MAT3" });

                        tran.Commit();
                    }

                    using (var tran = db.BeginTransaction())
                    {
                        db.Add(new MockImageContainer(testRes.Luna_NRM) { Name = "Luna_NRM" });
                        db.Add(new MockImageContainer(testRes.Luna_NRM) { Name = "Luna_NRM1" });
                        db.Add(new MockImageContainer(testRes.Luna_NRM) { Name = "Luna_NRM2" });
                        db.Add(new MockImageContainer(testRes.Luna_NRM) { Name = "Luna_NRM3" });

                        tran.Commit();
                    }
                }

                using (var db = new Database<string, ResourceContainer>(_testName + ".database"))
                {
                    var len = db.Load();

                    Assert.AreEqual(12, len);

                    Assert.AreEqual(db.Fetch("Luna_DIFF").GetResource<Bitmap>().Width, testRes.Luna_DIFF.Width);
                    Assert.AreEqual(db.Fetch("Luna_MAT").GetResource<Bitmap>().Width, testRes.Luna_MAT.Width);
                    Assert.AreEqual(db.Fetch("Luna_NRM").GetResource<Bitmap>().Width, testRes.Luna_NRM.Width);

                    var d = DynamicMemberManager.GetManager(db);
                    var idx = DynamicMemberManager.GetManager(d._primaryIndex);
                    var pt = DynamicMemberManager.GetManager(idx._pTree);

                    Assert.AreEqual(1, pt._cache.Count);
                    Assert.AreEqual(13, pt._cache[0].Count);
                }
            }
        }
        public void PubSubNeverPicksUpOwnTransactions()
        {
            _testName = System.Reflection.MethodInfo.GetCurrentMethod().Name.GetHashCode().ToString();

            using (var fLock = new ManagedFileLock(_testName))
            {
                Cleanup();

                using (var pdb1 = new Database<Guid, MockClassA>(_testName + ".subscriber" + ".database", "ReplicationID", new FileCore<Guid, long>())
                    .WithPublishing("Test", new FilePublisher<Guid, MockClassA>(Path.Combine(Environment.CurrentDirectory, _testName)))
                    .WithSubscription("Test", new FileSubscriber<Guid, MockClassA>(Path.Combine(Environment.CurrentDirectory, _testName), new TimeSpan(0, 0, 0, 0, 500))))
                {
                    pdb1.Load();
                    pdb1.Clear();

                    using (var t = pdb1.BeginTransaction())
                    {
                        pdb1.Delete(o => o != null);

                        t.Commit();
                    }

                    Assert.IsTrue(Directory.Exists(Path.Combine(Environment.CurrentDirectory, _testName)));

                    var objects = TestResourceFactory.GetMockClassAObjects(25).OfType<MockClassC>().ToList();
                    var negativeObjects = TestResourceFactory.GetMockClassAObjects(25).OfType<MockClassC>().ToList();

                    using (var t = pdb1.BeginTransaction())
                    {
                        objects.ForEach(o => pdb1.Add(o));

                        t.Commit();
                    }

                    var testTran = new MockTransaction<Guid, MockClassA>(
                        new TransactionManager<Guid, MockClassA>(
                            new MockTransactionFactory<Guid, MockClassA>()
                            , new TransactionSynchronizer<Guid, MockClassA>()));

                    testTran.Source = pdb1.TransactionSource;

                    foreach (var no in negativeObjects)
                        testTran.Enlist(Action.Create, no.ReplicationID, (MockClassA)no);

                    testTran.Commit();

                    var formatter = new BSONFormatter();

                    using (var fs = new FileStream(
                        Path.Combine(Environment.CurrentDirectory, _testName, testTran.Id.ToString() + ".trans")
                        , FileMode.OpenOrCreate, FileAccess.ReadWrite, FileShare.None, 4096, false))
                    {
                        var s = formatter.FormatObjStream(testTran);

                        s.WriteAllTo(fs);

                        fs.Flush();
                        fs.Close();
                    }

                    Thread.Sleep(750);

                    var sw = new Stopwatch();
                    sw.Start();

                    while (pdb1.FileFlushQueueActive && sw.ElapsedMilliseconds < 3000)
                        Thread.Sleep(100);

                    Assert.AreEqual(25, pdb1.Length);
                }
            }
        }