Ejemplo n.º 1
0
        public void Regex_based_matching(string source, string target, string streamId, string actorId)
        {
            var system = new ActorSystemMock();

            var attribute = new StreamSubscriptionAttribute
            {
                Source = source,
                Target = target
            };

            var type       = typeof(TestActor);
            var dispatcher = new Dispatcher(type);

            var specification = StreamSubscriptionSpecification.From(type, attribute, dispatcher);

            specification.Type = ActorTypeName.Of(typeof(TestActor));

            var match = specification.Match(system, streamId);

            if (match == StreamSubscriptionMatch.None)
            {
                Assert.That(actorId, Is.Null);
                return;
            }

            var message = new object();

            match.Receiver(message);

            Assert.That(system.RequestedRef, Is.Not.Null);
            Assert.That(system.RequestedRef.Path, Is.EqualTo(typeof(TestActor).ToActorPath(actorId)));
            Assert.That(system.RequestedRef.MessagePassedToTell, Is.SameAs(message));
        }
Ejemplo n.º 2
0
 internal static void Reset()
 {
     ActorTypeName.Reset();
     Activator = new DefaultActorActivator();
     dispatchers.Clear();
     Conventions = null;
 }
Ejemplo n.º 3
0
        public static ActorPath ToActorPath(this Type type, string id)
        {
            Requires.NotNull(type, nameof(type));
            var key = ActorTypeName.Of(type);

            return(ActorPath.From(key, id));
        }
Ejemplo n.º 4
0
 static EndpointConfiguration BuildInterface(Type actor)
 {
     if (ActorTypeName.IsRegistered(actor))
     {
         return(null); // assume endpoint was already build from implementation
     }
     return(new ActorConfiguration(ActorTypeName.Register(actor)));
 }
        StreamSubscriptionSpecification(Type actor, string provider, Func <string, string> matcher, Func <object, string> selector = null, Func <object, bool> filter = null)
        {
            Requires.NotNullOrWhitespace(provider, nameof(provider));
            Requires.NotNull(matcher, nameof(matcher));

            Type          = ActorTypeName.Of(actor);
            Provider      = provider;
            this.matcher  = matcher;
            this.selector = selector;

            this.filter = filter ?? (x => true);
        }
Ejemplo n.º 6
0
        static EndpointConfiguration BuildWorker(Type worker)
        {
            var config = new WorkerConfiguration(ActorTypeName.Register(worker));

            SetReentrancy(worker, config);
            SetKeepAliveTimeout(worker, config);
            SetReceiver(worker, config);
            SetAutorun(worker, config);
            SetStickiness(worker, config);
            SetInvoker(worker, config);

            return(config);
        }
Ejemplo n.º 7
0
        static EndpointConfiguration BuildActor(Type actor)
        {
            var config = new ActorConfiguration(ActorTypeName.Register(actor));

            SetPlacement(actor, config);
            SetReentrancy(actor, config);
            SetKeepAliveTimeout(actor, config);
            SetReceiver(actor, config);
            SetAutorun(actor, config);
            SetStickiness(actor, config);
            SetInvoker(actor, config);

            return(config);
        }
Ejemplo n.º 8
0
        void RegisterAutoruns()
        {
            var autoruns = new Dictionary <string, string[]>();

            foreach (var actor in assemblies.SelectMany(x => x.ActorTypes()))
            {
                var ids = AutorunAttribute.From(actor);
                if (ids.Length > 0)
                {
                    autoruns.Add(ActorTypeName.Of(actor), ids);
                }
            }

            Bootstrapper <AutorunBootstrapper>(autoruns);
        }
Ejemplo n.º 9
0
        public void Dynamic_target_matching()
        {
            var system = new ActorSystemMock();

            var type       = typeof(DynamicTargetSelectorActor);
            var dispatcher = new Dispatcher(type);

            var specification = StreamSubscriptionSpecification.From(type, dispatcher).ElementAt(0);

            specification.Type = ActorTypeName.Of(typeof(DynamicTargetSelectorActor));

            var match = specification.Match(system, "foo");

            var message = new object();

            match.Receiver(message);

            Assert.That(system.RequestedRef, Is.Not.Null);
            Assert.That(system.RequestedRef.Path, Is.EqualTo(typeof(DynamicTargetSelectorActor).ToActorPath("bar")));
            Assert.That(system.RequestedRef.MessagePassedToTell, Is.SameAs(message));
        }