Example #1
0
            public async Task Client_to_stream()
            {
                var stream = system.StreamOf <ItemData>("sms", "sms-123");

                var received     = new List <ItemData>();
                var subscription = await stream.Subscribe(
                    (item, _) => received.Add(item));

                await stream.Publish(new ItemData("foo"));

                await Task.Delay(timeout);

                Assert.That(received.Count, Is.EqualTo(1));
                Assert.That(received[0].Text, Is.EqualTo("foo"));

                await subscription.Unsubscribe();

                received.Clear();

                await stream.Publish(new ItemData("bar"));

                await Task.Delay(timeout);

                Assert.That(received.Count, Is.EqualTo(0));
            }
Example #2
0
            public async Task Resuming_on_reactivation()
            {
                var consumer = system.ActorOf <TConsumer>("cons");
                await consumer.Tell(new Subscribe());

                var stream = system.StreamOf(provider, $"{provider}-42");
                await stream.Push("e-123");

                await Task.Delay(timeout);

                var received = await consumer.Ask(new Received());

                Assert.That(received.Count, Is.EqualTo(1));
                Assert.That(received[0], Is.EqualTo("e-123"));

                await consumer.Tell(new Deactivate());

                await Task.Delay(TimeSpan.FromSeconds(61));

                await stream.Push("e-456");

                await Task.Delay(timeout);

                received = await consumer.Ask(new Received());

                Assert.That(received.Count, Is.EqualTo(1));
                Assert.That(received[0], Is.EqualTo("e-456"));
            }
Example #3
0
            public async Task Resuming_on_reactivation()
            {
                var consumer = system.ActorOf <ITestConsumerActor>("cons");
                await consumer.Tell(new Subscribe());

                var stream = system.StreamOf <object>("sms", "sms-42");
                await stream.Publish("e-123");

                await Task.Delay(timeout);

                var received = await consumer.Ask(new Received());

                Assert.That(received.Count, Is.EqualTo(1));
                Assert.That(received[0], Is.EqualTo("e-123"));

                await consumer.Tell(new Kill());

                await Task.Delay(TimeSpan.FromSeconds(61));

                await stream.Publish("e-456");

                await Task.Delay(timeout);

                received = await consumer.Ask(new Received());

                Assert.That(received.Count, Is.EqualTo(1));
                Assert.That(received[0], Is.EqualTo("e-456"));
            }
            public async Task Client_to_stream()
            {
                var stream = system.StreamOf(provider, $"{provider}-123");

                var received     = new List <Item>();
                var subscription = await stream.Subscribe <Item>(
                    item => received.Add(item));

                await stream.Push(new Item("foo"));

                await Task.Delay(timeout);

                Assert.That(received.Count, Is.EqualTo(1));
                Assert.That(received[0].Text, Is.EqualTo("foo"));

                await subscription.Unsubscribe();

                received.Clear();

                await stream.Push("bar");

                await Task.Delay(timeout);

                Assert.That(received.Count, Is.EqualTo(0));
            }
Example #5
0
            public async void Client_to_stream()
            {
                var stream = system.StreamOf("sms", "cs");

                await stream.Push("e");

                await Task.Delay(100);

                var consumer = system.ActorOf <TestClientToStreamConsumerActor>("#");
                var received = await consumer.Ask(new Received());

                Assert.That(received, Is.EquivalentTo(new[] { "e" }));
            }
            public async Task Client_to_stream <T>() where T : Actor
            {
                var stream = system.StreamOf(provider, "cs");

                await stream.Push("ce");

                await Task.Delay(timeout);

                var consumer = system.ActorOf <T>("#");
                var received = await consumer.Ask(new Received());

                Assert.That(received, Is.EquivalentTo(new[] { "ce" }));
            }
Example #7
0
            public async void Learn_about_get_all_subscription_handles()
            {
                var a1 = system.ActorOf <TestSubscriptionHandlesActor>("123");
                var a2 = system.ActorOf <TestSubscriptionHandlesActor>("456");

                Assert.That((await a1.Ask <int>("count")), Is.EqualTo(1),
                            "Should return handles registered only by the current actor");

                Assert.That((await a2.Ask <int>("count")), Is.EqualTo(1),
                            "Should return handles registered only by the current actor");

                var stream = system.StreamOf("sms", "111");

                Assert.That((await stream.GetAllSubscriptionHandles()).Count, Is.EqualTo(0),
                            "Should not return all registered handles when requested from the client side");
            }
Example #8
0
            public async Task Intercepting_stream_messages()
            {
                var stream = system.StreamOf <ItemData>("sms", "test-stream-interception");

                var actor = system.FreshActorOf <ITestActor>();
                await actor.Tell(new Subscribe { Stream = stream });

                await stream.Publish(new ItemData { Text = "foo" });

                await Task.Delay(TimeSpan.FromMilliseconds(10));

                var received = await actor.Ask(new GetReceivedFromStream());

                Assert.That(received.Count, Is.EqualTo(1));
                Assert.That(received[0], Is.EqualTo("foo.intercepted"));
            }
Example #9
0
        async Task Subscribe()
        {
            var room = system.StreamOf <ChatRoomMessage>("sms", RoomName);

            subscription = await room.Subscribe((message, _) =>
            {
                if (message.User != UserName)
                {
                    Console.WriteLine(message.Text);
                }
            });
        }
        async Task Subscribe()
        {
            var room = system.StreamOf(Constants.StreamProviderNameDefault, Constants.StreamNameSpaceCustomers);

            subscription = await room.Subscribe <ChatRoomMessage>(message =>
            {
                if (message.User != UserName)
                {
                    Console.WriteLine(message.Text);
                }
            });
        }
Example #11
0
            public async void Client_to_stream()
            {
                var stream = system.StreamOf <SimpleMessageStreamProvider>("123");

                var observer = new TestStreamObserver();
                await stream.SubscribeAsync(observer);

                await stream.OnNextAsync("event");

                await Task.Delay(100);

                Assert.That(observer.Received.Count, Is.EqualTo(1));
                Assert.That(observer.Received[0], Is.EqualTo("event"));
            }
Example #12
0
            public async Task When_actor_received_reentrant_message_via_Stream()
            {
                var actor = system.FreshActorOf <TestReentrantStreamConsumerActor>();
                await actor.Tell(new Activate());

                var stream1 = system.StreamOf("sms", "s1");
                var stream2 = system.StreamOf("sms", "s2");

                var i1 = stream2.Push("1");
                await Task.Delay(100);

                var i2 = stream1.Push(2);
                await Task.Delay(100);

                var inProgress = await actor.Ask(new GetStreamMessagesInProgress());

                Assert.That(inProgress, Has.Count.EqualTo(2));
                Assert.That(inProgress[0], Is.EqualTo("1"));
                Assert.That(inProgress[1], Is.EqualTo(2));

                await i1;
                await i2;
            }
Example #13
0
            public async void Intercepting_stream_messages()
            {
                var stream = system.StreamOf("sms", "test-stream-interception");

                var actor = system.FreshActorOf <TestStreamActor>();
                await actor.Tell(new Subscribe { Stream = stream });

                await stream.Push("foo");

                await Task.Delay(TimeSpan.FromMilliseconds(10));

                var received = await actor.Ask(new Received());

                Assert.That(received.Count, Is.EqualTo(1));
                Assert.That(received[0], Is.EqualTo("foo.intercepted"));
            }
Example #14
0
            public async void Sticky_actors_shoud_be_automatically_resurrected()
            {
                var events = new List <string>();

                var stream = system.StreamOf("sms", "sticky");
                await stream.Subscribe <string>(e => events.Add(e));

                var sticky = system.ActorOf <TestActor>("sticky");
                await sticky.Tell(new Deactivate());

                // first activation (from Deactivate message)
                Assert.That(events.Count, Is.EqualTo(1));

                // wait until min reminder timeout (1 minute)
                Thread.Sleep(TimeSpan.FromMinutes(1.5));

                // auto-reactivation (from automatically registered reminder message)
                Assert.That(events.Count, Is.EqualTo(2));
            }
Example #15
0
 /// <summary>
 /// Acquires the stream reference for the given id and type of the stream.
 /// </summary>
 /// <typeparam name="TStream">The type of the stream</typeparam>
 /// <param name="system">The reference to actor system</param>
 /// <param name="id">The id</param>
 /// <returns>A stream reference</returns>
 public static StreamRef StreamOf <TStream>(this IActorSystem system, string id) where TStream : IStreamProvider
 {
     return(system.StreamOf(StreamPath.From(typeof(TStream), id)));
 }
Example #16
0
 /// <summary>
 /// Acquires the stream reference for the given id and type of the stream.
 /// </summary>
 /// <param name="system">The reference to actor system</param>
 /// <param name="provider">The name of the stream provider</param>
 /// <param name="id">The id</param>
 /// <returns>A stream reference</returns>
 public static StreamRef StreamOf(this IActorSystem system, string provider, string id)
 {
     return system.StreamOf(StreamPath.From(provider, id));
 }
Example #17
0
 /// <summary>
 /// Acquires the stream reference for the given provider name and id of the stream.
 /// </summary>
 /// <param name="system">The reference to actor system</param>
 /// <param name="provider">The name of the stream provider</param>
 /// <param name="id">The id</param>
 /// <typeparam name="TItem">The type of the stream item</typeparam>
 /// <returns>A stream reference</returns>
 public static StreamRef <TItem> StreamOf <TItem>(this IActorSystem system, string provider, string id)
 {
     return(system.StreamOf <TItem>(StreamPath.From(provider, id)));
 }
Example #18
0
 public ChatClient(IActorSystem system, string user, string room)
 {
     this.user = system.ActorOf <ChatUser>(user);
     this.room = system.StreamOf("sms", room);
 }
Example #19
0
 public ChatClient(IActorSystem system, string user, string room)
 {
     this.user = system.ActorOf<ChatUser>(user);
     this.room = system.StreamOf<SimpleMessageStreamProvider>(room);
 }
Example #20
0
 public ChatClient(IActorSystem system, string user, string room)
 {
     this.user = system.ActorOf<ChatUser>(user);
     this.room = system.StreamOf("sms", room);
 }
            public async Task Client_to_stream <T>() where T : IActorGrain, IGrainWithStringKey
            {
                var stream = system.StreamOf <object>(provider, "cs");

                await stream.Publish("ce");

                await Task.Delay(timeout);

                var consumer = system.ActorOf <T>("#cs");
                var received = await consumer.Ask(new Received());

                Assert.That(received, Is.EquivalentTo(new[] { "ce" }));
            }
Example #22
0
 public ChatClient(IActorSystem system, string user, string room)
 {
     this.user = system.ActorOf <ChatUser>(user);
     this.room = system.StreamOf <SimpleMessageStreamProvider>(room);
 }