Exemple #1
0
        static async Task RunClientAsync(RespConnection client, int pingsPerClient, int pipelineDepth, string payload)
        {
            var frame = string.IsNullOrEmpty(payload)
                ? s_ping
                : RespValue.CreateAggregate(RespType.Array, "PING", payload);
            var expected = string.IsNullOrEmpty(payload)
                ? s_pong
                : RespValue.Create(RespType.BlobString, payload);

            if (pipelineDepth == 1)
            {
                for (int i = 0; i < pingsPerClient; i++)
                {
                    await client.SendAsync(frame).ConfigureAwait(false);

                    using var result = await client.ReceiveAsync().ConfigureAwait(false);

                    result.Value.ThrowIfError();

                    if (!result.Value.Equals(expected))
                    {
                        Throw();
                    }
                    // await client.PingAsync();
                }
            }
            else
            {
                using var frames = Replicate(frame, pipelineDepth);
                for (int i = 0; i < pingsPerClient; i++)
                {
                    using var batch = await client.BatchAsync(frames.Value).ConfigureAwait(false);

                    CheckBatchForErrors(batch.Value, expected);
                }
            }
        }
Exemple #2
0
        public void TestBytes()
        {
            const int MAX_LENGTH = 800;
            var       sourceData = ArrayPool <byte> .Shared.Rent(MAX_LENGTH);

            var target = ArrayPool <byte> .Shared.Rent(MAX_LENGTH + 2);

            try
            {
                var rand = new Random(12345);
                rand.NextBytes(sourceData);
                for (int i = 0; i < MAX_LENGTH; i++)
                {
                    int       offset = MAX_LENGTH - i;
                    var       seq    = new ReadOnlySequence <byte>(sourceData, offset, i);
                    RespValue resp   = RespValue.Create(RespType.BlobString, seq);

                    Assert.Equal(i, resp.GetByteCount());
                    var dest = new Span <byte>(target, 1, i);
                    Array.Clear(target, 0, i + 2);
                    Assert.Equal(i, resp.CopyTo(dest));
                    Assert.Equal(0, target[0]);
                    Assert.Equal(0, target[i + 1]);
                    for (int j = 0; j < i; j++)
                    {
                        Assert.Equal(sourceData[j + offset], target[j + 1]);
                    }
                }
            }
            finally
            {
                ArrayPool <byte> .Shared.Return(sourceData);

                ArrayPool <byte> .Shared.Return(target);
            }
        }
Exemple #3
0
 public void SimpleExamples(string payload, RespType expectedType, string expectedText)
 => Verify(payload, RespValue.Create(expectedType, expectedText), null);