Skip to content

Commit

Permalink
Merge pull request #55 from hmcts/feature/event-handler-changes
Browse files Browse the repository at this point in the history
Tidying up event handlers. made first task to send messages to event hu…
  • Loading branch information
muralikaturi authored Jul 23, 2019
2 parents ea92bf1 + 3886d06 commit 1098393
Show file tree
Hide file tree
Showing 14 changed files with 17 additions and 116 deletions.
13 changes: 3 additions & 10 deletions VideoAPI/VideoApi.Events/Handlers/DisconnectedEventHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,11 @@ protected override async Task PublishStatusAsync(CallbackEvent callbackEvent)
private async Task PublishParticipantDisconnectMessage()
{
var participantState = ParticipantState.Disconnected;
var command =
new UpdateParticipantStatusCommand(SourceConference.Id, SourceParticipant.Id, participantState);
await PublishParticipantStatusMessage(participantState);

var command = new UpdateParticipantStatusCommand(SourceConference.Id, SourceParticipant.Id, participantState);
await CommandHandler.Handle(command);
await AddDisconnectedTask();
await PublishParticipantStatusMessage(participantState);
}

private async Task AddDisconnectedTask()
Expand Down Expand Up @@ -62,13 +62,6 @@ private async Task PublishSuspendedEventMessage()
await CommandHandler.Handle(updateConferenceStatusCommand);

await AddSuspendedTask();

var hearingEventMessage = new HearingEventMessage
{
ConferenceId = SourceConference.Id,
ConferenceStatus = conferenceState
};
await ServiceBusQueueClient.AddMessageToQueue(hearingEventMessage);
}
}
}
16 changes: 4 additions & 12 deletions VideoAPI/VideoApi.Events/Handlers/JoinedEventHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,27 +26,19 @@ protected override async Task PublishStatusAsync(CallbackEvent callbackEvent)
var isJudge = SourceParticipant.UserRole == UserRole.Judge;
var participantState = isJudge ? ParticipantState.InHearing : ParticipantState.Available;

var command =
new UpdateParticipantStatusCommand(SourceConference.Id, SourceParticipant.Id, participantState);
await CommandHandler.Handle(command);
await PublishParticipantStatusMessage(participantState);

if (isJudge) await PublishLiveEventMessage();

var command = new UpdateParticipantStatusCommand(SourceConference.Id, SourceParticipant.Id, participantState);
await CommandHandler.Handle(command);
}

private async Task PublishLiveEventMessage()
{
var conferenceEvent = ConferenceState.InSession;
var hearingEventMessage = new HearingEventMessage
{
ConferenceId = SourceConference.Id,
ConferenceStatus = conferenceEvent
};

await PublishConferenceStatusMessage(conferenceEvent);
var command = new UpdateConferenceStatusCommand(SourceConference.Id, ConferenceState.InSession);
await CommandHandler.Handle(command);
await PublishConferenceStatusMessage(conferenceEvent);
await ServiceBusQueueClient.AddMessageToQueue(hearingEventMessage);
}
}
}
15 changes: 2 additions & 13 deletions VideoAPI/VideoApi.Events/Handlers/JudgeAvailableEventHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,21 +24,10 @@ public JudgeAvailableEventHandler(IQueryHandler queryHandler, ICommandHandler co
protected override async Task PublishStatusAsync(CallbackEvent callbackEvent)
{
var participantState = ParticipantState.Available;

var command =
new UpdateParticipantStatusCommand(SourceConference.Id, SourceParticipant.Id, participantState);
await CommandHandler.Handle(command);

await PublishParticipantStatusMessage(participantState);

var participantEventMessage = new ParticipantEventMessage
{
ConferenceId = SourceConference.Id,
ParticipantId = SourceParticipant.ParticipantRefId,
ParticipantState = participantState
};

await ServiceBusQueueClient.AddMessageToQueue(participantEventMessage);
var command = new UpdateParticipantStatusCommand(SourceConference.Id, SourceParticipant.Id, participantState);
await CommandHandler.Handle(command);
}
}
}
14 changes: 2 additions & 12 deletions VideoAPI/VideoApi.Events/Handlers/LeaveEventHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,20 +24,10 @@ public LeaveEventHandler(IQueryHandler queryHandler, ICommandHandler commandHand
protected override async Task PublishStatusAsync(CallbackEvent callbackEvent)
{
var participantState = ParticipantState.Disconnected;
var command =
new UpdateParticipantStatusCommand(SourceConference.Id, SourceParticipant.Id, participantState);
await CommandHandler.Handle(command);

await PublishParticipantStatusMessage(participantState);

var participantEventMessage = new ParticipantEventMessage
{
ConferenceId = SourceConference.Id,
ParticipantId = SourceParticipant.ParticipantRefId,
ParticipantState = participantState
};

await ServiceBusQueueClient.AddMessageToQueue(participantEventMessage);
var command = new UpdateParticipantStatusCommand(SourceConference.Id, SourceParticipant.Id, participantState);
await CommandHandler.Handle(command);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,11 @@ public ParticipantJoiningEventHandler(IQueryHandler queryHandler, ICommandHandle
protected override async Task PublishStatusAsync(CallbackEvent callbackEvent)
{
var participantState = ParticipantState.Joining;
await PublishParticipantStatusMessage(participantState);

var command = new UpdateParticipantStatusCommand(SourceConference.Id,
SourceParticipant.Id, participantState);
await CommandHandler.Handle(command);
await PublishParticipantStatusMessage(participantState);
}
}
}
12 changes: 2 additions & 10 deletions VideoAPI/VideoApi.Events/Handlers/PauseEventHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,18 +24,10 @@ public PauseEventHandler(IQueryHandler queryHandler, ICommandHandler commandHand
protected override async Task PublishStatusAsync(CallbackEvent callbackEvent)
{
var conferenceState = ConferenceState.Paused;
var command =
new UpdateConferenceStatusCommand(SourceConference.Id, conferenceState);
await CommandHandler.Handle(command);

await PublishConferenceStatusMessage(conferenceState);
var hearingEventMessage = new HearingEventMessage
{
ConferenceId = SourceConference.Id,
ConferenceStatus = conferenceState
};

await ServiceBusQueueClient.AddMessageToQueue(hearingEventMessage);
var command = new UpdateConferenceStatusCommand(SourceConference.Id, conferenceState);
await CommandHandler.Handle(command);
}
}
}
15 changes: 3 additions & 12 deletions VideoAPI/VideoApi.Events/Handlers/TransferEventHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,19 +25,10 @@ public TransferEventHandler(IQueryHandler queryHandler, ICommandHandler commandH
protected override async Task PublishStatusAsync(CallbackEvent callbackEvent)
{
var participantStatus = DeriveParticipantStatusForTransferEvent(callbackEvent);
var command =
new UpdateParticipantStatusCommand(SourceConference.Id, SourceParticipant.Id, participantStatus);
await CommandHandler.Handle(command);

var participantEventMessage = new ParticipantEventMessage
{
ConferenceId = SourceConference.Id,
ParticipantId = SourceParticipant.ParticipantRefId,
ParticipantState = participantStatus
};

await PublishParticipantStatusMessage(participantStatus);
await ServiceBusQueueClient.AddMessageToQueue(participantEventMessage);

var command = new UpdateParticipantStatusCommand(SourceConference.Id, SourceParticipant.Id, participantStatus);
await CommandHandler.Handle(command);
}

private static ParticipantState DeriveParticipantStatusForTransferEvent(CallbackEvent callbackEvent)
Expand Down
6 changes: 0 additions & 6 deletions VideoAPI/VideoApi.Services/Clients/UserApiClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -646,12 +646,6 @@ public async System.Threading.Tasks.Task CheckServiceHealthAsync(System.Threadin
throw new UserApiException("Server Error", (int)response_.StatusCode, responseText_, headers_, null);
}
else
if (status_ == "401")
{
string responseText_ = ( response_.Content == null ) ? null : await response_.Content.ReadAsStringAsync().ConfigureAwait(false);
throw new UserApiException("Unauthorized", (int)response_.StatusCode, responseText_, headers_, null);
}
else
if (status_ != "200" && status_ != "204")
{
var responseData_ = response_.Content == null ? null : await response_.Content.ReadAsStringAsync().ConfigureAwait(false);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -146,13 +146,6 @@ public async Task
command.ConferenceId == conference.Id &&
command.OriginId == participantForEvent.Id &&
command.TaskType == TaskType.Judge)), Times.Once);

// Verify messages sent to ASB queue
ServiceBusQueueClient.Count.Should().Be(1);

var hearingEventMessage = ServiceBusQueueClient.ReadMessageFromQueue();
hearingEventMessage.Should().BeOfType<HearingEventMessage>();
((HearingEventMessage) hearingEventMessage).ConferenceStatus.Should().Be(ConferenceState.Suspended);
}
}
}
8 changes: 0 additions & 8 deletions VideoAPI/VideoApi.UnitTests/Events/JoinedEventHandlerTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -82,14 +82,6 @@ public async Task
x => x.ConferenceStatusMessage(conference.Id, ConferenceState.InSession),
Times.Exactly(participantCount));

// Verify service bus
ServiceBusQueueClient.Count.Should().Be(1);

var hearingEventMessage = ServiceBusQueueClient.ReadMessageFromQueue();
hearingEventMessage.Should().BeOfType<HearingEventMessage>();
((HearingEventMessage) hearingEventMessage).ConferenceStatus.Should().Be(ConferenceState.InSession);
hearingEventMessage.MessageType.Should().Be(MessageType.Hearing);

CommandHandlerMock.Verify(
x => x.Handle(It.Is<UpdateParticipantStatusCommand>(command =>
command.ConferenceId == conference.Id &&
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,6 @@ public async Task should_send_available_participant_messages_when_judge_availabl
x => x.ParticipantStatusMessage(participantForEvent.Username, ParticipantState.Available),
Times.Exactly(participantCount));

ServiceBusQueueClient.Count.Should().Be(1);
var participantMessage = ServiceBusQueueClient.ReadMessageFromQueue();
participantMessage.Should().BeOfType<ParticipantEventMessage>();
((ParticipantEventMessage) participantMessage).ParticipantState.Should()
.Be(ParticipantState.Available);

CommandHandlerMock.Verify(
x => x.Handle(It.Is<UpdateParticipantStatusCommand>(command =>
command.ConferenceId == conference.Id &&
Expand Down
5 changes: 0 additions & 5 deletions VideoAPI/VideoApi.UnitTests/Events/LeaveEventHandlerTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,6 @@ public async Task should_send_available_message_to_participants_and_service_bus_
x => x.ParticipantStatusMessage(_eventHandler.SourceParticipant.Username,
ParticipantState.Disconnected), Times.Exactly(participantCount));

ServiceBusQueueClient.Count.Should().Be(1);
var participantMessage = (ParticipantEventMessage) ServiceBusQueueClient.ReadMessageFromQueue();
participantMessage.Should().BeOfType<ParticipantEventMessage>();
participantMessage.ParticipantState.Should().Be(ParticipantState.Disconnected);

CommandHandlerMock.Verify(
x => x.Handle(It.Is<UpdateParticipantStatusCommand>(command =>
command.ConferenceId == conference.Id &&
Expand Down
7 changes: 0 additions & 7 deletions VideoAPI/VideoApi.UnitTests/Events/PauseEventHandlerTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,6 @@ public async Task should_send_messages_to_participants_and_service_bus_on_pause(
EventHubClientMock.Verify(x => x.ConferenceStatusMessage(conference.Id, ConferenceState.Paused),
Times.Exactly(participantCount));

// Verify messages sent to ASB queue
ServiceBusQueueClient.Count.Should().Be(1);

var eventMessage = ServiceBusQueueClient.ReadMessageFromQueue();
eventMessage.Should().BeOfType<HearingEventMessage>();
((HearingEventMessage) eventMessage).ConferenceStatus.Should().Be(ConferenceState.Paused);

CommandHandlerMock.Verify(
x => x.Handle(It.Is<UpdateConferenceStatusCommand>(command =>
command.ConferenceId == conference.Id &&
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,13 +49,6 @@ public async Task should_send_participant__status_messages_to_clients_and_asb_wh
x => x.ParticipantStatusMessage(_eventHandler.SourceParticipant.Username,
status), Times.Exactly(participantCount));

// Verify messages sent to ASB queue
ServiceBusQueueClient.Count.Should().Be(1);

var participantEventMessage = ServiceBusQueueClient.ReadMessageFromQueue();
participantEventMessage.Should().BeOfType<ParticipantEventMessage>();
((ParticipantEventMessage) participantEventMessage).ParticipantState.Should().Be(status);

CommandHandlerMock.Verify(
x => x.Handle(It.Is<UpdateParticipantStatusCommand>(command =>
command.ConferenceId == conference.Id &&
Expand Down

0 comments on commit 1098393

Please sign in to comment.