private async Task Start()
        {
            _call = _client.Read(RequestMetadata.Create(_userCredentials), cancellationToken: _disposed.Token);

            try {
                await _call.RequestStream.WriteAsync(new ReadReq {
                    Options = _options
                });

                if (!await _call.ResponseStream.MoveNext(_disposed.Token) ||
                    _call.ResponseStream.Current.ContentCase != ReadResp.ContentOneofCase.Empty)
                {
                    throw new InvalidOperationException();
                }
            } catch (Exception ex) {
                SubscriptionDropped(SubscriptionDroppedReason.ServerError, ex);
                return;
            } finally {
                _started.SetResult(true);
            }

#pragma warning disable 4014
            Task.Run(Subscribe);
#pragma warning restore 4014
        }
Ejemplo n.º 2
0
            protected override async Task Given()
            {
                _persistentSubscriptionsClient = new PersistentSubscriptions.PersistentSubscriptionsClient(Channel);

                var settings = WithoutExtraStatistics(TestPersistentSubscriptionSettings);

                await _persistentSubscriptionsClient.CreateAsync(new CreateReq {
                    Options = new CreateReq.Types.Options {
                        GroupName = _groupName,
                        Stream    = new CreateReq.Types.StreamOptions {
                            Start            = new Empty(),
                            StreamIdentifier = new StreamIdentifier {
                                StreamName = ByteString.CopyFromUtf8(_streamName)
                            }
                        },
                        Settings = settings
                    }
                }, GetCallOptions(AdminCredentials));

                // create a connection to the persistent subscription
                var call = _persistentSubscriptionsClient.Read(GetCallOptions(AdminCredentials));
                await call.RequestStream.WriteAsync(new ReadReq {
                    Options = new ReadReq.Types.Options {
                        GroupName        = _groupName,
                        StreamIdentifier = new StreamIdentifier {
                            StreamName = ByteString.CopyFromUtf8(_streamName)
                        },
                        UuidOption = new ReadReq.Types.Options.Types.UUIDOption {
                            Structured = new Empty()
                        },
                        BufferSize = 10
                    }
                });

                await call.ResponseStream.MoveNext().ConfigureAwait(false);

                Assert.IsTrue(call.ResponseStream.Current.ContentCase == ReadResp.ContentOneofCase.SubscriptionConfirmation);

                var expectedConnection = new SubscriptionInfo.Types.ConnectionInfo()
                {
                    Username       = "******",
                    AvailableSlots = 10,
                    ConnectionName = "\u003cunknown\u003e"
                };

                _expectedSubscriptionInfo = GetSubscriptionInfoFromSettings(settings,
                                                                            _groupName, _streamName, "0", string.Empty, new [] { expectedConnection });
            }
        private async Task Start()
        {
            _call = _client.Read(RequestMetadata.Create(_userCredentials), cancellationToken: _disposed.Token);

            try {
                await _call.RequestStream.WriteAsync(new ReadReq {
                    Options = _options
                }).ConfigureAwait(false);

                if (!await _call.ResponseStream.MoveNext(_disposed.Token).ConfigureAwait(false) ||
                    _call.ResponseStream.Current.ContentCase != ReadResp.ContentOneofCase.SubscriptionConfirmation)
                {
                    throw new InvalidOperationException();
                }
            } catch (Exception ex) {
                SubscriptionDropped(SubscriptionDroppedReason.ServerError, ex);
                return;
            } finally {
                _started.SetResult(true);
            }

            _ = Subscribe();
        }