Ejemplo n.º 1
0
        public async Task CreateSubscriptionToRestrictedChannel()
        {
            var client = new RtmClientBuilder(Config.Endpoint, Config.AppKey).Build();
            await client.StartAndWaitConnected();

            var channel = Config.RestrictedChannel;

            var queue = client.CreateStateQueue();

            client.SetClientErrorObserver(queue);
            var subObserver = new TestSubscriptionObserverQueue(queue);

            subObserver.ObserveAll();

            client.CreateSubscription(channel, SubscriptionModes.Advanced, subObserver);

            await queue.AssertDequeue(
                "rtm:created",
                "rtm:enter-unsubscribed",
                "rtm:leave-unsubscribed",
                "rtm:enter-subscribing",
                "rtm:subscribe-error:SubscribeException:authorization_denied",
                "rtm:leave-subscribing",
                "rtm:enter-failed");

            await queue.AssertEmpty(client, millis : 200);

            await client.Dispose();
        }
Ejemplo n.º 2
0
        public async Task CreateFilterWIthExistingSubscriptionId()
        {
            var client = new RtmClientBuilder(Config.Endpoint, Config.AppKey).Build();
            await client.StartAndWaitConnected();

            var channel = GenerateRandomChannelName();

            client.CreateSubscription(channel, SubscriptionModes.Advanced, null);

            var queue = client.CreateStateQueue();

            client.SetClientErrorObserver(queue);
            var subObserver = new TestSubscriptionObserverQueue(queue);

            subObserver.ObserveAll();

            client.CreateSubscription(
                channel,
                new SubscriptionConfig(SubscriptionModes.Advanced, observer: subObserver)
            {
                Filter = $"select * FROM `{channel}`"
            });

            await queue.AssertDequeue("rtm:subscribe-error:InvalidOperationException");

            await queue.AssertEmpty(client, millis : 200);

            await client.Dispose();
        }
Ejemplo n.º 3
0
        public async Task RepeatSecondMessage()
        {
            var channel = GenerateRandomChannelName();
            var client  = new RtmClientBuilder(Config.Endpoint, Config.AppKey).Build();

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

            client.Start();

            await client.CreateSubscriptionAndWaitSubscribed(channel, null, obs);

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

            var pos = (await subData.DequeueAndVerify(channel, "first-message").ConfigureAwait(false)).Position;
            await client.Publish(channel, "second-message", Ack.Yes).ConfigureAwait(false);

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

            client.RemoveSubscription(channel);
            await client.CreateSubscriptionAndWaitSubscribed(channel, pos, obs).ConfigureAwait(false);

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

            client.RemoveSubscription(channel);
            client.Stop();
            await client.Dispose();
        }
Ejemplo n.º 4
0
    static void Main()
    {
        // Log messages from SDK to the console
        Trace.Listeners.Add(new ConsoleTraceListener());

        IRtmClient client = new RtmClientBuilder(endpoint, appkey)
                            .SetRoleSecretAuthenticator(role, roleSecretKey)
                            .Build();

        client.OnEnterConnected += cn =>
                                   Console.WriteLine("Connected to Satori RTM and authenticated as " + role);

        client.OnError += ex =>
        {
            var authEx = ex as AuthException;
            if (authEx != null)
            {
                Console.WriteLine("Failed to authenticate: " + ex.Message);
            }
            else
            {
                Console.WriteLine("Error occurred: " + ex.Message);
            }
        };

        client.Start();

        Console.ReadKey();

        // Stop and clean up the client before exiting the program
        client.Dispose().Wait();
    }
Ejemplo n.º 5
0
        public async Task RestartOnSubscriptionError()
        {
            var trigger = new TaskCompletionSource <bool>();
            var counts  = 3;
            var client  = new RtmClientBuilder(Config.Endpoint, Config.AppKey).Build();
            await client.Yield();

            var obs = new SubscriptionObserver();

            client.CreateSubscription(string.Empty, SubscriptionModes.Advanced, obs);
            obs.OnEnterFailed += (s) =>
            {
                if (counts == 0)
                {
                    trigger.TrySetResult(true);
                }
                else
                {
                    counts -= 1;
                    client.Restart();
                }
            };
            client.Start();
            await trigger.Task;

            client.Stop();
            await client.Dispose();
        }
    static void Main()
    {
        // Log messages from SDK to the console
        Trace.Listeners.Add(new ConsoleTraceListener());

        IRtmClient client = new RtmClientBuilder(endpoint, appkey).Build();

        client.OnEnterConnected += cn => Console.WriteLine("Connected to Satori RTM!");
        client.Start();

        // Create subscription observer to observe channel subscription events
        var observer = new SubscriptionObserver();

        observer.OnSubscriptionData += (ISubscription sub, RtmSubscriptionData data) =>
        {
            foreach (JToken jToken in data.Messages)
            {
                Console.WriteLine("Got message: " + jToken);
            }
        };

        client.CreateSubscription(channel, SubscriptionModes.Simple, observer);

        Console.ReadKey();

        // Stop and clean up the client before exiting the program
        client.Dispose().Wait();
    }
Ejemplo n.º 7
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();
        }
        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();
        }
Ejemplo n.º 9
0
        static void Main()
        {
            int intIndexOfForLoop = 0;

            // DataStorage.strCryptoCurrencySearchCriteria = View.DrawStartScreen(); //turn off for debug

            Trace.Listeners.Add(new ConsoleTraceListener());
            IRtmClient client = new RtmClientBuilder(endpoint, appkey).Build();

            client.OnEnterConnected += cn => Console.WriteLine("Connected to Data Steam");
            client.Start();
            var observer = new SubscriptionObserver();

            observer.OnSubscriptionData += (ISubscription sub, RtmSubscriptionData data) =>
            {
                foreach (JToken msg in data.Messages)
                {
                    Message msgTempMessage = new Message(ReadToObject(msg.ToString()));

                    Controller.Loop(msgTempMessage, intIndexOfForLoop);

                    intIndexOfForLoop = intIndexOfForLoop + 1;
                }
            };


            client.CreateSubscription(channel, SubscriptionModes.Simple, observer);
            Console.ReadKey();
            client.Dispose().Wait();
        }
Ejemplo n.º 10
0
        public async Task SubscribeToRestrictedChannelWhenAuthorized()
        {
            var client = new RtmClientBuilder(Config.Endpoint, Config.AppKey)
                         .SetRoleSecretAuthenticator(Config.Role, Config.RoleSecretKey)
                         .Build();

            var queue = client.CreateStateQueue();

            client.Start();

            var channel = GenerateRandomChannelName();

            var subObs = new TestSubscriptionObserverQueue(queue);

            subObs.ObserveSubscriptionState();
            subObs.ObserveSubscriptionPdu();
            client.CreateSubscription(channel, SubscriptionModes.Advanced, subObs);

            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("rtm:created"));
            Assert.That(await queue.Dequeue(), Is.EqualTo("rtm:enter-unsubscribed"));
            Assert.That(await queue.Dequeue(), Is.EqualTo("leave-connecting"));
            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("enter-connected"));
            Assert.That(await queue.Dequeue(), Is.EqualTo("rtm:leave-subscribing"));
            Assert.That(await queue.Dequeue(), Is.EqualTo("rtm:enter-subscribed"));

            await client.Dispose();
        }
Ejemplo n.º 11
0
        public async Task FailToAuthenticateWithBadKey()
        {
            var client = new RtmClientBuilder(Config.Endpoint, Config.AppKey)
                         .SetRoleSecretAuthenticator(Config.Role, "bad_secret_key")
                         .Build();

            Exception error = null;

            client.OnError += ex => error = ex is AggregateException ? ex.InnerException : ex;

            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(error, Is.TypeOf <AuthException>());

            Assert.That(await queue.Dequeue(), Is.EqualTo("enter-awaiting"));

            client.Stop();
            Assert.That(await queue.Dequeue(), Is.EqualTo("leave-awaiting"));
            Assert.That(await queue.Dequeue(), Is.EqualTo("enter-stopped"));

            await client.Dispose();
        }
Ejemplo n.º 12
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();
        }
Ejemplo n.º 13
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();
        }
Ejemplo n.º 14
0
        public async Task FailOnOutOfSyncWhenAdvancedMode()
        {
            var channel = GenerateRandomChannelName();

            var client = new RtmClientBuilder(Config.Endpoint, Config.AppKey)
                         .SetConnector(ConnectAndOutOfSyncOnData)
                         .Build();

            var queue = client.CreateStateQueue();

            var obs = new TestSubscriptionObserverQueue(queue);

            obs.ObserveSubscriptionState();
            obs.ObserveSubscriptionPdu();

            client.OnError += ex =>
            {
                queue.Enqueue($"error:{ex.Message}");
            };

            client.CreateSubscription(channel, SubscriptionModes.Advanced, obs);

            RtmSubscriptionError subError = null;

            obs.OnSubscriptionError += (_, error) => subError = error;

            client.Start();

            await queue.AssertDequeue(
                "rtm:created",
                "rtm:enter-unsubscribed",
                "leave-stopped",
                "enter-connecting",
                "leave-connecting",
                "rtm:leave-unsubscribed",
                "rtm:enter-subscribing",
                "enter-connected",
                "rtm:leave-subscribing",
                "rtm:enter-subscribed");

            // trigger subscription/info
            await client.Publish(channel, "msg", Ack.Yes);

            await queue.AssertDequeue(
                $"rtm:leave-subscribed",
                "rtm:enter-failed",
                $"rtm:subscription-error:{RtmSubscriptionError.OutOfSync}");

            var sub = await client.GetSubscription(channel);

            Assert.That(subError.Position, Is.EqualTo(sub.Position));

            await queue.AssertEmpty(client, millis : 200);

            await client.Dispose();
        }
Ejemplo n.º 15
0
        public async Task FastForwardOnOutOfSyncWhenSimpleMode()
        {
            var channel = GenerateRandomChannelName();

            var client = new RtmClientBuilder(Config.Endpoint, Config.AppKey)
                         .SetConnector(ConnectAndFastForwardOnData)
                         .Build();

            var queue = client.CreateStateQueue();

            var obs = new TestSubscriptionObserverQueue(queue);

            obs.ObserveSubscriptionState();
            obs.ObserveSubscriptionPdu();

            client.OnError += ex =>
            {
                queue.Enqueue($"error:{ex.Message}");
            };

            RtmSubscriptionInfo subInfo = null;

            obs.OnSubscriptionInfo += (_, info) => subInfo = info;

            client.CreateSubscription(channel, SubscriptionModes.Simple, obs);

            client.Start();

            await queue.AssertDequeue(
                "rtm:created",
                "rtm:enter-unsubscribed",
                "leave-stopped",
                "enter-connecting",
                "leave-connecting",
                "rtm:leave-unsubscribed",
                "rtm:enter-subscribing",
                "enter-connected",
                "rtm:leave-subscribing",
                "rtm:enter-subscribed");

            // trigger subscription/info
            await client.Publish(channel, "msg", Ack.Yes);

            // on connected info
            Assert.That(await queue.Dequeue(), Is.EqualTo($"rtm:subscription-info:{RtmSubscriptionInfo.FastForward}"));

            var sub = await client.GetSubscription(channel);

            Assert.That(sub.Position, Is.EqualTo(null));
            Assert.That(subInfo.Position, Is.Not.EqualTo(null));

            await queue.AssertEmpty(client, millis : 200);

            await client.Dispose();
        }
Ejemplo n.º 16
0
        public async Task TwoClients()
        {
            var channel    = GenerateRandomChannelName();
            int i          = 0;
            var msg        = $"message-{i++}";
            var subscriber = (RtmClient) new RtmClientBuilder(Config.Endpoint, Config.AppKey).Build();

            var publisher = new RtmClientBuilder(Config.Endpoint, Config.AppKey).Build();

            publisher.Start();
            subscriber.Start();

            var subObs  = new SubscriptionObserver();
            var subData = subObs.CreateSubscriptionDataQueue();
            await subscriber.CreateSubscriptionAndWaitSubscribed(channel, null, subObs).ConfigureAwait(false);

            await publisher.Publish(channel, msg, Ack.Yes).ConfigureAwait(false);

            await subData.DequeueAndVerify(channel, msg).ConfigureAwait(false);

            subscriber.Stop();
            if ((await subscriber.GetStateAsync()).GetConnection() != null)
            {
                throw new Exception("test failed");
            }

            do
            {
                msg = $"message-{i++}";
                await publisher.Publish(channel, msg, Ack.Yes).ConfigureAwait(false);

                await Task.Delay(500);

                RtmSubscriptionData data;
                if (subData.TryDequeue(out data))
                {
                    throw new Exception("test failed");
                }

                subscriber.Start();

                await subData.DequeueAndVerify(channel, msg).ConfigureAwait(false);

                subscriber.Stop();
                GC.Collect();
            } while (i < 3);

            await subscriber.Dispose();

            publisher.Stop();
            await publisher.Dispose();
        }
Ejemplo n.º 17
0
    static void Main()
    {
        // Log messages from SDK to the console
        Trace.Listeners.Add(new ConsoleTraceListener());

        IRtmClient client = new RtmClientBuilder(endpoint, appkey).Build();

        client.OnEnterConnected += cn => Console.WriteLine("Connected to Satori RTM!");

        client.OnError += ex =>
                          Console.WriteLine("Failed to connect: " + ex.Message);

        client.Start();

        var observer = new SubscriptionObserver();

        observer.OnEnterSubscribed += (ISubscription sub) =>
                                      Console.WriteLine("Subscribed to: " + sub.SubscriptionId);

        observer.OnLeaveSubscribed += (ISubscription sub) =>
                                      Console.WriteLine("Unsubscribed from: " + sub.SubscriptionId);

        observer.OnSubscriptionData += (ISubscription sub, RtmSubscriptionData data) =>
        {
            foreach (JToken jToken in data.Messages)
            {
                Console.WriteLine("Got message: " + jToken);
            }
        };

        observer.OnSubscribeError += (ISubscription sub, Exception err) =>
                                     Console.WriteLine("Failed to subscribe: " + err.Message);

        observer.OnSubscriptionError += (ISubscription sub, RtmSubscriptionError err) =>
                                        Console.WriteLine("Subscription failed. RTM sent the unsolicited error {0}: {1}", err.Code, err.Reason);

        client.CreateSubscription("animals", SubscriptionModes.Simple, observer);

        client.RemoveSubscription("animals");

        var cfg = new SubscriptionConfig(SubscriptionModes.Simple, observer)
        {
            Filter = "SELECT * FROM `animals` WHERE who LIKE 'z%'"
        };

        client.CreateSubscription("animals", cfg);

        Console.ReadKey();

        // Stop and clean up the client before exiting the program
        client.Dispose().Wait();
    }
Ejemplo n.º 18
0
        public async Task ThrowWhenTooManyRequests()
        {
            var client = new RtmClientBuilder(Config.Endpoint, Config.AppKey)
            {
                PendingActionQueueLength = 2
            }.Build();

            var channel = GenerateRandomChannelName();

            var t1 = client.Publish(channel, 1, Ack.Yes);
            var t2 = client.Publish(channel, 2, Ack.Yes);
            var t3 = client.Publish(channel, 3, Ack.Yes);

            await Task.WhenAny(t1, t2, t3);

            Assert.That(t1.Status, Is.EqualTo(TaskStatus.WaitingForActivation));
            Assert.That(t2.Status, Is.EqualTo(TaskStatus.WaitingForActivation));
            Assert.That(t3.Status, Is.EqualTo(TaskStatus.Faulted));
            Assert.That(t3.Exception.InnerException, Is.InstanceOf(typeof(QueueFullException)));

            client.Start();

            await t1;
            await t2;

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

            var queue = client.CreateStateQueue();

            client.Stop();

            Assert.That(await queue.Dequeue(), Is.EqualTo("leave-connected"));

            var t5 = client.Publish(channel, 5, Ack.Yes);
            var t6 = client.Publish(channel, 6, Ack.Yes);
            var t7 = client.Publish(channel, 7, Ack.Yes);

            await Task.WhenAny(t5, t6, t7);

            Assert.That(t5.Status, Is.EqualTo(TaskStatus.WaitingForActivation));
            Assert.That(t6.Status, Is.EqualTo(TaskStatus.WaitingForActivation));
            Assert.That(t7.Status, Is.EqualTo(TaskStatus.Faulted));
            Assert.That(t7.Exception.InnerException, Is.InstanceOf(typeof(QueueFullException)));

            client.Start();
            await t5;
            await t6;

            await client.Dispose();
        }
        public async Task ReadAfterWrite()
        {
            var channel = GenerateRandomChannelName();
            var client  = new RtmClientBuilder(Config.Endpoint, Config.AppKey).Build();

            client.Start();

            var msg = "foo";
            await client.Write(channel, msg, Ack.Yes);

            var reply = await client.Read <string>(channel);

            Assert.That(reply.Message, Is.EqualTo(msg));

            await client.Dispose();
        }
Ejemplo n.º 20
0
    public override bool FinishedLaunching(UIApplication application, NSDictionary launchOptions)
    {
        IRtmClient client = new RtmClientBuilder(endpoint, appkey).Build();

        client.OnEnterConnected += cn =>
                                   Console.WriteLine("Connected to Satori RTM!");

        client.OnError += ex =>
                          Console.WriteLine("Failed to connect: " + ex.Message);

        client.Start();

        // Publish, subscribe, and perform other operations here

        return(true);
    }
Ejemplo n.º 21
0
        public async Task ThrowWhenDisconnectedAndMaxPendingQueueLengthIsZero()
        {
            var client = new RtmClientBuilder(Config.Endpoint, Config.AppKey)
            {
                PendingActionQueueLength = 0
            }.Build();

            var channel = GenerateRandomChannelName();

            var queue = client.CreateStateQueue();

            try
            {
                await client.Publish(channel, 1, Ack.Yes);

                Assert.Fail();
            }
            catch (Exception ex)
            {
                Assert.That(ex, Is.InstanceOf(typeof(QueueFullException)));
            }

            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"));

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

            client.Stop();
            Assert.That(await queue.Dequeue(), Is.EqualTo("leave-connected"));

            try
            {
                await client.Publish(channel, 2, Ack.Yes);

                Assert.Fail();
            }
            catch (Exception ex)
            {
                Assert.That(ex, Is.InstanceOf(typeof(QueueFullException)));
            }

            await client.Dispose();
        }
Ejemplo n.º 22
0
        public async Task StopOnConnected()
        {
            var client = new RtmClientBuilder(Config.Endpoint, Config.AppKey).Build();
            var cs     = new TaskCompletionSource <bool>();

            client.OnEnterConnected += _ =>
            {
                client.Stop();
            };
            client.OnEnterStopped += () =>
            {
                cs.TrySetResult(true);
            };
            client.Start();
            await cs.Task;
            await client.Dispose();
        }
Ejemplo n.º 23
0
        public async Task ReconnectIfConnectionCannotBeEstablished()
        {
            var client = new RtmClientBuilder("ws://bad_endpoint", "bad_key").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-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-awaiting"));
            Assert.That(await queue.Dequeue(), Is.EqualTo("leave-awaiting"));
            Assert.That(await queue.Dequeue(), Is.EqualTo("enter-connecting"));

            await client.Dispose();
        }
Ejemplo n.º 24
0
        public async Task RemoveSubscriptionThatDoesntExist()
        {
            var client = new RtmClientBuilder(Config.Endpoint, Config.AppKey).Build();
            await client.StartAndWaitConnected();

            var channel = GenerateRandomChannelName();

            var queue = client.CreateStateQueue();

            client.SetClientErrorObserver(queue);

            client.RemoveSubscription(channel);

            await queue.AssertDequeue("error:InvalidOperationException");

            await queue.AssertEmpty(client, millis : 200);

            await client.Dispose();
        }
Ejemplo n.º 25
0
    protected override void OnCreate(Bundle bundle)
    {
        base.OnCreate(bundle);

        // Set our view from the "main" layout resource
        SetContentView(Resource.Layout.Main);

        IRtmClient client = new RtmClientBuilder(endpoint, appkey).Build();

        client.OnEnterConnected += cn =>
                                   Log.Info("", "Connected to Satori RTM!");

        client.OnError += ex =>
                          Log.Error("", "Failed to connect: " + ex.Message);

        client.Start();

        // Publish, subscribe, and perform other operations here
    }
Ejemplo n.º 26
0
        public async Task AuthenticateWithSuccess()
        {
            var client = new RtmClientBuilder(Config.Endpoint, Config.AppKey)
                         .SetRoleSecretAuthenticator(Config.Role, Config.RoleSecretKey)
                         .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"));

            client.Stop();
            Assert.That(await queue.Dequeue(), Is.EqualTo("leave-connected"));

            await client.Dispose();
        }
Ejemplo n.º 27
0
        public async Task PublishToRestrictedChannelWhenNotAuthorized()
        {
            var client = new RtmClientBuilder(Config.Endpoint, Config.AppKey).Build();

            await client.Yield();

            client.Start();

            try
            {
                var restrictedChannel = Config.RestrictedChannel;
                await client.Publish(restrictedChannel, "foo", Ack.Yes);
            }
            catch (PduException ex)
            {
                Assert.That(ex.Error.Code, Is.EqualTo(AuthErrorCodes.AuthorizationDenied));
            }

            await client.Dispose();
        }
Ejemplo n.º 28
0
    static void Main()
    {
        // Log messages from SDK to the console
        Trace.Listeners.Add(new ConsoleTraceListener());

        IRtmClient client = new RtmClientBuilder(endpoint, appkey).Build();

        client.OnEnterConnected += cn => Console.WriteLine("Connected to Satori RTM!");

        client.OnError += ex =>
                          Console.WriteLine("Failed to connect: " + ex.Message);

        client.Start();

        Async(client);

        Console.ReadKey();

        // Stop and clean up the client before exiting the program
        client.Dispose().Wait();
    }
        public async Task ReadOldMessage()
        {
            var channel = GenerateRandomChannelName();
            var client  = new RtmClientBuilder(Config.Endpoint, Config.AppKey).Build();

            client.Start();

            var msg1       = "foo";
            var msg2       = "bar";
            var writeReply = await client.Write(channel, msg1, Ack.Yes);

            await client.Write(channel, msg2, Ack.Yes);

            var readReply = await client.Read <string>(new RtmReadRequest
            {
                Channel  = channel,
                Position = writeReply.Position
            });

            Assert.That(readReply.Message, Is.EqualTo(msg1));

            await client.Dispose();
        }
Ejemplo n.º 30
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)
            {
            }
        }