public void Parse_InvalidUris() { Assert.Null(EpoxyTransport.Parse(null, LoggerTests.BlackHole)); Assert.Null(EpoxyTransport.Parse(string.Empty, LoggerTests.BlackHole)); Assert.Null(EpoxyTransport.Parse("127.0.0.1", LoggerTests.BlackHole)); Assert.Null(EpoxyTransport.Parse("cows", LoggerTests.BlackHole)); Assert.Null(EpoxyTransport.Parse(":12", LoggerTests.BlackHole)); Assert.Null(EpoxyTransport.Parse("epoxy://127.0.0.1:1000:1000", LoggerTests.BlackHole)); }
public async Task ListenOnPortZero_ActuallyListensOnSomeOtherPort() { EpoxyTransport transport = MakeTransport(); listener = transport.MakeListener(localhostEndpoint); await listener.StartAsync(); Assert.AreNotEqual(0, listener.ListenEndpoint.Port); }
public void Parse_AcceptableUris() { var endpoint = EpoxyTransport.Parse("epoxy://127.0.0.1", LoggerTests.BlackHole); Assert.NotNull(endpoint); Assert.AreEqual("127.0.0.1", endpoint.Value.Host); Assert.AreEqual(EpoxyTransport.DefaultInsecurePort, endpoint.Value.Port); Assert.False(endpoint.Value.UseTls); endpoint = EpoxyTransport.Parse("epoxy://127.0.0.1/", LoggerTests.BlackHole); Assert.NotNull(endpoint); Assert.AreEqual("127.0.0.1", endpoint.Value.Host); Assert.AreEqual(EpoxyTransport.DefaultInsecurePort, endpoint.Value.Port); Assert.False(endpoint.Value.UseTls); endpoint = EpoxyTransport.Parse("epoxy://127.0.0.1:10000", LoggerTests.BlackHole); Assert.NotNull(endpoint); Assert.AreEqual("127.0.0.1", endpoint.Value.Host); Assert.AreEqual(10000, endpoint.Value.Port); Assert.False(endpoint.Value.UseTls); endpoint = EpoxyTransport.Parse("epoxy://127.0.0.1:10000/", LoggerTests.BlackHole); Assert.NotNull(endpoint); Assert.AreEqual("127.0.0.1", endpoint.Value.Host); Assert.AreEqual(10000, endpoint.Value.Port); Assert.False(endpoint.Value.UseTls); endpoint = EpoxyTransport.Parse("epoxy://localhost", LoggerTests.BlackHole); Assert.NotNull(endpoint); Assert.AreEqual("localhost", endpoint.Value.Host); Assert.AreEqual(EpoxyTransport.DefaultInsecurePort, endpoint.Value.Port); Assert.False(endpoint.Value.UseTls); endpoint = EpoxyTransport.Parse("epoxy://localhost/", LoggerTests.BlackHole); Assert.NotNull(endpoint); Assert.AreEqual("localhost", endpoint.Value.Host); Assert.AreEqual(EpoxyTransport.DefaultInsecurePort, endpoint.Value.Port); Assert.False(endpoint.Value.UseTls); endpoint = EpoxyTransport.Parse("epoxy://localhost:10000", LoggerTests.BlackHole); Assert.NotNull(endpoint); Assert.AreEqual("localhost", endpoint.Value.Host); Assert.AreEqual(10000, endpoint.Value.Port); Assert.False(endpoint.Value.UseTls); endpoint = EpoxyTransport.Parse("epoxy://localhost:10000/", LoggerTests.BlackHole); Assert.NotNull(endpoint); Assert.AreEqual("localhost", endpoint.Value.Host); Assert.AreEqual(10000, endpoint.Value.Port); Assert.False(endpoint.Value.UseTls); }
public async Task StopAsync_ClosesAllOutstandingConnections() { EpoxyTransport transport = MakeTransport(); var listener = transport.MakeListener(localhostEndpoint); await listener.StartAsync(); var clientConnection = await transport.ConnectToAsync(localhostAddress); await listener.StopAsync(); Assert.Throws <InvalidOperationException>( async() => await clientConnection.RequestResponseAsync <Dummy, Dummy>( AnyServiceName, AnyMethodName, AnyMessage, CancellationToken.None)); }
public void Parse_EpoxysUris() { var endpoint = EpoxyTransport.Parse("epoxys://use-default-secure-port", LoggerTests.BlackHole); Assert.NotNull(endpoint); Assert.AreEqual("use-default-secure-port", endpoint.Value.Host); Assert.AreEqual(EpoxyTransport.DefaultSecurePort, endpoint.Value.Port); Assert.True(endpoint.Value.UseTls); endpoint = EpoxyTransport.Parse("epoxys://use-custom-port:10000/", LoggerTests.BlackHole); Assert.NotNull(endpoint); Assert.AreEqual("use-custom-port", endpoint.Value.Host); Assert.AreEqual(10000, endpoint.Value.Port); Assert.True(endpoint.Value.UseTls); }
public async Task OneConnectionStalledDuringHandshake_CanAcceptAnother() { EpoxyTransport transport = MakeTransport(); var listener = transport.MakeListener(localhostEndpoint); await listener.StartAsync(); var noHandshakeConnection = new TcpClient(); // This will just establish a TCP connection. It won't perform the Epoxy handshake, so // the listener will just be sitting there waiting for the client to send some data. await noHandshakeConnection.ConnectAsync(localhostEndpoint.Address, localhostEndpoint.Port); var connectTask = transport.ConnectToAsync(localhostAddress); bool didConnect = connectTask.Wait(TimeSpan.FromSeconds(10)); Assert.IsTrue(didConnect, "Timed out waiting for connection to be established."); }
static Task StartServiceListenersAsync(EpoxyTransport transport) { // On some systems, "localhost" resolves to an IPv4 address, while // on others it resolves to an IPv6 address. To make this work on // both kinds of systems, we create a listener for both loopback // addresses. var service = new SimpleService(); EpoxyListener listenerIpv4 = transport.MakeListener(serviceEndpointIpv4); listenerIpv4.AddService(service); EpoxyListener listenerIpv6 = transport.MakeListener(serviceEndpointIpv6); listenerIpv6.AddService(service); return(Task.WhenAll(listenerIpv4.StartAsync(), listenerIpv6.StartAsync())); }
public async Task ConnectedEvent_SetDisconnectError_DisconnectsConnection() { const int DisconnectErrorCode = 100; const string DisconnectMessage = "Go away!"; EpoxyTransport transport = MakeTransport(); listener = transport.MakeListener(localhostEndpoint); var connectedEventDone = new ManualResetEventSlim(initialState: false); listener.Connected += (sender, args) => { args.DisconnectError = new Error { error_code = DisconnectErrorCode, message = DisconnectMessage }; connectedEventDone.Set(); }; var disconnectedEventDone = new ManualResetEventSlim(initialState: false); listener.Disconnected += (sender, args) => { disconnectedEventDone.Set(); }; await listener.StartAsync(); try { await transport.ConnectToAsync(localhostAddress); Assert.Fail("Expected exception to be thrown."); } catch (EpoxyProtocolErrorException pex) { Assert.That(pex.Message, Is.StringContaining("rejected")); Assert.IsNotNull(pex.Details); var errorDetails = pex.Details.Deserialize(); Assert.AreEqual(DisconnectErrorCode, errorDetails.error_code); Assert.AreEqual(DisconnectMessage, errorDetails.message); } }
public void ParseStringAddress_ValidIpWithPort_ReturnsIpEndpoint() { var result = EpoxyTransport.ParseStringAddress(AnyIpAddressString + ":" + AnyPort); Assert.AreEqual(new IPEndPoint(AnyIpAddress, AnyPort), result); }
public void ParseStringAddress_ValidIpNoPort_ReturnsIpEndpoint() { var result = EpoxyTransport.ParseStringAddress(AnyIpAddressString); Assert.AreEqual(new IPEndPoint(AnyIpAddress, EpoxyTransport.DefaultPort), result); }
public void ParseStringAddress_NullOrEmpty_Throws() { Assert.Throws <ArgumentException>(() => EpoxyTransport.ParseStringAddress(null)); Assert.Throws <ArgumentException>(() => EpoxyTransport.ParseStringAddress(string.Empty)); }
private static void Shutdown(EpoxyTransport transport) { Task.WaitAll(transport.StopAsync(), pingConnection.StopAsync(), reverseConnection.StopAsync()); }
public void Parse_NoResourceBesidesRootOrParamsAllowed() { Assert.Null(EpoxyTransport.Parse("epoxy://127.0.0.1/cows", LoggerTests.BlackHole)); Assert.Null(EpoxyTransport.Parse("epoxy://127.0.0.1?cows=cows", LoggerTests.BlackHole)); }
public void Parse_SchemeMustBeEpoxyish() { Assert.Null(EpoxyTransport.Parse("http://127.0.0.1", LoggerTests.BlackHole)); }
public void ParseStringAddress_InvalidIpAddress_Throws() { Assert.Throws <ArgumentException>(() => EpoxyTransport.ParseStringAddress("not an ip")); Assert.Throws <ArgumentException>(() => EpoxyTransport.ParseStringAddress("not an ip:12345")); Assert.Throws <ArgumentException>(() => EpoxyTransport.ParseStringAddress("not an ip:no a port")); }
public void ParseStringAddress_InvalidPortAddress_Throws() { Assert.Throws <ArgumentException>(() => EpoxyTransport.ParseStringAddress("10.1.2.3:")); Assert.Throws <ArgumentException>(() => EpoxyTransport.ParseStringAddress("10.1.2.3::")); Assert.Throws <ArgumentException>(() => EpoxyTransport.ParseStringAddress("10.1.2.3:not a port")); }