You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@reef.apache.org by ma...@apache.org on 2016/11/23 00:52:50 UTC

reef git commit: [REEF-1672] Define Immutable Counters and Gauges

Repository: reef
Updated Branches:
  refs/heads/master 6eb3a8929 -> fd2a746ee


[REEF-1672] Define Immutable Counters and Gauges

This addressed the issue by
  * introducing Immutable gauges and counter classes.
  * introducing corresponding tests.

JIRA:
  [REEF-1672](https://issues.apache.org/jira/browse/REEF-1672)

Pull request:
  This closes #1183


Project: http://git-wip-us.apache.org/repos/asf/reef/repo
Commit: http://git-wip-us.apache.org/repos/asf/reef/commit/fd2a746e
Tree: http://git-wip-us.apache.org/repos/asf/reef/tree/fd2a746e
Diff: http://git-wip-us.apache.org/repos/asf/reef/diff/fd2a746e

Branch: refs/heads/master
Commit: fd2a746ee7b71a9e95cf784a86fd3d241eaf558b
Parents: 6eb3a89
Author: dhruv <dh...@apache.org>
Authored: Thu Nov 17 10:46:01 2016 -0800
Committer: Mariia Mykhailova <ma...@apache.org>
Committed: Tue Nov 22 16:15:06 2016 -0800

----------------------------------------------------------------------
 .../Org.Apache.REEF.Common.Tests.csproj         |  1 +
 .../metrics/ImmutableMetricImplTests.cs         | 90 ++++++++++++++++++++
 .../metrics/MetricTestUtils.cs                  | 27 ++++++
 .../Org.Apache.REEF.Common.csproj               |  3 +
 .../metrics/MetricsSystem/ImmutableCounter.cs   | 39 +++++++++
 .../MetricsSystem/ImmutableDoubleGauge.cs       | 39 +++++++++
 .../metrics/MetricsSystem/ImmutableLongGauge.cs | 39 +++++++++
 7 files changed, 238 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/reef/blob/fd2a746e/lang/cs/Org.Apache.REEF.Common.Tests/Org.Apache.REEF.Common.Tests.csproj
----------------------------------------------------------------------
diff --git a/lang/cs/Org.Apache.REEF.Common.Tests/Org.Apache.REEF.Common.Tests.csproj b/lang/cs/Org.Apache.REEF.Common.Tests/Org.Apache.REEF.Common.Tests.csproj
index b169990..f49bbfb 100644
--- a/lang/cs/Org.Apache.REEF.Common.Tests/Org.Apache.REEF.Common.Tests.csproj
+++ b/lang/cs/Org.Apache.REEF.Common.Tests/Org.Apache.REEF.Common.Tests.csproj
@@ -47,6 +47,7 @@ under the License.
       <Link>Properties\SharedAssemblyInfo.cs</Link>
     </Compile>
     <Compile Include="Metrics\DefaultMetricSourceTests.cs" />
+    <Compile Include="Metrics\ImmutableMetricImplTests.cs" />
     <Compile Include="Metrics\ImmutableMetricTest.cs" />
     <Compile Include="Metrics\MetricTestUtils.cs" />
     <Compile Include="Metrics\MutableMetricTest.cs" />

http://git-wip-us.apache.org/repos/asf/reef/blob/fd2a746e/lang/cs/Org.Apache.REEF.Common.Tests/metrics/ImmutableMetricImplTests.cs
----------------------------------------------------------------------
diff --git a/lang/cs/Org.Apache.REEF.Common.Tests/metrics/ImmutableMetricImplTests.cs b/lang/cs/Org.Apache.REEF.Common.Tests/metrics/ImmutableMetricImplTests.cs
new file mode 100644
index 0000000..6fd8d9f
--- /dev/null
+++ b/lang/cs/Org.Apache.REEF.Common.Tests/metrics/ImmutableMetricImplTests.cs
@@ -0,0 +1,90 @@
+\ufeff// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//   http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+using Org.Apache.REEF.Common.Metrics.Api;
+using Org.Apache.REEF.Common.Metrics.MetricsSystem;
+using Xunit;
+
+namespace Org.Apache.REEF.Common.Tests.Metrics
+{
+    /// <summary>
+    /// Tests various implementations of <see cref="IImmutableMetric"/>
+    /// </summary>
+    public sealed class ImmutableMetricImplTests
+    {
+        /// <summary>
+        /// Tests <see cref="ImmutableCounter"/>. Creates the class and verifies 
+        /// that all functions and properties work correctly.
+        /// </summary>
+        [Fact]
+        public void TestImmutableCounter()
+        {
+            const string name = "default";
+            const string desc = "default";
+            const long value = 3;
+            ImmutableCounter counter = new ImmutableCounter(new MetricsInfoImpl(name, desc), value);
+            Assert.Equal(value, counter.LongValue);
+            Assert.Null(counter.NumericValue);
+            Assert.Equal(MetricType.Counter, counter.TypeOfMetric);
+
+            MetricTestUtils.MetricsVisitorForTests visitor = new MetricTestUtils.MetricsVisitorForTests();
+            counter.Visit(visitor);
+            Assert.Equal(value, visitor.CounterValue);
+        }
+
+        /// <summary>
+        /// Tests <see cref="ImmutableLongGauge"/>. Creates the class and verifies 
+        /// that all functions and properties work correctly.
+        /// </summary>
+        [Fact]
+        public void TestImmutableLongGauge()
+        {
+            const string name = "default";
+            const string desc = "default";
+            const long value = 3;
+            var gauge = new ImmutableLongGauge(new MetricsInfoImpl(name, desc), value);
+            Assert.Equal(value, gauge.LongValue);
+            Assert.Null(gauge.NumericValue);
+            Assert.Equal(MetricType.Gauge, gauge.TypeOfMetric);
+
+            MetricTestUtils.MetricsVisitorForTests visitor = new MetricTestUtils.MetricsVisitorForTests();
+            gauge.Visit(visitor);
+            Assert.Equal(value, visitor.LongGauge);
+        }
+
+        /// <summary>
+        /// Tests <see cref="ImmutableDoubleGauge"/>. Creates the class and verifies 
+        /// that all functions and properties work correctly.</summary>
+        [Fact]
+        public void TestImmutableDoubleGauge()
+        {
+            const string name = "default";
+            const string desc = "default";
+            const double value = 4.3;
+            var gauge = new ImmutableDoubleGauge(new MetricsInfoImpl(name, desc), value);
+            Assert.NotNull(gauge.NumericValue);
+            Assert.True(gauge.NumericValue.HasValue, "Numerical field should have value.");
+            Assert.Equal(value, gauge.NumericValue.Value, 10);
+            Assert.Null(gauge.LongValue);
+            Assert.Equal(MetricType.Gauge, gauge.TypeOfMetric);
+
+            MetricTestUtils.MetricsVisitorForTests visitor = new MetricTestUtils.MetricsVisitorForTests();
+            gauge.Visit(visitor);
+            Assert.Equal(value, visitor.DoubleGauge, 10);
+        }
+    }
+}

http://git-wip-us.apache.org/repos/asf/reef/blob/fd2a746e/lang/cs/Org.Apache.REEF.Common.Tests/metrics/MetricTestUtils.cs
----------------------------------------------------------------------
diff --git a/lang/cs/Org.Apache.REEF.Common.Tests/metrics/MetricTestUtils.cs b/lang/cs/Org.Apache.REEF.Common.Tests/metrics/MetricTestUtils.cs
index 357e8a5..0a0738b 100644
--- a/lang/cs/Org.Apache.REEF.Common.Tests/metrics/MetricTestUtils.cs
+++ b/lang/cs/Org.Apache.REEF.Common.Tests/metrics/MetricTestUtils.cs
@@ -175,5 +175,32 @@ namespace Org.Apache.REEF.Common.Tests.Metrics
                 throw new System.NotImplementedException();
             }
         }
+
+        /// <summary>
+        /// Metrics visitor implementation.
+        /// </summary>
+        internal sealed class MetricsVisitorForTests : IMetricsVisitor
+        {
+            public long CounterValue { get; private set; }
+
+            public long LongGauge { get; private set; }
+
+            public double DoubleGauge { get; private set; }
+
+            public void Gauge(IMetricsInfo info, long value)
+            {
+                LongGauge = value;
+            }
+
+            public void Gauge(IMetricsInfo info, double value)
+            {
+                DoubleGauge = value;
+            }
+
+            public void Counter(IMetricsInfo info, long value)
+            {
+                CounterValue = value;
+            }
+        }
     }
 }

http://git-wip-us.apache.org/repos/asf/reef/blob/fd2a746e/lang/cs/Org.Apache.REEF.Common/Org.Apache.REEF.Common.csproj
----------------------------------------------------------------------
diff --git a/lang/cs/Org.Apache.REEF.Common/Org.Apache.REEF.Common.csproj b/lang/cs/Org.Apache.REEF.Common/Org.Apache.REEF.Common.csproj
index 71c16bf..8399e43 100644
--- a/lang/cs/Org.Apache.REEF.Common/Org.Apache.REEF.Common.csproj
+++ b/lang/cs/Org.Apache.REEF.Common/Org.Apache.REEF.Common.csproj
@@ -137,6 +137,9 @@ under the License.
     <Compile Include="Metrics\Api\MetricsTag.cs" />
     <Compile Include="Metrics\Api\MetricType.cs" />
     <Compile Include="Metrics\Api\SnapshotRequest.cs" />
+    <Compile Include="Metrics\MetricsSystem\ImmutableCounter.cs" />
+    <Compile Include="Metrics\MetricsSystem\ImmutableDoubleGauge.cs" />
+    <Compile Include="Metrics\MetricsSystem\ImmutableLongGauge.cs" />
     <Compile Include="Metrics\MutableMetricsLayer\DefaultMetricsFactoryImpl.cs" />
     <Compile Include="Metrics\MutableMetricsLayer\DefaultMetricsSourceConfiguration.cs" />
     <Compile Include="Metrics\MutableMetricsLayer\DefaultMetricsSourceImpl.cs" />

http://git-wip-us.apache.org/repos/asf/reef/blob/fd2a746e/lang/cs/Org.Apache.REEF.Common/metrics/MetricsSystem/ImmutableCounter.cs
----------------------------------------------------------------------
diff --git a/lang/cs/Org.Apache.REEF.Common/metrics/MetricsSystem/ImmutableCounter.cs b/lang/cs/Org.Apache.REEF.Common/metrics/MetricsSystem/ImmutableCounter.cs
new file mode 100644
index 0000000..fd4e15a
--- /dev/null
+++ b/lang/cs/Org.Apache.REEF.Common/metrics/MetricsSystem/ImmutableCounter.cs
@@ -0,0 +1,39 @@
+\ufeff// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//   http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+using Org.Apache.REEF.Common.Metrics.Api;
+
+namespace Org.Apache.REEF.Common.Metrics.MetricsSystem
+{
+    /// <summary>
+    /// Immutable Counter implementation. All the counters added in 
+    /// <see cref="IMetricsRecordBuilder"/> will be internally converted to 
+    /// this class instance in metrics system.
+    /// </summary>
+    internal sealed class ImmutableCounter : ImmutableMetricsImpl
+    {
+        /// <summary>
+        /// Constructor.
+        /// </summary>
+        /// <param name="info">Meta data of the counter</param>
+        /// <param name="value">Value of the counter</param>
+        public ImmutableCounter(IMetricsInfo info, long value)
+            : base(info, value, MetricType.Counter, (visitor) => visitor.Counter(info, value))
+        {
+        }
+    }
+}

http://git-wip-us.apache.org/repos/asf/reef/blob/fd2a746e/lang/cs/Org.Apache.REEF.Common/metrics/MetricsSystem/ImmutableDoubleGauge.cs
----------------------------------------------------------------------
diff --git a/lang/cs/Org.Apache.REEF.Common/metrics/MetricsSystem/ImmutableDoubleGauge.cs b/lang/cs/Org.Apache.REEF.Common/metrics/MetricsSystem/ImmutableDoubleGauge.cs
new file mode 100644
index 0000000..d5af491
--- /dev/null
+++ b/lang/cs/Org.Apache.REEF.Common/metrics/MetricsSystem/ImmutableDoubleGauge.cs
@@ -0,0 +1,39 @@
+\ufeff// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//   http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+using Org.Apache.REEF.Common.Metrics.Api;
+
+namespace Org.Apache.REEF.Common.Metrics.MetricsSystem
+{
+    /// <summary>
+    /// Immutable double gauge implementation. All the double gauges added in 
+    /// <see cref="IMetricsRecordBuilder"/> will be internally converted to 
+    /// this class instance in metrics system.
+    /// </summary>
+    internal sealed class ImmutableDoubleGauge : ImmutableMetricsImpl
+    {
+        /// <summary>
+        /// Constructor.
+        /// </summary>
+        /// <param name="info">Meta data of the gauge</param>
+        /// <param name="value">Value of the gauge</param>
+        public ImmutableDoubleGauge(IMetricsInfo info, double value)
+            : base(info, value, MetricType.Gauge, (visitor) => visitor.Gauge(info, value))
+        {
+        }
+    }
+}

http://git-wip-us.apache.org/repos/asf/reef/blob/fd2a746e/lang/cs/Org.Apache.REEF.Common/metrics/MetricsSystem/ImmutableLongGauge.cs
----------------------------------------------------------------------
diff --git a/lang/cs/Org.Apache.REEF.Common/metrics/MetricsSystem/ImmutableLongGauge.cs b/lang/cs/Org.Apache.REEF.Common/metrics/MetricsSystem/ImmutableLongGauge.cs
new file mode 100644
index 0000000..f624bf6
--- /dev/null
+++ b/lang/cs/Org.Apache.REEF.Common/metrics/MetricsSystem/ImmutableLongGauge.cs
@@ -0,0 +1,39 @@
+\ufeff// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//   http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+using Org.Apache.REEF.Common.Metrics.Api;
+
+namespace Org.Apache.REEF.Common.Metrics.MetricsSystem
+{
+    /// <summary>
+    /// Immutable long gauge implementation. All the long gauges added in 
+    /// <see cref="IMetricsRecordBuilder"/> will be internally converted to 
+    /// this class instance in metrics system.
+    /// </summary>
+    internal sealed class ImmutableLongGauge : ImmutableMetricsImpl
+    {
+        /// <summary>
+        /// Constructor.
+        /// </summary>
+        /// <param name="info">Meta data of the gauge</param>
+        /// <param name="value">Value of the gauge</param>
+        public ImmutableLongGauge(IMetricsInfo info, long value)
+            : base(info, value, MetricType.Gauge, (visitor) => visitor.Gauge(info, value))
+        {
+        }
+    }
+}