Beispiel #1
0
        public void TestCacheNeverStrategy()
        {
            GentleSettings.CacheObjects       = true;
            GentleSettings.SkipQueryExecution = true;
            GentleSettings.UniqingScope       = UniqingScope.Thread;
            CacheManager.Clear();

            ObjectMap map = ObjectFactory.GetMap(Broker.SessionBroker, typeof(MailingList));

            map.CacheStrategy = CacheStrategy.Never;

            int beforeCount = CacheManager.Count;

            MailingList.Retrieve(1);
            MailingList.Retrieve(2);
            Assert.AreEqual(beforeCount, CacheManager.Count);

            MailingList ml = new MailingList("test", "*****@*****.**");

            ml.Persist();
            Assert.AreEqual(beforeCount, CacheManager.Count);

            ml.Remove();
            Assert.AreEqual(beforeCount, CacheManager.Count);
            Assert.AreEqual(0, GentleStatistics.CacheHits);
            Assert.AreEqual(0, GentleStatistics.CacheMisses);
            Assert.AreEqual(beforeCount, GentleStatistics.CacheSize);
        }
Beispiel #2
0
        public void TestQueryResultInvalidationAndUniqing()
        {
            GentleSettings.CacheObjects       = true;
            GentleSettings.SkipQueryExecution = false;
            GentleSettings.UniqingScope       = UniqingScope.Thread;
            CacheManager.Clear();
            ObjectMap map = ObjectFactory.GetMap(Broker.SessionBroker, typeof(MailingList));

            if (map.CacheStrategy != CacheStrategy.Never)
            {
                // read all objects before insert
                IList before = Broker.RetrieveList(typeof(MailingList));
                Assert.IsTrue(before.Count > 0, "Unable to run test without data.");
                // insert a new instance
                MailingList ml = new MailingList("test", "*****@*****.**");
                ml.Persist();
                // read all objects after insert
                IList after = Broker.RetrieveList(typeof(MailingList));
                Assert.IsTrue(after.Contains(ml), "The object just persisted not included in result" +
                              " (cache not invalidated and/or object not added to cache).");
                // compare lists
                Assert.AreEqual(before.Count + 1, after.Count, "Invalid cache result.");
                // re-read single object
                MailingList mlread = MailingList.Retrieve(ml.Id);
                Assert.AreSame(ml, mlread, "Uniqing broken: new instance returned.");
            }
        }
Beispiel #3
0
        public void TestTypeInstanceRetrieval()
        {
            MailingList ml = MailingList.Retrieve("*****@*****.**");

            Assert.IsNotNull(ml);
            Assert.AreEqual("*****@*****.**", ml.SenderAddress);
        }
Beispiel #4
0
        public void TestObjectUniqing()
        {
            GentleSettings.SkipQueryExecution = false;
            ObjectMap map = ObjectFactory.GetMap(Broker.SessionBroker, typeof(MailingList));

            if (map.CacheStrategy != CacheStrategy.Never)
            {
                // test without cache
                CacheManager.Clear();
                GentleSettings.CacheObjects = false;
                int cacheCount = CacheManager.Count;
                l1 = MailingList.Retrieve(1);
                Assert.IsTrue(CacheManager.Count == cacheCount, "Item was erroneously added to cache.");
                l2 = MailingList.Retrieve(1);
                Assert.AreNotSame(l1, l2, "Object references are supposed to be different.");
                Check.LogInfo(LogCategories.General, "TestObjectUniqing --- after execution (without cache):");
                GentleStatistics.LogStatistics(LogCategories.Cache);
                // test with cache
                GentleSettings.CacheObjects = true;
                l1 = MailingList.Retrieve(1);
                Assert.IsTrue(CacheManager.Count == ++cacheCount, "Item was not added to cache.");
                l2 = MailingList.Retrieve(1);
                Assert.IsTrue(CacheManager.Count == cacheCount, "Item was added to cache again.");
                Assert.AreSame(l1, l2, "Object references are supposed to be identical.");
                Check.LogInfo(LogCategories.General, "TestObjectUniqing --- after execution (with cache)");
                GentleStatistics.LogStatistics(LogCategories.Cache);
            }
        }
Beispiel #5
0
        public void TestOrderByRetrieval()
        {
            GentleSqlFactory sf = Broker.GetSqlFactory();
            // first verify that data set is ok for test
            SqlBuilder sb = new SqlBuilder(StatementType.Select, typeof(MailingList));

            // get ascending
            sb.AddOrderByField(true, "SenderAddress");
            SqlResult sr = Broker.Execute(sb.GetStatement(true));

            Assert.IsTrue(sr.ErrorCode == 0 && sr.RowsContained == MailingList.ListAll.Count,
                          "Wrong number of rows were selected.");
            IList lists = ObjectFactory.GetCollection(typeof(MailingList), sr);

            Assert.IsNotNull(lists, "Test case invalid if row count is not 3.");
            Assert.IsTrue(lists.Count == 3, "Test case invalid if row count is not 3.");
            l1 = lists[0] as MailingList;
            l2 = lists[2] as MailingList;
            Assert.IsTrue(l1.SenderAddress.StartsWith("ann"), "Test case invalid if row order is wrong.");
            Assert.IsTrue(l2.SenderAddress.StartsWith("inf"), "Test case invalid if row order is wrong.");
            // now fetch the reverse ordered list
            sb = new SqlBuilder(StatementType.Select, typeof(MailingList));
            sb.AddOrderByField(false, "SenderAddress");
            sr = Broker.Execute(sb.GetStatement(true));
            Assert.IsTrue(sr.ErrorCode == 0 && sr.RowsContained == MailingList.ListAll.Count,
                          "Wrong number of rows were selected.");
            IList lists2 = ObjectFactory.GetCollection(typeof(MailingList), sr);

            l1 = lists2[0] as MailingList;
            l2 = lists2[2] as MailingList;
            Assert.IsTrue(l1.SenderAddress.StartsWith("inf"), "Result set was in wrong order.");
            Assert.IsTrue(l2.SenderAddress.StartsWith("ann"), "Result set was in wrong order.");
        }
Beispiel #6
0
        public void TestCRUD()
        {
            l1 = new MailingList("Test 1", "*****@*****.**");
            // insert
            l1.Persist();
            Assert.IsTrue(l1.Id > 0, "The List object was not assigned an id by the database!");
            Assert.AreEqual(l1.Name, "Test 1", "The List object was not properly inserted!");
            Assert.AreEqual(l1.SenderAddress, "*****@*****.**", "The List object was not properly inserted!");
            // select
            l2 = MailingList.Retrieve(l1.Id);
            // verify select/insert
            Assert.IsTrue(l2.Id != 0, "The List object could not be retrieved from the database!");
            Assert.AreEqual(l1.Id, l2.Id, "The List object could not be retrieved from the database!");
            Assert.AreEqual("Test 1", l2.Name, "The List object was not properly retrieved on construction!");
            Assert.AreEqual("*****@*****.**", l2.SenderAddress,
                            "The List object was not properly retrieved on construction!");
            // update
            l2.Name          = "Test 2";
            l2.SenderAddress = "*****@*****.**";
            l2.Persist();
            // verify update
            l1 = MailingList.Retrieve(l2.Id);
            Assert.AreEqual(l2.Name, l1.Name, "Name not updated!");
            Assert.AreEqual(l2.SenderAddress, l1.SenderAddress, "SenderAddress not updated!");
            // delete
            l2.Remove();
            // verify delete by counting the number of rows
            SqlBuilder sb = new SqlBuilder(StatementType.Count, typeof(MailingList));

            sb.AddConstraint(Operator.Equals, "Id", l1.Id);
            SqlResult sr = Broker.Execute(sb.GetStatement(true));

            Assert.AreEqual(0, sr.Count, "Object not removed");
        }
 public void TestCustomListUsingInConstraint()
 {
     // subselects not supported by the inferior mysql engine - skip test.
     if (!Broker.ProviderName.Equals("MySQL"))
     {
         GentleSqlFactory sf = Broker.GetSqlFactory();
         // first, select the number of expected entries
         SqlBuilder sb  = new SqlBuilder(StatementType.Count, typeof(MailingList));
         string     sql = String.Format("select distinct MemberAddress from {0}",
                                        sf.GetTableName("ListMember"));
         sb.AddConstraint(Operator.In, "SenderAddress", Broker.Execute(sql), "MemberAddress");
         SqlResult sr       = Broker.Execute(sb.GetStatement());
         int       expected = sr.Count;
         // verify list retrieval (using IList data)
         IList lists = MailingList.ListByCustomListConstraint();
         Assert.IsNotNull(lists);
         Assert.AreEqual(expected, lists.Count);
         // verify same result using alternative approach (using SqlResult data)
         sb = new SqlBuilder(StatementType.Select, typeof(Member));
         SqlResult members = sb.GetStatement(true).Execute();
         sb = new SqlBuilder(StatementType.Select, typeof(MailingList));
         // use column name as indexer into SqlResult for list constraints
         sb.AddConstraint(Operator.In, "SenderAddress", members, "MemberAddress");
         SqlStatement stmt = sb.GetStatement(true);
         lists = ObjectFactory.GetCollection(typeof(MailingList), stmt.Execute());
         Assert.IsNotNull(lists);
         Assert.AreEqual(expected, lists.Count);
     }
 }
Beispiel #8
0
		public void TestObjectUniqing()
		{
			GentleSettings.SkipQueryExecution = false;
			ObjectMap map = ObjectFactory.GetMap( Broker.SessionBroker, typeof(MailingList) );
			if( map.CacheStrategy != CacheStrategy.Never )
			{
				// test without cache
				CacheManager.Clear();
				GentleSettings.CacheObjects = false;
				int cacheCount = CacheManager.Count;
				l1 = MailingList.Retrieve( 1 );
				Assert.IsTrue( CacheManager.Count == cacheCount, "Item was erroneously added to cache." );
				l2 = MailingList.Retrieve( 1 );
				Assert.AreNotSame( l1, l2, "Object references are supposed to be different." );
				Check.LogInfo( LogCategories.General, "TestObjectUniqing --- after execution (without cache):" );
				GentleStatistics.LogStatistics( LogCategories.Cache );
				// test with cache
				GentleSettings.CacheObjects = true;
				l1 = MailingList.Retrieve( 1 );
				Assert.IsTrue( CacheManager.Count == ++cacheCount, "Item was not added to cache." );
				l2 = MailingList.Retrieve( 1 );
				Assert.IsTrue( CacheManager.Count == cacheCount, "Item was added to cache again." );
				Assert.AreSame( l1, l2, "Object references are supposed to be identical." );
				Check.LogInfo( LogCategories.General, "TestObjectUniqing --- after execution (with cache)" );
				GentleStatistics.LogStatistics( LogCategories.Cache );
			}
		}
Beispiel #9
0
		public void TestCRUD()
		{
			l1 = new MailingList( "Test 1", "*****@*****.**" );
			// insert
			l1.Persist();
			Assert.IsTrue( l1.Id > 0, "The List object was not assigned an id by the database!" );
			Assert.AreEqual( l1.Name, "Test 1", "The List object was not properly inserted!" );
			Assert.AreEqual( l1.SenderAddress, "*****@*****.**", "The List object was not properly inserted!" );
			// select
			l2 = MailingList.Retrieve( l1.Id );
			// verify select/insert
			Assert.IsTrue( l2.Id != 0, "The List object could not be retrieved from the database!" );
			Assert.AreEqual( l1.Id, l2.Id, "The List object could not be retrieved from the database!" );
			Assert.AreEqual( "Test 1", l2.Name, "The List object was not properly retrieved on construction!" );
			Assert.AreEqual( "*****@*****.**", l2.SenderAddress,
			                 "The List object was not properly retrieved on construction!" );
			// update
			l2.Name = "Test 2";
			l2.SenderAddress = "*****@*****.**";
			l2.Persist();
			// verify update
			l1 = MailingList.Retrieve( l2.Id );
			Assert.AreEqual( l2.Name, l1.Name, "Name not updated!" );
			Assert.AreEqual( l2.SenderAddress, l1.SenderAddress, "SenderAddress not updated!" );
			// delete
			l2.Remove();
			// verify delete by counting the number of rows
			SqlBuilder sb = new SqlBuilder( StatementType.Count, typeof(MailingList) );
			sb.AddConstraint( Operator.Equals, "Id", l1.Id );
			SqlResult sr = Broker.Execute( sb.GetStatement( true ) );
			Assert.AreEqual( 0, sr.Count, "Object not removed" );
		}
        public void Insert(int count)
        {
            MailingList ml;

            for (int i = 0; i < count; i++)
            {
                ml = new MailingList("xxx" + i, "xxx" + i + "@xxx.xxx");
                ml.Persist();
            }
        }
Beispiel #11
0
 public void TestCacheRemove()
 {
     l1 = MailingList.Retrieve(1);
     CacheManager.Clear();
     CacheManager.Insert("mylist", l1);
     Assert.AreEqual(1, CacheManager.Count, "Item not added to cache.");
     CacheManager.Remove("mylist");
     l1 = CacheManager.Get("mylist") as MailingList;
     Assert.IsNull(l1, "Item was still found in the cache.");
     Assert.AreEqual(0, CacheManager.Count, "Item not removed from the cache.");
 }
Beispiel #12
0
 public void TestGentleListWithConcurrency()
 {
     if (GentleSettings.ConcurrencyControl)
     {
         MailingList list    = MailingList.Retrieve(1);
         GentleList  members = new GentleList(typeof(MemberCC), list);
         Assert.AreEqual(2, members.Count, "List not initialized.");
         IList check = Broker.RetrieveList(typeof(MemberCC), list.GetKey());
         Assert.AreEqual(2, check.Count, "List contents dubious.");
     }
 }
Beispiel #13
0
		public void TestCacheRemove()
		{
			l1 = MailingList.Retrieve( 1 );
			CacheManager.Clear();
			CacheManager.Insert( "mylist", l1 );
			Assert.AreEqual( 1, CacheManager.Count, "Item not added to cache." );
			CacheManager.Remove( "mylist" );
			l1 = CacheManager.Get( "mylist" ) as MailingList;
			Assert.IsNull( l1, "Item was still found in the cache." );
			Assert.AreEqual( 0, CacheManager.Count, "Item not removed from the cache." );
		}
Beispiel #14
0
 public void TestCacheWeakReferenceExpiration()
 {
     l1 = MailingList.Retrieve(1);
     CacheManager.Clear();
     CacheManager.Insert("mylist", l1);
     Assert.AreEqual(1, CacheManager.Count, "Item not added to cache.");
     l1 = null;
     GC.Collect();
     l2 = CacheManager.Get("mylist") as MailingList;
     Assert.IsNull(l2, "Item was still found in the cache.");
     Assert.AreEqual(0, CacheManager.Count, "Item not removed from the cache.");
 }
Beispiel #15
0
		public void TestCacheWeakReferenceExpiration()
		{
			l1 = MailingList.Retrieve( 1 );
			CacheManager.Clear();
			CacheManager.Insert( "mylist", l1 );
			Assert.AreEqual( 1, CacheManager.Count, "Item not added to cache." );
			l1 = null;
			GC.Collect();
			l2 = CacheManager.Get( "mylist" ) as MailingList;
			Assert.IsNull( l2, "Item was still found in the cache." );
			Assert.AreEqual( 0, CacheManager.Count, "Item not removed from the cache." );
		}
        public void TestSelectOverhead()
        {
            Probe       probe = new Probe(3, true);
            MailingList ml    = MailingList.Retrieve(1);

            probe.Mark(1);
            ml = MailingList.Retrieve(1);
            probe.End(1);
            Check.LogInfo(LogCategories.General, "=================[ Select ]=================");
            Check.LogInfo(LogCategories.General, "First       : {0}", probe.Diff(0, 1));
            Check.LogInfo(LogCategories.General, "Second      : {0}", probe.Diff(1, 2));
            Check.LogInfo(LogCategories.General, "Total       : {0}", probe);
            Check.LogInfo(LogCategories.General, "Overhead    : {0}", probe.Diff(0, 1) - probe.Diff(1, 2));
        }
Beispiel #17
0
		public void Init()
		{
			// make sure we have only 4 members 
			SqlBuilder sb = new SqlBuilder( StatementType.Delete, typeof(MemberCC) );
			sb.AddConstraint( Operator.GreaterThan, "Id", 4 );
			Broker.Execute( sb.GetStatement( true ) );
			// make sure we have only 3 lists 
			sb = new SqlBuilder( StatementType.Delete, typeof(MailingList) );
			sb.AddConstraint( Operator.GreaterThan, "Id", 3 );
			Broker.Execute( sb.GetStatement( true ) );
			// create an empty mailing list
			list = new MailingList( "SomeList", "*****@*****.**" );
			list.Persist();
		}
        public void TestManualProviderCreation()
        {
            string name    = Configurator.GetKey(null, "Gentle.Framework/DefaultProvider/@name");
            string connStr = Configurator.GetKey(null, "Gentle.Framework/DefaultProvider/@connectionString");
            string schema  = Configurator.GetKey(null, "Gentle.Framework/DefaultProvider/@schema");
            //connStr = @"Server=(local)\SQLExpress;Database=Gentle;Integrated Security=true";
            PersistenceBroker broker = ProviderFactory.GetProvider("test", name, connStr, schema).Broker;
            IList             list   = broker.RetrieveList(typeof(MailingList));

            Assert.IsNotNull(list, "No result returned.");
            Assert.IsTrue(list.Count > 0, "List was empty.");
            MailingList ml = list[0] as MailingList;

            ml.Persist();
        }
Beispiel #19
0
        public void Init()
        {
            // make sure we have only 4 members
            SqlBuilder sb = new SqlBuilder(StatementType.Delete, typeof(MemberCCSD));

            sb.AddConstraint(Operator.GreaterThan, "Id", 4);
            Broker.Execute(sb.GetStatement(true));
            // make sure we have only 3 lists
            sb = new SqlBuilder(StatementType.Delete, typeof(MailingList));
            sb.AddConstraint(Operator.GreaterThan, "Id", 3);
            Broker.Execute(sb.GetStatement(true));
            // create an empty mailing list
            list = new MailingList("SomeList", "*****@*****.**");
            list.Persist();
        }
Beispiel #20
0
        public void TestCustomListUsingLikeConstraint()
        {
            GentleSqlFactory sf = Broker.GetSqlFactory();
            // first, select the number of expected entries
            SqlBuilder sb = new SqlBuilder(StatementType.Count, typeof(MailingList));

            sb.AddConstraint(Operator.Like, "SenderAddress", "%.com");
            SqlResult sr       = Broker.Execute(sb.GetStatement(true));
            int       expected = sr.Count;
            // verify list retrieval
            IList lists = MailingList.ListByDomain(".com");

            Assert.IsNotNull(lists);
            Assert.AreEqual(expected, lists.Count);
        }
 public void TestSelectBatch1000()
 {
     // skip Jet/Access - simply too slow for my temper..
     if (Broker.ProviderName != "Jet")
     {
         Insert(997);                   // assume first 3 exist
         Probe       probe = new Probe(3, true);
         MailingList ml    = MailingList.Retrieve(1);
         probe.Mark(1);
         IList list = MailingList.ListAll;
         probe.End(list.Count);
         Check.LogInfo(LogCategories.General, "=================[ Select Batch ]=================");
         Check.LogInfo(LogCategories.General, "First       : {0}", probe.Diff(0, 1));
         Check.LogInfo(LogCategories.General, "Next 1.000  : {0}", probe.Diff(1, 2));
         Check.LogInfo(LogCategories.General, "Time/Op     : {0}", probe.Diff(1, 2).TimePerOperation);
     }
 }
        public void TestCachingObjectOnly()
        {
            MailingList ml;

            CacheManager.Clear();
            // make sure only objects (and not statements or result sets) are cached
            GentleSettings.CacheObjects       = true;
            GentleSettings.CacheStatements    = false;
            GentleSettings.SkipQueryExecution = false;
            ObjectMap map      = ObjectFactory.GetMap(null, typeof(MailingList));
            int       expected = CacheManager.Count + 1;

            ml = MailingList.Retrieve(1);
            Assert.AreEqual(expected, CacheManager.Count, "Incorrect cache count.");
            ml = MailingList.Retrieve(1);
            Assert.AreEqual(expected, CacheManager.Count, "Incorrect cache count.");
        }
Beispiel #23
0
        public void TestTransaction()
        {
            // create some variables to work with
            l1 = MailingList.Retrieve(1);               // reuse existing list
            Member member = new Member(l1.Id, "Trans", "*****@*****.**");
            // create and populate the transaction
            Transaction t = new Transaction();

            t.Update(l1);
            t.Persist(member);
            t.Commit();
            // try updates and deletes
            member.Name = "Action";
            t           = new Transaction();
            t.Update(member);
            t.Remove(member);
            t.Commit();
        }
        public void TestSelectBatch10000()
        {
            Insert(9997);               // assume first 3 exist
            Probe       probe = new Probe(4, true);
            MailingList ml    = MailingList.Retrieve(1);

            probe.Mark(1);
            IList list = MailingList.ListAll;

            probe.Mark(list.Count);
            SqlResult sr = Broker.Retrieve(typeof(MailingList), new Key(typeof(MailingList), true));

            probe.End(sr.RowsContained);
            Check.LogInfo(LogCategories.General, "=================[ Select Batch ]=================");
            Check.LogInfo(LogCategories.General, "First       : {0}", probe.Diff(0, 1));
            Check.LogInfo(LogCategories.General, "Next 10.000 : {0}", probe.Diff(1, 2));
            Check.LogInfo(LogCategories.General, "Time/Op     : {0}", probe.Diff(1, 2).TimePerOperation);
            Check.LogInfo(LogCategories.General, "Raw 10.000  : {0}", probe.Diff(2, 3));
            Check.LogInfo(LogCategories.General, "Time/RawOp  : {0}", probe.Diff(2, 3).TimePerOperation);
        }
Beispiel #25
0
        public void TestSkipQueryExecution()
        {
            GentleSettings.CacheStatements    = true;
            GentleSettings.CacheObjects       = true;
            GentleSettings.SkipQueryExecution = true;
            ObjectMap map = ObjectFactory.GetMap(Broker.SessionBroker, typeof(MailingList));

            if (map.CacheStrategy != CacheStrategy.Never)
            {
                CacheManager.Clear();
                l1 = MailingList.Retrieve(1);
                Assert.IsTrue(CacheManager.Count == 2, "Expected both query result info and object in cache.");
                for (int i = 0; i < 10; i++)
                {
                    l1 = MailingList.Retrieve(1);
                }
                Assert.IsTrue(CacheManager.Count == 2, "Unexpected change in cache contents.");
                // strangely enough, SkippedQueries is only 9 when executing all tests, but
                // 10 when this test is executed alone?!
                Assert.IsTrue(GentleStatistics.SkippedQueries >= 9,
                              String.Format("Unexpected number of skipped queries (was: {0} expected: 10).", GentleStatistics.SkippedQueries));
            }
        }
Beispiel #26
0
        public void TestUniqingScope()
        {
            GentleSettings.CacheObjects       = true;
            GentleSettings.SkipQueryExecution = false;
            GentleSettings.UniqingScope       = UniqingScope.Thread;
            CacheManager.Clear();
            ObjectMap map = ObjectFactory.GetMap(Broker.SessionBroker, typeof(MailingList));

            if (map.CacheStrategy != CacheStrategy.Never)
            {
                // access in this thread (populates cache)
                int cacheCount1stThread = CacheManager.Count;
                l1 = MailingList.Retrieve(1);
                Assert.IsTrue(CacheManager.Count == ++cacheCount1stThread, "Item was not added to cache.");
                l2 = MailingList.Retrieve(1);
                Assert.IsTrue(CacheManager.Count == cacheCount1stThread, "Item was added to cache again.");
                Assert.AreSame(l1, l2, "Object references are supposed to be identical.");
                Check.LogInfo(LogCategories.General, "TestUniqingScope --- after execution (thread {0}):", SystemSettings.ThreadIdentity);
                GentleStatistics.LogStatistics(LogCategories.Cache);
                // access same type in separate thread
                Thread thread = new Thread(RetrieveSpecificList);
                // remember the threads id (check for name to match SystemSettings.ThreadIdentity behavior)
                string threadId            = thread.Name != null ? thread.Name : thread.GetHashCode().ToString();
                int    cacheCount2ndThread = CacheManager.GetCount(threadId);
                thread.Start();
                thread.Join();                 // wait for completion
                // we should see only a mailinglist being added to the cache
                Assert.AreEqual(cacheCount1stThread, CacheManager.Count, "Item was added to wrong cache store.");
                Assert.AreEqual(++cacheCount2ndThread, CacheManager.GetCount(threadId), "Item was not added to cache for 2nd thread.");
                Check.LogInfo(LogCategories.General, "TestUniqingScope --- after execution (thread {0}):", thread.GetHashCode());
                GentleStatistics.LogStatistics(LogCategories.Cache);
                // under normal circumstances we should make sure to clean items belonging to the
                // terminated thread; lets test that this works too :)
                CacheManager.Clear(threadId);
                Assert.AreEqual(--cacheCount2ndThread, CacheManager.GetCount(threadId), "Items were not properly flushed from the cache.");
            }
        }
        public void TestInsertSelectBatch()
        {
            Probe probe = new Probe(3, true);

            Insert(1);
            probe.Mark(1);
            Insert(100000);
            probe.Mark(100000);
            Check.LogInfo(LogCategories.General, "=================[ Insert Large Batch ]=================");
            Check.LogInfo(LogCategories.General, "First Insert: {0}", probe.Diff(0, 1));
            Check.LogInfo(LogCategories.General, "Next 100.000: {0}", probe.Diff(1, 2));
            Check.LogInfo(LogCategories.General, "Time/Op     : {0}", probe.Diff(1, 2).TimePerOperation);
            probe = new Probe(3, true);
            MailingList ml = MailingList.Retrieve(1);

            probe.Mark(1);
            IList list = MailingList.ListAll;

            probe.End(list.Count);
            Check.LogInfo(LogCategories.General, "=================[ Select Large Batch ]=================");
            Check.LogInfo(LogCategories.General, "First Select: {0}", probe.Diff(0, 1));
            Check.LogInfo(LogCategories.General, "Next 100.000: {0}", probe.Diff(1, 2));
            Check.LogInfo(LogCategories.General, "Time/Op     : {0}", probe.Diff(1, 2).TimePerOperation);
        }
Beispiel #28
0
		public void TestCacheNeverStrategy()
		{
			GentleSettings.CacheObjects = true;
			GentleSettings.SkipQueryExecution = true;
			GentleSettings.UniqingScope = UniqingScope.Thread;
			CacheManager.Clear();

			ObjectMap map = ObjectFactory.GetMap( Broker.SessionBroker, typeof(MailingList) );
			map.CacheStrategy = CacheStrategy.Never;

			int beforeCount = CacheManager.Count;

			MailingList.Retrieve( 1 );
			MailingList.Retrieve( 2 );
			Assert.AreEqual( beforeCount, CacheManager.Count );

			MailingList ml = new MailingList( "test", "*****@*****.**" );
			ml.Persist();
			Assert.AreEqual( beforeCount, CacheManager.Count );

			ml.Remove();
			Assert.AreEqual( beforeCount, CacheManager.Count );
			Assert.AreEqual( 0, GentleStatistics.CacheHits );
			Assert.AreEqual( 0, GentleStatistics.CacheMisses );
			Assert.AreEqual( beforeCount, GentleStatistics.CacheSize );
		}
Beispiel #29
0
		public void TestOrderByRetrieval()
		{
			GentleSqlFactory sf = Broker.GetSqlFactory();
			// first verify that data set is ok for test
			SqlBuilder sb = new SqlBuilder( StatementType.Select, typeof(MailingList) );
			// get ascending
			sb.AddOrderByField( true, "SenderAddress" );
			SqlResult sr = Broker.Execute( sb.GetStatement( true ) );
			Assert.IsTrue( sr.ErrorCode == 0 && sr.RowsContained == MailingList.ListAll.Count,
			               "Wrong number of rows were selected." );
			IList lists = ObjectFactory.GetCollection( typeof(MailingList), sr );
			Assert.IsNotNull( lists, "Test case invalid if row count is not 3." );
			Assert.IsTrue( lists.Count == 3, "Test case invalid if row count is not 3." );
			l1 = lists[ 0 ] as MailingList;
			l2 = lists[ 2 ] as MailingList;
			Assert.IsTrue( l1.SenderAddress.StartsWith( "ann" ), "Test case invalid if row order is wrong." );
			Assert.IsTrue( l2.SenderAddress.StartsWith( "inf" ), "Test case invalid if row order is wrong." );
			// now fetch the reverse ordered list
			sb = new SqlBuilder( StatementType.Select, typeof(MailingList) );
			sb.AddOrderByField( false, "SenderAddress" );
			sr = Broker.Execute( sb.GetStatement( true ) );
			Assert.IsTrue( sr.ErrorCode == 0 && sr.RowsContained == MailingList.ListAll.Count,
			               "Wrong number of rows were selected." );
			IList lists2 = ObjectFactory.GetCollection( typeof(MailingList), sr );
			l1 = lists2[ 0 ] as MailingList;
			l2 = lists2[ 2 ] as MailingList;
			Assert.IsTrue( l1.SenderAddress.StartsWith( "inf" ), "Result set was in wrong order." );
			Assert.IsTrue( l2.SenderAddress.StartsWith( "ann" ), "Result set was in wrong order." );
		}
Beispiel #30
0
		public void TestQueryResultInvalidationAndUniqing()
		{
			GentleSettings.CacheObjects = true;
			GentleSettings.SkipQueryExecution = false;
			GentleSettings.UniqingScope = UniqingScope.Thread;
			CacheManager.Clear();
			ObjectMap map = ObjectFactory.GetMap( Broker.SessionBroker, typeof(MailingList) );
			if( map.CacheStrategy != CacheStrategy.Never )
			{
				// read all objects before insert
				IList before = Broker.RetrieveList( typeof(MailingList) );
				Assert.IsTrue( before.Count > 0, "Unable to run test without data." );
				// insert a new instance
				MailingList ml = new MailingList( "test", "*****@*****.**" );
				ml.Persist();
				// read all objects after insert
				IList after = Broker.RetrieveList( typeof(MailingList) );
				Assert.IsTrue( after.Contains( ml ), "The object just persisted not included in result" +
				                                     " (cache not invalidated and/or object not added to cache)." );
				// compare lists
				Assert.AreEqual( before.Count + 1, after.Count, "Invalid cache result." );
				// re-read single object
				MailingList mlread = MailingList.Retrieve( ml.Id );
				Assert.AreSame( ml, mlread, "Uniqing broken: new instance returned." );
			}
		}
		public void Insert( int count )
		{
			MailingList ml;
			for( int i = 0; i < count; i++ )
			{
				ml = new MailingList( "xxx" + i, "xxx" + i + "@xxx.xxx" );
				ml.Persist();
			}
		}
Beispiel #32
0
		public void TestUniqingScope()
		{
			GentleSettings.CacheObjects = true;
			GentleSettings.SkipQueryExecution = false;
			GentleSettings.UniqingScope = UniqingScope.Thread;
			CacheManager.Clear();
			ObjectMap map = ObjectFactory.GetMap( Broker.SessionBroker, typeof(MailingList) );
			if( map.CacheStrategy != CacheStrategy.Never )
			{
				// access in this thread (populates cache)
				int cacheCount1stThread = CacheManager.Count;
				l1 = MailingList.Retrieve( 1 );
				Assert.IsTrue( CacheManager.Count == ++cacheCount1stThread, "Item was not added to cache." );
				l2 = MailingList.Retrieve( 1 );
				Assert.IsTrue( CacheManager.Count == cacheCount1stThread, "Item was added to cache again." );
				Assert.AreSame( l1, l2, "Object references are supposed to be identical." );
				Check.LogInfo( LogCategories.General, "TestUniqingScope --- after execution (thread {0}):", SystemSettings.ThreadIdentity );
				GentleStatistics.LogStatistics( LogCategories.Cache );
				// access same type in separate thread
				Thread thread = new Thread( RetrieveSpecificList );
				// remember the threads id (check for name to match SystemSettings.ThreadIdentity behavior)
				string threadId = thread.Name != null ? thread.Name : thread.GetHashCode().ToString();
				int cacheCount2ndThread = CacheManager.GetCount( threadId );
				thread.Start();
				thread.Join(); // wait for completion
				// we should see only a mailinglist being added to the cache
				Assert.AreEqual( cacheCount1stThread, CacheManager.Count, "Item was added to wrong cache store." );
				Assert.AreEqual( ++cacheCount2ndThread, CacheManager.GetCount( threadId ), "Item was not added to cache for 2nd thread." );
				Check.LogInfo( LogCategories.General, "TestUniqingScope --- after execution (thread {0}):", thread.GetHashCode() );
				GentleStatistics.LogStatistics( LogCategories.Cache );
				// under normal circumstances we should make sure to clean items belonging to the 
				// terminated thread; lets test that this works too :)
				CacheManager.Clear( threadId );
				Assert.AreEqual( --cacheCount2ndThread, CacheManager.GetCount( threadId ), "Items were not properly flushed from the cache." );
			}
		}
Beispiel #33
0
		public void TestSkipQueryExecution()
		{
			GentleSettings.CacheStatements = true;
			GentleSettings.CacheObjects = true;
			GentleSettings.SkipQueryExecution = true;
			ObjectMap map = ObjectFactory.GetMap( Broker.SessionBroker, typeof(MailingList) );
			if( map.CacheStrategy != CacheStrategy.Never )
			{
				CacheManager.Clear();
				l1 = MailingList.Retrieve( 1 );
				Assert.IsTrue( CacheManager.Count == 2, "Expected both query result info and object in cache." );
				for( int i = 0; i < 10; i++ )
				{
					l1 = MailingList.Retrieve( 1 );
				}
				Assert.IsTrue( CacheManager.Count == 2, "Unexpected change in cache contents." );
				// strangely enough, SkippedQueries is only 9 when executing all tests, but 
				// 10 when this test is executed alone?! 
				Assert.IsTrue( GentleStatistics.SkippedQueries >= 9,
				               String.Format( "Unexpected number of skipped queries (was: {0} expected: 10).", GentleStatistics.SkippedQueries ) );
			}
		}
Beispiel #34
0
		public void TestTransaction()
		{
			// create some variables to work with
			l1 = MailingList.Retrieve( 1 ); // reuse existing list
			Member member = new Member( l1.Id, "Trans", "*****@*****.**" );
			// create and populate the transaction
			Transaction t = new Transaction();
			t.Update( l1 );
			t.Persist( member );
			t.Commit();
			// try updates and deletes
			member.Name = "Action";
			t = new Transaction();
			t.Update( member );
			t.Remove( member );
			t.Commit();
		}
Beispiel #35
0
        public void TestPaging()
        {
            GentleSqlFactory sf = Broker.GetSqlFactory();

            if (sf.HasCapability(Capability.Paging))
            {
                // first verify that data set is ok for test
                IList lists = MailingList.ListAll;
                Assert.IsNotNull(lists, "Test case invalid if row count is below 3.");
                Assert.IsTrue(lists.Count >= 3, "Test case invalid if row count is below 3.");
                // try with 1 row limit
                SqlBuilder sb = new SqlBuilder(StatementType.Select, typeof(MailingList));
                sb.SetRowLimit(1);
                SqlResult sr = Broker.Execute(sb.GetStatement(true));
                // verify result
                Assert.IsTrue(sr.ErrorCode == 0 && sr.RowsContained > 0, "No rows were selected.");
                Assert.AreEqual(1, sr.RowsContained, "Result set 1 was not limited.");
                MailingList ml = ObjectFactory.GetInstance(typeof(MailingList), sr) as MailingList;
                Assert.AreEqual((lists[0] as MailingList).Id, ml.Id, "Wrong row(s) retrieved.");
                // get next result
                sr = sr.Next();
                Assert.IsTrue(sr.ErrorCode == 0 && sr.RowsContained > 0, "No rows were selected.");
                Assert.AreEqual(1, sr.RowsContained, "Result set 2 was not limited.");
                ml = ObjectFactory.GetInstance(typeof(MailingList), sr) as MailingList;
                Assert.AreEqual((lists[1] as MailingList).Id, ml.Id, "Wrong row(s) retrieved.");
                // get next result
                sr = sr.Next();
                Assert.IsTrue(sr.ErrorCode == 0 && sr.RowsContained > 0, "No rows were selected.");
                Assert.AreEqual(1, sr.RowsContained, "Result set 3 was not limited.");
                ml = ObjectFactory.GetInstance(typeof(MailingList), sr) as MailingList;
                Assert.AreEqual((lists[2] as MailingList).Id, ml.Id, "Wrong row(s) retrieved.");
                // try the previous again
                sr = sr.Previous();
                Assert.IsTrue(sr.ErrorCode == 0 && sr.RowsContained > 0, "No rows were selected.");
                Assert.AreEqual(1, sr.RowsContained, "Result set 4 was not limited.");
                ml = ObjectFactory.GetInstance(typeof(MailingList), sr) as MailingList;
                Assert.AreEqual((lists[1] as MailingList).Id, ml.Id, "Wrong row(s) retrieved.");

                //Try Page Numbers..
                sr = sr.Page(2);
                Assert.IsTrue(sr.ErrorCode == 0 && sr.RowsContained > 0, "No rows were selected.");
                Assert.AreEqual(1, sr.RowsContained, "Result set 5 was not limited.");
                ml = ObjectFactory.GetInstance(typeof(MailingList), sr) as MailingList;
                Assert.AreEqual((lists[1] as MailingList).Id, ml.Id, "Wrong row(s) retrieved.");

                sr = sr.Page(1);
                Assert.IsTrue(sr.ErrorCode == 0 && sr.RowsContained > 0, "No rows were selected.");
                Assert.AreEqual(1, sr.RowsContained, "Result set 6 was not limited.");
                ml = ObjectFactory.GetInstance(typeof(MailingList), sr) as MailingList;
                Assert.AreEqual((lists[0] as MailingList).Id, ml.Id, "Wrong row(s) retrieved.");

                sr = sr.Next();
                Assert.IsTrue(sr.ErrorCode == 0 && sr.RowsContained > 0, "No rows were selected.");
                Assert.AreEqual(1, sr.RowsContained, "Result set 7 was not limited.");
                ml = ObjectFactory.GetInstance(typeof(MailingList), sr) as MailingList;
                Assert.AreEqual((lists[1] as MailingList).Id, ml.Id, "Wrong row(s) retrieved.");

                sr = sr.Page(3);
                Assert.IsTrue(sr.ErrorCode == 0 && sr.RowsContained > 0, "No rows were selected.");
                Assert.AreEqual(1, sr.RowsContained, "Result set 8 was not limited.");
                ml = ObjectFactory.GetInstance(typeof(MailingList), sr) as MailingList;
                Assert.AreEqual((lists[2] as MailingList).Id, ml.Id, "Wrong row(s) retrieved.");

                //Test for Page 0 - should return first page
                sr = sr.Page(0);
                Assert.IsTrue(sr.ErrorCode == 0 && sr.RowsContained > 0, "No rows were selected.");
                Assert.AreEqual(1, sr.RowsContained, "Result set 9 was not limited.");
                ml = ObjectFactory.GetInstance(typeof(MailingList), sr) as MailingList;
                Assert.AreEqual((lists[0] as MailingList).Id, ml.Id, "Wrong row(s) retrieved.");

                //Test for invalid page - should return no rows
                sr = sr.Page(1 + (lists.Count / sr.Statement.RowLimit));
                Assert.IsTrue(sr.ErrorCode == 0 && sr.RowsContained == 0);
            }
        }
Beispiel #36
0
 private static void RetrieveSpecificList()
 {
     MailingList ml = MailingList.Retrieve(1);
 }