Ejemplo n.º 1
0
            public void ReturnFriendlyDescription()
            {
                var correlationId = GuidStrategy.NewGuid();
                var reference     = new SagaReference(typeof(Saga), correlationId);

                Assert.Equal($"{typeof (Saga)} - {correlationId}", reference.ToString());
            }
            public void ReturnFriendlyDescription()
            {
                var correlationId = GuidStrategy.NewGuid();
                var reference = new SagaReference(typeof(Saga), correlationId);

                Assert.Equal($"{typeof (Saga)} - {correlationId}", reference.ToString());
            }
Ejemplo n.º 3
0
        public async Task <IEnumerable <ISagaCommand> > RunAsync(ISagaEvent sagaEvent, ISagaStepAdapter step)
        {
            var eventReference = new SagaReference(step.Version, step.Index, SagaMessageType.Event, sagaEvent.ProcessId, sagaEvent.TransactionId, sagaEvent);

            await _store
            .AddReferences(eventReference)
            .ConfigureAwait(false);

            var commands = await step
                           .RunAsync(sagaEvent)
                           .ConfigureAwait(false);

            if (commands is null)
            {
                return(Enumerable.Empty <ISagaCommand>());
            }

            var commandReferences = commands
                                    .Select(cmnd => new SagaReference(step.Version, step.Index, SagaMessageType.Command, cmnd.ProcessId, cmnd.TransactionId, cmnd))
                                    .ToArray();

            await _store
            .AddReferences(commandReferences)
            .ConfigureAwait(false);

            return(commands);
        }
            public void AlwaysReturnConsistentValue()
            {
                var correlationId = GuidStrategy.NewGuid();
                var reference1 = new SagaReference(typeof(Saga), correlationId);
                var reference2 = new SagaReference(typeof(Saga), correlationId);

                Assert.Equal(reference1.GetHashCode(), reference2.GetHashCode());
            }
            public void SagaReferenceCanBeBoxed()
            {
                var correlationId = GuidStrategy.NewGuid();
                var reference1 = new SagaReference(typeof(Saga), correlationId);
                var reference2 = new SagaReference(typeof(Saga), correlationId);

                Assert.True(reference1.Equals((Object)reference2));
            }
            public void TypeAndIdMustBeEqual()
            {
                var correlationId = GuidStrategy.NewGuid();
                var reference1 = new SagaReference(typeof(Saga), correlationId);
                var reference2 = new SagaReference(typeof(Saga), correlationId);

                Assert.True(reference1.Equals(reference2));
            }
Ejemplo n.º 7
0
            public void SagaReferenceCanBeBoxed()
            {
                var correlationId = GuidStrategy.NewGuid();
                var reference1    = new SagaReference(typeof(Saga), correlationId);
                var reference2    = new SagaReference(typeof(Saga), correlationId);

                Assert.True(reference1.Equals((Object)reference2));
            }
Ejemplo n.º 8
0
            public void AlwaysReturnConsistentValue()
            {
                var correlationId = GuidStrategy.NewGuid();
                var reference1    = new SagaReference(typeof(Saga), correlationId);
                var reference2    = new SagaReference(typeof(Saga), correlationId);

                Assert.Equal(reference1.GetHashCode(), reference2.GetHashCode());
            }
Ejemplo n.º 9
0
            public void TypeAndIdMustBeEqual()
            {
                var correlationId = GuidStrategy.NewGuid();
                var reference1    = new SagaReference(typeof(Saga), correlationId);
                var reference2    = new SagaReference(typeof(Saga), correlationId);

                Assert.True(reference1.Equals(reference2));
            }
Ejemplo n.º 10
0
            public void RemoveAllSagaTimeoutsForSpecifiedSagaReference()
            {
                var sagaReference = new SagaReference(typeof(Saga), Guid.NewGuid());
                var timeout1      = new SagaTimeout(typeof(Saga), sagaReference.SagaId, DateTime.UtcNow);
                var timeout2      = new SagaTimeout(typeof(Saga), sagaReference.SagaId, DateTime.UtcNow.AddSeconds(1));

                collection.Add(timeout1);
                collection.Add(timeout2);
                collection.Remove(sagaReference);

                Assert.False(collection.Contains(timeout1));
                Assert.False(collection.Contains(timeout2));
                Assert.False(collection.Contains(sagaReference));
            }
Ejemplo n.º 11
0
        public async Task <ActionResult> DeleteSaga(
            [FromRoute] SagaReference reference,
            CancellationToken cancellationToken)
        {
            var command = new DeleteSagaCommand(reference.SagaId);

            try
            {
                await _sender.Send(command, cancellationToken);
            }
            catch (SagaNotFoundException e)
            {
                return(NotFound(e.Message));
            }

            return(NoContent());
        }
Ejemplo n.º 12
0
        public async Task <ActionResult <IReadOnlyList <SagaModel> > > GetSaga(
            [FromRoute] SagaReference reference,
            CancellationToken cancellationToken)
        {
            var query = new GetSagaQuery(reference.SagaId);

            try
            {
                var response = await _sender.Send(query, cancellationToken);

                return(Ok(_mapper.Map <SagaModel>(response)));
            }
            catch (SagaNotFoundException e)
            {
                return(NotFound(e.Message));
            }
        }
Ejemplo n.º 13
0
        public async Task <ActionResult> UpdateSaga(
            [FromRoute] SagaReference reference,
            [FromBody] UpdateSagaRequest request,
            CancellationToken cancellationToken)
        {
            var command = new UpdateSagaCommand(reference.SagaId, request.Title);

            try
            {
                await _sender.Send(command, cancellationToken);
            }
            catch (SagaNotFoundException e)
            {
                return(NotFound(e.Message));
            }

            return(NoContent());
        }
Ejemplo n.º 14
0
        public async Task <ActionResult <SagaModel> > CreateChapter(
            [FromRoute] SagaReference reference,
            [FromBody] CreateChapterRequest request,
            CancellationToken cancellationToken)
        {
            var command = new CreateChapterCommand(reference.SagaId, request.Content);

            try
            {
                var response = await _sender.Send(command, cancellationToken);

                return(Ok(_mapper.Map <ChapterModel>(response)));
            }
            catch (SagaNotFoundException e)
            {
                return(NotFound(e.Message));
            }
        }
 /// <summary>
 /// Clear the saga timeout associated with the specified <paramref name="sagaReference"/>.
 /// </summary>
 /// <param name="sagaReference">The saga reference to clear a scheduled timeout.</param>
 private void ClearTimeoutInternal(SagaReference sagaReference)
 {
     sagaTimeouts.Remove(sagaReference);
 }
        /// <summary>
        /// Clear the saga timeout associated with the specified <paramref name="sagaReference"/> (thread-safe).
        /// </summary>
        /// <param name="sagaReference">The saga reference to clear a scheduled timeout.</param>
        public void ClearTimeout(SagaReference sagaReference)
        {
            Log.Trace("Clearing saga timeout for {0}", sagaReference);

            lock (syncLock)
            {
                ClearTimeoutInternal(sagaReference);
            }

            Log.Trace("Saga timeout cleared for {0}", sagaReference);
        }
Ejemplo n.º 17
0
 /// <summary>
 /// Initializes a new instance of <see cref="SagaLock"/>.
 /// </summary>
 /// <param name="sagaReference">The saga reference associated with this saga lock instance.</param>
 public SagaLock(SagaReference sagaReference)
 {
     this.sagaReference = sagaReference;
 }
            public void RemoveAllSagaTimeoutsForSpecifiedSagaReference()
            {
                var sagaReference = new SagaReference(typeof(Saga), Guid.NewGuid());
                var timeout1 = new SagaTimeout(typeof(Saga), sagaReference.SagaId, DateTime.UtcNow);
                var timeout2 = new SagaTimeout(typeof(Saga), sagaReference.SagaId, DateTime.UtcNow.AddSeconds(1));

                collection.Add(timeout1);
                collection.Add(timeout2);
                collection.Remove(sagaReference);

                Assert.False(collection.Contains(timeout1));
                Assert.False(collection.Contains(timeout2));
                Assert.False(collection.Contains(sagaReference));
            }