Example #1
0
        public static void Main(string[] args)
        {
            Log.Logger = new LoggerConfiguration()
                .WriteTo.ColoredConsole()
                .CreateLogger();

            Console.Title = "Halibut Client";

            var hostName = args.FirstOrDefault() ?? "localhost";
            var port = args.Skip(1).FirstOrDefault() ?? "8433";

            var certificate = new X509Certificate2("HalibutClient.pfx");

            using (var runtime = new HalibutRuntime(certificate))
            {
                Console.WriteLine("creating calculator");
                var calculator = runtime.CreateClient<ICalculatorService>("https://" + hostName + ":" + port + "/", "EF3A7A69AFE0D13130370B44A228F5CD15C069BC");

                Console.WriteLine("making call 1");
                var result = calculator.Add(12, 18);
                Console.WriteLine("making call 2");
                result = calculator.Add(12, 18);

                Console.WriteLine("12 + 18 = " + result);
                Console.ReadKey();
            }
        }
Example #2
0
        public static void Main(string[] args)
        {
            Log.Logger = new LoggerConfiguration()
                         .WriteTo.ColoredConsole()
                         .CreateLogger();

            Console.Title = "Halibut Client";

            var hostName = args.FirstOrDefault() ?? "localhost";
            var port     = args.Skip(1).FirstOrDefault() ?? "8433";

            var certificate = new X509Certificate2("HalibutClient.pfx");

            using (var runtime = new HalibutRuntime(certificate))
            {
                Console.WriteLine("creating calculator");
                var calculator = runtime.CreateClient <ICalculatorService>("https://" + hostName + ":" + port + "/", "EF3A7A69AFE0D13130370B44A228F5CD15C069BC");

                Console.WriteLine("making call 1");
                var result = calculator.Add(12, 18);
                Console.WriteLine("making call 2");
                result = calculator.Add(12, 18);


                Console.WriteLine("12 + 18 = " + result);
                Console.ReadKey();
            }
        }
Example #3
0
        public void OctopusCanSendMessagesToWebSocketPollingTentacle()
        {
            const int octopusPort = 8450;

            AddSslCertToLocalStoreAndRegisterFor("0.0.0.0:" + octopusPort);

            try
            {
                using (var octopus = new HalibutRuntime(services, Certificates.Octopus))
                    using (var tentaclePolling = new HalibutRuntime(services, Certificates.TentaclePolling))
                    {
                        octopus.ListenWebSocket($"https://+:{octopusPort}/Halibut");
                        octopus.Trust(Certificates.TentaclePollingPublicThumbprint);

                        tentaclePolling.Poll(new Uri("poll://SQ-TENTAPOLL"), new ServiceEndPoint(new Uri($"wss://localhost:{octopusPort}/Halibut"), Certificates.SslThumbprint));

                        var echo = octopus.CreateClient <IEchoService>("poll://SQ-TENTAPOLL", Certificates.TentaclePollingPublicThumbprint);
                        for (var i = 0; i < 2000; i++)
                        {
                            echo.SayHello("Deploy package A" + i).Should().Be("Deploy package A" + i + "...");
                        }
                    }
            }
            finally
            {
                RemoveSslCertBindingFor("0.0.0.0:" + octopusPort);
            }
        }
Example #4
0
 public void StartClient()
 {
     var DaClient     = new HalibutRuntime(Configuration.ClientCertificate);
     var DaService    = DaClient.CreateClient <ITestService>(Configuration.ClientEndpoint, Configuration.ServerCertificate.Thumbprint);
     var IntTester    = DaService.Add(1, 5);
     var StringSender = DaService.Send("Hi mom");
 }
Example #5
0
        public void OctopusCanSendMessagesToWebSocketPollingTentacle()
        {
            var       services    = GetDelegateServiceFactory();
            const int octopusPort = 8450;

            AddSslCertToLocalStoreAndRegisterFor("0.0.0.0:" + octopusPort);

            try
            {
                using (var octopus = new HalibutRuntime(services, Certificates.Octopus))
                    using (var tentaclePolling = new HalibutRuntime(services, Certificates.TentaclePolling))
                    {
                        octopus.ListenWebSocket($"https://+:{octopusPort}/Halibut");
                        octopus.Trust(Certificates.TentaclePollingPublicThumbprint);

                        tentaclePolling.Poll(new Uri("poll://SQ-TENTAPOLL"), new ServiceEndPoint(new Uri($"wss://localhost:{octopusPort}/Halibut"), Certificates.SslThumbprint));

                        var echo = octopus.CreateClient <IEchoService>("poll://SQ-TENTAPOLL", Certificates.TentaclePollingPublicThumbprint);
                        for (var i = 0; i < 2000; i++)
                        {
                            echo.SayHello("Deploy package A" + i).Should().Be("Deploy package A" + i + "...");
                        }
                    }
            }
            catch (NotSupportedException nse) when(nse.Message == "The netstandard build of this library cannot act as the client in a WebSocket polling setup")
            {
                Assert.Inconclusive("This test cannot run on the netstandard build");
            }
            finally
            {
                RemoveSslCertBindingFor("0.0.0.0:" + octopusPort);
            }
        }
Example #6
0
 static void RunListeningClient(X509Certificate2 clientCertificate, int port, string remoteThumbprint, bool expectSuccess = true)
 {
     using (var runtime = new HalibutRuntime(clientCertificate))
     {
         var calculator = runtime.CreateClient <ICalculatorService>($"https://localhost:{port}/", remoteThumbprint);
         MakeRequest(calculator, "listening", expectSuccess);
     }
 }
 public void FailOnInvalidHostname()
 {
     using (var octopus = new HalibutRuntime(services, Certificates.Octopus))
     {
         var echo = octopus.CreateClient<IEchoService>("https://sduj08ud9382ujd98dw9fh934hdj2389u982:8000", Certificates.TentacleListeningPublicThumbprint);
         var ex = Assert.Throws<HalibutClientException>(() => echo.Crash());
         Assert.That(ex.Message, Does.Contain("when sending a request to 'https://sduj08ud9382ujd98dw9fh934hdj2389u982:8000/', before the request").And.Contains("No such host is known"));
     }
 }
 public void FailOnInvalidPort()
 {
     using (var octopus = new HalibutRuntime(services, Certificates.Octopus))
     {
         var echo = octopus.CreateClient<IEchoService>("https://google.com:88", Certificates.TentacleListeningPublicThumbprint);
         var ex = Assert.Throws<HalibutClientException>(() => echo.Crash());
         Assert.That(ex.Message, Does.Contain("when sending a request to 'https://google.com:88/', before the request"));
     }
 }
 public void FailsWhenSendingToPollingMachineButNothingPicksItUp()
 {
     using (var octopus = new HalibutRuntime(services, Certificates.Octopus))
     {
         var echo = octopus.CreateClient<IEchoService>("poll://SQ-TENTAPOLL", Certificates.TentaclePollingPublicThumbprint);
         var error = Assert.Throws<HalibutClientException>(() => echo.SayHello("Paul"));
         Assert.That(error.Message, Does.Contain("the polling endpoint did not collect the request within the allowed time"));
     }
 }
Example #10
0
 public void FailsWhenSendingToPollingMachineButNothingPicksItUp()
 {
     using (var octopus = new HalibutRuntime(services, Certificates.Octopus))
     {
         var echo  = octopus.CreateClient <IEchoService>("poll://SQ-TENTAPOLL", Certificates.TentaclePollingPublicThumbprint);
         var error = Assert.Throws <HalibutClientException>(() => echo.SayHello("Paul"));
         error.Message.Should().Contain("the polling endpoint did not collect the request within the allowed time");
     }
 }
Example #11
0
 public void FailOnInvalidHostname()
 {
     using (var octopus = new HalibutRuntime(services, Certificates.Octopus))
     {
         var echo = octopus.CreateClient <IEchoService>("https://sduj08ud9382ujd98dw9fh934hdj2389u982:8000", Certificates.TentacleListeningPublicThumbprint);
         var ex   = Assert.Throws <HalibutClientException>(() => echo.Crash());
         ex.Message.Should().Contain("when sending a request to 'https://sduj08ud9382ujd98dw9fh934hdj2389u982:8000/', before the request").And.Contain("No such host is known");
     }
 }
Example #12
0
 public void FailOnInvalidPort()
 {
     using (var octopus = new HalibutRuntime(services, Certificates.Octopus))
     {
         var echo = octopus.CreateClient <IEchoService>("https://google.com:88", Certificates.TentacleListeningPublicThumbprint);
         var ex   = Assert.Throws <HalibutClientException>(() => echo.Crash());
         ex.Message.Should().Contain("when sending a request to 'https://google.com:88/', before the request");
     }
 }
Example #13
0
        protected override void ProcessRecord()
        {
            using (var runtime = new HalibutRuntime(Configuration.ClientCertificate))
            {
                var pairing = runtime.CreateClient <IPairingService>(Configuration.ClientEndpoint,
                                                                     Configuration.ServerCertificate.Thumbprint);

                pairing.DualShockDevices.ToList().ForEach(WriteObject);
            }
        }
        public void FailOnInvalidHostname()
        {
            var services = GetStubDelegateServiceFactory();

            using (var octopus = new HalibutRuntime(services, Certificates.Octopus))
            {
                var echo = octopus.CreateClient <IEchoService>("https://sduj08ud9382ujd98dw9fh934hdj2389u982:8000", Certificates.TentacleListeningPublicThumbprint);
                var ex   = Assert.Throws <HalibutClientException>(() => echo.Crash());
                ex.Message.Should().Contain("when sending a request to 'https://sduj08ud9382ujd98dw9fh934hdj2389u982:8000/', before the request")
                .And.Contain(RuntimeInformation.IsOSPlatform(OSPlatform.Windows) ? "No such host is known" : "No such device or address");
            }
        }
Example #15
0
        static void RunClient(int port)
        {
            using (var runtime = new HalibutRuntime(ClientCertificate))
            {
                var calculator = runtime.CreateClient<ICalculatorService>("https://localhost:" + port + "/", "EF3A7A69AFE0D13130370B44A228F5CD15C069BC");

                for (int i = 0; i < RequestsPerClient; i++)
                {
                    var result = calculator.Add(12, 18);
                    Debug.Assert(result == 30);
                }
            }
        }
Example #16
0
        static void RunClient(int port)
        {
            using (var runtime = new HalibutRuntime(ClientCertificate))
            {
                var calculator = runtime.CreateClient <ICalculatorService>("https://localhost:" + port + "/", "EF3A7A69AFE0D13130370B44A228F5CD15C069BC");

                for (int i = 0; i < RequestsPerClient; i++)
                {
                    var result = calculator.Add(12, 18);
                    Debug.Assert(result == 30);
                }
            }
        }
Example #17
0
        public void FailWhenServerThrowsAnException()
        {
            using (var octopus = new HalibutRuntime(services, Certificates.Octopus))
                using (var tentacleListening = new HalibutRuntime(services, Certificates.TentacleListening))
                {
                    var tentaclePort = tentacleListening.Listen();
                    tentacleListening.Trust(Certificates.OctopusPublicThumbprint);

                    var echo = octopus.CreateClient <IEchoService>("https://localhost:" + tentaclePort, Certificates.TentacleListeningPublicThumbprint);
                    var ex   = Assert.Throws <HalibutClientException>(() => echo.Crash());
                    ex.Message.Should().Contain("at Halibut.Tests.TestServices.EchoService.Crash()").And.Contain("divide by zero");
                }
        }
Example #18
0
        public void FailWhenListeningServerPresentsWrongCertificate()
        {
            using (var octopus = new HalibutRuntime(services, Certificates.Octopus))
                using (var tentacleListening = new HalibutRuntime(services, Certificates.TentacleListening))
                {
                    var tentaclePort = tentacleListening.Listen();
                    tentacleListening.Trust(Certificates.OctopusPublicThumbprint);

                    var echo = octopus.CreateClient <IEchoService>("https://localhost:" + tentaclePort, Certificates.TentaclePollingPublicThumbprint);

                    var ex = Assert.Throws <HalibutClientException>(() => echo.SayHello("World"));
                }
        }
        public void FailWhenListeningServerPresentsWrongCertificate()
        {
            using (var octopus = new HalibutRuntime(services, Certificates.Octopus))
            using (var tentacleListening = new HalibutRuntime(services, Certificates.TentacleListening))
            {
                var tentaclePort = tentacleListening.Listen();
                tentacleListening.Trust(Certificates.OctopusPublicThumbprint);

                var echo = octopus.CreateClient<IEchoService>("https://localhost:" + tentaclePort, Certificates.TentaclePollingPublicThumbprint);

                var ex = Assert.Throws<HalibutClientException>(() => echo.SayHello("World"));
            }
        }
Example #20
0
 private void DeployPackageButtonClicked(object sender, EventArgs e)
 {
     Execute.Background(delegate
     {
         foreach (var tentacle in tentacles)
         {
             log.WriteLine("Checking health of: " + tentacle);
             var healthCheckService = serverHalibutRuntime.CreateClient <IHealthCheckService>(tentacle);
             var isOnline           = healthCheckService.IsOnline();
             log.WriteLine("Result: " + isOnline);
         }
     });
 }
Example #21
0
        protected override void ProcessRecord()
        {
            if (!string.IsNullOrEmpty(HostAddress))
            {
                using (var runtime = new HalibutRuntime(Configuration.ClientCertificate))
                {
                    var pairing = runtime.CreateClient <IPairingService>(Configuration.ClientEndpoint,
                                                                         Configuration.ServerCertificate.Thumbprint);

                    var host = new UniqueAddress(HostAddress);

                    pairing.Pair(pairing.DualShockDevices.First(d => d.Equals(Device)), host);
                }
            }
        }
Example #22
0
        public void FailWhenServerThrowsAnExceptionOnPolling()
        {
            using (var octopus = new HalibutRuntime(services, Certificates.Octopus))
                using (var tentaclePolling = new HalibutRuntime(services, Certificates.TentaclePolling))
                {
                    var octopusPort = octopus.Listen();
                    octopus.Trust(Certificates.TentaclePollingPublicThumbprint);

                    tentaclePolling.Poll(new Uri("poll://SQ-TENTAPOLL"), new ServiceEndPoint(new Uri("https://localhost:" + octopusPort), Certificates.OctopusPublicThumbprint));

                    var echo = octopus.CreateClient <IEchoService>("poll://SQ-TENTAPOLL", Certificates.TentaclePollingPublicThumbprint);
                    var ex   = Assert.Throws <HalibutClientException>(() => echo.Crash());
                    ex.Message.Should().Contain("at Halibut.Tests.TestServices.EchoService.Crash()").And.Contain("divide by zero");
                }
        }
Example #23
0
        public void FailOnInvalidPort()
        {
            var services = GetStubDelegateServiceFactory();

            using (var octopus = new HalibutRuntime(services, Certificates.Octopus))
            {
                var endpoint = new ServiceEndPoint("https://google.com:88", Certificates.TentacleListeningPublicThumbprint)
                {
                    TcpClientConnectTimeout = TimeSpan.FromSeconds(2),
                    RetryCountLimit         = 2
                };
                var echo = octopus.CreateClient <IEchoService>(endpoint);
                var ex   = Assert.Throws <HalibutClientException>(() => echo.Crash());
                ex.Message.Should().Be("An error occurred when sending a request to 'https://google.com:88/', before the request could begin: The client was unable to establish the initial connection within 00:00:02.");
            }
        }
Example #24
0
        public void FailsWhenSendingToPollingMachineButNothingPicksItUp()
        {
            var services = GetStubDelegateServiceFactory();

            using (var octopus = new HalibutRuntime(services, Certificates.Octopus))
            {
                var endpoint = new ServiceEndPoint("poll://SQ-TENTAPOLL", Certificates.TentaclePollingPublicThumbprint)
                {
                    TcpClientConnectTimeout    = TimeSpan.FromSeconds(1),
                    PollingRequestQueueTimeout = TimeSpan.FromSeconds(5)
                };
                var echo  = octopus.CreateClient <IEchoService>(endpoint);
                var error = Assert.Throws <HalibutClientException>(() => echo.SayHello("Paul"));
                error.Message.Should().Contain("the polling endpoint did not collect the request within the allowed time");
            }
        }
Example #25
0
        public static void Main(string[] args)
        {
            Log.Logger = new LoggerConfiguration()
                         .WriteTo.ColoredConsole()
                         .CreateLogger();

            Console.Title = "Halibut Client";
            var certificate = new X509Certificate2("HalibutClient.pfx");

            var hostName = args.FirstOrDefault() ?? "localhost";
            var port     = args.Skip(1).FirstOrDefault() ?? "8433";

            using (var runtime = new HalibutRuntime(certificate))
            {
                //Begin make request of Listening server
                //var calculator = runtime.CreateClient<ICalculatorService>("https://" + hostName + ":" + port + "/", "EF3A7A69AFE0D13130370B44A228F5CD15C069BC");
                //End make request of Listening server

                //Begin make request of Polling server
                //var endPoint = new IPEndPoint(IPAddress.IPv6Any, 8433);
                //runtime.Listen(endPoint);
                //runtime.Trust("EF3A7A69AFE0D13130370B44A228F5CD15C069BC");
                //var calculator = runtime.CreateClient<ICalculatorService>("poll://SQ-TENTAPOLL", "2074529C99D93D5955FEECA859AEAC6092741205");
                //End make request of Polling server

                //Begin make request of WebSocket Polling server
                AddSslCertToLocalStoreAndRegisterFor("0.0.0.0:8433");
                runtime.ListenWebSocket("https://+:8433/Halibut");
                runtime.Trust("EF3A7A69AFE0D13130370B44A228F5CD15C069BC");
                var calculator = runtime.CreateClient <ICalculatorService>("poll://SQ-TENTAPOLL", "2074529C99D93D5955FEECA859AEAC6092741205");
                //End make request of WebSocket Polling server

                while (true)
                {
                    try
                    {
                        var result = calculator.Add(12, 18);
                        Console.WriteLine("12 + 18 = " + result);
                        Console.ReadKey();
                    }
                    catch (Exception ex)
                    {
                        Console.Write(ex.Message);
                    }
                }
            }
        }
Example #26
0
        public void OctopusCanSendMessagesToPollingTentacle()
        {
            using (var octopus = new HalibutRuntime(services, Certificates.Octopus))
            using (var tentaclePolling = new HalibutRuntime(services, Certificates.TentaclePolling))
            {
                var octopusPort = octopus.Listen();
                octopus.Trust(Certificates.TentaclePollingPublicThumbprint);

                tentaclePolling.Poll(new Uri("poll://SQ-TENTAPOLL"), new ServiceEndPoint(new Uri("https://localhost:" + octopusPort), Certificates.OctopusPublicThumbprint));

                var echo = octopus.CreateClient<IEchoService>("poll://SQ-TENTAPOLL", Certificates.TentaclePollingPublicThumbprint);
                for (var i = 0; i < 2000; i++)
                {
                    Assert.That(echo.SayHello("Deploy package A" + i), Is.EqualTo("Deploy package A" + i + "..."));
                }
            }
        }
Example #27
0
        public void OctopusCanSendMessagesToPollingTentacle()
        {
            using (var octopus = new HalibutRuntime(services, Certificates.Octopus))
                using (var tentaclePolling = new HalibutRuntime(services, Certificates.TentaclePolling))
                {
                    var octopusPort = octopus.Listen();
                    octopus.Trust(Certificates.TentaclePollingPublicThumbprint);

                    tentaclePolling.Poll(new Uri("poll://SQ-TENTAPOLL"), new ServiceEndPoint(new Uri("https://localhost:" + octopusPort), Certificates.OctopusPublicThumbprint));

                    var echo = octopus.CreateClient <IEchoService>("poll://SQ-TENTAPOLL", Certificates.TentaclePollingPublicThumbprint);
                    for (var i = 0; i < 2000; i++)
                    {
                        Assert.That(echo.SayHello("Deploy package A" + i), Is.EqualTo("Deploy package A" + i + "..."));
                    }
                }
        }
Example #28
0
        public void OctopusCanSendMessagesToListeningTentacle()
        {
            using (var octopus = new HalibutRuntime(services, Certificates.Octopus))
                using (var tentacleListening = new HalibutRuntime(services, Certificates.TentacleListening))
                {
                    var tentaclePort = tentacleListening.Listen();
                    tentacleListening.Trust(Certificates.OctopusPublicThumbprint);

                    var echo = octopus.CreateClient <IEchoService>("https://localhost:" + tentaclePort, Certificates.TentacleListeningPublicThumbprint);
                    Assert.That(echo.SayHello("Deploy package A"), Is.EqualTo("Deploy package A..."));
                    var watch = Stopwatch.StartNew();
                    for (var i = 0; i < 2000; i++)
                    {
                        Assert.That(echo.SayHello("Deploy package A"), Is.EqualTo("Deploy package A..."));
                    }

                    Console.WriteLine("Complete in {0:n0}ms", watch.ElapsedMilliseconds);
                }
        }
Example #29
0
        public void OctopusCanSendMessagesToListeningTentacle()
        {
            using (var octopus = new HalibutRuntime(services, Certificates.Octopus))
            using (var tentacleListening = new HalibutRuntime(services, Certificates.TentacleListening))
            {
                var tentaclePort = tentacleListening.Listen();
                tentacleListening.Trust(Certificates.OctopusPublicThumbprint);

                var echo = octopus.CreateClient<IEchoService>("https://localhost:" + tentaclePort, Certificates.TentacleListeningPublicThumbprint);
                Assert.That(echo.SayHello("Deploy package A"), Is.EqualTo("Deploy package A..."));
                var watch = Stopwatch.StartNew();
                for (var i = 0; i < 2000; i++)
                {
                    Assert.That(echo.SayHello("Deploy package A"), Is.EqualTo("Deploy package A..."));
                }

                Console.WriteLine("Complete in {0:n0}ms", watch.ElapsedMilliseconds);
            }
        }
Example #30
0
        public void StreamsCanBeSentToListening()
        {
            using (var octopus = new HalibutRuntime(services, Certificates.Octopus))
                using (var tentacleListening = new HalibutRuntime(services, Certificates.TentacleListening))
                {
                    var tentaclePort = tentacleListening.Listen();
                    tentacleListening.Trust(Certificates.OctopusPublicThumbprint);

                    var data = new byte[1024 * 1024 + 15];
                    new Random().NextBytes(data);

                    var echo = octopus.CreateClient <IEchoService>("https://localhost:" + tentaclePort, Certificates.TentacleListeningPublicThumbprint);

                    for (var i = 0; i < 100; i++)
                    {
                        var count = echo.CountBytes(DataStream.FromBytes(data));
                        Assert.That(count, Is.EqualTo(1024 * 1024 + 15));
                    }
                }
        }
Example #31
0
        static void RunWebSocketPollingClient(HalibutRuntime server, X509Certificate2 clientCertificate, string remoteThumbprint, string trustedCertificate, bool expectSuccess = true)
        {
            using (var runtime = new HalibutRuntime(clientCertificate))
            {
                runtime.ListenWebSocket("https://+:8434/Halibut");
                runtime.Trust(trustedCertificate);

                var serverEndpoint = new ServiceEndPoint(new Uri("wss://localhost:8434/Halibut"), Certificates.SslThumbprint)
                {
                    TcpClientConnectTimeout = TimeSpan.FromSeconds(5)
                };
                server.Poll(new Uri("poll://SQ-WEBSOCKETPOLL"), serverEndpoint);

                var clientEndpoint = new ServiceEndPoint("poll://SQ-WEBSOCKETPOLL", remoteThumbprint);
                var calculator     = runtime.CreateClient <ICalculatorService>(clientEndpoint);

                MakeRequest(calculator, "websocket polling", expectSuccess);

                runtime.Disconnect(clientEndpoint);
            }
        }
Example #32
0
        public void StreamsCanBeSentToPolling()
        {
            using (var octopus = new HalibutRuntime(services, Certificates.Octopus))
                using (var tentaclePolling = new HalibutRuntime(services, Certificates.TentaclePolling))
                {
                    var octopusPort = octopus.Listen();
                    octopus.Trust(Certificates.TentaclePollingPublicThumbprint);

                    tentaclePolling.Poll(new Uri("poll://SQ-TENTAPOLL"), new ServiceEndPoint(new Uri("https://localhost:" + octopusPort), Certificates.OctopusPublicThumbprint));

                    var echo = octopus.CreateClient <IEchoService>("poll://SQ-TENTAPOLL", Certificates.TentaclePollingPublicThumbprint);

                    var data = new byte[1024 * 1024 + 15];
                    new Random().NextBytes(data);

                    for (var i = 0; i < 100; i++)
                    {
                        var count = echo.CountBytes(DataStream.FromBytes(data));
                        count.Should().Be(1024 * 1024 + 15);
                    }
                }
        }
Example #33
0
        public void StreamsCanBeSentToListeningWithProgressReporting()
        {
            using (var octopus = new HalibutRuntime(services, Certificates.Octopus))
                using (var tentacleListening = new HalibutRuntime(services, Certificates.TentacleListening))
                {
                    var tentaclePort = tentacleListening.Listen();
                    tentacleListening.Trust(Certificates.OctopusPublicThumbprint);

                    var progressReported = new List <int>();

                    var data = new byte[1024 * 1024 * 16 + 15];
                    new Random().NextBytes(data);
                    var stream = new MemoryStream(data);

                    var echo = octopus.CreateClient <IEchoService>("https://localhost:" + tentaclePort, Certificates.TentacleListeningPublicThumbprint);

                    var count = echo.CountBytes(DataStream.FromStream(stream, progressReported.Add));
                    Assert.That(count, Is.EqualTo(1024 * 1024 * 16 + 15));

                    CollectionAssert.AreEqual(Enumerable.Range(1, 100).ToList(), progressReported);
                }
        }
Example #34
0
        public void SupportsDifferentServiceContractMethods()
        {
            var services = GetDelegateServiceFactory();

            services.Register <ISupportedServices>(() => new SupportedServices());
            using (var octopus = new HalibutRuntime(Certificates.Octopus))
                using (var tentacleListening = new HalibutRuntime(services, Certificates.TentacleListening))
                {
                    tentacleListening.Trust(Certificates.OctopusPublicThumbprint);
                    var tentaclePort = tentacleListening.Listen();

                    var echo = octopus.CreateClient <ISupportedServices>("https://localhost:" + tentaclePort, Certificates.TentacleListeningPublicThumbprint);
                    echo.MethodReturningVoid(12, 14);

                    echo.Hello().Should().Be("Hello");
                    echo.Hello("a").Should().Be("Hello a");
                    echo.Hello("a", "b").Should().Be("Hello a b");
                    echo.Hello("a", "b", "c").Should().Be("Hello a b c");
                    echo.Hello("a", "b", "c", "d").Should().Be("Hello a b c d");
                    echo.Hello("a", "b", "c", "d", "e").Should().Be("Hello a b c d e");
                    echo.Hello("a", "b", "c", "d", "e", "f").Should().Be("Hello a b c d e f");
                    echo.Hello("a", "b", "c", "d", "e", "f", "g").Should().Be("Hello a b c d e f g");
                    echo.Hello("a", "b", "c", "d", "e", "f", "g", "h").Should().Be("Hello a b c d e f g h");
                    echo.Hello("a", "b", "c", "d", "e", "f", "g", "h", "i").Should().Be("Hello a b c d e f g h i");
                    echo.Hello("a", "b", "c", "d", "e", "f", "g", "h", "i", "j").Should().Be("Hello a b c d e f g h i j");
                    echo.Hello("a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k").Should().Be("Hello a b c d e f g h i j k");

                    echo.Add(1, 2).Should().Be(3);
                    echo.Add(1.00, 2.00).Should().Be(3.00);
                    echo.Add(1.10M, 2.10M).Should().Be(3.20M);

                    echo.Ambiguous("a", "b").Should().Be("Hello string");
                    echo.Ambiguous("a", new Tuple <string, string>("a", "b")).Should().Be("Hello tuple");

                    var ex = Assert.Throws <HalibutClientException>(() => echo.Ambiguous("a", (string)null));
                    ex.Message.Should().Contain("Ambiguous");
                }
        }
Example #35
0
        static void RunPollingClient(HalibutRuntime server, X509Certificate2 clientCertificate, string remoteThumbprint, bool expectSuccess = true)
        {
            using (var runtime = new HalibutRuntime(clientCertificate))
            {
                runtime.Listen(new IPEndPoint(IPAddress.IPv6Any, 8433));
                runtime.Trust(Certificates.OctopusPublicThumbprint);

                //setup polling
                var serverEndpoint = new ServiceEndPoint(new Uri("https://localhost:8433"), Certificates.TentaclePollingPublicThumbprint)
                {
                    TcpClientConnectTimeout = TimeSpan.FromSeconds(5)
                };
                server.Poll(new Uri("poll://SQ-TENTAPOLL"), serverEndpoint);

                var clientEndpoint = new ServiceEndPoint("poll://SQ-TENTAPOLL", remoteThumbprint);

                var calculator = runtime.CreateClient <ICalculatorService>(clientEndpoint);

                MakeRequest(calculator, "polling", expectSuccess);

                runtime.Disconnect(clientEndpoint);
            }
        }
Example #36
0
        static void Main(string[] args)
        {
            Log.Logger = new LoggerConfiguration()
                         .WriteTo.ColoredConsole()
                         .CreateLogger();

            var services = new DelegateServiceFactory();

            services.Register <ICalculatorService>(() => new CalculatorService());

            using (var client = new HalibutRuntime(services, ClientCertificate))
                using (var server = new HalibutRuntime(services, ServerCertificate))
                {
                    var octopusPort = client.Listen();
                    client.Trust(ServerCertificate.Thumbprint);

                    server.Poll(new Uri(PollUrl), new ServiceEndPoint(new Uri("https://localhost:" + octopusPort), ClientCertificate.Thumbprint));

                    var calculator = client.CreateClient <ICalculatorService>(PollUrl, ServerCertificate.Thumbprint);
                    var result     = calculator.Add(12, 18);
                    Debug.Assert(result == 30);
                }
            Console.ReadKey();
        }
Example #37
0
        public void StreamsCanBeSentToListeningWithProgressReporting()
        {
            var services = GetDelegateServiceFactory();

            using (var octopus = new HalibutRuntime(services, Certificates.Octopus))
                using (var tentacleListening = new HalibutRuntime(services, Certificates.TentacleListening))
                {
                    var tentaclePort = tentacleListening.Listen();
                    tentacleListening.Trust(Certificates.OctopusPublicThumbprint);

                    var progressReported = new List <int>();

                    var data = new byte[1024 * 1024 * 16 + 15];
                    new Random().NextBytes(data);
                    var stream = new MemoryStream(data);

                    var echo = octopus.CreateClient <IEchoService>("https://localhost:" + tentaclePort, Certificates.TentacleListeningPublicThumbprint);

                    var count = echo.CountBytes(DataStream.FromStream(stream, progressReported.Add));
                    count.Should().Be(1024 * 1024 * 16 + 15);

                    progressReported.Should().ContainInOrder(Enumerable.Range(1, 100));
                }
        }
        public void FailWhenServerThrowsAnExceptionOnPolling()
        {
            using (var octopus = new HalibutRuntime(services, Certificates.Octopus))
            using (var tentaclePolling = new HalibutRuntime(services, Certificates.TentaclePolling))
            {
                var octopusPort = octopus.Listen();
                octopus.Trust(Certificates.TentaclePollingPublicThumbprint);

                tentaclePolling.Poll(new Uri("poll://SQ-TENTAPOLL"), new ServiceEndPoint(new Uri("https://localhost:" + octopusPort), Certificates.OctopusPublicThumbprint));

                var echo = octopus.CreateClient<IEchoService>("poll://SQ-TENTAPOLL", Certificates.TentaclePollingPublicThumbprint);
                var ex = Assert.Throws<HalibutClientException>(() => echo.Crash());
                Assert.That(ex.Message, Does.Contain("at Halibut.Tests.TestServices.EchoService.Crash()").And.Contains("divide by zero"));
            }
        }
        public void FailWhenServerThrowsAnException()
        {
            using (var octopus = new HalibutRuntime(services, Certificates.Octopus))
            using (var tentacleListening = new HalibutRuntime(services, Certificates.TentacleListening))
            {
                var tentaclePort = tentacleListening.Listen();
                tentacleListening.Trust(Certificates.OctopusPublicThumbprint);

                var echo = octopus.CreateClient<IEchoService>("https://localhost:" + tentaclePort, Certificates.TentacleListeningPublicThumbprint);
                var ex = Assert.Throws<HalibutClientException>(() => echo.Crash());
                Assert.That(ex.Message, Is.StringContaining("at Halibut.Tests.TestServices.EchoService.Crash()").And.StringContaining("divide by zero"));
            }
        }
Example #40
0
        public void StreamsCanBeSentToListeningWithProgressReporting()
        {
            using (var octopus = new HalibutRuntime(services, Certificates.Octopus))
            using (var tentacleListening = new HalibutRuntime(services, Certificates.TentacleListening))
            {
                var tentaclePort = tentacleListening.Listen();
                tentacleListening.Trust(Certificates.OctopusPublicThumbprint);

                var progressReported = new List<int>();

                var data = new byte[1024 * 1024 * 16 + 15];
                new Random().NextBytes(data);
                var stream = new MemoryStream(data);

                var echo = octopus.CreateClient<IEchoService>("https://localhost:" + tentaclePort, Certificates.TentacleListeningPublicThumbprint);

                var count = echo.CountBytes(DataStream.FromStream(stream, progressReported.Add));
                Assert.That(count, Is.EqualTo(1024 * 1024 * 16 + 15));

                CollectionAssert.AreEqual(Enumerable.Range(1, 100).ToList(), progressReported);
            }
        }
Example #41
0
        public void SupportsDifferentServiceContractMethods()
        {
            services.Register<ISupportedServices>(() => new SupportedServices());
            using (var octopus = new HalibutRuntime(Certificates.Octopus))
            using (var tentacleListening = new HalibutRuntime(services, Certificates.TentacleListening))
            {
                tentacleListening.Trust(Certificates.OctopusPublicThumbprint);
                var tentaclePort = tentacleListening.Listen();

                var echo = octopus.CreateClient<ISupportedServices>("https://localhost:" + tentaclePort, Certificates.TentacleListeningPublicThumbprint);
                echo.MethodReturningVoid(12, 14);

                Assert.That(echo.Hello(), Is.EqualTo("Hello"));
                Assert.That(echo.Hello("a"), Is.EqualTo("Hello a"));
                Assert.That(echo.Hello("a", "b"), Is.EqualTo("Hello a b"));
                Assert.That(echo.Hello("a", "b", "c"), Is.EqualTo("Hello a b c"));
                Assert.That(echo.Hello("a", "b", "c", "d"), Is.EqualTo("Hello a b c d"));
                Assert.That(echo.Hello("a", "b", "c", "d", "e"), Is.EqualTo("Hello a b c d e"));
                Assert.That(echo.Hello("a", "b", "c", "d", "e", "f"), Is.EqualTo("Hello a b c d e f"));
                Assert.That(echo.Hello("a", "b", "c", "d", "e", "f", "g"), Is.EqualTo("Hello a b c d e f g"));
                Assert.That(echo.Hello("a", "b", "c", "d", "e", "f", "g", "h"), Is.EqualTo("Hello a b c d e f g h"));
                Assert.That(echo.Hello("a", "b", "c", "d", "e", "f", "g", "h", "i"), Is.EqualTo("Hello a b c d e f g h i"));
                Assert.That(echo.Hello("a", "b", "c", "d", "e", "f", "g", "h", "i", "j"), Is.EqualTo("Hello a b c d e f g h i j"));
                Assert.That(echo.Hello("a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k"), Is.EqualTo("Hello a b c d e f g h i j k"));

                Assert.That(echo.Add(1, 2), Is.EqualTo(3));
                Assert.That(echo.Add(1.00, 2.00), Is.EqualTo(3.00));
                Assert.That(echo.Add(1.10M, 2.10M), Is.EqualTo(3.20M));

                Assert.That(echo.Ambiguous("a", "b"), Is.EqualTo("Hello string"));
                Assert.That(echo.Ambiguous("a", new Tuple<string, string>("a", "b")), Is.EqualTo("Hello tuple"));

                var ex = Assert.Throws<HalibutClientException>(() => echo.Ambiguous("a", (string)null));
                Assert.That(ex.Message, Is.StringContaining("Ambiguous"));
            }
        }
Example #42
0
        public void StreamsCanBeSentToListening()
        {
            using (var octopus = new HalibutRuntime(services, Certificates.Octopus))
            using (var tentacleListening = new HalibutRuntime(services, Certificates.TentacleListening))
            {
                var tentaclePort = tentacleListening.Listen();
                tentacleListening.Trust(Certificates.OctopusPublicThumbprint);

                var data = new byte[1024 * 1024 + 15];
                new Random().NextBytes(data);

                var echo = octopus.CreateClient<IEchoService>("https://localhost:" + tentaclePort, Certificates.TentacleListeningPublicThumbprint);

                for (var i = 0; i < 100; i++)
                {
                    var count = echo.CountBytes(DataStream.FromBytes(data));
                    Assert.That(count, Is.EqualTo(1024 * 1024 + 15));
                }
            }
        }