Example #1
0
 public void Test4()
 {
     ISoodaCache c = new SoodaInProcessCache();
     c.Add("Contact", 2, DummyEntry(2), TimeSpan.FromHours(1), false);
     c.Add("Contact", 2, DummyEntry(3), TimeSpan.FromHours(1), false);
     Assert.AreEqual(3, c.Find("Contact", 2).DataLoadedMask);
 }
Example #2
0
 public void Test2()
 {
     ISoodaCache c = new SoodaInProcessCache();
     c.Add("Contact", 2, DummyEntry(2), TimeSpan.FromHours(1), false);
     c.Invalidate("Contact", 2, SoodaCacheInvalidateReason.Updated);
     Assert.IsNull(c.Find("Contact", 2));
 }
Example #3
0
 public void Test3()
 {
     ISoodaCache c = new SoodaInProcessCache();
     c.Add("Contact", 2, DummyEntry(2), TimeSpan.FromHours(1), false);
     //c.Invalidate("Contact", 2, SoodaCacheInvalidateReason.Updated);
     Assert.IsNotNull(c.Find("Contact", 2));
     Assert.AreEqual(2, c.Find("Contact", 2).DataLoadedMask);
 }
        public void Test10()
        {
            using (TestSqlDataSource testDataSource = new TestSqlDataSource("default"))
            {
                testDataSource.Open();

                SoodaInProcessCache myCache = new SoodaInProcessCache();
                using (SoodaTransaction tran = new SoodaTransaction())
                {
                    tran.RegisterDataSource(testDataSource);
                    tran.Cache = myCache;
                    tran.CachingPolicy = new SoodaCacheAllPolicy();

                    string ck1 = SoodaCache.GetCollectionKey("Vehicle", new SoodaWhereClause(true));
                    VehicleList c1 = Vehicle.GetList(true);

                    string ck2 = SoodaCache.GetCollectionKey("Bike", new SoodaWhereClause(true));
                    BikeList c2 = Bike.GetList(true);

                    string ck3 = SoodaCache.GetCollectionKey("Bike", new SoodaWhereClause(false));
                    BikeList c3 = Bike.GetList(false);

                    Assert.IsNotNull(myCache.LoadCollection(ck1));
                    Assert.IsNotNull(myCache.LoadCollection(ck2));
                    Assert.IsNotNull(myCache.LoadCollection(ck3));

                    myCache.Evict("Vehicle", 1);

                    // ck2 is not evicted because vehicle[1] is not a bike
                    // ck3 is not evicted because it contains zero objects

                    Assert.IsNull(myCache.LoadCollection(ck1));
                    Assert.IsNotNull(myCache.LoadCollection(ck2));
                    Assert.IsNotNull(myCache.LoadCollection(ck3));
                }
            }
        }
        public void Test11()
        {
            using (TestSqlDataSource testDataSource = new TestSqlDataSource("default"))
            {
                testDataSource.Open();

                SoodaInProcessCache myCache = new SoodaInProcessCache();
                using (SoodaTransaction tran = new SoodaTransaction())
                {
                    tran.RegisterDataSource(testDataSource);
                    tran.Cache = myCache;
                    tran.CachingPolicy = new SoodaCacheAllPolicy();

                    string ck1 = SoodaCache.GetCollectionKey("Vehicle", new SoodaWhereClause(true));
                    VehicleList c1 = Vehicle.GetList(true, SoodaSnapshotOptions.KeysOnly);

                    string ck2 = SoodaCache.GetCollectionKey("Bike", new SoodaWhereClause(true));
                    BikeList c2 = Bike.GetList(true, SoodaSnapshotOptions.KeysOnly);

                    string ck3 = SoodaCache.GetCollectionKey("Bike", new SoodaWhereClause(false));
                    BikeList c3 = Bike.GetList(false, SoodaSnapshotOptions.KeysOnly);

                    Assert.IsNotNull(myCache.LoadCollection(ck1));
                    Assert.IsNotNull(myCache.LoadCollection(ck2));
                    Assert.IsNotNull(myCache.LoadCollection(ck3));

                    myCache.Evict("Vehicle", 1);

                    // nothing is evicted from collection cache because we requested KeysOnly

                    Assert.IsNotNull(myCache.LoadCollection(ck1));
                    Assert.IsNotNull(myCache.LoadCollection(ck2));
                    Assert.IsNotNull(myCache.LoadCollection(ck3));
                }
            }
        }
 public void Test8()
 {
     SoodaInProcessCache c = new SoodaInProcessCache();
     c.Add("Contact", 1, DummyEntry(1), TimeSpan.FromMilliseconds(150), false);
     c.Add("Contact", 2, DummyEntry(2), TimeSpan.FromMilliseconds(150), false);
     c.Add("Contact", 3, DummyEntry(3), TimeSpan.FromMilliseconds(150), false);
     string ck = "Contact where 1=2";
     c.StoreCollection(ck, "Contact", new int[] { 1, 2, 3 }, new string[] { "Contact", "Group", "Role" }, true, TimeSpan.FromMilliseconds(150), false);
     Assert.IsNotNull(c.Find("Contact", 3));
     System.Threading.Thread.Sleep(200);
     Console.WriteLine("*** Sweeping ***");
     c.Sweep();
     Console.WriteLine("*** Finished ***");
     Assert.IsNull(c.Find("Contact", 3));
 }
 public void Test7()
 {
     SoodaInProcessCache c = new SoodaInProcessCache();
     c.Add("Contact", 3, DummyEntry(3), TimeSpan.FromMilliseconds(50), false);
     Assert.IsNotNull(c.Find("Contact", 3));
     System.Threading.Thread.Sleep(100);
     c.Sweep();
     Assert.IsNull(c.Find("Contact", 3));
 }
 public void Test6()
 {
     ISoodaCache c = new SoodaInProcessCache();
     c.Add("Contact", 1, DummyEntry(1), TimeSpan.FromHours(1), false);
     c.Add("Contact", 2, DummyEntry(2), TimeSpan.FromHours(1), false);
     c.Add("Contact", 3, DummyEntry(3), TimeSpan.FromHours(1), false);
     string ck = "Contact where 1=2";
     c.StoreCollection(ck, "Contact", new int[] { 1, 2, 3 }, new string[] { "Contact", "Group", "Role" }, true, TimeSpan.FromHours(1), false);
     Assert.IsNotNull(c.LoadCollection(ck));
     Assert.AreEqual(3, c.LoadCollection(ck).Count);
     c.Invalidate("Group", 3, SoodaCacheInvalidateReason.Updated);
     Assert.IsNull(c.LoadCollection(ck));
 }
 public void Test5()
 {
     ISoodaCache c = new SoodaInProcessCache();
     string ck = "Contact where 1=2";
     c.Add("Contact", 1, DummyEntry(1), TimeSpan.FromHours(1), false);
     c.Add("Contact", 2, DummyEntry(2), TimeSpan.FromHours(1), false);
     c.Add("Contact", 3, DummyEntry(3), TimeSpan.FromHours(1), false);
     c.StoreCollection(ck, "Contact", new int[] { 1, 2, 3 }, new string[0], true, TimeSpan.FromHours(1), false);
     Assert.IsNotNull(c.LoadCollection(ck));
     Assert.AreEqual(3, c.LoadCollection(ck).Count);
     c.Evict("Contact", 3);
     Assert.IsNull(c.LoadCollection(ck));
 }
 public EndCommitCaller(SoodaInProcessCache sipc)
 {
     _sipc = sipc;
 }
Example #11
0
        public void Test5()
        {
            using (TestSqlDataSource testDataSource = new TestSqlDataSource("default"))
            {
                testDataSource.Open();

                SoodaInProcessCache myCache = new SoodaInProcessCache();
                using (SoodaTransaction tran = new SoodaTransaction())
                {
                    tran.RegisterDataSource(testDataSource);
                    tran.Cache = myCache;
                    tran.CachingPolicy = new SoodaCacheAllPolicy();

                    ContactList cl = Role.Employee.Members.GetSnapshot();
                }
                Assert.IsNotNull(myCache.LoadCollection("ContactToRole where Role = 1"));
                using (SoodaTransaction tran = new SoodaTransaction())
                {
                    tran.RegisterDataSource(testDataSource);
                    tran.Cache = myCache;
                    tran.CachingPolicy = new SoodaCacheAllPolicy();

                    Assert.AreEqual(0, tran.Statistics.CollectionCacheHits);
                    Assert.AreEqual(0, tran.Statistics.CollectionCacheMisses);

                    // make sure w have a cache hit
                    ContactList cl = Role.Employee.Members.GetSnapshot();
                    Assert.AreEqual(1, tran.Statistics.CollectionCacheHits);
                    Assert.AreEqual(0, tran.Statistics.CollectionCacheMisses);
                }
            }
        }
Example #12
0
 public void Test1()
 {
     ISoodaCache c = new SoodaInProcessCache();
     Assert.IsNull(c.Find("Contact", 2));
 }
Example #13
0
        public void Test6()
        {
            using (TestSqlDataSource testDataSource = new TestSqlDataSource("default"))
            {
                testDataSource.Open();

                SoodaInProcessCache myCache = new SoodaInProcessCache();
                using (SoodaTransaction tran = new SoodaTransaction())
                {
                    tran.RegisterDataSource(testDataSource);
                    tran.Cache = myCache;
                    tran.CachingPolicy = new SoodaCacheAllPolicy();

                    ContactList cl = Role.Employee.Members.GetSnapshot();
                }
                // make sure it's in cache
                Assert.IsNotNull(myCache.LoadCollection("ContactToRole where Role = 1"));
                using (SoodaTransaction tran = new SoodaTransaction())
                {
                    tran.RegisterDataSource(testDataSource);
                    tran.Cache = myCache;
                    tran.CachingPolicy = new SoodaCacheAllPolicy();

                    // add role
                    Contact.Eva.Roles.Add(Role.Customer);

                    // force precommit
                    tran.SaveObjectChanges();

                    Assert.AreEqual(0, tran.Statistics.CollectionCacheHits);
                    Assert.AreEqual(0, tran.Statistics.CollectionCacheMisses);

                    // make sure w have a cache miss
                    ContactList cl = Role.Employee.Members.GetSnapshot();
                    Assert.AreEqual(0, tran.Statistics.CollectionCacheHits);
                    Assert.AreEqual(1, tran.Statistics.CollectionCacheMisses);
                    tran.Commit();
                }
                // make sure it's NOT in cache
                Assert.IsNull(myCache.LoadCollection("ContactToRole where Role = 1"));
            }
        }
 public EndCommitCaller(SoodaInProcessCache sipc)
 {
     _sipc = sipc;
 }