public static async Task AssertDequeue <T>(this QueueAsync <T> queue, params T[] items)
 {
     foreach (var item in items)
     {
         Assert.That(await queue.Dequeue(), Is.EqualTo(item));
     }
 }
Beispiel #2
0
        public async Task RepeatFirstMessage()
        {
            var channel = GenerateRandomChannelName();
            var client  = new RtmClientBuilder(Config.Endpoint, Config.AppKey).Build();
            await client.Yield();

            var subObs  = new SubscriptionObserver();
            var subData = subObs.CreateSubscriptionDataQueue();

            var subscription = new QueueAsync <string>();

            subObs.OnEnterSubscribed += s =>
            {
                subscription.Enqueue(s.Position);
            };

            client.Start();
            client.CreateSubscription(channel, SubscriptionModes.Advanced, subObs);
            var pos = await subscription.Dequeue().ConfigureAwait(false);

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

            await subData.DequeueAndVerify(channel, "message-1").ConfigureAwait(false);

            await client.Yield();

            client.RemoveSubscription(channel);
            client.CreateSubscription(
                channel,
                new SubscriptionConfig(SubscriptionModes.Advanced, position: pos, observer: subObs));
            await subData.DequeueAndVerify(channel, "message-1").ConfigureAwait(false);

            await client.Dispose();
        }
        public static async Task <RtmSubscriptionData> DequeueAndVerify <T>(this QueueAsync <RtmSubscriptionData> subscriptionData, string subscriptionId, T message)
        {
            var d = await subscriptionData.Dequeue().ConfigureAwait(false);

            if (d.SubscriptionId != subscriptionId)
            {
                throw new Exception("wrong channel");
            }

            if (d.Messages.Length != 1)
            {
                throw new Exception("only one message was expected");
            }

            if (!d.Messages[0].ToObject <T>().Equals(message))
            {
                throw new Exception("not equals");
            }

            return(d);
        }
Beispiel #4
0
 public Task <string> Dequeue()
 {
     return(_queue.Dequeue());
 }
Beispiel #5
0
        public async Task SubscribeWithAdvancedModeAndPosition()
        {
            var channel = GenerateRandomChannelName();
            var reqs    = new QueueAsync <Pdu <object> >();
            var reps    = new QueueAsync <Pdu>();
            var client  = (RtmClient) new RtmClientBuilder(Config.Endpoint, Config.AppKey)
                          .SetConnector((url, opts, ct) => TestConnection.Connect(url, opts, ct, reqs, reps))
                          .Build();

            client.Start();

            // get position
            client.CreateSubscription(
                channel,
                new SubscriptionConfig(SubscriptionModes.Simple));

            Assert.That((await reqs.Dequeue()).Action, Is.EqualTo("rtm/subscribe"));

            var rep1 = await reps.Dequeue();

            Assert.That(rep1.Action, Is.EqualTo("rtm/subscribe/ok"));
            var pos1 = rep1.As <RtmSubscribeReply>().Body.Position;

            client.RemoveSubscription(channel);
            Assert.That((await reqs.Dequeue()).Action, Is.EqualTo("rtm/unsubscribe"));
            Assert.That((await reps.Dequeue()).Action, Is.EqualTo("rtm/unsubscribe/ok"));

            await client.Yield();

            var sub = await client.GetSubscription(channel);

            Assert.That(sub, Is.Null); // subscription is removed

            client.CreateSubscription(
                channel,
                new SubscriptionConfig(SubscriptionModes.Advanced, position: pos1));

            var req3 = await reqs.Dequeue();

            var body3 = (RtmSubscribeRequest)req3.Body;

            Assert.That(req3.Action, Is.EqualTo("rtm/subscribe"));
            Assert.That(body3.Position, Is.EqualTo(pos1));
            Assert.That(body3.FastForward, Is.False);

            var rep3 = await reps.Dequeue();

            Assert.That(rep3.Action, Is.EqualTo("rtm/subscribe/ok"));
            var pos2 = rep3.As <RtmSubscribeReply>().Body.Position;

            // cause resubsubscription
            var conn = await client.GetConnection();

            await conn.Close();

            var req4 = await reqs.Dequeue();

            var body4 = (RtmSubscribeRequest)req4.Body;

            Assert.That(req4.Action, Is.EqualTo("rtm/subscribe"));
            Assert.That(body4.Position, Is.EqualTo(pos2));
            Assert.That(body4.FastForward, Is.False);

            var rep4 = await reps.Dequeue();

            Assert.That(rep4.Action, Is.EqualTo("rtm/subscribe/ok"));

            await client.Dispose();
        }