Exemplo n.º 1
0
        public void CounterInitialisationDefault()
        {
            //// Arrange
            PlayerPrefs.DeleteAll();

            //// Act
            var counterConfiguration = new CounterConfiguration()
            {
                SaveBest = CounterConfiguration.SaveType.None
            };
            var counter = new Counter(counterConfiguration);

            //// Assert
            Assert.AreEqual(counterConfiguration, counter.Configuration, "Counter configuration not initialised correctly");
            Assert.AreEqual(-1, counter.Identifier, "Identifier configuration not initialised correctly");
            Assert.AreEqual(0, counter.IntAmount, "IntAmount not initialised correctly");
            Assert.AreEqual(0, counter.IntAmountSaved, "IntAmountLastSaved not initialised correctly");
            Assert.AreEqual(0, counter.IntAmountBest, "IntAmountBest not initialised correctly");
            Assert.AreEqual(0, counter.IntAmountBestSaved, "IntAmountBestLastSaved not initialised correctly");
            Assert.AreEqual(0, counter.FloatAmount, "FloatAmount not initialised correctly");
            Assert.AreEqual(0, counter.FloatAmountSaved, "FloatAmountLastSaved not initialised correctly");
            Assert.AreEqual(0, counter.FloatAmountBest, "FloatAmountBest not initialised correctly");
            Assert.AreEqual(0, counter.FloatAmountBestSaved, "FloatAmountBestLastSaved not initialised correctly");
            Assert.AreEqual(CounterConfiguration.CounterTypeEnum.Int, counter.Configuration.CounterType, "Configuration.CounterType not initialised correctly");
            Assert.AreEqual(0, counter.Configuration.IntMinimum, "Configuration.IntMinimum not initialised correctly");
            Assert.AreEqual(int.MaxValue, counter.Configuration.IntMaximum, "Configuration.IntMaximum not initialised correctly");
            Assert.AreEqual(0, counter.Configuration.FloatMinimum, "Configuration.FloatMinimum not initialised correctly");
            Assert.AreEqual(float.MaxValue, counter.Configuration.FloatMaximum, "Configuration.FloatMaximum not initialised correctly");
            Assert.AreEqual(CounterConfiguration.SaveType.None, counter.Configuration.Save, "Configuration.PersistChanges not initialised correctly");
        }
Exemplo n.º 2
0
        public void BoundariesStrongTest()
        {
            string counterName  = "strongTestBoundaries";
            int    initialValue = 1;
            var    rcm          = remoteManager.GetCounterManager();
            var    cc           = new CounterConfiguration(initialValue, 0, 20, 0, CounterType.BOUNDED_STRONG, Storage.VOLATILE);

            rcm.DefineCounter(counterName, cc);
            var counter = rcm.GetStrongCounter(counterName);

            Assert.AreEqual(1, counter.GetValue());
            Assert.Throws <Infinispan.HotRod.Exceptions.CounterLowerBoundException>(() =>
                                                                                    { counter.AddAndGet(-10); });
            Assert.Throws <Infinispan.HotRod.Exceptions.CounterUpperBoundException>(() =>
                                                                                    { counter.AddAndGet(30); });
            Assert.Throws <Infinispan.HotRod.Exceptions.CounterLowerBoundException>(() =>
                                                                                    { counter.CompareAndSet(20, -1); });
            Assert.Throws <Infinispan.HotRod.Exceptions.CounterUpperBoundException>(() =>
                                                                                    { counter.CompareAndSet(20, 21); });
            Assert.Throws <Infinispan.HotRod.Exceptions.CounterLowerBoundException>(() =>
                                                                                    { counter.CompareAndSwap(20, -1); });
            Assert.Throws <Infinispan.HotRod.Exceptions.CounterUpperBoundException>(() =>
                                                                                    { counter.CompareAndSwap(20, 21); });
            rcm.Remove(counterName);
        }
Exemplo n.º 3
0
        public void ConfigurationWeakTest()
        {
            string counterName = "weakTestConfiguration";
            var    rcm         = remoteManager.GetCounterManager();
            var    cc          = new CounterConfiguration(0, 0, 0, 64, CounterType.WEAK, Storage.VOLATILE);

            rcm.DefineCounter(counterName, cc);
            var counter = rcm.GetWeakCounter(counterName);
            ICounterConfiguration retCc = counter.GetConfiguration();

            Assert.AreEqual(cc.GetConcurrencyLevel(), retCc.GetConcurrencyLevel());
            Assert.AreEqual(cc.GetType(), retCc.GetType());
            Assert.AreEqual(cc.GetStorage(), retCc.GetStorage());
            Assert.AreEqual(counter.GetName(), counterName);
            rcm.Remove(counterName);

            string counterName1 = "weakTestConfiguration1";
            var    cc1          = new CounterConfiguration(0, 0, 0, 1, CounterType.WEAK, Storage.PERSISTENT);

            rcm.DefineCounter(counterName1, cc1);
            counter = rcm.GetWeakCounter(counterName1);
            ICounterConfiguration retCc1 = counter.GetConfiguration();

            Assert.AreEqual(cc1.GetConcurrencyLevel(), retCc1.GetConcurrencyLevel());
            Assert.AreEqual(cc1.GetType(), retCc1.GetType());
            Assert.AreEqual(cc1.GetStorage(), retCc1.GetStorage());
            Assert.AreEqual(counter.GetName(), counterName1);
            rcm.Remove(counterName1);
        }
Exemplo n.º 4
0
        public void CounterPersistentValuesSavedInt(string prefsPrefix,
                                                    string counterName, int amount, int bestAmount)
        {
            //// Arrange
            PlayerPrefs.DeleteAll();

            var counterConfiguration = new CounterConfiguration()
            {
                Name        = counterName,
                Save        = CounterConfiguration.SaveType.Always,
                CounterType = CounterConfiguration.CounterTypeEnum.Int
            };
            var counter = new Counter(counterConfiguration, prefsPrefix);

            counter.IntAmount = bestAmount; // to set best
            counter.IntAmount = amount;

            //// Act
            counter.UpdatePlayerPrefs();
            PlayerPrefs.Save();

            //// Assert
            Assert.AreEqual(amount, PlayerPrefs.GetInt(string.Format("{0}CI.{1}", prefsPrefix, counterName), 0), "IntAmount not saved correctly");
            Assert.AreEqual(bestAmount, PlayerPrefs.GetInt(string.Format("{0}CIH.{1}", prefsPrefix, counterName), 0), "HighestIntAmount not saved correctly");
        }
Exemplo n.º 5
0
        public void CounterNonPersistentValuesNotSavedFloat(string prefsPrefix,
                                                            string counterName, float amount, float bestAmount)
        {
            //// Arrange
            PlayerPrefs.DeleteAll();

            var counterConfiguration = new CounterConfiguration()
            {
                Name        = counterName,
                SaveBest    = CounterConfiguration.SaveType.None, // Save defaults to none
                CounterType = CounterConfiguration.CounterTypeEnum.Float
            };
            var counter = new Counter(counterConfiguration, prefsPrefix);

            counter.FloatAmount = amount;
            //counter.FloatAmountBest = bestAmount;

            //// Act
            counter.UpdatePlayerPrefs();
            PlayerPrefs.Save();

            //// Assert
            Assert.IsFalse(PlayerPrefs.HasKey(string.Format("{0}CI.{1}", prefsPrefix, counterName)), "FloatAmount should not have been saved");
            Assert.IsFalse(PlayerPrefs.HasKey(string.Format("{0}CIH.{1}", prefsPrefix, counterName)), "HighestFloatAmount should not have been saved");
        }
Exemplo n.º 6
0
        public void AddRemoveCounterWithListenerWeakTest()
        {
            Semaphore s = new Semaphore(0, 1);
            Action <Event.CounterEvent> a = (Event.CounterEvent e) =>
            {
                s.Release();
            };

            string counterName = "weak1TestAddRemoveListener";

            Event.CounterListener cl = new Event.CounterListener(counterName, a);
            var rcm = remoteManager.GetCounterManager();
            var cc  = new CounterConfiguration(5, 0, 20, 8, CounterType.WEAK, Storage.VOLATILE);

            rcm.DefineCounter(counterName, cc);
            var    counter = rcm.GetWeakCounter(counterName);
            object o       = counter.AddListener(cl);

            counter.Add(10);
            Assert.True(s.WaitOne(5000));
            counter.Remove();

            // After the remove no events should arrive
            changeCounterFromAnotherCacheManager();
            Assert.False(s.WaitOne(5000));

            // if the counter is recreated, events should come again
            var counter1 = rcm.GetWeakCounter(counterName);

            counter1.Add(10);
            Assert.AreEqual(15, counter1.GetValue());
            Assert.True(s.WaitOne(5000));
            counter.RemoveListener(o);
        }
Exemplo n.º 7
0
        public void ConfigurationStrongTest()
        {
            string counterName = "strongTestConfiguration";
            var    rcm         = remoteManager.GetCounterManager();
            var    cc          = new CounterConfiguration(0, -256, 65536, 64, CounterType.BOUNDED_STRONG, Storage.VOLATILE);

            rcm.DefineCounter(counterName, cc);
            var counter = rcm.GetStrongCounter(counterName);
            ICounterConfiguration retCc = counter.GetConfiguration();

            Assert.AreEqual(cc.GetLowerBound(), retCc.GetLowerBound());
            Assert.AreEqual(cc.GetUpperBound(), retCc.GetUpperBound());
            Assert.AreEqual(0, retCc.GetConcurrencyLevel());
            Assert.AreEqual(cc.GetType(), retCc.GetType());
            Assert.AreEqual(cc.GetStorage(), retCc.GetStorage());
            Assert.AreEqual(counter.GetName(), counterName);
            rcm.Remove(counterName);

            string counterName1 = "strongTestConfiguration1";
            var    cc1          = new CounterConfiguration(0, -100, 100, 1, CounterType.UNBOUNDED_STRONG,
                                                           Storage.PERSISTENT);

            rcm.DefineCounter(counterName1, cc1);
            counter = rcm.GetStrongCounter(counterName1);
            ICounterConfiguration retCc1 = counter.GetConfiguration();

            Assert.AreEqual(0, retCc1.GetLowerBound());
            Assert.AreEqual(0, retCc1.GetUpperBound());
            Assert.AreEqual(0, retCc1.GetConcurrencyLevel());
            Assert.AreEqual(cc1.GetType(), retCc1.GetType());
            Assert.AreEqual(cc1.GetStorage(), retCc1.GetStorage());
            Assert.AreEqual(counter.GetName(), counterName1);
            rcm.Remove(counterName1);
        }
        public override void OnInspectorGUI()
        {
            serializedObject.Update();

            ShowHeaderGUI();

            EditorGUILayout.PropertyField(_gameItemTypeProperty);
            EditorGUILayout.PropertyField(_contextProperty);

            var counterConfiguration = GameConfiguration.Instance.GetCounterConfiguration((GameConfiguration.GameItemType)_gameItemTypeProperty.enumValueIndex);

            string[] _counters = new string[counterConfiguration.Count];
            _counterIndex = 0; // initialise incase gameitem type changed
            for (int i = 0; i < counterConfiguration.Count; i++)
            {
                _counters[i] = counterConfiguration[i].Name;
                if (_counters[i] == _counterProperty.stringValue)
                {
                    _counterIndex = i;
                }
            }
            int newIndex = EditorGUILayout.Popup("Counter", _counterIndex, _counters);

            if (newIndex != _counterIndex || string.IsNullOrEmpty(_counterProperty.stringValue))
            {
                _counterProperty.stringValue = _counters[newIndex];
                _counterIndex = newIndex;
            }
            CounterConfiguration = counterConfiguration[_counterIndex];

            ShowFooterGUI();

            serializedObject.ApplyModifiedProperties();
        }
Exemplo n.º 9
0
        public Counter CreateCounter(string name, string help, CounterConfiguration configuration)
        {
            configuration = configuration ?? CounterConfiguration.Default;

            var metric = new Counter(name, help, configuration.LabelNames, configuration.SuppressInitialValue);

            return((Counter)_registry.GetOrAdd(metric));
        }
Exemplo n.º 10
0
        public void AddRemoveListenerWeakTest()
        {
            Semaphore s                   = new Semaphore(0, 1);
            bool      secondEvent         = false;
            Action <Event.CounterEvent> a = (Event.CounterEvent e) =>
            {
                if (!secondEvent)
                {
                    Assert.AreEqual(5, e.OldValue);
                    Assert.AreEqual(15, e.NewValue);
                    Assert.AreEqual(Event.CounterState.VALID, e.NewState);
                    Assert.AreEqual(Event.CounterState.VALID, e.OldState);
                    secondEvent = true;
                }
                s.Release();
            };

            Action <Event.CounterEvent> a2 = (Event.CounterEvent e) =>
            {
                Assert.AreEqual(6, e.OldValue);
                Assert.AreEqual(16, e.NewValue);
                Assert.AreEqual(Event.CounterState.VALID, e.NewState);
                Assert.AreEqual(Event.CounterState.VALID, e.OldState);
                s.Release();
            };

            string counterName = "weakTestAddRemoveListener";

            Event.CounterListener cl  = new Event.CounterListener(counterName, a);
            Event.CounterListener cl1 = new Event.CounterListener(counterName, a2);
            var rcm = remoteManager.GetCounterManager();
            var cc  = new CounterConfiguration(5, 0, 20, 8, CounterType.WEAK, Storage.VOLATILE);

            rcm.DefineCounter(counterName, cc);
            var    counter = rcm.GetWeakCounter(counterName);
            object o       = counter.AddListener(cl);

            counter.Add(10);
            Assert.True(s.WaitOne(5000));
            counter.RemoveListener(o);
            counter.Add(-9);
            Assert.False(s.WaitOne(5000));

            object o1 = counter.AddListener(cl1);

            counter.Add(10);
            Assert.True(s.WaitOne(5000));
            counter.RemoveListener(o1);
        }
Exemplo n.º 11
0
        public void CompareAndSetStrongTest()
        {
            string counterName  = "strongTestCompareAndSet";
            int    initialValue = 2;
            var    rcm          = remoteManager.GetCounterManager();
            var    cc           = new CounterConfiguration(initialValue, 0, 0, 0, CounterType.UNBOUNDED_STRONG, Storage.VOLATILE);

            rcm.DefineCounter(counterName, cc);
            var counter = rcm.GetStrongCounter(counterName);

            Assert.False(counter.CompareAndSet(0, 1));
            Assert.True(counter.CompareAndSet(2, 3));
            Assert.True(counter.CompareAndSet(3, 4));
            rcm.Remove(counterName);
        }
Exemplo n.º 12
0
        public void ResetStrongTest()
        {
            string counterName  = "strongTestReset";
            int    initialValue = 5;
            var    rcm          = remoteManager.GetCounterManager();
            var    cc           = new CounterConfiguration(initialValue, 0, 200, 8, CounterType.BOUNDED_STRONG, Storage.VOLATILE);

            rcm.DefineCounter(counterName, cc);
            var counter = rcm.GetStrongCounter(counterName);
            int val     = counter.GetValue();
            var name    = counter.GetName();

            Assert.AreEqual(initialValue, counter.GetValue());
            rcm.Remove(counterName);
        }
Exemplo n.º 13
0
        public void CompareAndSwapStrongTest()
        {
            string counterName  = "strongTestCompareAndSwap";
            int    initialValue = 3;
            var    rcm          = remoteManager.GetCounterManager();
            var    cc           = new CounterConfiguration(initialValue, 0, 0, 0, CounterType.UNBOUNDED_STRONG, Storage.VOLATILE);

            rcm.DefineCounter(counterName, cc);
            var counter = rcm.GetStrongCounter(counterName);

            Assert.AreEqual(3, counter.CompareAndSwap(1, 2));
            Assert.AreEqual(3, counter.CompareAndSwap(3, 2));
            Assert.AreEqual(2, counter.CompareAndSwap(3, 4));
            Assert.AreEqual(2, counter.CompareAndSwap(2, 5));
            rcm.Remove(counterName);
        }
Exemplo n.º 14
0
        public void AddStrongTest()
        {
            string counterName  = "strongTestAdd";
            int    initialValue = 10;
            var    rcm          = remoteManager.GetCounterManager();
            var    cc           = new CounterConfiguration(initialValue, 0, 0, 8, CounterType.UNBOUNDED_STRONG, Storage.VOLATILE);

            rcm.DefineCounter(counterName, cc);
            var counter = rcm.GetStrongCounter(counterName);

            Assert.AreEqual(counter.GetValue(), 10);
            Assert.AreEqual(counter.AddAndGet(10), 20);
            Assert.AreEqual(counter.AddAndGet(-20), 0);
            Assert.AreEqual(counter.AddAndGet(-20), -20);
            rcm.Remove(counterName);
        }
Exemplo n.º 15
0
        public void ResetWeakTest()
        {
            string counterName  = "weakTestReset";
            int    initialValue = 5;
            var    rcm          = remoteManager.GetCounterManager();
            var    cc           = new CounterConfiguration(initialValue, 0, 0, 8, CounterType.WEAK, Storage.VOLATILE);

            rcm.DefineCounter(counterName, cc);
            var counter = rcm.GetWeakCounter(counterName);

            Assert.AreEqual(5, counter.GetValue());
            counter.Add(100);
            Assert.AreEqual(105, counter.GetValue());
            counter.Reset();
            Assert.AreEqual(counter.GetValue(), initialValue);
            rcm.Remove(counterName);
        }
Exemplo n.º 16
0
        public StronglyTypedRavenSettings(NameValueCollection settings)
        {
            Replication = new ReplicationConfiguration();
            Voron       = new VoronConfiguration();
            Esent       = new EsentConfiguration();
            Prefetcher  = new PrefetcherConfiguration();
            FileSystem  = new FileSystemConfiguration();
            Counter     = new CounterConfiguration();
            TimeSeries  = new TimeSeriesConfiguration();
            Encryption  = new EncryptionConfiguration();
            Indexing    = new IndexingConfiguration();
            WebSockets  = new WebSocketsConfiguration();
            Cluster     = new ClusterConfiguration();
            Monitoring  = new MonitoringConfiguration();
            Studio      = new StudioConfiguration();

            this.settings = settings;
        }
Exemplo n.º 17
0
        protected virtual ICollector <ICounter> CreateErrorTotalCounter()
        {
            string[] defaultLabels = new[] { "operation", "sli_error_type", "sli_dependency" };

            var configuration = new CounterConfiguration
            {
                SuppressInitialValue = true,
                LabelNames           = defaultLabels
            };

            _options.ConfigureErrorTotalCounter?.Invoke(configuration);

            if (configuration.LabelNames != defaultLabels)
            {
                throw new ArgumentException("The error total counter configuration is missing the required default labels");
            }

            return(_metrics.CreateCounter("http_server_errors_total", "The number of HTTP requests resulting in an error", configuration));
        }
Exemplo n.º 18
0
        public void CounterSetFloatWithinBounds(float min, float max, float amount, float expected)
        {
            //// Arrange
            PlayerPrefs.DeleteAll();

            var counterConfiguration = new CounterConfiguration()
            {
                Name         = "Counter",
                CounterType  = CounterConfiguration.CounterTypeEnum.Float,
                SaveBest     = CounterConfiguration.SaveType.None,
                FloatMinimum = min,
                FloatMaximum = max
            };
            var counter = new Counter(counterConfiguration);

            //// Act
            counter.Set(amount);

            //// Assert
            Assert.AreEqual(expected, counter.FloatAmount, "Amount not set correctly.");
        }
Exemplo n.º 19
0
        public void FloatAmountChangeHandlerCalled(int expectedMessages, int expectedBestMessages, float amount1, float amount2)
        {
            //// Arrange
            var counterConfiguration = new CounterConfiguration()
            {
                SaveBest = CounterConfiguration.SaveType.None
            };
            var counterCallbackTestClass = new CounterCallbackTestClass();
            var counter = new Counter(counterConfiguration, counterChangedCallbacks: counterCallbackTestClass);

            counter.Set(amount1);

            //// Act
            counter.Set(amount2);

            //// Assert
            Assert.AreEqual(expectedMessages, counterCallbackTestClass.FloatAmountChangedCounter, "Incorrect number of messages sent.");
            Assert.AreEqual(expectedBestMessages, counterCallbackTestClass.FloatAmountBestChangedCounter, "Incorrect number of messages sent.");
            Assert.AreEqual(amount1, counterCallbackTestClass.OldFloatAmount, "Incorrect old amount in message.");
            Assert.AreEqual(amount2, counterCallbackTestClass.NewFloatAmount, "Incorrect new amount in message.");
        }
        /// <summary>
        /// This function can be overridden by inheriting classes, but if it isn't, draw the default for it's properties.
        /// </summary>
        protected override void DrawGUI()
        {
            EditorGUILayout.PropertyField(_gameItemTypeProperty);
            EditorGUILayout.PropertyField(_contextProperty);

            var counterConfiguration = GameConfiguration.Instance.GetCounterConfiguration((GameConfiguration.GameItemType)_gameItemTypeProperty.enumValueIndex);
            var counters             = new string[counterConfiguration.Count];

            _counterIndex = 0; // initialise incase gameitem type changed
            for (int i = 0; i < counterConfiguration.Count; i++)
            {
                counters[i] = counterConfiguration[i].Name;
                if (counters[i] == _counterProperty.stringValue)
                {
                    _counterIndex = i;
                }
            }

            int newIndex = EditorGUILayout.Popup("Counter", _counterIndex, counters);

            if (newIndex != _counterIndex || string.IsNullOrEmpty(_counterProperty.stringValue))
            {
                _counterProperty.stringValue = counters[newIndex];
                _counterIndex = newIndex;
            }
            CounterConfiguration = counterConfiguration[_counterIndex];

            EditorGUILayout.BeginHorizontal();
            EditorGUILayout.PrefixLabel(new GUIContent("Amount", "The value to compare against"));
            EditorGUILayout.PropertyField(_comparisonProperty, GUIContent.none, GUILayout.ExpandWidth(true));
            if (CounterConfiguration.CounterType == CounterConfiguration.CounterTypeEnum.Int)
            {
                EditorGUILayout.PropertyField(_intAmountProperty, GUIContent.none, GUILayout.ExpandWidth(true));
            }
            else
            {
                EditorGUILayout.PropertyField(_floatAmountProperty, GUIContent.none, GUILayout.ExpandWidth(true));
            }
            EditorGUILayout.EndHorizontal();
        }
Exemplo n.º 21
0
        public void CounterInitialisationPersistentFloatValuesLoaded(string prefsPrefix, string counterName, float amount, float bestAmount)
        {
            //// Arrange
            PlayerPrefs.DeleteAll();
            PlayerPrefs.SetFloat(string.Format("{0}CF.{1}", prefsPrefix, counterName), amount);
            PlayerPrefs.SetFloat(string.Format("{0}CFH.{1}", prefsPrefix, counterName), bestAmount);

            //// Act
            var counterConfiguration = new CounterConfiguration()
            {
                Name        = counterName,
                Save        = CounterConfiguration.SaveType.Always,
                CounterType = CounterConfiguration.CounterTypeEnum.Float
            };
            var counter = new Counter(counterConfiguration, prefsPrefix);

            counter.LoadFromPrefs();

            //// Assert
            Assert.AreEqual(amount, counter.FloatAmount, "FloatAmount not set correctly");
            Assert.AreEqual(bestAmount, counter.FloatAmountBest, "HighestFloatAmount not set correctly");
        }
Exemplo n.º 22
0
        public void CounterResetInt(int defaultAmount, int amount)
        {
            //// Arrange
            PlayerPrefs.DeleteAll();

            var counterConfiguration = new CounterConfiguration()
            {
                Name        = "Counter",
                CounterType = CounterConfiguration.CounterTypeEnum.Int,
                IntDefault  = defaultAmount,
                SaveBest    = CounterConfiguration.SaveType.None,
            };
            var counter = new Counter(counterConfiguration);

            counter.Set(amount);

            //// Act
            counter.Reset();

            //// Assert
            Assert.AreEqual(defaultAmount, counter.IntAmount, "Reset did not set default amount correctly.");
        }
Exemplo n.º 23
0
        /// <summary>
        /// Constructor to hold necessary references.
        /// </summary>
        /// <param name="counterConfigurationEntry"></param>
        /// <param name="prefsPrefix"></param>
        /// <param name="identifier"></param>
        /// <param name="counterChangedCallbacks"></param>
        public Counter(CounterConfiguration counterConfigurationEntry, string prefsPrefix = null,
                       int identifier = -1, ICounterChangedCallback counterChangedCallbacks = null)
        {
            Assert.IsTrue(prefsPrefix != null ||
                          (counterConfigurationEntry.Save == CounterConfiguration.SaveType.None && counterConfigurationEntry.SaveBest == CounterConfiguration.SaveType.None),
                          "If persisting a counter then ensure to pass a valid prefs prefix to use.");

            Configuration = counterConfigurationEntry;
            Identifier    = identifier;
            if (counterConfigurationEntry.CounterType == CounterConfiguration.CounterTypeEnum.Int)
            {
                IntAmount = counterConfigurationEntry.IntDefault;
            }
            else
            {
                FloatAmount = counterConfigurationEntry.FloatDefault;
            }

            _prefsPrefix             = prefsPrefix;
            _counterChangedCallbacks = counterChangedCallbacks;

            SetupPrefsKeys();
        }
Exemplo n.º 24
0
        public void PushToSavedFloat(float amount, float amountBest, CounterConfiguration.SaveType save, CounterConfiguration.SaveType saveBest)
        {
            //// Arrange
            PlayerPrefs.DeleteAll();

            var counterConfiguration = new CounterConfiguration()
            {
                Save     = save,
                SaveBest = saveBest
            };
            var counter = new Counter(counterConfiguration, "Prefix.");

            counter.FloatAmount = amount;
            //counter.FloatAmountBest = amountBest;

            //// Act
            counter.PushToSaved();

            //// Assert
            if (save == CounterConfiguration.SaveType.None)
            {
                Assert.AreEqual(0, counter.FloatAmountSaved, "FloatAmount wrongly pushed to save.");
            }
            else
            {
                Assert.AreEqual(counter.FloatAmount, counter.FloatAmountSaved, "Amount not pushed to save.");
            }

            if (saveBest == CounterConfiguration.SaveType.None)
            {
                Assert.AreEqual(0, counter.FloatAmountBestSaved, "FloatAmountBest wrongly pushed to save.");
            }
            else
            {
                Assert.AreEqual(counter.FloatAmountBest, counter.FloatAmountBestSaved, "IntAmountBest not pushed to save.");
            }
        }
Exemplo n.º 25
0
        public RavenConfiguration()
        {
            Settings = new NameValueCollection(StringComparer.OrdinalIgnoreCase);

            Core = new CoreConfiguration(this);

            FileSystem = new FileSystemConfiguration(Core);
            Counter    = new CounterConfiguration(Core);
            TimeSeries = new TimeSeriesConfiguration(Core);

            Replication = new ReplicationConfiguration();
            Prefetcher  = new PrefetcherConfiguration();
            Storage     = new StorageConfiguration();
            Encryption  = new EncryptionConfiguration();
            Indexing    = new IndexingConfiguration();
            WebSockets  = new WebSocketsConfiguration();
            Cluster     = new ClusterConfiguration();
            Monitoring  = new MonitoringConfiguration();
            Queries     = new QueryConfiguration();
            Patching    = new PatchingConfiguration();
            BulkInsert  = new BulkInsertConfiguration();
            Server      = new ServerConfiguration();
            Memory      = new MemoryConfiguration();
            Expiration  = new ExpirationBundleConfiguration();
            Versioning  = new VersioningBundleConfiguration();
            Studio      = new StudioConfiguration();
            Tenants     = new TenantConfiguration();
            Licensing   = new LicenseConfiguration();
            Quotas      = new QuotasBundleConfiguration();

            IndexingClassifier = new DefaultIndexingClassifier();

            Catalog = new AggregateCatalog(CurrentAssemblyCatalog);

            Catalog.Changed += (sender, args) => ResetContainer();
        }
Exemplo n.º 26
0
        public void CounterInitialisationPersistentIntValuesLoaded(string prefsPrefix, string counterName, int amount, int bestAmount)
        {
            //// Arrange
            PlayerPrefs.DeleteAll();
            PlayerPrefs.SetInt(string.Format("{0}CI.{1}", prefsPrefix, counterName), amount);
            PlayerPrefs.SetInt(string.Format("{0}CIH.{1}", prefsPrefix, counterName), bestAmount);

            //// Act
            var counterConfiguration = new CounterConfiguration()
            {
                Name        = counterName,
                Save        = CounterConfiguration.SaveType.Always, //SaveBest defaults to Always
                CounterType = CounterConfiguration.CounterTypeEnum.Int
            };
            var counter = new Counter(counterConfiguration, prefsPrefix);

            counter.LoadFromPrefs();

            //// Assert
            Assert.AreEqual(amount, counter.IntAmount, "IntAmount not set correctly");
            Assert.AreEqual(amount, counter.IntAmountSaved, "IntAmountLastSaved not set correctly");
            Assert.AreEqual(bestAmount, counter.IntAmountBest, "IntAmountBest not set correctly");
            Assert.AreEqual(bestAmount, counter.IntAmountBestSaved, "IntAmountBestLastSaved not set correctly");
        }
Exemplo n.º 27
0
        public void CounterInitialisationPersistentFloatValuesNotLoaded(string prefsPrefix, string counterName, float amount, float bestAmount)
        {
            //// Arrange
            PlayerPrefs.DeleteAll();
            PlayerPrefs.SetFloat(string.Format("{0}CI.{1}", prefsPrefix, counterName), amount);
            PlayerPrefs.SetFloat(string.Format("{0}CIH.{1}", prefsPrefix, counterName), bestAmount);

            //// Act
            var counterConfiguration = new CounterConfiguration()
            {
                Name        = counterName,
                SaveBest    = CounterConfiguration.SaveType.None, //Save defaults to None
                CounterType = CounterConfiguration.CounterTypeEnum.Float
            };
            var counter = new Counter(counterConfiguration, prefsPrefix);

            counter.LoadFromPrefs();

            //// Assert
            Assert.AreEqual(0, counter.FloatAmount, "FloatAmount not set correctly");
            Assert.AreEqual(0, counter.FloatAmountSaved, "FloatAmountSaved not set correctly");
            Assert.AreEqual(0, counter.FloatAmountBest, "FloatAmountBest not set correctly");
            Assert.AreEqual(0, counter.FloatAmountBestSaved, "FloatAmountBestSaved not set correctly");
        }
Exemplo n.º 28
0
 /// <summary>
 /// Counters only increase in value and reset to zero when the process restarts.
 /// </summary>
 public static Counter CreateCounter(string name, string help, CounterConfiguration configuration = null) =>
 _defaultFactory.CreateCounter(name, help, configuration);
Exemplo n.º 29
0
        public void BasicListenerStrongTest()
        {
            int       step = 0;
            Semaphore s    = new Semaphore(0, 1);
            Action <Event.CounterEvent> a2 = (Event.CounterEvent e) =>
            {
                switch (step)
                {
                case 0:
                    Assert.AreEqual(5, e.OldValue);
                    Assert.AreEqual(15, e.NewValue);
                    Assert.AreEqual(Event.CounterState.VALID, e.NewState);
                    Assert.AreEqual(Event.CounterState.VALID, e.OldState);
                    s.Release();
                    break;

                case 1:
                    Assert.AreEqual(15, e.OldValue);
                    Assert.AreEqual(0, e.NewValue);
                    Assert.AreEqual(Event.CounterState.LOWER_BOUND_REACHED, e.NewState);
                    Assert.AreEqual(Event.CounterState.VALID, e.OldState);
                    s.Release();
                    break;

                case 2:
                    Assert.AreEqual(0, e.OldValue);
                    Assert.AreEqual(20, e.NewValue);
                    Assert.AreEqual(Event.CounterState.UPPER_BOUND_REACHED, e.NewState);
                    Assert.AreEqual(Event.CounterState.LOWER_BOUND_REACHED, e.OldState);
                    s.Release();
                    break;

                default:
                    Assert.Fail();
                    break;
                }
            };


            string counterName = "strongTestBasicListener";

            Event.CounterListener cl = new Event.CounterListener(counterName, a2);
            var rcm = remoteManager.GetCounterManager();
            var cc  = new CounterConfiguration(5, 0, 20, 8, CounterType.BOUNDED_STRONG, Storage.VOLATILE);

            rcm.DefineCounter(counterName, cc);
            var    counter = rcm.GetStrongCounter(counterName);
            object o       = counter.AddListener(cl);

            counter.AddAndGet(10);
            Assert.True(s.WaitOne(15000));
            step = 1;
            try
            {
                counter.AddAndGet(-20);
            }
            catch (CounterLowerBoundException)
            {
            }
            Assert.True(s.WaitOne(15000));
            step = 2;
            try
            {
                counter.AddAndGet(30);
            }
            catch (CounterUpperBoundException)
            {
            }
            Assert.True(s.WaitOne(15000));
            counter.RemoveListener(o);
        }
Exemplo n.º 30
0
 public Counter GetOrAddCounter(string name, string description, CounterConfiguration config = null)
 {
     return(Counters.GetOrAdd(name, Prometheus.Metrics.CreateCounter(name, description, config)));
 }