public static void WorksWith <TEndPoint, TListener, TClient>(TEndPoint endPoint) where TListener : IListener <TClient>, IBindable <TListener, TEndPoint>, IHandle, IDisposable, new() where TClient : IUVStream <ArraySegment <byte> >, IConnectable <TClient, TEndPoint>, IHandle, IDisposable, new() { var server = new TListener(); server.Unref(); server.Bind(endPoint); server.Listen(); server.Connection += () => server.Accept().Shutdown(); int callbacks = 0; var failClient = new TClient(); Timeout.In <TEndPoint>(TimeSpan.FromTicks(1), failClient.Connect)(endPoint, (exception) => { Assert.IsType <TimeoutException>(exception); failClient.Dispose(); callbacks++; }); var successClient = new TClient(); Timeout.In <TEndPoint>(TimeSpan.FromMilliseconds(100), successClient.Connect)(endPoint, (exception) => { Assert.Equal <Exception>(null, exception); successClient.Dispose(); callbacks++; }); Loop.Default.Run(); server.Dispose(); Assert.Equal <int>(2, callbacks); }
public void Timeout_is_expired_after_expected_time(int milliseconds) { var timeout = Timeout.In(TimeSpan.FromMilliseconds(milliseconds)); Thread.Sleep(milliseconds + 1); Assert.True(timeout.IsExpired); }
public void Timeout_does_not_expires_before_time(int milliseconds) { var timeout = Timeout.In(TimeSpan.FromMilliseconds(milliseconds)); Thread.Sleep(milliseconds - 10); Assert.False(timeout.IsExpired); }
public AggregateCommand(Stream stream, object command, TimeSpan timeout) { Argument.RequiresNotNull(stream, nameof(stream)); Argument.RequiresNotNull(command, nameof(command)); this.CommandID = Guid.NewGuid(); this.Stream = stream; this.Command = command; this.Timeout = Timeout.In(timeout); }
public void Handles_queries() { var proj = CreateAndInitializeTestProjection(); var q = new TestQuery(); Sys.EventStream.Publish(new Query <TestQuery>(CreateTestProbe(), q, Timeout.In(1000))); ExpectMsg <TestQuery>(o => o == q); }
public void Does_not_handle_expired_queries() { var proj = CreateAndInitializeTestProjection(); // create an event to expire in 10 ms var q = new Query <TestQuery>(CreateTestProbe(), new TestQuery(), Timeout.In(10)); // forces the projection to sleep for 100 ms proj.Tell(100); // publish the expired event Sys.EventStream.Publish(q); ExpectMsg <string>(s => s == "expired"); }
public static Task ConnectAsync <TType, TEndPoint>(this IConnectable <TType, TEndPoint> client, TEndPoint endPoint, TimeSpan timeout) { return(HelperFunctions.Wrap(endPoint, Timeout.In <TEndPoint>(timeout, client.Connect))); }
public static Task ConnectAsync <TType>(this IConnectable <TType, IPEndPoint> client, string address, int port, TimeSpan timeout) { return(HelperFunctions.Wrap(address, port, Timeout.In <string, int>(timeout, client.Connect))); }