Esempio n. 1
0
        public async Task DelayedPublish()
        {
            var channel = GenerateRandomChannelName();

            var subClient = new RtmClientBuilder(Config.Endpoint, Config.AppKey).Build();
            await subClient.Yield();

            subClient.Start();
            var subData = new TestSubscriptionObserverQueue();

            subData.ObserveSubscriptionPdu();
            await subClient.CreateSubscriptionAndWaitSubscribed(channel, null, subData);

            var pubClient = new RtmClientBuilder(Config.Endpoint, Config.AppKey).Build();
            await pubClient.Yield();

            var noAckTask   = pubClient.Publish(channel, "no-ack", Ack.No);
            var withAckTask = pubClient.Publish(channel, "with-ack", Ack.Yes);
            await Task.Delay(100);

            Assert.That(noAckTask.Status, Is.EqualTo(TaskStatus.WaitingForActivation));
            Assert.That(withAckTask.Status, Is.EqualTo(TaskStatus.WaitingForActivation));

            pubClient.Start();
            await noAckTask.ConfigureAwait(false);

            await withAckTask.ConfigureAwait(false);

            Assert.That(await subData.Dequeue(), Is.EqualTo("rtm:subscription-data:no-ack"));
            Assert.That(await subData.Dequeue(), Is.EqualTo("rtm:subscription-data:with-ack"));

            await subClient.Dispose();

            await pubClient.Dispose();
        }
Esempio n. 2
0
        public async Task AutoResubscribe()
        {
            var channel = GenerateRandomChannelName();
            var client  = (RtmClient) new RtmClientBuilder(Config.Endpoint, Config.AppKey).Build();
            var queue   = client.CreateStateQueue();

            client.Start();
            Assert.That(await queue.Dequeue(), Is.EqualTo("leave-stopped"));
            Assert.That(await queue.Dequeue(), Is.EqualTo("enter-connecting"));
            Assert.That(await queue.Dequeue(), Is.EqualTo("leave-connecting"));
            Assert.That(await queue.Dequeue(), Is.EqualTo("enter-connected"));

            var subData = new TestSubscriptionObserverQueue();

            subData.ObserveSubscriptionPdu();
            await client.CreateSubscriptionAndWaitSubscribed(channel, null, subData).ConfigureAwait(false);

            await client.Publish(channel, "message-1", Ack.No).ConfigureAwait(false);

            await client.Yield();

            Assert.That(await subData.Dequeue(), Is.EqualTo("rtm:subscription-data:message-1"));

            var cn = await client.GetConnection();

            await cn.Close();

            Assert.That(await queue.Dequeue(), Is.EqualTo("leave-connected"));
            Assert.That(await queue.Dequeue(), Is.EqualTo("enter-awaiting"));
            Assert.That(await queue.Dequeue(), Is.EqualTo("leave-awaiting"));
            Assert.That(await queue.Dequeue(), Is.EqualTo("enter-connecting"));
            Assert.That(await queue.Dequeue(), Is.EqualTo("leave-connecting"));
            Assert.That(await queue.Dequeue(), Is.EqualTo("enter-connected"));
            await client.Publish(channel, "message-2", Ack.No).ConfigureAwait(false);

            await client.Yield();

            Assert.That(await subData.Dequeue(), Is.EqualTo("rtm:subscription-data:message-2"));
            await client.Dispose();

            Assert.That(await queue.Dequeue(), Is.EqualTo("leave-connected"));
            Assert.That(await queue.Dequeue(), Is.EqualTo("enter-disposed"));
            await Task.Delay(200);

            await client.Yield();

            Assert.That(queue.TryDequeue() == null);
            Assert.That(subData.TryDequeue() == null);
        }
        public async Task WriteNullShouldBeOk()
        {
            var channel = GenerateRandomChannelName();
            var client  = new RtmClientBuilder(Config.Endpoint, Config.AppKey).Build();

            client.Start();

            var queue = new TestSubscriptionObserverQueue();
            await client.CreateSubscriptionAndWaitSubscribed(channel, null, queue);

            await client.Yield();

            queue.ObserveSubscriptionState();
            queue.ObserveSubscriptionPdu();

            await client.Write(channel, (string)null, Ack.Yes);

            Assert.That(await queue.Dequeue(), Is.EqualTo("rtm:subscription-data:"));

            await Task.Delay(200);

            await client.Yield();

            Assert.That(queue.TryDequeue() == null);

            await client.Dispose();
        }
 public static async Task AssertDequeue(this TestSubscriptionObserverQueue queue, params string[] items)
 {
     foreach (var item in items)
     {
         Assert.That(await queue.Dequeue(), Is.EqualTo(item));
     }
 }
Esempio n. 5
0
        public async Task TwoSubscriptionsWithDifferentNames()
        {
            var client = new RtmClientBuilder(Config.Endpoint, Config.AppKey).Build();

            var channel = GenerateRandomChannelName();
            var subId1  = "s1_" + channel;
            var subId2  = "s2_" + channel;

            await client.StartAndWaitConnected();

            var subCfg = new SubscriptionConfig(SubscriptionModes.Advanced)
            {
                Filter = $"select * FROM `{channel}`"
            };

            var queue1 = new TestSubscriptionObserverQueue();

            queue1.ObserveSubscriptionState();
            queue1.ObserveSubscriptionPdu();
            subCfg.Observer = queue1;
            client.CreateSubscription(subId1, subCfg);

            Assert.That(await queue1.Dequeue(), Is.EqualTo("rtm:created"));
            Assert.That(await queue1.Dequeue(), Is.EqualTo("rtm:enter-unsubscribed"));
            Assert.That(await queue1.Dequeue(), Is.EqualTo("rtm:leave-unsubscribed"));
            Assert.That(await queue1.Dequeue(), Is.EqualTo("rtm:enter-subscribing"));
            Assert.That(await queue1.Dequeue(), Is.EqualTo("rtm:leave-subscribing"));
            Assert.That(await queue1.Dequeue(), Is.EqualTo("rtm:enter-subscribed"));

            var queue2 = new TestSubscriptionObserverQueue();

            queue2.ObserveSubscriptionState();
            queue2.ObserveSubscriptionPdu();
            subCfg.Observer = queue2;
            client.CreateSubscription(subId2, subCfg);

            Assert.That(await queue2.Dequeue(), Is.EqualTo("rtm:created"));
            Assert.That(await queue2.Dequeue(), Is.EqualTo("rtm:enter-unsubscribed"));
            Assert.That(await queue2.Dequeue(), Is.EqualTo("rtm:leave-unsubscribed"));
            Assert.That(await queue2.Dequeue(), Is.EqualTo("rtm:enter-subscribing"));
            Assert.That(await queue2.Dequeue(), Is.EqualTo("rtm:leave-subscribing"));
            Assert.That(await queue2.Dequeue(), Is.EqualTo("rtm:enter-subscribed"));

            var msg = new JObject(new JProperty("filed", "value"));

            await client.Publish(channel, msg, Ack.Yes);

            Assert.That(await queue1.Dequeue(), Is.EqualTo($"rtm:subscription-data:{msg}"));
            Assert.That(await queue2.Dequeue(), Is.EqualTo($"rtm:subscription-data:{msg}"));

            await Task.Delay(200);

            await client.Yield();

            Assert.That(queue1.TryDequeue(), Is.EqualTo(null));
            Assert.That(queue2.TryDequeue(), Is.EqualTo(null));

            await client.Dispose();
        }
Esempio n. 6
0
        public async Task AutoDeleteSubscriptionOnDispose()
        {
            var channel = GenerateRandomChannelName();
            var client  = new RtmClientBuilder(Config.Endpoint, Config.AppKey).Build();
            await client.Yield();

            var queue = new TestSubscriptionObserverQueue();

            queue.ObserveSubscriptionState();

            client.Start();
            client.CreateSubscription(channel, SubscriptionModes.Advanced, queue);

            Assert.That(await queue.Dequeue(), Is.EqualTo("rtm:created"));
            Assert.That(await queue.Dequeue(), Is.EqualTo("rtm:enter-unsubscribed"));
            Assert.That(await queue.Dequeue(), Is.EqualTo("rtm:leave-unsubscribed"));
            Assert.That(await queue.Dequeue(), Is.EqualTo("rtm:enter-subscribing"));
            Assert.That(await queue.Dequeue(), Is.EqualTo("rtm:leave-subscribing"));
            Assert.That(await queue.Dequeue(), Is.EqualTo("rtm:enter-subscribed"));

            await client.Dispose();

            Assert.That(await queue.Dequeue(), Is.EqualTo("rtm:leave-subscribed"));
            Assert.That(await queue.Dequeue(), Is.EqualTo("rtm:enter-unsubscribed"));
            Assert.That(await queue.Dequeue(), Is.EqualTo("rtm:leave-unsubscribed"));
            Assert.That(await queue.Dequeue(), Is.EqualTo("rtm:deleted"));

            try
            {
                await client.GetSubscription(channel);

                Assert.Fail("Subscription wasn't removed");
            }
            catch (InvalidOperationException)
            {
            }
        }