void LockConflict(SessionBase sharedReadSession) { string host = null; Random r = new Random(5); SessionPool sessionPool = new SessionPool(3, () => new ServerClientSession(systemDir, host, 2000, false)); try { int iCounter = 0; int sessionId1 = -1; SessionBase session1 = null; for (int i = 0; i < 50; i++) { try { session1 = sessionPool.GetSession(out sessionId1); session1.BeginUpdate(); Dokument Doc_A = new Dokument(); Doc_A.Name = "Test A"; session1.Persist(Doc_A); Console.WriteLine(Doc_A.ToString()); int sessionId2 = -1; SessionBase session2 = null; try { session2 = sessionPool.GetSession(out sessionId2); session2.BeginUpdate(); Dokument Doc_B = new Dokument(); Doc_B.Name = "Test_B"; session2.Persist(Doc_B); Console.WriteLine(Doc_B.ToString()); session2.Commit(); } finally { sessionPool.FreeSession(sessionId2, session2); } session1.Commit(); sharedReadSession.ForceDatabaseCacheValidation(); session1.BeginRead(); ulong ct = session1.AllObjects <Dokument>(false).Count; Console.WriteLine("Number of Dokument found by normal session: " + ct); session1.Commit(); ct = sharedReadSession.AllObjects <Dokument>(false).Count; Console.WriteLine("Number of Dokument found by shared read session: " + ct); } finally { sessionPool.FreeSession(sessionId1, session1); } iCounter++; Console.WriteLine(" -> " + iCounter.ToString()); } } catch (Exception ex) { Console.WriteLine(ex.Message); throw; } }
internal T withRecordset <T>(Func <Recordset <Person>, T> produce) { using (var sess = sessionPool.GetSession()) using (var trans = sess.BeginTransaction()) { return(produce(sess.Recordset <Person>())); } }
public async Task Execute_HaveOCCExceptionsAndAbortFailuresWithinRetryLimit_Succeeded() { var mockCreator = new Mock <Func <Task <Session> > >(); var mockSession = new Mock <Session>(null, null, null, null, null); mockCreator.Setup(x => x()).ReturnsAsync(mockSession.Object); var retry = new Mock <Func <int, Task> >(); var sendCommandResponseStart = new StartTransactionResult { TransactionId = "testTransactionIdddddd" }; var h1 = QldbHash.ToQldbHash("testTransactionIdddddd"); var sendCommandResponseCommit = new CommitTransactionResult { CommitDigest = new MemoryStream(h1.Hash), TransactionId = "testTransactionIdddddd" }; var abortResponse = new AbortTransactionResult { }; var serviceException = new AmazonServiceException(); mockSession.Setup(x => x.StartTransaction(It.IsAny <CancellationToken>())) .ReturnsAsync(sendCommandResponseStart); mockSession.Setup(x => x.CommitTransaction(It.IsAny <string>(), It.IsAny <MemoryStream>(), It.IsAny <CancellationToken>())) .ReturnsAsync(sendCommandResponseCommit); mockSession.SetupSequence(x => x.AbortTransaction(It.IsAny <CancellationToken>())) .ThrowsAsync(serviceException) .ReturnsAsync(abortResponse) .ThrowsAsync(serviceException); var mockFunction = new Mock <Func <TransactionExecutor, Task <int> > >(); mockFunction.SetupSequence(f => f.Invoke(It.IsAny <TransactionExecutor>())) .ThrowsAsync(new OccConflictException("occ")) .ThrowsAsync(new OccConflictException("occ")) .ThrowsAsync(new OccConflictException("occ")) .ReturnsAsync(1); var mockRetry = new Mock <Action <int> >(); var pool = new SessionPool(mockCreator.Object, QldbDriverBuilder.CreateDefaultRetryHandler(NullLogger.Instance), 2, NullLogger.Instance); var session1 = await pool.GetSession(); var session2 = await pool.GetSession(); session1.Release(); session2.Release(); await pool.Execute(mockFunction.Object, Driver.RetryPolicy.Builder().Build(), retry.Object); mockCreator.Verify(x => x(), Times.Exactly(2)); retry.Verify(r => r.Invoke(It.IsAny <int>()), Times.Exactly(3)); Assert.AreEqual(2, pool.AvailablePermit()); }
public void Execute_HaveISE_Succeeded() { var mockCreator = new Mock <Func <Session> >(); var mockSession = new Mock <Session>(null, null, null, null, null); mockCreator.Setup(x => x()).Returns(mockSession.Object); var retry = new Mock <Action <int> >(); var sendCommandResponseStart = new StartTransactionResult { TransactionId = "testTransactionIdddddd" }; var h1 = QldbHash.ToQldbHash("testTransactionIdddddd"); var sendCommandResponseCommit = new CommitTransactionResult { CommitDigest = new MemoryStream(h1.Hash), TransactionId = "testTransactionIdddddd" }; mockSession.Setup(x => x.StartTransaction()) .Returns(sendCommandResponseStart); mockSession.Setup(x => x.CommitTransaction(It.IsAny <string>(), It.IsAny <MemoryStream>())) .Returns(sendCommandResponseCommit); var mockFunction = new Mock <Func <TransactionExecutor, int> >(); mockFunction.SetupSequence(f => f.Invoke(It.IsAny <TransactionExecutor>())) .Throws(new InvalidSessionException("invalid")) .Throws(new InvalidSessionException("invalid")) .Throws(new InvalidSessionException("invalid")) .Throws(new InvalidSessionException("invalid")) .Returns(1); var mockRetry = new Mock <Action <int> >(); var pool = new SessionPool(mockCreator.Object, QldbDriverBuilder.CreateDefaultRetryHandler(NullLogger.Instance), 2, NullLogger.Instance); var session1 = pool.GetSession(); var session2 = pool.GetSession(); session1.Release(); session2.Release(); pool.Execute(mockFunction.Object, Driver.RetryPolicy.Builder().Build(), retry.Object); mockCreator.Verify(x => x(), Times.Exactly(6)); retry.Verify(r => r.Invoke(It.IsAny <int>()), Times.Exactly(4)); Assert.AreEqual(2, pool.AvailablePermit()); }
public TimeSpan insert(int howMany) { List <Record> batch = RandomSource.batch(howMany).ToList(); Stopwatch sw = Stopwatch.StartNew(); using (var sess = pool.GetSession()) using (var trans = sess.BeginTransaction()) { sess.Cursor <Record>().AddRange(batch); trans.Commit(); } return(sw.Elapsed); }
public async Task GetSession_GetTwoSessionsFromPoolOfOne_TimeoutOnSecondGet() { var mockCreator = new Mock <Func <Task <Session> > >(); var mockSession = new Mock <Session>(null, null, null, null, null).Object; mockCreator.Setup(x => x()).ReturnsAsync(mockSession); var pool = new SessionPool(mockCreator.Object, QldbDriverBuilder.CreateDefaultRetryHandler(NullLogger.Instance), 1, NullLogger.Instance); var returnedSession = pool.GetSession(); await Assert.ThrowsExceptionAsync <QldbDriverException>(() => pool.GetSession()); Assert.IsNotNull(returnedSession); mockCreator.Verify(x => x(), Times.Exactly(1)); }
public void ShouldCloseSessionGotFromAvailableIfPoolDisposeStarted() { var sessions = new Queue <IPooledSession>(); var healthyMock = new Mock <IPooledSession>(); healthyMock.Setup(x => x.IsHealthy).Returns(true); var pool = new SessionPool(sessions, null); pool.NumberOfAvailableSessions.Should().Be(0); pool.NumberOfInUseSessions.Should().Be(0); // this is to simulate we call GetSession after available.clear in pool.Dispose() pool.Dispose(); sessions.Enqueue(healthyMock.Object); pool.NumberOfAvailableSessions.Should().Be(1); var exception = Record.Exception(() => pool.GetSession()); pool.NumberOfAvailableSessions.Should().Be(0); pool.NumberOfInUseSessions.Should().Be(0); healthyMock.Verify(x => x.Reset(), Times.Once); healthyMock.Verify(x => x.Close(), Times.Once); exception.Should().BeOfType <InvalidOperationException>(); exception.Message.Should().Contain("the SessionPool is already started to dispose"); }
public void ShouldNotExceedIdleLimit() { var mock = new Mock <IConnection>(); mock.Setup(x => x.IsOpen).Returns(true); var config = new Config { MaxIdleSessionPoolSize = 2 }; var pool = new SessionPool(TestUri, AuthTokens.None, null, config, mock.Object); var sessions = new List <ISession>(); for (var i = 0; i < 4; i++) { sessions.Add(pool.GetSession()); pool.NumberOfAvailableSessions.Should().BeLessOrEqualTo(2); } foreach (var session in sessions) { session.Dispose(); pool.NumberOfAvailableSessions.Should().BeLessOrEqualTo(2); } pool.NumberOfAvailableSessions.Should().Be(2); }
public void ShouldReuseReusableSessionWhenReusableSessionInQueue() { var sessions = new Queue <IPooledSession>(); var healthyMock = new Mock <IPooledSession>(); healthyMock.Setup(x => x.IsHealthy).Returns(true); var unhealthyMock = new Mock <IPooledSession>(); unhealthyMock.Setup(x => x.IsHealthy).Returns(false); sessions.Enqueue(unhealthyMock.Object); sessions.Enqueue(healthyMock.Object); var pool = new SessionPool(sessions, null); pool.NumberOfAvailableSessions.Should().Be(2); pool.NumberOfInUseSessions.Should().Be(0); var session = pool.GetSession(); pool.NumberOfAvailableSessions.Should().Be(0); pool.NumberOfInUseSessions.Should().Be(1); unhealthyMock.Verify(x => x.Reset(), Times.Never); unhealthyMock.Verify(x => x.Close(), Times.Once); healthyMock.Verify(x => x.Reset(), Times.Once); session.Should().Be(healthyMock.Object); }
private void TestRoundTrippedValueViaValueSerializer(ref TField original) { var codecProvider = ServiceProvider.GetRequiredService <IValueSerializerProvider>(); var serializer = codecProvider.GetValueSerializer <TField>(); var pipe = new Pipe(); using var writerSession = SessionPool.GetSession(); var writer = Writer.Create(pipe.Writer, writerSession); var writerCodec = serializer; writerCodec.Serialize(ref writer, ref original); writer.WriteEndObject(); writer.Commit(); _ = pipe.Writer.FlushAsync().AsTask().GetAwaiter().GetResult(); pipe.Writer.Complete(); _ = pipe.Reader.TryRead(out var readResult); using var readerSession = SessionPool.GetSession(); var reader = Reader.Create(readResult.Buffer, readerSession); var readerCodec = serializer; TField deserialized = default; readerCodec.Deserialize(ref reader, ref deserialized); pipe.Reader.AdvanceTo(readResult.Buffer.End); pipe.Reader.Complete(); var isEqual = Equals(original, deserialized); Assert.True( isEqual, isEqual ? string.Empty : $"Deserialized value \"{deserialized}\" must equal original value \"{original}\""); Assert.Equal(writerSession.ReferencedObjects.CurrentReferenceId, readerSession.ReferencedObjects.CurrentReferenceId); }
public void ShouldCreateNewSessionWhenQueueOnlyContainsUnResetableSessions() { var mock = new Mock <IConnection>(); var sessions = new Queue <IPooledSession>(); var unhealthyId = Guid.NewGuid(); var unhealthyMock = new Mock <IPooledSession>(); unhealthyMock.Setup(x => x.IsHealthy).Returns(true); unhealthyMock.Setup(x => x.Reset()).Throws <Exception>(); //failed to reset unhealthyMock.Setup(x => x.Id).Returns(unhealthyId); sessions.Enqueue(unhealthyMock.Object); var pool = new SessionPool(sessions, null, mock.Object); pool.NumberOfAvailableSessions.Should().Be(1); pool.NumberOfInUseSessions.Should().Be(0); var session = pool.GetSession(); pool.NumberOfAvailableSessions.Should().Be(0); pool.NumberOfInUseSessions.Should().Be(1); unhealthyMock.Verify(x => x.Reset(), Times.Once); unhealthyMock.Verify(x => x.Close(), Times.Once); session.Should().NotBeNull(); ((IPooledSession)session).Id.Should().NotBe(unhealthyId); }
public void ShouldNotThrowExceptionWhenIdlePoolSizeReached() { var mock = new Mock <IConnection>(); var config = new Config { MaxIdleSessionPoolSize = 2 }; var pool = new SessionPool(TestUri, AuthTokens.None, null, config, mock.Object); pool.GetSession(); pool.GetSession(); pool.NumberOfAvailableSessions.Should().Be(0); pool.NumberOfInUseSessions.Should().Be(2); var ex = Record.Exception(() => pool.GetSession()); ex.Should().BeNull(); }
public void ShouldCreateNewSessionWhenQueueIsEmpty() { var mock = new Mock <IConnection>(); var pool = new SessionPool(TestUri, AuthTokens.None, null, Config.DefaultConfig, mock.Object); pool.GetSession(); pool.NumberOfAvailableSessions.Should().Be(0); pool.NumberOfInUseSessions.Should().Be(1); }
public Service(SessionPool sessionsPool) { this.sessionPool = sessionsPool; using (var sess = sessionPool.GetSession()) { iTypeSerializer ser = sess.serializer.FindSerializerForType(typeof(Person)); orderBySex = Queries.sort <Person, Person.eSex>(ser, p => p.sex, false); filterBySex = Queries.filter(ser, (Person p, Person.eSex arg) => p.sex == arg); } }
public void GetSession_FailedToCreateSession_ThrowTheOriginalException() { var mockCreator = new Mock <Func <Session> >(); var exception = new AmazonServiceException("test"); mockCreator.Setup(x => x()).Throws(exception); var pool = new SessionPool(mockCreator.Object, QldbDriverBuilder.CreateDefaultRetryHandler(NullLogger.Instance), 1, NullLogger.Instance); Assert.ThrowsException <AmazonServiceException>(() => pool.GetSession()); }
public void GetSession_GetSessionFromPool_ExpectedSessionReturned() { var mockCreator = new Mock <Func <Session> >(); var session = new Session(null, null, null, "testSessionId", null); mockCreator.Setup(x => x()).Returns(session); var pool = new SessionPool(mockCreator.Object, QldbDriverBuilder.CreateDefaultRetryHandler(NullLogger.Instance), 1, NullLogger.Instance); var returnedSession = pool.GetSession(); Assert.AreEqual(session.SessionId, returnedSession.GetSessionId()); }
public void Dispose_DisposeSessionPool_DestroyAllSessions() { var mockCreator = new Mock <Func <Session> >(); var mockSession1 = new Mock <Session>(null, null, null, null, null); var mockSession2 = new Mock <Session>(null, null, null, null, null); mockCreator.SetupSequence(x => x()).Returns(mockSession1.Object).Returns(mockSession2.Object); var pool = new SessionPool(mockCreator.Object, QldbDriverBuilder.CreateDefaultRetryHandler(NullLogger.Instance), 2, NullLogger.Instance); var session1 = pool.GetSession(); var session2 = pool.GetSession(); session1.Release(); session2.Release(); pool.Dispose(); mockSession1.Verify(s => s.End(), Times.Exactly(1)); mockSession2.Verify(s => s.End(), Times.Exactly(1)); }
public ComplexTypeBenchmarks() { this.orleansSerializer = new ClientBuilder() .ConfigureDefaults() .UseLocalhostClustering() .Configure <ClusterOptions>(o => o.ClusterId = o.ServiceId = "test") .ConfigureApplicationParts(parts => parts.AddApplicationPart(typeof(SimpleClass).Assembly).WithCodeGeneration()) .Build().ServiceProvider.GetRequiredService <SerializationManager>(); var services = new ServiceCollection(); services .AddHagar() .AddISerializableSupport() .AddSerializers(typeof(Program).Assembly); var serviceProvider = services.BuildServiceProvider(); this.hagarSerializer = serviceProvider.GetRequiredService <Serializer <ComplexClass> >(); this.structSerializer = serviceProvider.GetRequiredService <Serializer <SimpleStruct> >(); this.sessionPool = serviceProvider.GetRequiredService <SessionPool>(); this.value = new ComplexClass { BaseInt = 192, Int = 501, String = "bananas", //Array = Enumerable.Range(0, 60).ToArray(), //MultiDimensionalArray = new[,] {{0, 2, 4}, {1, 5, 6}} }; this.value.AlsoSelf = this.value.BaseSelf = this.value.Self = this.value; this.structValue = new SimpleStruct { Int = 42, Bool = true, Guid = Guid.NewGuid() }; this.session = sessionPool.GetSession(); var writer = new Writer(HagarBuffer); this.hagarSerializer.Serialize(this.value, session, ref writer); var bytes = new byte[HagarBuffer.GetMemory().Length]; HagarBuffer.GetReadOnlySequence().CopyTo(bytes); this.hagarBytes = new ReadOnlySequence <byte>(bytes); HagarBuffer.Reset(); var writer2 = new BinaryTokenStreamWriter(); this.orleansSerializer.Serialize(this.value, writer2); this.orleansBytes = writer2.ToBytes(); this.readBytesLength = Math.Min(bytes.Length, orleansBytes.Sum(x => x.Count)); }
public void GetSession_GetSessionFromPool_NewSessionReturned() { var mockCreator = new Mock <Func <Session> >(); var mockSession = new Mock <Session>(null, null, null, null, null).Object; mockCreator.Setup(x => x()).Returns(mockSession); var pool = new SessionPool(mockCreator.Object, QldbDriverBuilder.CreateDefaultRetryHandler(NullLogger.Instance), 1, NullLogger.Instance); var returnedSession = pool.GetSession(); Assert.IsNotNull(returnedSession); mockCreator.Verify(x => x(), Times.Exactly(1)); }
public async Task Dispose_DisposeSessionPool_DestroyAllSessions() { var mockCreator = new Mock <Func <Task <Session> > >(); var mockSession1 = new Mock <Session>(null, null, null, null, null); var mockSession2 = new Mock <Session>(null, null, null, null, null); mockCreator.SetupSequence(x => x()).ReturnsAsync(mockSession1.Object).ReturnsAsync(mockSession2.Object); var pool = new SessionPool(mockCreator.Object, QldbDriverBuilder.CreateDefaultRetryHandler(NullLogger.Instance), 2, NullLogger.Instance); var session1 = await pool.GetSession(); var session2 = await pool.GetSession(); session1.Release(); session2.Release(); await pool.DisposeAsync(); mockSession1.Verify(s => s.End(It.IsAny <CancellationToken>()), Times.Exactly(1)); mockSession2.Verify(s => s.End(It.IsAny <CancellationToken>()), Times.Exactly(1)); }
public void GetSession_GetTwoSessionsFromPoolOfOneAfterFirstOneDisposed_NoThrowOnSecondGet() { var mockCreator = new Mock <Func <Session> >(); var mockSession = new Mock <Session>(null, null, null, null, null); mockCreator.Setup(x => x()).Returns(mockSession.Object); mockSession.Setup(x => x.StartTransaction()).Returns(new StartTransactionResult { TransactionId = "testTransactionIdddddd" }); var pool = new SessionPool(mockCreator.Object, QldbDriverBuilder.CreateDefaultRetryHandler(NullLogger.Instance), 1, NullLogger.Instance); var returnedSession = pool.GetSession(); returnedSession.Release(); var nextSession = pool.GetSession(); Assert.IsNotNull(nextSession); nextSession.StartTransaction(); mockCreator.Verify(x => x(), Times.Exactly(1)); }
public async Task GetSession_DisposeSession_ShouldNotEndSession() { var mockCreator = new Mock <Func <Task <Session> > >(); var mockSession = new Mock <Session>(null, null, null, null, null); mockCreator.Setup(x => x()).ReturnsAsync(mockSession.Object); var pool = new SessionPool(mockCreator.Object, QldbDriverBuilder.CreateDefaultRetryHandler(NullLogger.Instance), 1, NullLogger.Instance); var returnedSession = await pool.GetSession(); returnedSession.Release(); mockSession.Verify(s => s.End(It.IsAny <CancellationToken>()), Times.Exactly(0)); }
public void GetSession_DisposeSession_ShouldNotEndSession() { var mockCreator = new Mock <Func <Session> >(); var mockSession = new Mock <Session>(null, null, null, null, null); mockCreator.Setup(x => x()).Returns(mockSession.Object); var pool = new SessionPool(mockCreator.Object, QldbDriverBuilder.CreateDefaultRetryHandler(NullLogger.Instance), 1, NullLogger.Instance); var returnedSession = pool.GetSession(); returnedSession.Release(); mockSession.Verify(s => s.End(), Times.Exactly(0)); }
/// <summary>Copy a file from EFS to the specified System.Stream.</summary> /// <remarks>Unlike the rest of the code in this class, this method is safe to call from any thread.</remarks> /// <param name="sOutput"></param> /// <param name="idFile"></param> void CopyFileToStream(Stream sOutput, int idFile) { using (var s = pool.GetSession()) using (var trans = s.BeginTransaction()) { var e = EFS.byId(rs, idFile); if (null == e) { throw new FileNotFoundException(); } using (var sInput = e.data.Read(rs.cursor)) EFS.CopyStream(sInput, sOutput); } }
// This one is the real. public Form1(SessionPool _pool) { InitializeComponent(); pool = _pool; sess = pool.GetSession(); rs = sess.Recordset <EfsEntry>(); EFS.Initialize(rs); fileIo = new FileIoThread(); // fileIo = new TrivialFileIo(); InitFoldersView(); }
public void ShouldCloseNewSessionIfPoolDisposeStarted() { var mock = new Mock <IConnection>(); var pool = new SessionPool(TestUri, AuthTokens.None, null, Config.DefaultConfig, mock.Object); pool.NumberOfAvailableSessions.Should().Be(0); pool.NumberOfInUseSessions.Should().Be(0); // this is to simulate we call GetSession after available.clear in pool.Dispose() pool.Dispose(); pool.NumberOfAvailableSessions.Should().Be(0); pool.NumberOfInUseSessions.Should().Be(0); var exception = Record.Exception(() => pool.GetSession()); pool.NumberOfAvailableSessions.Should().Be(0); pool.NumberOfInUseSessions.Should().Be(0); exception.Should().BeOfType <InvalidOperationException>(); exception.Message.Should().Contain("the SessionPool is already started to dispose"); }
public void ShouldReuseOldSessionWhenHealthySessionInQueue() { var sessions = new Queue <IPooledSession>(); var mock = new Mock <IPooledSession>(); mock.Setup(x => x.IsHealthy).Returns(true); sessions.Enqueue(mock.Object); var pool = new SessionPool(sessions, null); pool.NumberOfAvailableSessions.Should().Be(1); pool.NumberOfInUseSessions.Should().Be(0); var session = pool.GetSession(); pool.NumberOfAvailableSessions.Should().Be(0); pool.NumberOfInUseSessions.Should().Be(1); mock.Verify(x => x.Reset(), Times.Once); session.Should().Be(mock.Object); }
public void ShouldGiveSessionsFromPoolIfAvailable() { var mock = new Mock <IConnection>(); mock.Setup(x => x.IsOpen).Returns(true); var config = new Config { MaxIdleSessionPoolSize = 2 }; var pool = new SessionPool(TestUri, AuthTokens.None, null, config, mock.Object); for (var i = 0; i < 4; i++) { var session = pool.GetSession(); pool.NumberOfAvailableSessions.Should().Be(0); session.Dispose(); pool.NumberOfAvailableSessions.Should().Be(1); } pool.NumberOfAvailableSessions.Should().Be(1); }
public bool Remove(string key) { using (var sess = sessionPool.GetSession()) using (var trans = sess.BeginTransaction()) { var rs = sess.Recordset <DictionaryEntry>(); rs.filterFindEqual("key", key); if (!rs.applyFilter()) { return(false); } rs.cursor.delCurrent(); trans.Commit(); return(true); } }
static void Main(string[] args) { Console.WriteLine("Starting the service..."); EsentDatabase.Settings settings = new EsentDatabase.Settings() { maxConcurrentSessions = 16, folderLocation = Environment.ExpandEnvironmentVariables(@"%APPDATA%\EsentDemoApp") }; using (SessionPool pool = EsentDatabase.open(settings, typeof(Person))) { if (pool.isNewDatabase) { using (var sess = pool.GetSession()) PopulateDemoDatabase(sess); } Service singletoneInstance = new Service(pool); using (ServiceHost host = new ServiceHost(singletoneInstance, ServiceConfig.baseAddress)) { host.AddServiceEndpoint(typeof(iPersonsService), new NetNamedPipeBinding(), ServiceConfig.pipeName); host.Open(); ServiceConfig.eventServerReady.Set(); try { Console.WriteLine("Server running. Press any key to shut down"); Console.ReadKey(true); Console.WriteLine("Shutting down..."); } finally { ServiceConfig.eventServerReady.Reset(); } } } Console.WriteLine("The service has stopped."); }
void LockConflict(SessionBase sharedReadSession) { string host = null; Random r = new Random(5); SessionPool sessionPool = new SessionPool(3, () => new ServerClientSession(systemDir, host, 2000, false)); try { int iCounter = 0; int sessionId1 = -1; SessionBase session1 = null; for (int i = 0; i < 50; i++) { try { session1 = sessionPool.GetSession(out sessionId1); session1.BeginUpdate(); Dokument Doc_A = new Dokument(); Doc_A.Name = "Test A"; session1.Persist(Doc_A); Console.WriteLine(Doc_A.ToString()); int sessionId2 = -1; SessionBase session2 = null; try { session2 = sessionPool.GetSession(out sessionId2); session2.BeginUpdate(); Dokument Doc_B = new Dokument(); Doc_B.Name = "Test_B"; session2.Persist(Doc_B); Console.WriteLine(Doc_B.ToString()); session2.Commit(); } finally { sessionPool.FreeSession(sessionId2, session2); } session1.Commit(); sharedReadSession.ForceDatabaseCacheValidation(); session1.BeginRead(); ulong ct = session1.AllObjects<Dokument>(false).Count; Console.WriteLine("Number of Dokument found by normal session: " + ct); session1.Commit(); ct = sharedReadSession.AllObjects<Dokument>(false).Count; Console.WriteLine("Number of Dokument found by shared read session: " + ct); } finally { sessionPool.FreeSession(sessionId1, session1); } iCounter++; Console.WriteLine(" -> " + iCounter.ToString()); } } catch (Exception ex) { Console.WriteLine(ex.Message); throw; } }