コード例 #1
0
            public void CannotAquireLockIfLockAlreadyAquired()
            {
                var sagaId = GuidStrategy.NewGuid();
                using (var sagaLock = new SagaLock(typeof(Saga), sagaId))
                {
                    sagaLock.Aquire();
                    var ex = Assert.Throws<InvalidOperationException>(() => sagaLock.Aquire());

                    Assert.Equal(Exceptions.SagaLockAlreadyHeld.FormatWith(typeof(Saga), sagaId), ex.Message);
                }
            }
コード例 #2
0
            public void CannotAquireLockIfLockAlreadyAquired()
            {
                var sagaId = GuidStrategy.NewGuid();

                using (var sagaLock = new SagaLock(typeof(Saga), sagaId))
                {
                    sagaLock.Aquire();
                    var ex = Assert.Throws <InvalidOperationException>(() => sagaLock.Aquire());

                    Assert.Equal(Exceptions.SagaLockAlreadyHeld.FormatWith(typeof(Saga), sagaId), ex.Message);
                }
            }
コード例 #3
0
            public void AquireWillNotBlockIfAnotherLockAlreadyAquiredOnAnotherSaga()
            {
                var firstLockAquired  = new ManualResetEvent(initialState: false);
                var secondLockAquired = new ManualResetEvent(initialState: false);
                var blockedTime       = TimeSpan.Zero;

                Task.Factory.StartNew(() =>
                {
                    firstLockAquired.WaitOne();
                    using (var sagaLock = new SagaLock(typeof(Saga), GuidStrategy.NewGuid()))
                    {
                        var timer = Stopwatch.StartNew();

                        sagaLock.Aquire();
                        timer.Stop();

                        blockedTime = timer.Elapsed;
                        secondLockAquired.Set();
                    }
                });

                using (var sagaLock = new SagaLock(typeof(Saga), GuidStrategy.NewGuid()))
                {
                    sagaLock.Aquire();
                    firstLockAquired.Set();

                    Thread.Sleep(100);
                }

                secondLockAquired.WaitOne();

                Assert.InRange(blockedTime, TimeSpan.FromMilliseconds(0), TimeSpan.FromMilliseconds(50));
            }
コード例 #4
0
            public void AquireWillBlockIfAnotherLockAlreadyAquiredOnSameSaga()
            {
                var correlationId = GuidStrategy.NewGuid();
                var firstLockAquired = new ManualResetEvent(initialState: false);
                var secondLockAquired = new ManualResetEvent(initialState: false);
                var blockedTime = TimeSpan.Zero;

                Task.Factory.StartNew(() =>
                {
                    firstLockAquired.WaitOne();
                    using (var sagaLock = new SagaLock(typeof(Saga), correlationId))
                    {
                        var timer = Stopwatch.StartNew();

                        sagaLock.Aquire();
                        timer.Stop();

                        blockedTime = timer.Elapsed;
                        secondLockAquired.Set();
                    }
                });

                using (var sagaLock = new SagaLock(typeof(Saga), correlationId))
                {
                    sagaLock.Aquire();
                    firstLockAquired.Set();

                    Thread.Sleep(100);
                }

                secondLockAquired.WaitOne();

                Assert.InRange(blockedTime, TimeSpan.FromMilliseconds(50), TimeSpan.FromMilliseconds(150));
            }
コード例 #5
0
            public void CanDisposeIfLockAquired()
            {
                var sagaLock = new SagaLock(typeof(Saga), GuidStrategy.NewGuid());

                sagaLock.Aquire();

                sagaLock.Dispose();
            }
コード例 #6
0
            public void CanAquireLockIfNoLockAquired()
            {
                using (var sagaLock = new SagaLock(typeof(Saga), GuidStrategy.NewGuid()))
                {
                    sagaLock.Aquire();

                    Assert.True(sagaLock.Aquired);
                }
            }
コード例 #7
0
 public void CanDisposeMoreThanOnce()
 {
     using (var sagaLock = new SagaLock(typeof(Saga), GuidStrategy.NewGuid()))
     {
         sagaLock.Aquire();
         sagaLock.Dispose();
         sagaLock.Dispose();
     }
 }
コード例 #8
0
            public void CanAquireLockIfNoLockAquired()
            {
                using (var sagaLock = new SagaLock(typeof(Saga), GuidStrategy.NewGuid()))
                {
                    sagaLock.Aquire();

                    Assert.True(sagaLock.Aquired);
                }
            }
コード例 #9
0
            public void CanReleaseLockIfLockAquired()
            {
                using (var sagaLock = new SagaLock(typeof(Saga), GuidStrategy.NewGuid()))
                {
                    sagaLock.Aquire();
                    sagaLock.Release();

                    Assert.False(sagaLock.Aquired);
                }
            }
コード例 #10
0
 public void CanDisposeMoreThanOnce()
 {
     using (var sagaLock = new SagaLock(typeof(Saga), GuidStrategy.NewGuid()))
     {
         sagaLock.Aquire();
         sagaLock.Dispose();
         sagaLock.Dispose();
     }
 }
コード例 #11
0
            public void CanDisposeIfLockAquired()
            {
                var sagaLock = new SagaLock(typeof(Saga), GuidStrategy.NewGuid());

                sagaLock.Aquire();

                sagaLock.Dispose();
            }
コード例 #12
0
            public void CanReleaseLockIfLockAquired()
            {
                using (var sagaLock = new SagaLock(typeof(Saga), GuidStrategy.NewGuid()))
                {
                    sagaLock.Aquire();
                    sagaLock.Release();

                    Assert.False(sagaLock.Aquired);
                }
            }