You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@geode.apache.org by dh...@apache.org on 2019/07/22 22:09:14 UTC

[geode] 01/18: WIP - A new test

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

dhemery pushed a commit to branch GEODE-7001-region-entry-count
in repository https://gitbox.apache.org/repos/asf/geode.git

commit 85af93069a93a9721fa71f6ac52112dbf60b64a5
Author: Michael Oleske <mo...@pivotal.io>
AuthorDate: Mon Jul 8 16:58:11 2019 -0700

    WIP - A new test
    
    Co-authored-by: Michael Oleske <mo...@pivotal.io>
    Co-authored-by: Mark Hanson <mh...@pivotal.io>
---
 .../geode/internal/cache/CachePerfStats.java       |  8 ++---
 .../geode/internal/cache/RegionPerfStats.java      |  2 +-
 .../geode/internal/cache/RegionPerfStatsTest.java  | 39 +++++++++++++++++++---
 3 files changed, 39 insertions(+), 10 deletions(-)

diff --git a/geode-core/src/main/java/org/apache/geode/internal/cache/CachePerfStats.java b/geode-core/src/main/java/org/apache/geode/internal/cache/CachePerfStats.java
index ffb6180..c9d9f47 100644
--- a/geode-core/src/main/java/org/apache/geode/internal/cache/CachePerfStats.java
+++ b/geode-core/src/main/java/org/apache/geode/internal/cache/CachePerfStats.java
@@ -108,7 +108,7 @@ public class CachePerfStats {
   static final int reliableRegionsMissingFullAccessId;
   static final int reliableRegionsMissingLimitedAccessId;
   static final int reliableRegionsMissingNoAccessId;
-  static final int entryCountId;
+  static final int entryGaugeId;
   protected static final int eventsQueuedId;
   static final int retriesId;
 
@@ -573,7 +573,7 @@ public class CachePerfStats {
     reliableRegionsMissingFullAccessId = type.nameToId("reliableRegionsMissingFullAccess");
     reliableRegionsMissingLimitedAccessId = type.nameToId("reliableRegionsMissingLimitedAccess");
     reliableRegionsMissingNoAccessId = type.nameToId("reliableRegionsMissingNoAccess");
-    entryCountId = type.nameToId("entries");
+    entryGaugeId = type.nameToId("entries");
 
     eventsQueuedId = type.nameToId("eventsQueued");
 
@@ -1307,11 +1307,11 @@ public class CachePerfStats {
   }
 
   public void incEntryCount(int delta) {
-    stats.incLong(entryCountId, delta);
+    stats.incLong(entryGaugeId, delta);
   }
 
   public long getEntries() {
-    return stats.getLong(entryCountId);
+    return stats.getLong(entryGaugeId);
   }
 
   public void incRetries() {
diff --git a/geode-core/src/main/java/org/apache/geode/internal/cache/RegionPerfStats.java b/geode-core/src/main/java/org/apache/geode/internal/cache/RegionPerfStats.java
index f67104d..982374a 100644
--- a/geode-core/src/main/java/org/apache/geode/internal/cache/RegionPerfStats.java
+++ b/geode-core/src/main/java/org/apache/geode/internal/cache/RegionPerfStats.java
@@ -463,7 +463,7 @@ class RegionPerfStats extends CachePerfStats {
 
   @Override
   public void incEntryCount(int delta) {
-    stats.incLong(entryCountId, delta);
+    stats.incLong(entryGaugeId, delta);
     cachePerfStats.incEntryCount(delta);
   }
 
diff --git a/geode-core/src/test/java/org/apache/geode/internal/cache/RegionPerfStatsTest.java b/geode-core/src/test/java/org/apache/geode/internal/cache/RegionPerfStatsTest.java
index 30520c1..fb39158 100644
--- a/geode-core/src/test/java/org/apache/geode/internal/cache/RegionPerfStatsTest.java
+++ b/geode-core/src/test/java/org/apache/geode/internal/cache/RegionPerfStatsTest.java
@@ -14,37 +14,66 @@
  */
 package org.apache.geode.internal.cache;
 
+import static org.apache.geode.internal.cache.CachePerfStats.entryGaugeId;
 import static org.assertj.core.api.Assertions.assertThat;
 import static org.mockito.ArgumentMatchers.any;
 import static org.mockito.Mockito.mock;
 import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+import static org.mockito.quality.Strictness.STRICT_STUBS;
 
 import org.junit.Before;
+import org.junit.Rule;
 import org.junit.Test;
 import org.mockito.ArgumentCaptor;
+import org.mockito.junit.MockitoJUnit;
+import org.mockito.junit.MockitoRule;
 
+import org.apache.geode.Statistics;
 import org.apache.geode.StatisticsFactory;
 
 public class RegionPerfStatsTest {
 
   private StatisticsFactory statisticsFactory;
   private CachePerfStats cachePerfStats;
+  private Statistics statistics;
+  private final String theRegionName = "TheRegionName";
+  private RegionPerfStats subject;
+
+  @Rule
+  public MockitoRule mockitoRule = MockitoJUnit.rule().strictness(STRICT_STUBS);
 
   @Before
   public void setUp() {
     statisticsFactory = mock(StatisticsFactory.class);
+    statistics = mock(Statistics.class);
     cachePerfStats = mock(CachePerfStats.class);
-  }
 
-  @Test
-  public void textIdIsRegionStatsHyphenRegionName() throws Exception {
-    String theRegionName = "TheRegionName";
+    when(statisticsFactory.createAtomicStatistics(any(), any()))
+        .thenReturn(statistics);
 
-    new RegionPerfStats(statisticsFactory, cachePerfStats, theRegionName, () -> 0);
+    subject = new RegionPerfStats(statisticsFactory, cachePerfStats, theRegionName, () -> 0);
+  }
 
+  @Test
+  public void textIdIsRegionStatsHyphenRegionName() {
     ArgumentCaptor<String> captor = ArgumentCaptor.forClass(String.class);
     verify(statisticsFactory).createAtomicStatistics(any(), captor.capture());
 
     assertThat(captor.getValue()).isEqualTo("RegionStats-" + theRegionName);
   }
+
+  @Test
+  public void incEntryCount_whenDeltaIsPositive_increasesGauge() {
+    subject.incEntryCount(1);
+
+    verify(statistics).incLong(entryGaugeId, 1);
+  }
+
+  @Test
+  public void incEntryCount_whenDeltaIsNegative_decreasesGauge() {
+    subject.incEntryCount(-1);
+
+    verify(statistics).incLong(entryGaugeId, -1);
+  }
 }