/// <summary> /// Attempts to find and remove a subscription with the given client id on the message for the target subscription. /// </summary> /// <param name="message">The message containing the subscription id to stop.</param> /// <returns>Task.</returns> private async Task ExecuteStopRequest(ApolloClientStopMessage message) { var totalRemaining = _subscriptions.Remove(message.Id, out var subFound); if (subFound != null) { _reservedMessageIds.ReleaseMessageId(subFound.Id); if (totalRemaining == 0) { this.SubscriptionRouteRemoved?.Invoke(this, new ApolloSubscriptionFieldEventArgs(subFound.Field)); } _logger?.SubscriptionStopped(subFound); await this .SendMessage(new ApolloServerCompleteMessage(subFound.Id)) .ConfigureAwait(false); } else { var errorMessage = new ApolloServerErrorMessage( $"No active subscription exists with id '{message.Id}'", Constants.ErrorCodes.BAD_REQUEST, lastMessage: message, clientProvidedId: message.Id); await this .SendMessage(errorMessage) .ConfigureAwait(false); } }
public void ReleasedIdIsAllowedToBeAdded() { var client = new Mock <ISubscriptionClientProxy>().Object; var idSet = new ClientTrackedMessageIdSet(); var result = idSet.ReserveMessageId("abc123"); Assert.IsTrue(result); idSet.ReleaseMessageId("abc123"); result = idSet.ReserveMessageId("abc123"); Assert.IsTrue(result); }