public void ConnectionMaintanenceDuringFlush()
        {
            Prepare();
            ISession s = GetSessionUnderTest();

            s.BeginTransaction();

            IList entities = new ArrayList();

            for (int i = 0; i < 10; i++)
            {
                Other other = new Other("other-" + i);
                Silly silly = new Silly("silly-" + i, other);
                entities.Add(silly);
                s.Save(silly);
            }
            s.Flush();

            foreach (Silly silly in entities)
            {
                silly.Name       = "new-" + silly.Name;
                silly.Other.Name = "new-" + silly.Other.Name;
            }
//			long initialCount = sessions.Statistics.getConnectCount();
            s.Flush();
//			Assert.AreEqual(initialCount + 1, sessions.Statistics.getConnectCount(), "connection not maintained through Flush");

            s.Delete("from Silly");
            s.Delete("from Other");
            s.Transaction.Commit();
            Release(s);
            Done();
        }
        public void QueryIteration()
        {
            Prepare();
            ISession s     = GetSessionUnderTest();
            Silly    silly = new Silly("silly");

            s.Save(silly);
            s.Flush();

            IEnumerable en  = s.CreateQuery("from Silly").Enumerable();
            IEnumerator itr = en.GetEnumerator();

            Assert.IsTrue(itr.MoveNext());
            Silly silly2 = (Silly)itr.Current;

            Assert.AreEqual(silly, silly2);
            NHibernateUtil.Close(itr);

            itr = s.CreateQuery("from Silly").Enumerable().GetEnumerator();
            IEnumerator itr2 = s.CreateQuery("from Silly where name = 'silly'").Enumerable().GetEnumerator();

            Assert.IsTrue(itr.MoveNext());
            Assert.AreEqual(silly, itr.Current);
            Assert.IsTrue(itr2.MoveNext());
            Assert.AreEqual(silly, itr2.Current);

            NHibernateUtil.Close(itr);
            NHibernateUtil.Close(itr2);

            s.Delete(silly);
            s.Flush();

            Release(s);
            Done();
        }
Beispiel #3
0
        public async Task ConnectionMaintanenceDuringFlushAsync()
        {
            Prepare();
            ISession s = GetSessionUnderTest();

            using (var t = s.BeginTransaction())
            {
                IList <Silly> entities = new List <Silly>();
                for (int i = 0; i < 10; i++)
                {
                    Other other = new Other("other-" + i);
                    Silly silly = new Silly("silly-" + i, other);
                    entities.Add(silly);
                    await(s.SaveAsync(silly));
                }
                await(s.FlushAsync());

                foreach (Silly silly in entities)
                {
                    silly.Name       = "new-" + silly.Name;
                    silly.Other.Name = "new-" + silly.Other.Name;
                }
                // long initialCount = sessions.Statistics.getConnectCount();
                await(s.FlushAsync());
                //Assert.AreEqual(initialCount + 1, sessions.Statistics.getConnectCount(), "connection not maintained through Flush");

                await(s.DeleteAsync("from Silly"));
                await(s.DeleteAsync("from Other"));
                await(t.CommitAsync());
            }
            Release(s);
            Done();
        }
		public void SerializationOnAfterStatementAggressiveRelease()
		{
			Prepare();
			ISession s = GetSessionUnderTest();
			Silly silly = new Silly("silly");
			s.Save(silly);

			// this should cause the CM to obtain a connection, and then Release it
			s.Flush();

			// We should be able to serialize the session at this point...
			SerializationHelper.Serialize(s);

			s.Delete(silly);
			s.Flush();

			Release(s);
			Done();
		}
        public void SerializationOnAfterStatementAggressiveRelease()
        {
            Prepare();
            ISession s     = GetSessionUnderTest();
            Silly    silly = new Silly("silly");

            s.Save(silly);

            // this should cause the CM to obtain a connection, and then Release it
            s.Flush();

            // We should be able to serialize the session at this point...
            SerializationHelper.Serialize(s);

            s.Delete(silly);
            s.Flush();

            Release(s);
            Done();
        }
Beispiel #6
0
        public void SerializationFailsOnAfterStatementAggressiveReleaseWithOpenResources()
        {
            TestsContext.AssumeSystemTypeIsSerializable();

            Prepare();
            ISession s = GetSessionUnderTest();

            Silly silly = new Silly("silly");

            s.Save(silly);

            // this should cause the CM to obtain a connection, and then Release it
            s.Flush();

            // both scroll() and iterate() cause the batcher to hold on
            // to resources, which should make aggresive-Release not Release
            // the connection (and thus cause serialization to fail)
            IEnumerable en = s.CreateQuery("from Silly").Enumerable();

            try
            {
                SerializationHelper.Serialize(s);
                Assert.Fail(
                    "Serialization allowed on connected session; or aggressive Release released connection with open resources");
            }
            catch (InvalidOperationException)
            {
                // expected behavior
            }

            // Closing the ScrollableResults does currently force the batcher to
            // aggressively Release the connection
            NHibernateUtil.Close(en);
            SerializationHelper.Serialize(s);

            s.Delete(silly);
            s.Flush();

            Release(s);
            Done();
        }
Beispiel #7
0
        public async Task SerializationOnAfterStatementAggressiveReleaseAsync()
        {
            TestsContext.AssumeSystemTypeIsSerializable();

            Prepare();
            ISession s     = GetSessionUnderTest();
            Silly    silly = new Silly("silly");

            await(s.SaveAsync(silly));

            // this should cause the CM to obtain a connection, and then Release it
            await(s.FlushAsync());

            // We should be able to serialize the session at this point...
            SerializationHelper.Serialize(s);

            await(s.DeleteAsync(silly));
            await(s.FlushAsync());

            Release(s);
            Done();
        }
		public void SerializationFailsOnAfterStatementAggressiveReleaseWithOpenResources()
		{
			Prepare();
			ISession s = GetSessionUnderTest();

			Silly silly = new Silly("silly");
			s.Save(silly);

			// this should cause the CM to obtain a connection, and then Release it
			s.Flush();

			// both scroll() and iterate() cause the batcher to hold on
			// to resources, which should make aggresive-Release not Release
			// the connection (and thus cause serialization to fail)
			IEnumerable en = s.CreateQuery("from Silly").Enumerable();

			try
			{
				SerializationHelper.Serialize(s);
				Assert.Fail(
					"Serialization allowed on connected session; or aggressive Release released connection with open resources");
			}
			catch (InvalidOperationException)
			{
				// expected behavior
			}

			// Closing the ScrollableResults does currently force the batcher to
			// aggressively Release the connection
			NHibernateUtil.Close(en);
			SerializationHelper.Serialize(s);

			s.Delete(silly);
			s.Flush();

			Release(s);
			Done();
		}
        public void SuppliedConnection()
        {
            Prepare();

            IDbConnection originalConnection = sessions.ConnectionProvider.GetConnection();
            ISession      session            = sessions.OpenSession(originalConnection);

            Silly silly = new Silly("silly");

            session.Save(silly);

            // this will cause the connection manager to cycle through the aggressive Release logic;
            // it should not Release the connection since we explicitly suplied it ourselves.
            session.Flush();

            Assert.IsTrue(originalConnection == session.Connection, "Different connections");

            session.Delete(silly);
            session.Flush();

            Release(session);
            originalConnection.Close();
            Done();
        }
Beispiel #10
0
        public async Task SuppliedConnectionAsync()
        {
            Prepare();

            using (var originalConnection = await(Sfi.ConnectionProvider.GetConnectionAsync(CancellationToken.None)))
                using (var session = Sfi.WithOptions().Connection(originalConnection).OpenSession())
                {
                    var silly = new Silly("silly");
                    await(session.SaveAsync(silly));

                    // this will cause the connection manager to cycle through the aggressive Release logic;
                    // it should not Release the connection since we explicitly supplied it ourselves.
                    await(session.FlushAsync());

                    Assert.IsTrue(originalConnection == session.Connection, "Different connections");

                    await(session.DeleteAsync(silly));
                    await(session.FlushAsync());

                    Release(session);
                    originalConnection.Close();
                }
            Done();
        }
		public void ConnectionMaintanenceDuringFlush()
		{
			Prepare();
			ISession s = GetSessionUnderTest();
			s.BeginTransaction();

			IList<Silly> entities = new List<Silly>();
			for (int i = 0; i < 10; i++)
			{
				Other other = new Other("other-" + i);
				Silly silly = new Silly("silly-" + i, other);
				entities.Add(silly);
				s.Save(silly);
			}
			s.Flush();

			foreach (Silly silly in entities)
			{
				silly.Name = "new-" + silly.Name;
				silly.Other.Name = "new-" + silly.Other.Name;
			}
//			long initialCount = sessions.Statistics.getConnectCount();
			s.Flush();
//			Assert.AreEqual(initialCount + 1, sessions.Statistics.getConnectCount(), "connection not maintained through Flush");

			s.Delete("from Silly");
			s.Delete("from Other");
			s.Transaction.Commit();
			Release(s);
			Done();
		}
		public void SuppliedConnection()
		{
			Prepare();

			IDbConnection originalConnection = sessions.ConnectionProvider.GetConnection();
			ISession session = sessions.OpenSession(originalConnection);

			Silly silly = new Silly("silly");
			session.Save(silly);

			// this will cause the connection manager to cycle through the aggressive Release logic;
			// it should not Release the connection since we explicitly suplied it ourselves.
			session.Flush();

			Assert.IsTrue(originalConnection == session.Connection, "Different connections");

			session.Delete(silly);
			session.Flush();

			Release(session);
			originalConnection.Close();
			Done();
		}
		public void QueryIteration()
		{
			Prepare();
			ISession s = GetSessionUnderTest();
			Silly silly = new Silly("silly");
			s.Save(silly);
			s.Flush();

			IEnumerable en = s.CreateQuery("from Silly").Enumerable();
			IEnumerator itr = en.GetEnumerator();
			Assert.IsTrue(itr.MoveNext());
			Silly silly2 = (Silly) itr.Current;
			Assert.AreEqual(silly, silly2);
			NHibernateUtil.Close(itr);

			itr = s.CreateQuery("from Silly").Enumerable().GetEnumerator();
			IEnumerator itr2 = s.CreateQuery("from Silly where name = 'silly'").Enumerable().GetEnumerator();

			Assert.IsTrue(itr.MoveNext());
			Assert.AreEqual(silly, itr.Current);
			Assert.IsTrue(itr2.MoveNext());
			Assert.AreEqual(silly, itr2.Current);

			NHibernateUtil.Close(itr);
			NHibernateUtil.Close(itr2);

			s.Delete(silly);
			s.Flush();

			Release(s);
			Done();
		}