Ejemplo n.º 1
0
        public void DisposeNewChannelTest()
        {
            Guid activityId = Guid.NewGuid();

            Trace.CorrelationManager.ActivityId = activityId;
            // Assuming that this machine isn't running SMTP.
            using (Rntbd.Channel channel = new Rntbd.Channel(
                       new Uri("rntbd://localhost:25"),
                       RntbdTests.GetChannelProperties()))
            {
            }
        }
Ejemplo n.º 2
0
        public void DisposeInitializeFailedChannelTest()
        {
            Stopwatch sw      = Stopwatch.StartNew();
            TimeSpan  runTime = TimeSpan.FromSeconds(10);

            while (sw.Elapsed < runTime)
            {
                Guid activityId = Guid.NewGuid();
                Trace.CorrelationManager.ActivityId = activityId;
                // Assuming that this machine isn't running SMTP.
                using (Rntbd.Channel channel = new Rntbd.Channel(
                           new Uri("rntbd://localhost:25"),
                           RntbdTests.GetChannelProperties()))
                {
                    channel.Initialize(activityId);
                }
            }
        }
Ejemplo n.º 3
0
        public async Task DisposeInitializeFailedChannelAsyncTest()
        {
            const int msPerBucket = 50;
            const int buckets     = 2 * 1000 / msPerBucket + 1;
            const int seconds     = 10;
            Random    r           = new Random(RntbdTests.RandomSeed());
            Stopwatch sw          = Stopwatch.StartNew();
            TimeSpan  runTime     = TimeSpan.FromSeconds(seconds);

            while (sw.Elapsed < runTime)
            {
                Guid activityId = Guid.NewGuid();
                Trace.CorrelationManager.ActivityId = activityId;
                // Assuming that this machine isn't running SMTP.
                using (Rntbd.Channel channel = new Rntbd.Channel(
                           new Uri("rntbd://localhost:25"),
                           RntbdTests.GetChannelProperties()))
                {
                    channel.Initialize(activityId);
                    await Task.Delay(r.Next(1, buckets) *msPerBucket);
                }
            }
        }
Ejemplo n.º 4
0
        public async Task CallInitializeFailedChannelAsyncTest()
        {
            TimeSpan  totalRunTime   = TimeSpan.FromSeconds(15.0);
            TimeSpan  channelRunTime = TimeSpan.FromSeconds(5.0);
            Stopwatch outerSw        = Stopwatch.StartNew();

            while (outerSw.Elapsed < totalRunTime)
            {
                Guid activityId = Guid.NewGuid();
                Trace.CorrelationManager.ActivityId = activityId;
                using (Rntbd.Channel channel = new Rntbd.Channel(
                           new Uri("rntbd://localhost:25"),
                           RntbdTests.GetChannelProperties()))
                {
                    channel.Initialize(activityId);
                    Stopwatch innerSw = Stopwatch.StartNew();
                    while (innerSw.Elapsed < channelRunTime)
                    {
                        try
                        {
                            StoreResponse response = await channel.RequestAsync(
                                DocumentServiceRequest.Create(
                                    OperationType.Read,
                                    ResourceType.Document,
                                    AuthorizationTokenType.SecondaryReadonlyMasterKey),
                                new Uri("rntbd://localhost:25/foo/bar/baz"),
                                ResourceOperation.ReadDocument,
                                activityId);
                        }
                        catch (TransportException e)
                        {
                            Assert.AreEqual(activityId, e.ActivityId);
                            Assert.IsTrue(
                                (e.ErrorCode == TransportErrorCode.ConnectFailed) ||
                                (e.ErrorCode == TransportErrorCode.ConnectTimeout),
                                "Expected ConnectFailed or ConnectTimeout. Actual: {0}",
                                e.ErrorCode);
                            Exception rootCause = e.GetBaseException();
                            if (e.Equals(rootCause))
                            {
                                return;
                            }
                            SocketException socketException = rootCause as SocketException;
                            if (socketException != null)
                            {
                                if (socketException.SocketErrorCode != SocketError.ConnectionRefused)
                                {
                                    Assert.Fail(
                                        "Expected connection reset or " +
                                        "connection aborted. Actual: {0}",
                                        socketException.SocketErrorCode.ToString());
                                }
                            }
                            else
                            {
                                IOException ioException = rootCause as IOException;
                                Assert.IsTrue(ioException != null,
                                              "Expected IOException. Actual: {0} ({1})",
                                              rootCause.Message, rootCause.GetType());
                            }
                        }
                    }
                }
            }
        }
Ejemplo n.º 5
0
        public async Task ServerCloseOnSslNegotiationCompleteAsyncTest()
        {
            using (FaultyServer server = new FaultyServer())
            {
                server.OnConnectionEvent += (sender, args) =>
                {
                    if (args.EventType == FaultyServer.ConnectionEventType.SslNegotiationComplete)
                    {
                        RntbdTests.RandomSleep();
                        args.Close = true;
                    }
                };
                try
                {
                    await server.StartAsync();

                    Dictionary <OperationType, ResourceOperation> operationMap =
                        new Dictionary <OperationType, ResourceOperation>
                    {
                        [OperationType.Read]   = ResourceOperation.ReadDocument,
                        [OperationType.Upsert] = ResourceOperation.UpsertDocument,
                    };
                    foreach (OperationType operationType in new OperationType[]
                    {
                        OperationType.Read,
                        OperationType.Upsert
                    })
                    {
                        TimeSpan  runTime = TimeSpan.FromSeconds(10.0);
                        Stopwatch sw      = Stopwatch.StartNew();
                        while (sw.Elapsed < runTime)
                        {
                            Guid activityId = Guid.NewGuid();
                            Trace.CorrelationManager.ActivityId = activityId;

                            using (Rntbd.Channel channel = new Rntbd.Channel(
                                       server.Uri,
                                       RntbdTests.GetChannelProperties()))
                            {
                                channel.Initialize(activityId);

                                try
                                {
                                    ResourceType      resourceType      = ResourceType.Document;
                                    ResourceOperation resourceOperation = operationMap[operationType];
                                    StoreResponse     response          = await channel.RequestAsync(
                                        DocumentServiceRequest.Create(
                                            operationType,
                                            resourceType,
                                            AuthorizationTokenType.SecondaryReadonlyMasterKey),
                                        new Uri(server.Uri, "foo/bar/baz"),
                                        resourceOperation,
                                        activityId);
                                }
                                catch (TransportException e)
                                {
                                    Assert.AreEqual(activityId, e.ActivityId);
                                    Assert.IsTrue(
                                        (e.ErrorCode == TransportErrorCode.ReceiveFailed) ||
                                        (e.ErrorCode == TransportErrorCode.SslNegotiationFailed) ||
                                        (e.ErrorCode == TransportErrorCode.ReceiveStreamClosed),
                                        "Expected ReceiveFailed or ReceiveStreamClosed. Actual: {0}",
                                        e.ErrorCode);
                                    Exception rootCause = e.GetBaseException();
                                    if (e.Equals(rootCause))
                                    {
                                        return;
                                    }
                                    SocketException socketException = rootCause as SocketException;
                                    if (socketException != null)
                                    {
                                        if (socketException.SocketErrorCode != SocketError.ConnectionReset &&
                                            socketException.SocketErrorCode != SocketError.ConnectionAborted)
                                        {
                                            Assert.Fail(
                                                "Expected connection reset or " +
                                                "connection aborted. Actual: {0}",
                                                socketException.SocketErrorCode.ToString());
                                        }
                                    }
                                    else
                                    {
                                        IOException ioException = rootCause as IOException;
                                        Assert.IsTrue(ioException != null,
                                                      "Expected IOException. Actual: {0} ({1})",
                                                      rootCause.Message, rootCause.GetType());
                                    }
                                }
                            }
                        }
                    }
                }
                finally
                {
                    await server.StopAsync();
                }
            }
        }