Task <IRemoteControllerClient> ConnectToRemoteControllerAsync()
        {
            // assume we can start the RC, else mark the test as inconclusive without even trying
            // so... if starting the RC fails once, we probably have a problem (is it even running?)
            // and there is no point trying again and again - faster to stop here
            Assume.That(_canConnectToRemoveController, Is.True, () => "Cannot connect to the Remote Controller (is it running?).");

            try
            {
#if NETFRAMEWORK
                var transport = new Thrift.Transport.TFramedTransport(new Thrift.Transport.TSocket("localhost", 9701));
                transport.Open();
                var protocol = new Thrift.Protocol.TBinaryProtocol(transport);
                return(Task.FromResult(RemoteControllerClient.Create(protocol)));
#else
                var rcHostAddress    = NetworkAddress.GetIPAddressByName("localhost");
                var tSocketTransport = new Thrift.Transport.Client.TSocketTransport(rcHostAddress, 9701);
                var transport        = new Thrift.Transport.TFramedTransport(tSocketTransport);
                if (!transport.IsOpen)
                {
                    await transport.OpenAsync().CfAwait();
                }
                var protocol = new Thrift.Protocol.TBinaryProtocol(transport);
                return(RemoteControllerClient.Create(protocol));
#endif
            }
            catch (Exception e)
            {
                _canConnectToRemoveController = false; // fail fast other tests
                Logger?.LogDebug(e, "Cannot connect to the Remote Controller (is it running?)");
                throw new AssertionException("Cannot connect to the Remote Controller (is it running?)", e);
            }
        }
Esempio n. 2
0
        protected IRemoteController CreateRemoteController()
        {
            try
            {
#if NETFRAMEWORK
                var transport = new Thrift.Transport.TFramedTransport(new Thrift.Transport.TSocket("localhost", 9701));
                transport.Open();
                var protocol = new Thrift.Protocol.TBinaryProtocol(transport);
                return(new ThreadSafeRemoteController(protocol));
#else
                var rcHostAddress    = AddressUtil.GetAddressByName("localhost");
                var tSocketTransport = new Thrift.Transport.Client.TSocketTransport(rcHostAddress, 9701);
                var transport        = new Thrift.Transport.TFramedTransport(tSocketTransport);
                if (!transport.IsOpen)
                {
                    transport.OpenAsync().Wait();
                }
                var protocol = new Thrift.Protocol.TBinaryProtocol(transport);
                return(new ThreadSafeRemoteController(protocol));
#endif
            }
            catch (Exception e)
            {
                _logger.Finest("Cannot start Remote Controller", e);
                _logger.Finest(e.StackTrace);
                throw new AssertionException("Cannot start Remote Controller", e);
            }
        }