public void ConsistentHashingRouterMustSelectDestinationWithDefinedHashMapping()
        {
            ConsistentHashMapping hashMapping = msg =>
            {
                if (msg is Msg2)
                {
                    var m2 = msg as Msg2;
                    return(m2.Key);
                }

                return(null);
            };
            var router2 =
                Sys.ActorOf(new ConsistentHashingPool(1, null, null, null, hashMapping: hashMapping).Props(Props.Create <Echo>()), "router2");

            router2.Tell(new Msg2("a", "A"));
            var destinationA = ExpectMsg <IActorRef>();

            router2.Tell(new ConsistentHashableEnvelope("AA", "a"));
            ExpectMsg(destinationA);

            router2.Tell(new Msg2(17, "A"));
            var destinationB = ExpectMsg <IActorRef>();

            router2.Tell(new ConsistentHashableEnvelope("BB", 17));
            ExpectMsg(destinationB);

            router2.Tell(new Msg2(new MsgKey("c"), "C"));
            var destinationC = ExpectMsg <IActorRef>();

            router2.Tell(new ConsistentHashableEnvelope("CC", new MsgKey("c")));
            ExpectMsg(destinationC);
        }
Beispiel #2
0
        AClusterRouterWithConsistentHashingPoolMustHandleCombinationOfConfiguredRouterAndProgramaticallyDefinedHashMappingAndClusterConfig
            ()
        {
            RunOn(() =>
            {
                ConsistentHashMapping hashMapping = msg =>
                {
                    if (msg is string)
                    {
                        return(msg);
                    }
                    return(null);
                };

                var router4 =
                    Sys.ActorOf(
                        new ClusterRouterPool(local: new ConsistentHashingPool(0).WithHashMapping(hashMapping),
                                              settings: new ClusterRouterPoolSettings(totalInstances: 10, maxInstancesPerNode: 2,
                                                                                      allowLocalRoutees: true, useRole: null)).Props(Props.Create <ConsistentHashingRouterMultiNodeConfig.Echo>()), "router4");

                AssertHashMapping(router4);
            }, _config.First);

            EnterBarrier("after-7");
        }
Beispiel #3
0
 public ConsistentHashingGroup(IEnumerable <string> paths, int virtualNodesFactor = 0,
                               ConsistentHashMapping hashMapping = null)
     : base(paths)
 {
     VirtualNodesFactor = virtualNodesFactor;
     HashMapping        = hashMapping;
 }
        protected void A_cluster_router_with_consistent_hashing_pool_must_handle_combination_of_configured_router_and_programatically_defined_hash_mapping_and_cluster_config()
        {
            RunOn(() =>
            {
                ConsistentHashMapping hashMapping = msg =>
                {
                    if (msg is string)
                    {
                        return(msg);
                    }
                    return(null);
                };

                var router4 =
                    Sys.ActorOf(
                        new ClusterRouterPool(
                            local: new ConsistentHashingPool(0).WithHashMapping(hashMapping),
                            settings: new ClusterRouterPoolSettings(
                                10,
                                1,
                                allowLocalRoutees: true,
                                useRole: null)).Props(Props.Create <ConsistentHashingRouterMultiNodeConfig.Echo>()), "router4");

                AssertHashMapping(router4);
            }, _config.First);

            EnterBarrier("after-6");
        }
        public void ConsistentHashingGroupRouterMustSelectDestinationWithDefinedHashMapping()
        {
            ConsistentHashMapping hashMapping = msg =>
            {
                if (msg is Msg2)
                {
                    var m2 = msg as Msg2;
                    return(m2.Key);
                }

                return(null);
            };
            var router4 =
                Sys.ActorOf(Props.Empty.WithRouter(new ConsistentHashingGroup(new[] { c }, hashMapping: hashMapping)), "router4");

            router4.Tell(new Msg2("a", "A"));
            var destinationA = ExpectMsg <IActorRef>();

            router4.Tell(new ConsistentHashableEnvelope("AA", "a"));
            ExpectMsg(destinationA);

            router4.Tell(new Msg2(17, "A"));
            var destinationB = ExpectMsg <IActorRef>();

            router4.Tell(new ConsistentHashableEnvelope("BB", 17));
            ExpectMsg(destinationB);

            router4.Tell(new Msg2(new MsgKey("c"), "C"));
            var destinationC = ExpectMsg <IActorRef>();

            router4.Tell(new ConsistentHashableEnvelope("CC", new MsgKey("c")));
            ExpectMsg(destinationC);
        }
Beispiel #6
0
 public ConsistentHashingGroup(IEnumerable <IActorRef> routees, int virtualNodesFactor = 0,
                               ConsistentHashMapping hashMapping = null)
     : base(routees)
 {
     VirtualNodesFactor = virtualNodesFactor;
     HashMapping        = hashMapping;
 }
Beispiel #7
0
 /// <summary>
 /// Initializes a new instance of the <see cref="ConsistentHashingPool"/> class.
 /// </summary>
 /// <param name="nrOfInstances">The nr of instances.</param>
 /// <param name="resizer">The resizer.</param>
 /// <param name="supervisorStrategy">The supervisor strategy.</param>
 /// <param name="routerDispatcher">The router dispatcher.</param>
 /// <param name="usePoolDispatcher">if set to <c>true</c> [use pool dispatcher].</param>
 /// <param name="virtualNodesFactor">The number of virtual nodes to use on the hash ring</param>
 /// <param name="hashMapping">The consistent hash mapping function to use on incoming messages</param>
 public ConsistentHashingPool(int nrOfInstances, Resizer resizer, SupervisorStrategy supervisorStrategy,
                              string routerDispatcher, bool usePoolDispatcher = false, int virtualNodesFactor = 0,
                              ConsistentHashMapping hashMapping = null)
     : base(nrOfInstances, resizer, supervisorStrategy, routerDispatcher, usePoolDispatcher)
 {
     VirtualNodesFactor = virtualNodesFactor;
     _hashMapping       = hashMapping;
 }
Beispiel #8
0
 public ConsistentHashingRoutingLogic(ActorSystem system, int virtualNodesFactor,
                                      ConsistentHashMapping hashMapping)
 {
     _system      = system;
     _log         = new Lazy <ILoggingAdapter>(() => Logging.GetLogger(_system, this), true);
     _hashMapping = hashMapping;
     _selfAddress = system.AsInstanceOf <ExtendedActorSystem>().Provider.DefaultAddress;
     _vnodes      = virtualNodesFactor == 0 ? system.Settings.DefaultVirtualNodesFactor : virtualNodesFactor;
 }
Beispiel #9
0
        public ConsistentHashingRoutingLogic WithHashMapping(ConsistentHashMapping mapping)
        {
            if (mapping == null)
            {
                throw new ArgumentNullException("mapping");
            }

            return(new ConsistentHashingRoutingLogic(_system, _vnodes, mapping));
        }
 /// <summary>
 /// Initializes a new instance of the <see cref="ConsistentHashingGroup"/> class.
 /// </summary>
 /// <param name="paths">An enumeration of actor paths used by the group router.</param>
 /// <param name="virtualNodesFactor">The number of virtual nodes to use on the hash ring.</param>
 /// <param name="hashMapping">The consistent hash mapping function to use on incoming messages.</param>
 /// <param name="routerDispatcher">The dispatcher to use when passing messages to the routees.</param>
 public ConsistentHashingGroup(
     IEnumerable <string> paths,
     int virtualNodesFactor,
     ConsistentHashMapping hashMapping,
     string routerDispatcher)
     : base(paths, routerDispatcher)
 {
     VirtualNodesFactor = virtualNodesFactor;
     _hashMapping       = hashMapping;
 }
        public void AClusterRouterWithConsistentHashingGroupMustSendToSameDestinationsFromDifferentNodes()
        {
            Sys.ActorOf(Props.Create <ClusterConsistentHashingGroupSpecConfig.Destination>(), "dest");
            AwaitClusterUp(_config.First, _config.Second, _config.Third);
            EnterBarrier("after-1");

            ConsistentHashMapping hashMapping = msg =>
            {
                if (msg is string)
                {
                    return(msg);
                }
                return(null);
            };

            var paths = new List <string>()
            {
                "/user/dest"
            };
            var router =
                Sys.ActorOf(
                    new ClusterRouterGroup(new ConsistentHashingGroup(paths).WithHashMapping(hashMapping),
                                           new ClusterRouterGroupSettings(10, true, null, ImmutableHashSet.Create <string>(paths.ToArray())))
                    .Props(), "router");

            // it may take some time until router receives cluster member events
            AwaitAssert(() =>
            {
                var members = CurrentRoutees(router).Members;
                members.Count().ShouldBe(3);
            });
            var keys = new[] { "A", "B", "C", "D", "E", "F", "G" };

            foreach (var key in Enumerable.Range(1, 10).SelectMany(i => keys))
            {
                router.Tell(key, TestActor);
            }
            EnterBarrier("messages-sent");
            router.Tell(new Broadcast(new Get()));
            var a = ExpectMsg <ClusterConsistentHashingGroupSpecConfig.Collected>().Messages;
            var b = ExpectMsg <ClusterConsistentHashingGroupSpecConfig.Collected>().Messages;
            var c = ExpectMsg <ClusterConsistentHashingGroupSpecConfig.Collected>().Messages;

            a.Intersect(b).Count().ShouldBe(0);
            a.Intersect(c).Count().ShouldBe(0);
            b.Intersect(c).Count().ShouldBe(0);

            (a.Count + b.Count + c.Count).ShouldBe(keys.Length);
            EnterBarrier("after-2");
        }
Beispiel #12
0
        public void A_cluster_router_with_consistent_hashing_group_must_send_to_same_destinations_from_different_nodes()
        {
            ConsistentHashMapping hashMapping = msg =>
            {
                if (msg is string)
                {
                    return(msg);
                }
                return(null);
            };

            var paths = new List <string> {
                "/user/dest"
            };
            var router =
                Sys.ActorOf(
                    new ClusterRouterGroup(
                        local: new ConsistentHashingGroup(paths).WithHashMapping(hashMapping),
                        settings: new ClusterRouterGroupSettings(
                            10,
                            ImmutableHashSet.Create(paths.ToArray()),
                            allowLocalRoutees: true,
                            useRole: null))
                    .Props(), "router");

            // it may take some time until router receives cluster member events
            AwaitAssert(() =>
            {
                CurrentRoutees(router).Members.Should().HaveCount(3);
            });
            var keys = new[] { "A", "B", "C", "D", "E", "F", "G" };

            foreach (var key in Enumerable.Range(1, 10).SelectMany(i => keys))
            {
                router.Tell(key, TestActor);
            }
            EnterBarrier("messages-sent");
            router.Tell(new Broadcast(new ClusterConsistentHashingGroupSpecConfig.Get()));
            var a = ExpectMsg <ClusterConsistentHashingGroupSpecConfig.Collected>().Messages;
            var b = ExpectMsg <ClusterConsistentHashingGroupSpecConfig.Collected>().Messages;
            var c = ExpectMsg <ClusterConsistentHashingGroupSpecConfig.Collected>().Messages;

            a.Intersect(b).Count().Should().Be(0);
            a.Intersect(c).Count().Should().Be(0);
            b.Intersect(c).Count().Should().Be(0);

            (a.Count + b.Count + c.Count).Should().Be(keys.Length);
            EnterBarrier("after-2");
        }
        protected void A_cluster_router_with_consistent_hashing_pool_must_handle_combination_of_configured_router_and_programatically_defined_hash_mapping()
        {
            RunOn(() =>
            {
                ConsistentHashMapping hashMapping = msg =>
                {
                    if (msg is string)
                    {
                        return(msg);
                    }
                    return(null);
                };
                var router3 = Sys.ActorOf(new ConsistentHashingPool(nrOfInstances: 0).WithHashMapping(hashMapping)
                                          .Props(Props.Create <ConsistentHashingRouterMultiNodeConfig.Echo>()), "router3");

                AssertHashMapping(router3);
            }, _config.First);

            EnterBarrier("after-5");
        }
Beispiel #14
0
        AClusterRouterWithConsistentHashingPoolMustHandleCombinationOfConfiguredRouterAndProgramaticallyDefinedHashMapping()
        {
            RunOn(() =>
            {
                ConsistentHashMapping hashMapping = msg =>
                {
                    if (msg is string)
                    {
                        return(msg);
                    }
                    return(null);
                };
                var router3 =
                    Sys.ActorOf(new ConsistentHashingPool(0).WithHashMapping(hashMapping).Props(Props.Create <ConsistentHashingRouterMultiNodeConfig.Echo>()), "router3");

                AssertHashMapping(router3);
            }, _config.First);

            EnterBarrier("after-6");
        }
Beispiel #15
0
        public void Consistent_hashing_group_router_must_select_destination_with_defined_hash_mapping()
        {
            ConsistentHashMapping hashMapping = msg =>
            {
                if (msg is Msg2)
                {
                    var m2 = msg as Msg2;
                    return(m2.Key);
                }

                return(null);
            };

            var paths = new List <string> {
                c.Path.ToString()
            };
            var router4 = Sys.ActorOf(new ConsistentHashingGroup(paths, hashMapping).Props(), "router4");

            router4.Tell(new Msg2("a", "A"));
            var destinationA = ExpectMsg <IActorRef>();

            router4.Tell(new ConsistentHashableEnvelope("AA", "a"));
            ExpectMsg(destinationA);

            router4.Tell(new Msg2(17, "A"));
            var destinationB = ExpectMsg <IActorRef>();

            router4.Tell(new ConsistentHashableEnvelope("BB", 17));
            ExpectMsg(destinationB);

            router4.Tell(new Msg2(new MsgKey("c"), "C"));
            var destinationC = ExpectMsg <IActorRef>();

            router4.Tell(new ConsistentHashableEnvelope("CC", new MsgKey("c")));
            ExpectMsg(destinationC);
        }
 /// <summary>
 /// Initializes a new instance of the <see cref="ConsistentHashingPool"/> class.
 /// </summary>
 /// <param name="nrOfInstances">The initial number of routees in the pool.</param>
 /// <param name="resizer">The resizer to use when dynamically allocating routees to the pool.</param>
 /// <param name="supervisorStrategy">The strategy to use when supervising the pool.</param>
 /// <param name="routerDispatcher">The dispatcher to use when passing messages to the routees.</param>
 /// <param name="usePoolDispatcher"><c>true</c> to use the pool dispatcher; otherwise <c>false</c>.</param>
 /// <param name="virtualNodesFactor">The number of virtual nodes to use on the hash ring.</param>
 /// <param name="hashMapping">The consistent hash mapping function to use on incoming messages.</param>
 public ConsistentHashingPool(
     int nrOfInstances,
     Resizer resizer,
     SupervisorStrategy supervisorStrategy,
     string routerDispatcher,
     bool usePoolDispatcher = false,
     int virtualNodesFactor = 0,
     ConsistentHashMapping hashMapping = null)
     : base(nrOfInstances, resizer, supervisorStrategy, routerDispatcher, usePoolDispatcher)
 {
     VirtualNodesFactor = virtualNodesFactor;
     _hashMapping = hashMapping;
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="ConsistentHashingPool"/> class.
 /// </summary>
 /// <param name="nrOfInstances">The initial number of routees in the pool.</param>
 /// <param name="hashMapping">The consistent hash mapping function to use on incoming messages.</param>
 public ConsistentHashingPool(
     int nrOfInstances,
     ConsistentHashMapping hashMapping)
     : this(nrOfInstances, null, Pool.DefaultSupervisorStrategy, Dispatchers.DefaultDispatcherId, false, 0, hashMapping)
 {
 }
        /// <summary>
        /// Creates a new <see cref="ConsistentHashingRoutingLogic"/> router logic with a given <see cref="ConsistentHashMapping"/>.
        /// 
        /// <note>
        /// This method is immutable and returns a new instance of the router.
        /// </note>
        /// </summary>
        /// <param name="mapping">The <see cref="ConsistentHashMapping"/> used to configure the new router.</param>
        /// <exception cref="ArgumentNullException">
        /// This exception is thrown if the given <paramref name="mapping"/> is undefined.
        /// </exception>
        /// <returns>A new router logic with the provided <paramref name="mapping"/>.</returns>
        public ConsistentHashingRoutingLogic WithHashMapping(ConsistentHashMapping mapping)
        {
            if (mapping == null)
                throw new ArgumentNullException(nameof(mapping), "The mapping cannot be null.");

            return new ConsistentHashingRoutingLogic(_system, _vnodes, mapping);
        }
 /// <summary>
 /// Initializes a new instance of the <see cref="ConsistentHashingRoutingLogic"/> class.
 /// </summary>
 /// <param name="system">The actor system that owns the router with this logic.</param>
 /// <param name="virtualNodesFactor">The number of virtual nodes to use on the hash ring.</param>
 /// <param name="hashMapping">The consistent hash mapping function to use on incoming messages.</param>
 public ConsistentHashingRoutingLogic(ActorSystem system, int virtualNodesFactor,
     ConsistentHashMapping hashMapping)
 {
     _system = system;
     _log = new Lazy<ILoggingAdapter>(() => Logging.GetLogger(_system, this), true);
     _hashMapping = hashMapping;
     _selfAddress = system.AsInstanceOf<ExtendedActorSystem>().Provider.DefaultAddress;
     _vnodes = virtualNodesFactor == 0 ? system.Settings.DefaultVirtualNodesFactor : virtualNodesFactor;
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="ConsistentHashingGroup"/> class.
 /// </summary>
 /// <param name="paths">An enumeration of actor paths used by the group router.</param>
 /// <param name="hashMapping">The consistent hash mapping function to use on incoming messages.</param>
 public ConsistentHashingGroup(
     IEnumerable <string> paths,
     ConsistentHashMapping hashMapping)
     : this(paths, 0, hashMapping, Dispatchers.DefaultDispatcherId)
 {
 }
 public ConsistentHashingGroup(IEnumerable<IActorRef> routees, int virtualNodesFactor = 0,
     ConsistentHashMapping hashMapping = null)
     : base(routees)
 {
     VirtualNodesFactor = virtualNodesFactor;
     HashMapping = hashMapping;
 }
Beispiel #22
0
 /// <summary>
 /// Apply a <see cref="ConsistentHashMapping"/> to the <see cref="ConsistentHashingPool"/>.
 ///
 /// Note: this method is immutable and will return a new instance.
 /// </summary>
 public ConsistentHashingPool WithHashMapping(ConsistentHashMapping mapping)
 {
     return(new ConsistentHashingPool(NrOfInstances, Resizer, SupervisorStrategy, RouterDispatcher,
                                      UsePoolDispatcher, VirtualNodesFactor, mapping));
 }
        public ConsistentHashingRoutingLogic WithHashMapping(ConsistentHashMapping mapping)
        {
            if (mapping == null)
                throw new ArgumentNullException("mapping");

            return new ConsistentHashingRoutingLogic(_system, _vnodes, mapping);
        }
 /// <summary>
 /// Initializes a new instance of the <see cref="ConsistentHashingPool"/> class.
 /// </summary>
 /// <param name="nrOfInstances">The initial number of routees in the pool.</param>
 /// <param name="hashMapping">The consistent hash mapping function to use on incoming messages.</param>
 public ConsistentHashingPool(
     int nrOfInstances,
     ConsistentHashMapping hashMapping)
     : this(nrOfInstances, null, Pool.DefaultSupervisorStrategy, Dispatchers.DefaultDispatcherId, false, 0, hashMapping)
 {
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="ConsistentHashingGroup"/> class.
 /// </summary>
 /// <param name="paths">An enumeration of actor paths used by the group router.</param>
 /// <param name="virtualNodesFactor">The number of virtual nodes to use on the hash ring.</param>
 /// <param name="hashMapping">The consistent hash mapping function to use on incoming messages.</param>
 /// <param name="routerDispatcher">The dispatcher to use when passing messages to the routees.</param>
 public ConsistentHashingGroup(
     IEnumerable<string> paths,
     int virtualNodesFactor,
     ConsistentHashMapping hashMapping,
     string routerDispatcher)
     : base(paths, routerDispatcher)
 {
     VirtualNodesFactor = virtualNodesFactor;
     _hashMapping = hashMapping;
 }
 public ConsistentHashingGroup(IEnumerable<string> paths, int virtualNodesFactor = 0,
     ConsistentHashMapping hashMapping = null)
     : base(paths)
 {
     VirtualNodesFactor = virtualNodesFactor;
     HashMapping = hashMapping;
 }
 /// <summary>
 /// Creates a new <see cref="ConsistentHashingPool"/> router with a given <see cref="ConsistentHashMapping"/>.
 /// 
 /// <note>
 /// This method is immutable and returns a new instance of the router.
 /// </note>
 /// </summary>
 /// <param name="mapping">The <see cref="ConsistentHashMapping"/> used to configure the new router.</param>
 /// <returns>A new router with the provided <paramref name="mapping"/>.</returns>
 public ConsistentHashingPool WithHashMapping(ConsistentHashMapping mapping)
 {
     return new ConsistentHashingPool(NrOfInstances, Resizer, SupervisorStrategy, RouterDispatcher,
         UsePoolDispatcher, VirtualNodesFactor, mapping);
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="ConsistentHashingGroup"/> class.
 /// </summary>
 /// <param name="paths">An enumeration of actor paths used by the group router.</param>
 /// <param name="hashMapping">The consistent hash mapping function to use on incoming messages.</param>
 public ConsistentHashingGroup(
     IEnumerable<string> paths,
     ConsistentHashMapping hashMapping)
     : this(paths, 0, hashMapping, Dispatchers.DefaultDispatcherId)
 {
 }
 /// <summary>
 /// Creates a new <see cref="ConsistentHashingGroup"/> router with a given <see cref="ConsistentHashMapping"/>.
 ///
 /// <note>
 /// This method is immutable and returns a new instance of the router.
 /// </note>
 /// </summary>
 /// <param name="mapping">The <see cref="ConsistentHashMapping"/> used to configure the new router.</param>
 /// <returns>A new router with the provided <paramref name="mapping"/>.</returns>
 public ConsistentHashingGroup WithHashMapping(ConsistentHashMapping mapping)
 {
     return(new ConsistentHashingGroup(InternalPaths, VirtualNodesFactor, mapping, RouterDispatcher));
 }
 /// <summary>
 /// Creates a new <see cref="ConsistentHashingGroup"/> router with a given <see cref="ConsistentHashMapping"/>.
 /// 
 /// <note>
 /// This method is immutable and returns a new instance of the router.
 /// </note>
 /// </summary>
 /// <param name="mapping">The <see cref="ConsistentHashMapping"/> used to configure the new router.</param>
 /// <returns>A new router with the provided <paramref name="mapping"/>.</returns>
 public ConsistentHashingGroup WithHashMapping(ConsistentHashMapping mapping)
 {
     return new ConsistentHashingGroup(Paths, VirtualNodesFactor, mapping, RouterDispatcher);
 }
Beispiel #31
0
 /// <summary>
 /// Apply a <see cref="ConsistentHashMapping"/> to the <see cref="ConsistentHashingGroup"/>.
 ///
 /// Note: this method is immutable and will return a new instance.
 /// </summary>
 public ConsistentHashingGroup WithHashMapping(ConsistentHashMapping mapping)
 {
     return(new ConsistentHashingGroup(Paths, VirtualNodesFactor, mapping));
 }