-
Notifications
You must be signed in to change notification settings - Fork 750
/
Copy pathScatterGather.cs
71 lines (56 loc) · 2.02 KB
/
ScatterGather.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
using System.Threading;
using System.Threading.Tasks;
using NetMQ.Sockets;
using Xunit;
namespace NetMQ.Tests
{
public class ScatterGather
{
[Fact]
public void TestTcp()
{
using var scatter = new ScatterSocket();
using var gather = new GatherSocket();
int port = scatter.BindRandomPort("tcp://*");
gather.Connect($"tcp://127.0.0.1:{port}");
scatter.Send("1");
scatter.Send("2");
var m1 = gather.ReceiveString();
Assert.Equal("1", m1);
var m2 = gather.ReceiveString();
Assert.Equal("2", m2);
}
[Fact]
public void TestBlocking()
{
using var scatter = new ScatterSocket();
using var gather = new GatherSocket();
using var gather2 = new GatherSocket();
scatter.Bind("inproc://test-scatter-gather");
gather.Connect("inproc://test-scatter-gather");
gather2.Connect("inproc://test-scatter-gather");
scatter.Send("1");
scatter.Send("2");
var m1 = gather.ReceiveString();
Assert.Equal("1", m1);
var m2 = gather2.ReceiveString();
Assert.Equal("2", m2);
}
[Fact]
public async Task TestAsync()
{
using var scatter = new ScatterSocket();
using var gather = new GatherSocket();
using var gather2 = new GatherSocket();
scatter.Bind("inproc://test-scatter-gather");
gather.Connect("inproc://test-scatter-gather");
gather2.Connect("inproc://test-scatter-gather");
await scatter.SendAsync("1");
await scatter.SendAsync("2");
var m1 = await gather.ReceiveStringAsync();
Assert.Equal("1", m1);
var m2 = await gather2.ReceiveStringAsync();
Assert.Equal("2", m2);
}
}
}