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();
        }
예제 #2
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();
        }
예제 #3
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);
        }