Skip to content

Commit

Permalink
more readable specs
Browse files Browse the repository at this point in the history
  • Loading branch information
Horusiath committed Feb 26, 2017
1 parent 171807b commit ec41adb
Show file tree
Hide file tree
Showing 4 changed files with 124 additions and 66 deletions.
12 changes: 6 additions & 6 deletions src/core/Akka.Tests/IO/TcpIntegrationSpec.cs
Expand Up @@ -242,9 +242,9 @@ private void ChitChat(TestSetup.ConnectionDetail actors, int rounds = 100)
for (int i = 0; i < rounds; i++)
{
actors.ClientHandler.Send(actors.ClientConnection, Tcp.Write.Create(testData));
actors.ServerHandler.ExpectMsg<Tcp.Received>(x => x.Data.Count == 1 && x.Data.Head == 0, hint: $"matched at {i} round");
actors.ServerHandler.ExpectMsg<Tcp.Received>(x => x.Data.Count == 1 && x.Data.Head == 0, hint: $"server didn't received at {i} round");
actors.ServerHandler.Send(actors.ServerConnection, Tcp.Write.Create(testData));
actors.ClientHandler.ExpectMsg<Tcp.Received>(x => x.Data.Count == 1 && x.Data.Head == 0, hint: $"matched at {i} round");
actors.ClientHandler.ExpectMsg<Tcp.Received>(x => x.Data.Count == 1 && x.Data.Head == 0, hint: $"client didn't received at {i} round");
}
}

Expand All @@ -261,7 +261,7 @@ public TestSetup(AkkaSpec spec, bool shouldBindServer = true)
ConnectOptions = Enumerable.Empty<Inet.SocketOption>();
_spec = spec;
_shouldBindServer = shouldBindServer;
_bindHandler = _spec.CreateTestProbe();
_bindHandler = _spec.CreateTestProbe("bind-handler-probe");
_endpoint = TestUtils.TemporaryServerAddress();
}

Expand All @@ -274,14 +274,14 @@ public void BindServer()

public ConnectionDetail EstablishNewClientConnection()
{
var connectCommander = _spec.CreateTestProbe();
var connectCommander = _spec.CreateTestProbe("connect-commander-probe");
connectCommander.Send(_spec.Sys.Tcp(), new Tcp.Connect(_endpoint, options: ConnectOptions));
connectCommander.ExpectMsg<Tcp.Connected>();
var clientHandler = _spec.CreateTestProbe();
var clientHandler = _spec.CreateTestProbe("client-handler-probe");
connectCommander.Sender.Tell(new Tcp.Register(clientHandler.Ref));

_bindHandler.ExpectMsg<Tcp.Connected>();
var serverHandler = _spec.CreateTestProbe();
var serverHandler = _spec.CreateTestProbe("server-handler-probe");
_bindHandler.Sender.Tell(new Tcp.Register(serverHandler.Ref));

return new ConnectionDetail
Expand Down
5 changes: 3 additions & 2 deletions src/core/Akka.Tests/IO/UdpIntegrationSpec.cs
Expand Up @@ -14,21 +14,22 @@
using Akka.TestKit;
using Akka.Util.Internal;
using Xunit;
using Xunit.Abstractions;

namespace Akka.Tests.IO
{
public class UdpIntegrationSpec : AkkaSpec
{
private readonly IPEndPoint[] _addresses;

public UdpIntegrationSpec()
public UdpIntegrationSpec(ITestOutputHelper output)
: base(@"
akka.io.udp.max-channels = unlimited
akka.io.udp.nr-of-selectors = 1
akka.io.udp.direct-buffer-pool-limit = 100
akka.io.udp.direct-buffer-size = 1024
akka.loglevel = INFO
akka.actor.serialize-creators = on")
akka.actor.serialize-creators = on", output: output)
{
_addresses = TestUtils.TemporaryServerAddresses(6, udp: true).ToArray();
}
Expand Down
119 changes: 79 additions & 40 deletions src/core/Akka/IO/Tcp.cs
Expand Up @@ -58,14 +58,14 @@ public class Message : INoSerializationVerificationNeeded
/// <summary>
/// TBD
/// </summary>
public class Command : Message
public abstract class Command : Message
{
private readonly CommandFailed _failureMessage;

/// <summary>
/// TBD
/// </summary>
public Command()
protected Command()
{
_failureMessage = new CommandFailed(this);
}
Expand Down Expand Up @@ -111,23 +111,26 @@ public class Connect : Command
/// <summary>
/// TBD
/// </summary>
public EndPoint RemoteAddress { get; private set; }
public EndPoint RemoteAddress { get; }
/// <summary>
/// TBD
/// </summary>
public EndPoint LocalAddress { get; private set; }
public EndPoint LocalAddress { get; }
/// <summary>
/// TBD
/// </summary>
public IEnumerable<Inet.SocketOption> Options { get; private set; }
public IEnumerable<Inet.SocketOption> Options { get; }
/// <summary>
/// TBD
/// </summary>
public TimeSpan? Timeout { get; private set; }
public TimeSpan? Timeout { get; }
/// <summary>
/// TBD
/// </summary>
public bool PullMode { get; private set; }
public bool PullMode { get; }

public override string ToString() =>
$"Connect(remote: {RemoteAddress}, local: {LocalAddress}, timeout: {Timeout}, pullMode: {PullMode})";
}

/// <summary>
Expand Down Expand Up @@ -164,23 +167,26 @@ public class Bind : Command
/// <summary>
/// TBD
/// </summary>
public IActorRef Handler { get; set; }
public IActorRef Handler { get; }
/// <summary>
/// TBD
/// </summary>
public EndPoint LocalAddress { get; set; }
public EndPoint LocalAddress { get; }
/// <summary>
/// TBD
/// </summary>
public int Backlog { get; set; }
public int Backlog { get; }
/// <summary>
/// TBD
/// </summary>
public IEnumerable<Inet.SocketOption> Options { get; set; }
public IEnumerable<Inet.SocketOption> Options { get; }
/// <summary>
/// TBD
/// </summary>
public bool PullMode { get; set; }
public bool PullMode { get; }

public override string ToString() =>
$"Bind(addr: {LocalAddress}, handler: {Handler}, backlog: {Backlog}, pullMode: {PullMode})";
}

/// <summary>
Expand All @@ -207,15 +213,18 @@ public Register(IActorRef handler, bool keepOpenonPeerClosed = false, bool useRe
/// <summary>
/// TBD
/// </summary>
public IActorRef Handler { get; private set; }
public IActorRef Handler { get; }
/// <summary>
/// TBD
/// </summary>
public bool KeepOpenonPeerClosed { get; private set; }
public bool KeepOpenonPeerClosed { get; }
/// <summary>
/// TBD
/// </summary>
public bool UseResumeWriting { get; private set; }
public bool UseResumeWriting { get; }

public override string ToString() =>
$"Register(handler: {Handler}, keepOpenOnPeerClosed: {KeepOpenonPeerClosed}, resumeWriting: {UseResumeWriting})";
}

/// <summary>
Expand Down Expand Up @@ -349,7 +358,10 @@ public NoAck(object token)
/// <summary>
/// TBD
/// </summary>
public object Token { get; private set; }
public object Token { get; }

public override string ToString() =>
$"NoAck({Token})";
}

/// <summary>
Expand Down Expand Up @@ -450,11 +462,16 @@ public CompoundWrite Append(WriteCommand that)
/// </summary>
public class Write : SimpleWriteCommand
{
/// <summary>
/// TBD
/// </summary>
public static readonly Write Empty = new Write(ByteString.Empty, NoAck.Instance);

private readonly Event _ack;
/// <summary>
/// TBD
/// </summary>
public ByteString Data { get; private set; }
public ByteString Data { get; }

/// <summary>
/// TBD
Expand All @@ -470,6 +487,9 @@ private Write(ByteString data, Event ack)
Data = data;
}

public override string ToString() =>
$"Write(bytes: {Data.Count}, ack: {Ack})";

/// <summary>
/// TBD
/// </summary>
Expand All @@ -490,11 +510,6 @@ public static Write Create(ByteString data, Event ack)
{
return new Write(data, ack);
}

/// <summary>
/// TBD
/// </summary>
public static readonly Write Empty = new Write(ByteString.Empty, NoAck.Instance);
}

/// <summary>
Expand Down Expand Up @@ -533,15 +548,15 @@ public WriteFile(string filePath, long position, long count, Event ack)
/// <summary>
/// TBD
/// </summary>
public string FilePath { get; private set; }
public string FilePath { get; }
/// <summary>
/// TBD
/// </summary>
public long Position { get; private set; }
public long Position { get; }
/// <summary>
/// TBD
/// </summary>
public long Count { get; private set; }
public long Count { get; }

/// <summary>
/// TBD
Expand All @@ -550,6 +565,9 @@ public override Event Ack
{
get { return _ack; }
}

public override string ToString() =>
$"WriteFile(path: {FilePath}, position: {Position}, count: {Count}, ack: {Ack})";
}

/// <summary>
Expand Down Expand Up @@ -626,6 +644,9 @@ public WriteCommand TailCommand
{
get { return _tailCommand; }
}

public override string ToString() =>
$"CompoundWrite({Head}, {TailCommand})";
}

/// <summary>
Expand Down Expand Up @@ -685,7 +706,7 @@ public class ResumeAccepting : Command
/// <summary>
/// TBD
/// </summary>
public int BatchSize { get; private set; }
public int BatchSize { get; }

/// <summary>
/// TBD
Expand All @@ -695,6 +716,9 @@ public ResumeAccepting(int batchSize)
{
BatchSize = batchSize;
}

public override string ToString() =>
$"ResumeAccepting(batchSize: {BatchSize})";
}

// EVENTS
Expand Down Expand Up @@ -725,7 +749,10 @@ public Received(ByteString data)
/// <summary>
/// TBD
/// </summary>
public ByteString Data { get; private set; }
public ByteString Data { get; }

public override string ToString() =>
$"Received(bytes: {Data.Count})";
}

/// <summary>
Expand All @@ -750,11 +777,14 @@ public Connected(EndPoint remoteAddress, EndPoint localAddress)
/// <summary>
/// TBD
/// </summary>
public EndPoint RemoteAddress { get; private set; }
public EndPoint RemoteAddress { get; }
/// <summary>
/// TBD
/// </summary>
public EndPoint LocalAddress { get; private set; }
public EndPoint LocalAddress { get; }

public override string ToString() =>
$"Connected(local: {LocalAddress}, remote: {RemoteAddress})";
}

/// <summary>
Expand All @@ -775,7 +805,10 @@ public CommandFailed(Command cmd)
/// <summary>
/// TBD
/// </summary>
public Command Cmd { get; private set; }
public Command Cmd { get; }

public override string ToString() =>
$"CommandFailed({Cmd})";
}

/// <summary>
Expand Down Expand Up @@ -803,7 +836,7 @@ public class Bound : Event
/// <summary>
/// TBD
/// </summary>
public EndPoint LocalAddress { get; private set; }
public EndPoint LocalAddress { get; }

/// <summary>
/// TBD
Expand All @@ -813,6 +846,9 @@ public Bound(EndPoint localAddress)
{
LocalAddress = localAddress;
}

public override string ToString() =>
$"Bound({LocalAddress})";
}

/// <summary>
Expand Down Expand Up @@ -991,6 +1027,9 @@ public override string GetErrorCause()
{
return _cause;
}

public override string ToString() =>
$"ErrorClosed('{_cause}')";
}

private class ConnectionSupervisorStrategyImp : OneForOneStrategy
Expand Down Expand Up @@ -1057,41 +1096,41 @@ public TcpSettings(Config config)
/// <summary>
/// TBD
/// </summary>
public bool TraceLogging { get; private set; }
public bool TraceLogging { get; }

public int BatchAcceptLimit { get; private set; }
public int BatchAcceptLimit { get; }
/// <summary>
/// TBD
/// </summary>
public int DirectBufferSize { get; private set; }
public int DirectBufferSize { get; }
/// <summary>
/// TBD
/// </summary>
public int MaxDirectBufferPoolSize { get; private set; }
public int MaxDirectBufferPoolSize { get; }
/// <summary>
/// TBD
/// </summary>
public TimeSpan? RegisterTimeout { get; private set; }
public TimeSpan? RegisterTimeout { get; }
/// <summary>
/// TBD
/// </summary>
public int ReceivedMessageSizeLimit { get; private set; }
public int ReceivedMessageSizeLimit { get; }
/// <summary>
/// TBD
/// </summary>
public string ManagementDispatcher { get; private set; }
public string ManagementDispatcher { get; }
/// <summary>
/// TBD
/// </summary>
public string FileIODispatcher { get; private set; }
public string FileIODispatcher { get; }
/// <summary>
/// TBD
/// </summary>
public int TransferToLimit { get; set; }
/// <summary>
/// TBD
/// </summary>
public int FinishConnectRetries { get; private set; }
public int FinishConnectRetries { get; }
}

/// <summary>
Expand Down

0 comments on commit ec41adb

Please sign in to comment.