public RemoteBaggageRestrictionManagerTest()
 {
     _baggageRestrictionProxy = Substitute.For <IBaggageRestrictionManagerProxy>();
     _inMemoryMetricsFactory  = new InMemoryMetricsFactory();
     _metrics   = new MetricsImpl(_inMemoryMetricsFactory);
     _undertest = new RemoteBaggageRestrictionManager(SERVICE_NAME, _baggageRestrictionProxy, _metrics, false);
 }
Example #2
0
 public RemoteBaggageRestrictionManager(
     string serviceName,
     IBaggageRestrictionManagerProxy proxy,
     IMetrics metrics,
     bool denyBaggageOnInitializationFailure
     )
     : this(serviceName, proxy, metrics, denyBaggageOnInitializationFailure, DefaultRefreshInveral)
 {
 }
Example #3
0
 public RemoteBaggageRestrictionManager(
     string serviceName,
     IBaggageRestrictionManagerProxy proxy,
     IMetrics metrics,
     bool denyBaggageOnInitializationFailure,
     TimeSpan refreshInterval
     )
     : this(serviceName, proxy, metrics, denyBaggageOnInitializationFailure, refreshInterval, DefaultInitialDelay)
 {
 }
Example #4
0
        /// <summary>
        /// Creates a <see cref="RemoteBaggageRestrictionManager"/> that fetches <see cref="BaggageRestrictionResponse"/> from a remote
        /// agent and keeps track of <see cref="Restriction"/> for a service.
        /// <para/>
        /// <paramref name="initialDelay"/> is only exposed for testing purposes so users can determine when the first call to
        /// remote agent is made. Under normal operations, this RemoteBaggageRestrictionManager will start up and
        /// asynchronously fetch restrictions. If the user wants to know if restrictions are ready, they can check via
        /// isReady().
        /// </summary>
        /// <param name="serviceName">Restrictions for this service are kept track of.</param>
        /// <param name="proxy">Proxy to remote agent.</param>
        /// <param name="metrics">Metrics for metrics emission.</param>
        /// <param name="denyBaggageOnInitializationFailure">
        /// Determines the startup failure mode of <see cref="RemoteBaggageRestrictionManager"/>.
        /// If <paramref name="denyBaggageOnInitializationFailure"/> is true,
        /// <see cref="RemoteBaggageRestrictionManager"/> will not allow any baggage to be written
        /// until baggage restrictions have been retrieved from agent. If
        /// <paramref name="denyBaggageOnInitializationFailure"/> is false,
        /// <see cref="RemoteBaggageRestrictionManager"/> will allow any baggage to be written
        /// until baggage restrictions have been retrieved from agent.
        /// </param>
        /// <param name="refreshInterval">How often restriction are fetched from remote agent.</param>
        /// <param name="initialDelay">Delay before first fetch of restrictions.</param>
        public RemoteBaggageRestrictionManager(
            string serviceName,
            IBaggageRestrictionManagerProxy proxy,
            IMetrics metrics,
            bool denyBaggageOnInitializationFailure,
            TimeSpan refreshInterval,
            TimeSpan initialDelay
            )
        {
            _serviceName = serviceName;
            _proxy       = proxy;
            _metrics     = metrics;
            _denyBaggageOnInitializationFailure = denyBaggageOnInitializationFailure;
            _initialized        = false;
            _invalidRestriction = new Restriction(false, 0);
            _validRestriction   = new Restriction(true, Restriction.DefaultMaxValueLength);

            _pollTimer = new Timer(_ => { UpdateBaggageRestrictions(); }, null, initialDelay, refreshInterval);
        }