示例#1
0
        public void LeastShardAllocationStrategy_must_limit_number_of_simultaneous_rebalance()
        {
            var allocationStrategy = new LeastShardAllocationStrategy(rebalanceThreshold: 3, maxSimultaneousRebalance: 2);
            var allocations        = CreateAllocations(aCount: 1, bCount: 10);

            allocationStrategy.Rebalance(allocations, ImmutableHashSet <string> .Empty).Result.Should().BeEquivalentTo("002", "003");
            allocationStrategy.Rebalance(allocations, ImmutableHashSet <string> .Empty.Add("002").Add("003")).Result.Should().BeEmpty();
        }
示例#2
0
        public void LeastShardAllocationStrategy_must_rebalance_from_region_with_most_number_of_shards_4_4_0_rebalanceThreshold_1()
        {
            var allocationStrategy = new LeastShardAllocationStrategy(rebalanceThreshold: 1, maxSimultaneousRebalance: 10);
            var allocations        = CreateAllocations(aCount: 4, bCount: 4);

            allocationStrategy.Rebalance(allocations, ImmutableHashSet <string> .Empty).Result.Should().BeEquivalentTo("001");
            allocationStrategy.Rebalance(allocations, ImmutableHashSet <string> .Empty.Add("001")).Result.Should().BeEquivalentTo("005");
        }
示例#3
0
        public void LeastShardAllocationStrategy_must_rebalance_from_region_with_most_number_of_shards_5_5_0_rebalanceThreshold_2()
        {
            var allocationStrategy = new LeastShardAllocationStrategy(rebalanceThreshold: 2, maxSimultaneousRebalance: 10);
            var allocations        = CreateAllocations(aCount: 5, bCount: 5);

            // optimal would => [4, 4, 2] or even => [3, 4, 3]
            allocationStrategy.Rebalance(allocations, ImmutableHashSet <string> .Empty).Result.Should().BeEquivalentTo("001", "002");
            // if 001 and 002 are not started quickly enough this is stopping more than optimal
            allocationStrategy.Rebalance(allocations, ImmutableHashSet <string> .Empty.Add("001").Add("002")).Result.Should().BeEquivalentTo("006", "007");
            allocationStrategy.Rebalance(allocations, ImmutableHashSet <string> .Empty.Add("001").Add("002").Add("006").Add("007")).Result.Should().BeEquivalentTo("003");
        }
示例#4
0
        public void LeastShardAllocationStrategy_must_rebalance_rebalance_from_region_with_most_number_of_shards_1_3_0_rebalanceThreshold_2()
        {
            var allocationStrategy = new LeastShardAllocationStrategy(rebalanceThreshold: 2, maxSimultaneousRebalance: 10);
            var allocations        = CreateAllocations(aCount: 1, bCount: 2);

            // so far regionB has 2 shards and regionC has 0 shards, but the diff is <= rebalanceThreshold
            allocationStrategy.Rebalance(allocations, ImmutableHashSet <string> .Empty).Result.Should().BeEmpty();

            var allocations2 = CreateAllocations(aCount: 1, bCount: 3);

            allocationStrategy.Rebalance(allocations2, ImmutableHashSet <string> .Empty).Result.Should().BeEquivalentTo("002");
            allocationStrategy.Rebalance(allocations2, ImmutableHashSet <string> .Empty.Add("002")).Result.Should().BeEmpty();
        }
示例#5
0
        public void LeastShardAllocationStrategy_must_not_pick_shards_that_are_in_progress()
        {
            var allocationStrategy = new LeastShardAllocationStrategy(rebalanceThreshold: 3, maxSimultaneousRebalance: 4);
            var allocations        = CreateAllocations(aCount: 10);

            allocationStrategy.Rebalance(allocations, ImmutableHashSet <string> .Empty.Add("002").Add("003")).Result.Should().BeEquivalentTo("001", "004");
        }
示例#6
0
        public void LeastShardAllocationStrategy_must_not_rebalance_when_diff_equal_to_threshold_2_2_0_rebalanceThreshold_2()
        {
            var allocationStrategy = new LeastShardAllocationStrategy(rebalanceThreshold: 2, maxSimultaneousRebalance: 10);
            var allocations        = CreateAllocations(aCount: 2, bCount: 2);

            allocationStrategy.Rebalance(allocations, ImmutableHashSet <string> .Empty).Result.Should().BeEmpty();
        }
        public void LeastShardAllocationStrategy_dont_rebalance_excessive_shards_if_maxSimultaneousRebalance_gt_rebalanceThreshold()
        {
            var allocationStrategy = new LeastShardAllocationStrategy(2, 5);
            var allocations        = new Dictionary <IActorRef, IImmutableList <string> >
            {
                { _regionA, new [] { "shard1", "shard2", "shard3", "shard4", "shard5", "shard6", "shard7", "shard8" }.ToImmutableList() },
                { _regionB, new [] { "shard9", "shard10", "shard11", "shard12" }.ToImmutableList() }
            }.ToImmutableDictionary();

            var r1 = allocationStrategy.Rebalance(allocations, ImmutableHashSet.Create("shard2")).Result;

            r1.Should().BeEquivalentTo(new[] { "shard1", "shard3", "shard4" });

            var r2 = _allocationStrategy.Rebalance(allocations, ImmutableHashSet.Create("shard5", "shard6", "shard7", "shard8")).Result;

            r2.Count.Should().Be(0);
        }