public async Task OnlyOneConnectionMultiplexerIsCreated()
        {
            using (var clusterFixture = new StreamingClusterFixture())
                await clusterFixture.Dispatch(async() =>
                {
                    // Make sure some producer/consumers are set up
                    var dataSets = await CreateProducerConsumerStreamAwaiter(clusterFixture, 100, 10);
                    await Task.WhenAll(dataSets.Select(d => d.Awaiter));

                    var connectionMultiplexerFactory = (CachedConnectionMultiplexerFactory)clusterFixture.ClusterServices.GetRequiredService <IConnectionMultiplexerFactory>();
                    Assert.Single(connectionMultiplexerFactory.TestHook_ConnectionMultiplexers);
                });
        }
Ejemplo n.º 2
0
        public async Task TwoRedisStreamsWithDifferentStreamIdsAndDifferentStreamNamespacesOnlyReceiveTheirOwnMessages(int messageCount1, int messageCount2)
        {
            using (var clusterFixture = new StreamingClusterFixture())
            {
                await clusterFixture.Start();

                await clusterFixture.Dispatch(async() =>
                {
                    var streamId1 = Guid.NewGuid();
                    var streamId2 = Guid.NewGuid();

                    var streamNamespace1 = Guid.NewGuid().ToString();
                    var streamNamespace2 = Guid.NewGuid().ToString();

                    var streamSubscriptionAwaiter1 = await clusterFixture.SubscribeAndGetTaskAwaiter <string>(StreamProviderName, streamId1, streamNamespace1, messageCount1);
                    var streamSubscriptionAwaiter2 = await clusterFixture.SubscribeAndGetTaskAwaiter <string>(StreamProviderName, streamId2, streamNamespace2, messageCount2);

                    var publishTask1 = Task.Factory.StartNew(async() =>
                    {
                        for (var i = 0; i < messageCount1; i++)
                        {
                            await clusterFixture.PublishToStream(StreamProviderName, streamId1, streamNamespace1, $"test:{streamId1}-{streamNamespace1} message:{i}");
                        }
                    });
                    var publishTask2 = Task.Factory.StartNew(async() =>
                    {
                        for (var i = 0; i < messageCount2; i++)
                        {
                            await clusterFixture.PublishToStream(StreamProviderName, streamId2, streamNamespace2, $"test:{streamId2}-{streamNamespace2} message:{i}");
                        }
                    });

                    List <dynamic> items1 = null, items2 = null;
                    using (var cts = GetTokenSource())
                    {
                        var results = await Task.WhenAll(streamSubscriptionAwaiter1, streamSubscriptionAwaiter2).WaitAsync(cts.Token);
                        items1      = results[0];
                        items2      = results[1];
                    }

                    // Wait a little longer just in case something else is published (which would be bad)
                    await Task.Delay(100);

                    Assert.Equal(messageCount1, items1.Count);
                    Assert.Equal(messageCount2, items2.Count);

                    AssertEx.Equal(new object[messageCount1].Select((_, i) => $"test:{streamId1}-{streamNamespace1} message:{i}").OrderBy(x => x), items1.Cast <string>().OrderBy(x => x));
                    AssertEx.Equal(new object[messageCount2].Select((_, i) => $"test:{streamId2}-{streamNamespace2} message:{i}").OrderBy(x => x), items2.Cast <string>().OrderBy(x => x));
                });
            }
        }
        public async Task RedisStreamCanSendAndReceiveItem()
        {
            using (var clusterFixture = new StreamingClusterFixture())
                await clusterFixture.Dispatch(async() =>
                {
                    var streamId        = Guid.NewGuid();
                    var streamNamespace = Guid.NewGuid().ToString();

                    var streamSubscriptionAwaiter = await clusterFixture.SubscribeAndGetTaskAwaiter <string>(StreamProviderName, streamId, streamNamespace, 1);
                    await clusterFixture.PublishToStream(StreamProviderName, streamId, streamNamespace, "test");
                    using (var cts = GetTokenSource())
                    {
                        await streamSubscriptionAwaiter.WaitAsync(cts.Token);
                    }
                });
        }
        public async Task NRedisStreamsWithDifferentStreamIdsAndDifferentStreamNamespacesOnlyReceiveTheirOwnMessages(int n, int messageCount)
        {
            using (var clusterFixture = new StreamingClusterFixture())
                await clusterFixture.Dispatch(async() =>
                {
                    var dataSets = await CreateProducerConsumerStreamAwaiter(clusterFixture, n, messageCount);

                    await Task.WhenAll(dataSets.Select(d => d.Awaiter));

                    foreach (var set in dataSets)
                    {
                        var items = await set.Awaiter;
                        Assert.Equal(messageCount, items.Count);
                        AssertEx.Equal(new object[messageCount].Select((_, i) => $"test:{set.StreamId}-{set.StreamNamespace} message:{i}").OrderBy(x => x), items.Cast <string>().OrderBy(x => x));
                    }
                });
        }