コード例 #1
0
        /// <inheritdoc />
        public void Modify(Uri replica, IList <Uri> allReplicas, IReplicaStorageProvider storageProvider, Request request, RequestParameters parameters, ref double weight)
        {
            var clusterState = globalStorageProvider.ObtainGlobalValue(storageKey, ClusterStateFactory);

            ModifyClusterWeightsIfNeed(clusterState);

            weight = ModifyAndApplyLimits(weight, clusterState.Weights.Get(replica, settings.WeightsTTL));
        }
コード例 #2
0
 public void SetUp()
 {
     settings = new RelativeWeightSettings()
     {
         WeightUpdatePeriod            = 200.Milliseconds(),
         PenaltyMultiplier             = 100,
         InitialWeight                 = 1,
         StatisticSmoothingConstant    = 100.Milliseconds(),
         WeightsDownSmoothingConstant  = 100.Milliseconds(),
         WeightsRaiseSmoothingConstant = 100.Milliseconds(),
         WeightsTTL  = 5.Minutes(),
         MinWeight   = 0.005,
         Sensitivity = 3
     };
     clusterState = new ClusterState(
         timeProvider: Substitute.For <ITimeProvider>(),
         rawClusterStatistic: Substitute.For <IRawClusterStatistic>(),
         statisticHistory: Substitute.For <IStatisticHistory>(),
         relativeWeightCalculator: Substitute.For <IRelativeWeightCalculator>(),
         weightsNormalizer: Substitute.For <IWeightsNormalizer>(),
         weights: Substitute.For <IWeights>());
     replicaStorageProvider = Substitute.For <IReplicaStorageProvider>();
     storageProvider        = Substitute.For <IGlobalStorageProvider>();
     storageProvider.ObtainGlobalValue(Arg.Any <string>(), Arg.Any <Func <ClusterState> >())
     .Returns(info => clusterState);
     relativeWeightModifier = new RelativeWeightModifier(settings, "srv", "env", 0, 1, storageProvider);
 }