You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@geode.apache.org by go...@apache.org on 2017/09/19 21:57:27 UTC

[geode] branch develop updated: GEODE-3083: Fix geode-protobuf stats. - Enhance and rename test of basic messages and statistics to use the statistics directly. - Fix protobuf client statistics to properly update messages sent and received statistics. - Remove another use of stats file.

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

gosullivan 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 02d1edf  GEODE-3083: Fix geode-protobuf stats. - Enhance and rename test of basic messages and statistics to use the statistics directly. - Fix protobuf client statistics to properly update messages sent and received statistics. - Remove another use of stats file.
02d1edf is described below

commit 02d1edff0b6e24ee477415d636276363fcbbb311
Author: Sarge <md...@pivotal.io>
AuthorDate: Mon Sep 18 12:09:40 2017 -0700

    GEODE-3083: Fix geode-protobuf stats.
    - Enhance and rename test of basic messages and statistics to use the statistics directly.
    - Fix protobuf client statistics to properly update messages sent and received statistics.
    - Remove another use of stats file.
    
    Signed-off-by: Galen O'Sullivan <go...@pivotal.io>
---
 .../tier/sockets/ServerConnectionFactory.java      |  7 ++-
 .../statistics/ProtobufClientStatisticsImpl.java   |  4 +-
 .../acceptance/CacheConnectionJUnitTest.java       | 68 +++++++---------------
 .../acceptance/LocatorConnectionDUnitTest.java     |  6 --
 4 files changed, 26 insertions(+), 59 deletions(-)

diff --git a/geode-core/src/main/java/org/apache/geode/internal/cache/tier/sockets/ServerConnectionFactory.java b/geode-core/src/main/java/org/apache/geode/internal/cache/tier/sockets/ServerConnectionFactory.java
index ffc2d39..ed8f259 100644
--- a/geode-core/src/main/java/org/apache/geode/internal/cache/tier/sockets/ServerConnectionFactory.java
+++ b/geode-core/src/main/java/org/apache/geode/internal/cache/tier/sockets/ServerConnectionFactory.java
@@ -83,9 +83,9 @@ public class ServerConnectionFactory {
   }
 
   private ClientProtocolMessageHandler getOrCreateClientProtocolMessageHandler(
-      StatisticsFactory statisticsFactory, Acceptor acceptor) {
+      StatisticsFactory statisticsFactory, String serverName) {
     if (protocolHandler == null) {
-      return initializeMessageHandler(statisticsFactory, acceptor.getServerName());
+      return initializeMessageHandler(statisticsFactory, serverName);
     }
     return protocolHandler;
   }
@@ -103,7 +103,8 @@ public class ServerConnectionFactory {
 
         return new GenericProtocolServerConnection(socket, cache, helper, stats, hsTimeout,
             socketBufferSize, communicationModeStr, communicationMode, acceptor,
-            getOrCreateClientProtocolMessageHandler(cache.getDistributedSystem(), acceptor),
+            getOrCreateClientProtocolMessageHandler(cache.getDistributedSystem(),
+                acceptor.getServerName()),
             securityService, findStreamAuthenticator(authenticationMode));
       }
     } else {
diff --git a/geode-protobuf/src/main/java/org/apache/geode/protocol/protobuf/statistics/ProtobufClientStatisticsImpl.java b/geode-protobuf/src/main/java/org/apache/geode/protocol/protobuf/statistics/ProtobufClientStatisticsImpl.java
index 92f0610..7b9e725 100644
--- a/geode-protobuf/src/main/java/org/apache/geode/protocol/protobuf/statistics/ProtobufClientStatisticsImpl.java
+++ b/geode-protobuf/src/main/java/org/apache/geode/protocol/protobuf/statistics/ProtobufClientStatisticsImpl.java
@@ -64,8 +64,8 @@ public class ProtobufClientStatisticsImpl implements ProtobufClientStatistics {
     authenticationFailuresId = this.stats.nameToId("authenticationFailures");
     bytesReceivedId = this.stats.nameToId("bytesReceived");
     bytesSentId = this.stats.nameToId("bytesSent");
-    messagesReceivedId = this.stats.nameToId("bytesReceived");
-    messagesSentId = this.stats.nameToId("bytesSent");
+    messagesReceivedId = this.stats.nameToId("messagesReceived");
+    messagesSentId = this.stats.nameToId("messagesSent");
   }
 
   @Override
diff --git a/geode-protobuf/src/test/java/org/apache/geode/protocol/acceptance/CacheConnectionJUnitTest.java b/geode-protobuf/src/test/java/org/apache/geode/protocol/acceptance/CacheConnectionJUnitTest.java
index a4ba425..2a0680a 100644
--- a/geode-protobuf/src/test/java/org/apache/geode/protocol/acceptance/CacheConnectionJUnitTest.java
+++ b/geode-protobuf/src/test/java/org/apache/geode/protocol/acceptance/CacheConnectionJUnitTest.java
@@ -22,17 +22,15 @@ import static org.apache.geode.distributed.ConfigurationProperties.SSL_KEYSTORE_
 import static org.apache.geode.distributed.ConfigurationProperties.SSL_REQUIRE_AUTHENTICATION;
 import static org.apache.geode.distributed.ConfigurationProperties.SSL_TRUSTSTORE;
 import static org.apache.geode.distributed.ConfigurationProperties.SSL_TRUSTSTORE_PASSWORD;
-import static org.apache.geode.test.dunit.internal.JUnit4DistributedTestCase.disconnectAllFromDS;
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
 
-import java.io.File;
 import java.io.IOException;
 import java.io.OutputStream;
 import java.net.Socket;
 import java.util.Arrays;
 import java.util.Collection;
-import java.util.List;
 import java.util.Properties;
 import java.util.concurrent.TimeUnit;
 
@@ -48,11 +46,13 @@ import org.junit.rules.TestName;
 import org.junit.runner.RunWith;
 import org.junit.runners.Parameterized;
 
+import org.apache.geode.Statistics;
 import org.apache.geode.cache.Cache;
 import org.apache.geode.cache.CacheFactory;
 import org.apache.geode.cache.RegionFactory;
 import org.apache.geode.cache.server.CacheServer;
 import org.apache.geode.distributed.ConfigurationProperties;
+import org.apache.geode.distributed.internal.InternalDistributedSystem;
 import org.apache.geode.internal.AvailablePortHelper;
 import org.apache.geode.internal.admin.SSLConfig;
 import org.apache.geode.internal.cache.CacheServerImpl;
@@ -62,7 +62,6 @@ import org.apache.geode.internal.net.SocketCreatorFactory;
 import org.apache.geode.internal.protocol.protobuf.BasicTypes;
 import org.apache.geode.internal.protocol.protobuf.ClientProtocol;
 import org.apache.geode.internal.protocol.protobuf.RegionAPI;
-import org.apache.geode.internal.statistics.StatArchiveReader;
 import org.apache.geode.protocol.MessageUtil;
 import org.apache.geode.protocol.exception.InvalidProtocolMessageException;
 import org.apache.geode.protocol.protobuf.ProtobufSerializationService;
@@ -114,7 +113,6 @@ public class CacheConnectionJUnitTest {
 
   @Rule
   public TestName testName = new TestName();
-  private File statisticsArchiveFile;
 
   @Before
   public void setup() throws Exception {
@@ -127,9 +125,7 @@ public class CacheConnectionJUnitTest {
     cacheFactory.set(ConfigurationProperties.MCAST_PORT, "0");
     cacheFactory.set(ConfigurationProperties.ENABLE_CLUSTER_CONFIGURATION, "false");
     cacheFactory.set(ConfigurationProperties.USE_CLUSTER_CONFIGURATION, "false");
-    statisticsArchiveFile = temporaryFolder.newFile();
-    cacheFactory.set(ConfigurationProperties.STATISTIC_ARCHIVE_FILE,
-        statisticsArchiveFile.getPath());
+    cacheFactory.set(ConfigurationProperties.STATISTIC_SAMPLE_RATE, "100");
     cache = cacheFactory.create();
 
     CacheServer cacheServer = cache.addCacheServer();
@@ -162,7 +158,7 @@ public class CacheConnectionJUnitTest {
   }
 
   @Test
-  public void testNewProtocolHeaderLeadsToNewProtocolServerConnection() throws Exception {
+  public void testBasicMessagesAndStats() throws Exception {
     ProtobufProtocolSerializer protobufProtocolSerializer = new ProtobufProtocolSerializer();
     ClientProtocol.Message putMessage =
         MessageUtil.makePutRequestMessage(serializationService, TEST_KEY, TEST_VALUE, TEST_REGION,
@@ -175,45 +171,21 @@ public class CacheConnectionJUnitTest {
     protobufProtocolSerializer.serialize(getMessage, outputStream);
     validateGetResponse(socket, protobufProtocolSerializer, TEST_VALUE);
 
-    long startTime = System.currentTimeMillis();
-    Thread.sleep(3000);
-
-    long endTime = System.currentTimeMillis();
-
-    disconnectAllFromDS();
-
-    StatArchiveReader.ValueFilter filter = new StatArchiveReader.ValueFilter() {
-      @Override
-      public boolean archiveMatches(File archive) {
-        return true;
-      }
-
-      @Override
-      public boolean typeMatches(String type) {
-        return type.equals("ProtobufServerStats");
-      }
-
-      @Override
-      public boolean statMatches(String statName) {
-        return true;
-      }
-
-      @Override
-      public boolean instanceMatches(String textId, long numericId) {
-        return true;
-      }
-    };
-
-    StatArchiveReader reader = new StatArchiveReader(new File[] {statisticsArchiveFile},
-        new StatArchiveReader.ValueFilter[] {filter}, true);
-    List resourceInstList = reader.getResourceInstList();
-
-    assertEquals(1, resourceInstList.size());
-    StatArchiveReader.ResourceInst resourceInst =
-        (StatArchiveReader.ResourceInst) resourceInstList.iterator().next();
-    StatArchiveReader.StatValue statValue =
-        resourceInst.getStatValue("currentClientConnections").createTrimmed(startTime, endTime);
-    assertEquals(2.0, statValue.getSnapshotsMinimum(), 0.01);
+    InternalDistributedSystem distributedSystem =
+        (InternalDistributedSystem) cache.getDistributedSystem();
+    Statistics[] protobufServerStats =
+        distributedSystem.findStatisticsByType(distributedSystem.findType("ProtobufServerStats"));
+    assertEquals(1, protobufServerStats.length);
+    Statistics statistics = protobufServerStats[0];
+    assertEquals(1, statistics.get("currentClientConnections"));
+    assertEquals(2L, statistics.get("messagesReceived"));
+    assertEquals(2L, statistics.get("messagesSent"));
+    assertTrue(statistics.get("bytesReceived").longValue() > 0);
+    assertTrue(statistics.get("bytesSent").longValue() > 0);
+    assertEquals(1, statistics.get("clientConnectionStarts"));
+    assertEquals(0, statistics.get("clientConnectionTerminations"));
+    assertEquals(0L, statistics.get("authorizationViolations"));
+    assertEquals(0L, statistics.get("authenticationFailures"));
   }
 
   @Test
diff --git a/geode-protobuf/src/test/java/org/apache/geode/protocol/acceptance/LocatorConnectionDUnitTest.java b/geode-protobuf/src/test/java/org/apache/geode/protocol/acceptance/LocatorConnectionDUnitTest.java
index b4d3981..4e310d2 100644
--- a/geode-protobuf/src/test/java/org/apache/geode/protocol/acceptance/LocatorConnectionDUnitTest.java
+++ b/geode-protobuf/src/test/java/org/apache/geode/protocol/acceptance/LocatorConnectionDUnitTest.java
@@ -130,12 +130,6 @@ public class LocatorConnectionDUnitTest extends JUnit4CacheTestCase {
     Properties properties = super.getDistributedSystemProperties();
     properties.put(ConfigurationProperties.STATISTIC_SAMPLING_ENABLED, "true");
     properties.put(ConfigurationProperties.STATISTIC_SAMPLE_RATE, "100");
-    String statFileName = getUniqueName() + ".gfs";
-    properties.put(ConfigurationProperties.STATISTIC_ARCHIVE_FILE, statFileName);
-    File statFile = new File(statFileName);
-    if (statFile.exists()) {
-      statFile.delete();
-    }
     return properties;
   }
 

-- 
To stop receiving notification emails like this one, please contact
['"commits@geode.apache.org" <co...@geode.apache.org>'].