Exemple #1
0
        public void ConcurrentBeginWritesSecondFails()
        {
            // GIVEN: a QueuedStream
            var m     = new Mock <Stream>(MockBehavior.Strict);
            var q     = new QueuedStream(m.Object);
            var a     = new MockAsyncResult("A");
            var b     = new MockAsyncResult("B");
            var c     = new MockAsyncResult("C");
            var trace = new StringBuilder();

            m.SetupBeginWrite(a, trace);
            m.SetupEndWrite(a, trace);
            m.SetupBeginWrite(b, new ApplicationException("**ERROR**"), trace);
            m.SetupBeginWrite(c, trace);
            m.SetupEndWrite(c, trace);

            // WHEN: i make three concurrent calls to BeginWrite
            // AND : the second concurrent operation fails in BeginWrite
            q.BeginWrite(a.Data, 0, a.Data.Length, q.EndWrite, null);
            q.BeginWrite(b.Data, 0, b.Data.Length, ar =>
            {
                var ex = Assert.Throws <ApplicationException>(() => q.EndWrite(ar));
                trace.AppendFormat("EndWrite({0})", ex.Message);
            }, null);
            q.BeginWrite(c.Data, 0, c.Data.Length, q.EndWrite, null);
            a.Complete(trace);
            c.Complete(trace);

            // THEN: i expect BeginWrite of the underlying stream to be called one after each other
            // AND : and EndWrite of the second operation fails with and exception
            Assert.That(trace.ToString(), Is.EqualTo("BeginWrite(A) Complete(A) EndWrite(A)BeginWrite(**ERROR**)EndWrite(**ERROR**)BeginWrite(C) Complete(C) EndWrite(C)"));
            m.VerifyAll();
        }
Exemple #2
0
        public void ConcurrentBeginWritesFirstEndWriteFails()
        {
            // GIVEN: a QueuedStream
            var m     = new Mock <Stream>(MockBehavior.Strict);
            var q     = new QueuedStream(m.Object);
            var a     = new MockAsyncResult("A");
            var b     = new MockAsyncResult("B");
            var trace = new StringBuilder();

            m.SetupBeginWrite(a, trace);
            m.SetupEndWrite(a, new ApplicationException("**ERROR**"), trace);
            m.SetupBeginWrite(b, trace);
            m.SetupEndWrite(b, trace);

            // WHEN: i make two concurrent calls to BeginWrite
            // AND : the first concurrent operation fails in EndWrite
            q.BeginWrite(a.Data, 0, a.Data.Length, ar => Assert.Throws <ApplicationException>(() => q.EndWrite(ar)), null);
            q.BeginWrite(b.Data, 0, b.Data.Length, q.EndWrite, null);
            a.Complete(trace);
            b.Complete(trace);

            // THEN: i expect BeginWrite of the underlying stream to be called one after each other
            // AND : and EndWrite of the first operation fails with an exception
            Assert.That(trace.ToString(), Is.EqualTo("BeginWrite(A) Complete(A) EndWrite(**ERROR**)BeginWrite(B) Complete(B) EndWrite(B)"));
            m.VerifyAll();
        }
Exemple #3
0
        public void ConcurrentBeginWrites()
        {
            // GIVEN: a QueuedStream
            var m     = new Mock <Stream>();
            var q     = new QueuedStream(m.Object);
            var a     = new MockAsyncResult("A");
            var b     = new MockAsyncResult("B");
            var trace = new StringBuilder();

            m.SetupBeginWrite(a, trace);
            m.SetupEndWrite(a, trace);
            m.SetupBeginWrite(b, trace);
            m.SetupEndWrite(b, trace);

            // WHEN: i make two concurrent calls to BeginWrite
            q.BeginWrite(a.Data, 0, a.Data.Length, q.EndWrite, null);
            q.BeginWrite(b.Data, 0, b.Data.Length, q.EndWrite, null);
            a.Complete(trace);
            b.Complete(trace);

            // THEN: i expect BeginWrite of the underlying stream to be called one after each other
            Assert.That(trace.ToString(), Is.EqualTo("BeginWrite(A) Complete(A) EndWrite(A)BeginWrite(B) Complete(B) EndWrite(B)"));
            m.VerifyAll();
        }
        public void ConcurrentBeginWritesSecondFails()
        {
            // GIVEN: a QueuedStream
            var m = new Mock<Stream>(MockBehavior.Strict);
            var q = new QueuedStream(m.Object);
            var a = new MockAsyncResult("A");
            var b = new MockAsyncResult("B");
            var c = new MockAsyncResult("C");
            var trace = new StringBuilder();

            m.SetupBeginWrite(a, trace);
            m.SetupEndWrite(a, trace);
            m.SetupBeginWrite(b, new ApplicationException("**ERROR**"), trace);
            m.SetupBeginWrite(c, trace);
            m.SetupEndWrite(c, trace);

            // WHEN: i make three concurrent calls to BeginWrite
            // AND : the second concurrent operation fails in BeginWrite
            q.BeginWrite(a.Data, 0, a.Data.Length, q.EndWrite, null);
            q.BeginWrite(b.Data, 0, b.Data.Length, ar =>
            {
                var ex = Assert.Throws<ApplicationException>(() => q.EndWrite(ar));
                trace.AppendFormat("EndWrite({0})", ex.Message);
            }, null);
            q.BeginWrite(c.Data, 0, c.Data.Length, q.EndWrite, null);
            a.Complete(trace);
            c.Complete(trace);

            // THEN: i expect BeginWrite of the underlying stream to be called one after each other
            // AND : and EndWrite of the second operation fails with and exception
            Assert.That(trace.ToString(), Is.EqualTo("BeginWrite(A) Complete(A) EndWrite(A)BeginWrite(**ERROR**)EndWrite(**ERROR**)BeginWrite(C) Complete(C) EndWrite(C)"));
            m.VerifyAll();
        }
        public void ConcurrentBeginWritesFirstEndWriteFails()
        {
            // GIVEN: a QueuedStream
            var m = new Mock<Stream>(MockBehavior.Strict);
            var q = new QueuedStream(m.Object);
            var a = new MockAsyncResult("A");
            var b = new MockAsyncResult("B");
            var trace = new StringBuilder();

            m.SetupBeginWrite(a, trace);
            m.SetupEndWrite(a, new ApplicationException("**ERROR**"), trace);
            m.SetupBeginWrite(b, trace);
            m.SetupEndWrite(b, trace);

            // WHEN: i make two concurrent calls to BeginWrite
            // AND : the first concurrent operation fails in EndWrite
            q.BeginWrite(a.Data, 0, a.Data.Length, ar => Assert.Throws<ApplicationException>(() => q.EndWrite(ar)), null);
            q.BeginWrite(b.Data, 0, b.Data.Length, q.EndWrite, null);
            a.Complete(trace);
            b.Complete(trace);

            // THEN: i expect BeginWrite of the underlying stream to be called one after each other
            // AND : and EndWrite of the first operation fails with an exception
            Assert.That(trace.ToString(), Is.EqualTo("BeginWrite(A) Complete(A) EndWrite(**ERROR**)BeginWrite(B) Complete(B) EndWrite(B)"));
            m.VerifyAll();
        }
        public void ConcurrentBeginWrites()
        {
            // GIVEN: a QueuedStream
            var m = new Mock<Stream>();
            var q = new QueuedStream(m.Object);
            var a = new MockAsyncResult("A");
            var b = new MockAsyncResult("B");
            var trace = new StringBuilder();

            m.SetupBeginWrite(a, trace);
            m.SetupEndWrite(a, trace);
            m.SetupBeginWrite(b, trace);
            m.SetupEndWrite(b, trace);

            // WHEN: i make two concurrent calls to BeginWrite
            q.BeginWrite(a.Data, 0, a.Data.Length, q.EndWrite, null);
            q.BeginWrite(b.Data, 0, b.Data.Length, q.EndWrite, null);
            a.Complete(trace);
            b.Complete(trace);

            // THEN: i expect BeginWrite of the underlying stream to be called one after each other
            Assert.That(trace.ToString(), Is.EqualTo("BeginWrite(A) Complete(A) EndWrite(A)BeginWrite(B) Complete(B) EndWrite(B)"));
            m.VerifyAll();
        }