Ejemplo n.º 1
0
        private async Task ClientPublishSingleChannelTestImpl(IBroadcastChannelProvider provider, bool fireAndForget = true)
        {
            var grainKey  = Guid.NewGuid().ToString("N");
            var channelId = ChannelId.Create("some-namespace", grainKey);
            var stream    = provider.GetChannelWriter <int>(channelId);

            await stream.Publish(1);

            await stream.Publish(2);

            await stream.Publish(3);

            var grain  = _fixture.Client.GetGrain <ISimpleSubscriberGrain>(grainKey);
            var values = await Get(() => grain.GetValues(channelId), 3);

            Assert.Equal(3, values.Count);
            if (fireAndForget)
            {
                Assert.Contains(1, values);
                Assert.Contains(2, values);
                Assert.Contains(3, values);
            }
            else
            {
                Assert.Equal(1, values[0]);
                Assert.Equal(2, values[1]);
                Assert.Equal(3, values[2]);
            }
        }
Ejemplo n.º 2
0
        private async Task ClientPublishMultipleChannelTestImpl(IBroadcastChannelProvider provider)
        {
            var grainKey = Guid.NewGuid().ToString("N");
            var channels = new List <(ChannelId ChannelId, int ExpectedValue)>();

            for (var i = 0; i < 10; i++)
            {
                var id    = ChannelId.Create($"some-namespace{i}", grainKey);
                var value = i + 50;

                channels.Add((id, value));

                await provider.GetChannelWriter <int>(id).Publish(value);
            }

            var grain = _fixture.Client.GetGrain <ISimpleSubscriberGrain>(grainKey);

            foreach (var channel in channels)
            {
                var values = await Get(() => grain.GetValues(channel.ChannelId), 1);

                Assert.Single(values);
                Assert.Equal(channel.ExpectedValue, values[0]);
            }
        }
Ejemplo n.º 3
0
        public async Task <IActionResult> GetConnections(
            [FromQuery] string clientType,
            [FromQuery] string clientId,
            [FromQuery] string channelType,
            [FromQuery] string channelId
            )
        {
            var query = new FindConnectionsByClientTypeClientIdChannelTypeChannelId();

            if (!string.IsNullOrEmpty(clientType))
            {
                query.ClientType = ClientType.Create(clientType);
            }

            if (!string.IsNullOrEmpty(clientId))
            {
                query.ClientId = ClientId.Create(clientId);
            }

            if (!string.IsNullOrEmpty(channelType))
            {
                query.ChannelType = ChannelType.Create(channelType);
            }

            if (!string.IsNullOrEmpty(channelId))
            {
                query.ChannelId = ChannelId.Create(channelId);
            }

            IEnumerable <Connection> connections;

            try
            {
                connections =
                    await _findConnectionsByClientTypeClientIdChannelTypeChannelIdQueryHandler.HandleAsync(query);
            }
            catch (ValidationException validationException)
            {
                return(StatusCode(
                           (int)HttpStatusCode.UnprocessableEntity,
                           new { message = validationException.MessageToUser }
                           ));
            }

            var connectionDtos = connections.Select(ConnectionDto.CreateFromConnection);

            return(Ok(new ItemsEnvelope <ConnectionDto>(connectionDtos)));
        }
Ejemplo n.º 4
0
        private async Task MultipleSubscribersOneBadActorChannelTestImpl(IBroadcastChannelProvider provider, bool fireAndForget = true)
        {
            var grainKey  = Guid.NewGuid().ToString("N");
            var channelId = ChannelId.Create("multiple-namespaces-0", grainKey);
            var stream    = provider.GetChannelWriter <int>(channelId);

            var badGrain  = _fixture.Client.GetGrain <ISimpleSubscriberGrain>(grainKey);
            var goodGrain = _fixture.Client.GetGrain <IRegexNamespaceSubscriberGrain>(grainKey);

            await stream.Publish(1);

            if (fireAndForget)
            {
                var values = await Get(() => badGrain.GetValues(channelId), 1);

                Assert.Single(values);
            }
            await badGrain.ThrowsOnReceive(true);

            if (fireAndForget)
            {
                await stream.Publish(2);

                // Wait to be sure that published event reached the grain
                var counter = 0;
                var cts     = new CancellationTokenSource(CallTimeoutMs);
                while (!cts.IsCancellationRequested)
                {
                    counter = await badGrain.GetOnPublishedCounter();

                    if (counter == 1)
                    {
                        break;
                    }
                    await Task.Delay(10);
                }
                Assert.Equal(2, counter);
            }
            else
            {
                var ex = await Assert.ThrowsAsync <AggregateException>(() => stream.Publish(2));

                Assert.Single(ex.InnerExceptions);
            }
            await badGrain.ThrowsOnReceive(false);

            await stream.Publish(3);

            var goodValues = await Get(() => goodGrain.GetValues(channelId), 3);

            Assert.Equal(3, goodValues.Count);
            if (fireAndForget)
            {
                Assert.Contains(1, goodValues);
                Assert.Contains(2, goodValues);
                Assert.Contains(3, goodValues);
            }
            else
            {
                Assert.Equal(1, goodValues[0]);
                Assert.Equal(2, goodValues[1]);
                Assert.Equal(3, goodValues[2]);
            }

            var badValues = await Get(() => badGrain.GetValues(channelId), 2);

            Assert.Equal(2, badValues.Count);
            if (fireAndForget)
            {
                Assert.Contains(1, badValues);
                Assert.Contains(3, badValues);
            }
            else
            {
                Assert.Equal(1, badValues[0]);
                Assert.Equal(3, badValues[1]);
            }
        }