This is an automated email from the ASF dual-hosted git repository.

moleske pushed a commit to branch develop
in repository https://gitbox.apache.org/repos/asf/geode.git


The following commit(s) were added to refs/heads/develop by this push:
     new 5e97425  GEODE-6345: Change jvmPauses stat to long (#3143)
5e97425 is described below

commit 5e974258bcf80cf0a5470938d2dddac7f8adda82
Author: M. Oleske <mole...@users.noreply.github.com>
AuthorDate: Tue Feb 5 12:23:29 2019 -0800

    GEODE-6345: Change jvmPauses stat to long (#3143)
    
    Renamed a function per request.
    Changed a couple map lookups to array accesses
    Keeping JvmPausesIsALong to validate type
    
    Co-authored-by: Michael Oleske <mole...@pivotal.io>
    Co-authored-by: Kirk Lund <kl...@pivotal.io>
    Co-authored-by: Mark Hanson <mhan...@pivotal.io>
---
 .../internal/statistics/StatSamplerStats.java      | 61 ++++++++---------
 .../internal/statistics/StatSamplerStatsTest.java  | 80 ++++++++++++++++++++++
 2 files changed, 107 insertions(+), 34 deletions(-)

diff --git 
a/geode-core/src/main/java/org/apache/geode/internal/statistics/StatSamplerStats.java
 
b/geode-core/src/main/java/org/apache/geode/internal/statistics/StatSamplerStats.java
index 7224aa4..7609c92 100644
--- 
a/geode-core/src/main/java/org/apache/geode/internal/statistics/StatSamplerStats.java
+++ 
b/geode-core/src/main/java/org/apache/geode/internal/statistics/StatSamplerStats.java
@@ -24,24 +24,25 @@ import org.apache.geode.StatisticsTypeFactory;
  * Statistics related to the statistic sampler.
  */
 public class StatSamplerStats {
-  public static final String SAMPLE_COUNT = "sampleCount"; // int
-  public static final String SAMPLE_TIME = "sampleTime"; // long
-  public static final String DELAY_DURATION = "delayDuration"; // int
-  public static final String STAT_RESOURCES = "statResources"; // int
-  public static final String JVM_PAUSES = "jvmPauses"; // int
-  public static final String SAMPLE_CALLBACKS = "sampleCallbacks"; // int
-  public static final String SAMPLE_CALLBACK_ERRORS = "sampleCallbackErrors"; 
// int
-  public static final String SAMPLE_CALLBACK_DURATION = 
"sampleCallbackDuration"; // long
+  static final String SAMPLE_COUNT = "sampleCount";
+  private static final String SAMPLE_TIME = "sampleTime";
+  private static final String DELAY_DURATION = "delayDuration";
+  private static final String STAT_RESOURCES = "statResources";
+  private static final String JVM_PAUSES = "jvmPauses";
+  private static final String SAMPLE_CALLBACKS = "sampleCallbacks";
+  private static final String SAMPLE_CALLBACK_ERRORS = "sampleCallbackErrors";
+  private static final String SAMPLE_CALLBACK_DURATION = 
"sampleCallbackDuration";
 
   private static final StatisticsType samplerType;
   private static final int sampleCountId;
   private static final int sampleTimeId;
   private static final int delayDurationId;
   private static final int statResourcesId;
-  private static final int jvmPausesId;
+  static final int jvmPausesId;
   private static final int sampleCallbacksId;
   private static final int sampleCallbackErrorsId;
   private static final int sampleCallbackDurationId;
+
   static {
     StatisticsTypeFactory f = StatisticsTypeFactoryImpl.singleton();
     samplerType = f.createType("StatSampler", "Stats on the statistic 
sampler.",
@@ -56,7 +57,7 @@ public class StatSamplerStats {
             f.createIntGauge(STAT_RESOURCES,
                 "Current number of statistic resources being sampled by this 
sampler.", "resources",
                 false),
-            f.createIntCounter(JVM_PAUSES,
+            f.createLongCounter(JVM_PAUSES,
                 "Total number of JVM pauses (which may or may not be full GC 
pauses) detected by this sampler. A JVM pause is defined as a system event 
which kept the statistics sampler thread from sampling for 3000 or more 
milliseconds. This threshold can be customized by setting the system property 
gemfire.statSamplerDelayThreshold (units are milliseconds).",
                 "jvmPauses", false),
             f.createIntGauge(SAMPLE_CALLBACKS,
@@ -79,54 +80,46 @@ public class StatSamplerStats {
 
   private final Statistics samplerStats;
 
-  public StatSamplerStats(StatisticsFactory f, long id) {
+  StatSamplerStats(StatisticsFactory f, long id) {
     this.samplerStats = f.createStatistics(samplerType, "statSampler", id);
   }
 
-  public void tookSample(long nanosSpentWorking, int statResources, long 
nanosSpentSleeping) {
+  static StatisticsType getStatisticsType() {
+    return samplerType;
+  }
+
+  void tookSample(long nanosSpentWorking, int statResources, long 
nanosSpentSleeping) {
     this.samplerStats.incInt(sampleCountId, 1);
     this.samplerStats.incLong(sampleTimeId, nanosSpentWorking / 1000000);
     this.samplerStats.setInt(delayDurationId, (int) (nanosSpentSleeping / 
1000000));
     this.samplerStats.setInt(statResourcesId, statResources);
   }
 
-  public void incJvmPauses() {
-    this.samplerStats.incInt(jvmPausesId, 1);
+  void incJvmPauses() {
+    this.samplerStats.incLong(jvmPausesId, 1);
   }
 
-  public void incSampleCallbackErrors(int delta) {
+  void incSampleCallbackErrors(int delta) {
     this.samplerStats.incInt(sampleCallbackErrorsId, delta);
   }
 
-  public void setSampleCallbacks(int count) {
+  void setSampleCallbacks(int count) {
     this.samplerStats.setInt(sampleCallbacksId, count);
   }
 
-  public void incSampleCallbackDuration(long delta) {
+  void incSampleCallbackDuration(long delta) {
     this.samplerStats.incLong(sampleCallbackDurationId, delta);
   }
 
-  public int getSampleCount() {
-    return this.samplerStats.getInt(SAMPLE_COUNT);
-  }
-
-  public long getSampleTime() {
-    return this.samplerStats.getLong(SAMPLE_TIME);
-  }
-
-  public int getDelayDuration() {
-    return this.samplerStats.getInt(DELAY_DURATION);
-  }
-
-  public int getStatResources() {
-    return this.samplerStats.getInt(STAT_RESOURCES);
+  int getSampleCount() {
+    return this.samplerStats.getInt(sampleCountId);
   }
 
-  public int getJvmPauses() {
-    return this.samplerStats.getInt(JVM_PAUSES);
+  long getJvmPauses() {
+    return this.samplerStats.getLong(jvmPausesId);
   }
 
-  public void close() {
+  void close() {
     this.samplerStats.close();
   }
 
diff --git 
a/geode-core/src/test/java/org/apache/geode/internal/statistics/StatSamplerStatsTest.java
 
b/geode-core/src/test/java/org/apache/geode/internal/statistics/StatSamplerStatsTest.java
new file mode 100644
index 0000000..7b22ea5
--- /dev/null
+++ 
b/geode-core/src/test/java/org/apache/geode/internal/statistics/StatSamplerStatsTest.java
@@ -0,0 +1,80 @@
+/*
+ * 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.
+ */
+package org.apache.geode.internal.statistics;
+
+import static 
org.apache.geode.internal.statistics.StatSamplerStats.jvmPausesId;
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.mockito.ArgumentMatchers.eq;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.spy;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+
+import org.junit.Before;
+import org.junit.Test;
+
+import org.apache.geode.Statistics;
+import org.apache.geode.StatisticsFactory;
+import org.apache.geode.StatisticsType;
+
+public class StatSamplerStatsTest {
+  private static final String TEXT_ID = "statSampler";
+
+  private StatisticsType statisticsType;
+  private StatisticsFactory statisticsFactory;
+  private Statistics statistics;
+  private StatSamplerStats statSamplerStats;
+
+  @Before
+  public void setUp() {
+    statisticsType = StatSamplerStats.getStatisticsType();
+    statisticsFactory = mock(StatisticsFactory.class);
+
+    statistics = mock(Statistics.class);
+
+    when(statisticsFactory.createStatistics(eq(statisticsType), eq(TEXT_ID), 
eq(1L)))
+        .thenReturn(statistics);
+
+    statSamplerStats = new StatSamplerStats(statisticsFactory, 1);
+  }
+
+  @Test
+  public void getJvmPausesDelegatesToStatistics() {
+    statSamplerStats.getJvmPauses();
+
+    verify(statistics).getLong(eq(jvmPausesId));
+  }
+
+  @Test
+  public void incJvmPausesDelegatesToStatistics() {
+    statSamplerStats.incJvmPauses();
+
+    verify(statistics).incLong(eq(jvmPausesId), eq(1L));
+  }
+
+  @Test
+  public void jvmPausesIsALong() {
+    StatisticsManager statisticsManager = mock(StatisticsManager.class);
+    statistics = spy(new LocalStatisticsImpl(statisticsType, TEXT_ID, 1, 1, 
false, 0,
+        statisticsManager));
+    when(statisticsFactory.createStatistics(eq(statisticsType), eq(TEXT_ID), 
eq(1L)))
+        .thenReturn(statistics);
+    statSamplerStats = new StatSamplerStats(statisticsFactory, 1);
+    statistics.incLong(jvmPausesId, Integer.MAX_VALUE + 1L);
+
+    assertThat(statSamplerStats.getJvmPauses()).isPositive();
+  }
+
+}

Reply via email to