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()); }
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)); }
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 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 TypeAndIdMustBeEqual() { var correlationId = GuidStrategy.NewGuid(); var reference1 = new SagaReference(typeof(Saga), correlationId); var reference2 = new SagaReference(typeof(Saga), correlationId); Assert.True(reference1.Equals(reference2)); }
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)); }
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()); }
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)); } }
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()); }
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); }
/// <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)); }