public async Task Create(bool verifyResponse) { int port = verifyResponse ? 40905 : 40904; TestMqServer server = new TestMqServer(); server.Initialize(port); server.Start(); TmqClient client = new TmqClient(); client.Connect("tmq://localhost:" + port); TmqResponseCode created = await client.CreateQueue("ch-2", MessageA.ContentType, verifyResponse); Assert.Equal(TmqResponseCode.Ok, created); await Task.Delay(1000); Channel channel = server.Server.Channels.FirstOrDefault(x => x.Name == "ch-2"); Assert.NotNull(channel); ChannelQueue queue = channel.Queues.FirstOrDefault(); Assert.NotNull(queue); Assert.Equal(MessageA.ContentType, queue.Id); }
public async Task LeaveChannel() { TestMqServer server = new TestMqServer(); server.Initialize(41203); server.Start(); TmqClient client = new TmqClient(); client.Connect("tmq://localhost:41203"); TmqResponseCode joined = await client.Join("ch-1", true); Assert.Equal(TmqResponseCode.Ok, joined); TmqResponseCode left = await client.Leave("ch-1", false); Assert.Equal(TmqResponseCode.Ok, left); await Task.Delay(1000); Channel channel = server.Server.Channels.FirstOrDefault(); Assert.NotNull(channel); List <ChannelClient> clients = channel.ClientsClone; Assert.Empty(clients); }
public async Task Create(bool verifyResponse) { int port = verifyResponse ? 35905 : 35904; TestMqServer server = new TestMqServer(); server.Initialize(port); server.Start(); TmqClient client = new TmqClient(); client.Connect("tmq://localhost:" + port); TmqResponseCode created = await client.CreateChannel("new-channel", verifyResponse); if (verifyResponse) { Assert.Equal(TmqResponseCode.Ok, created); } else { await Task.Delay(1000); Assert.Equal(TmqResponseCode.Ok, created); } }
public async Task ConnectDisconnectStress(int concurrentClients, int connectionCount, int minAliveMs, int maxAliveMs) { Random rnd = new Random(); int connected = 0; int disconnected = 0; int port = 42110 + rnd.Next(0, 89); TestMqServer server = new TestMqServer(); server.Initialize(port); server.Start(); for (int i = 0; i < concurrentClients; i++) { Thread thread = new Thread(async() => { for (int j = 0; j < connectionCount; j++) { try { TmqClient client = new TmqClient(); client.Connect("tmq://localhost:" + port); Assert.True(client.IsConnected); Interlocked.Increment(ref connected); await Task.Delay(rnd.Next(minAliveMs, maxAliveMs)); client.Disconnect(); Interlocked.Increment(ref disconnected); await Task.Delay(50); Assert.True(client.IsConnected); } catch { } } }); thread.Start(); } TimeSpan total = TimeSpan.FromMilliseconds(maxAliveMs * connectionCount); TimeSpan elapsed = TimeSpan.Zero; while (elapsed < total) { elapsed += TimeSpan.FromMilliseconds(100); await Task.Delay(100); } await Task.Delay(maxAliveMs); await Task.Delay(3000); Assert.Equal(connected, concurrentClients * connectionCount); Assert.Equal(disconnected, concurrentClients * connectionCount); }
public void ConnectWithInfo() { TestMqServer server = new TestMqServer(); server.Initialize(42101); server.Start(); TmqClient client = new TmqClient(); client.Data.Properties.Add("Name", "Test-42101"); client.Connect("tmq://localhost:42101/path"); Thread.Sleep(50); Assert.True(client.IsConnected); Assert.Equal(1, server.ClientConnected); }
public void KeepAliveWithPingPong() { TestMqServer server = new TestMqServer(); server.Initialize(42104); server.Start(); TmqClient client = new TmqClient(); client.Data.Properties.Add("Name", "Test-42104"); client.Connect("tmq://localhost:42104/path"); Thread.Sleep(25000); Assert.True(client.IsConnected); Assert.Equal(1, server.ClientConnected); }
static void Main(string[] args) { TwinoServer server = new TwinoServer(ServerOptions.CreateDefault()); server.UseTmq(async(socket, msg) => { Console.WriteLine(msg); await Task.CompletedTask; }); server.Start(82); TmqClient client = new TmqClient(); client.Data.Properties.Add("Host", "localhost"); client.ClientId = "123"; client.Connect("tmq://localhost:82/sample"); Console.ReadLine(); }
public async Task JoinChannelWithResponse() { TestMqServer server = new TestMqServer(); server.Initialize(41202); server.Start(); TmqClient client = new TmqClient(); client.Connect("tmq://localhost:41202"); TmqResponseCode joined = await client.Join("ch-1", true); Assert.Equal(TmqResponseCode.Ok, joined); Channel channel = server.Server.Channels.FirstOrDefault(); Assert.NotNull(channel); List <ChannelClient> clients = channel.ClientsClone; Assert.Single(clients); }