You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@samza.apache.org by GitBox <gi...@apache.org> on 2020/03/06 20:15:22 UTC

[GitHub] [samza] xiefan46 commented on a change in pull request #1301: Samza-2478: Add new metrics to track key and value size of records written to RocksDb

xiefan46 commented on a change in pull request #1301: Samza-2478: Add new metrics to track key and value size of records written to RocksDb
URL: https://github.com/apache/samza/pull/1301#discussion_r389122368
 
 

 ##########
 File path: samza-test/src/test/java/org/apache/samza/storage/kv/TestKeyValueSizeHistogramMetric.java
 ##########
 @@ -0,0 +1,129 @@
+/*
+ * 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.samza.storage.kv;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+import java.util.Random;
+import org.apache.samza.SamzaException;
+import org.apache.samza.metrics.Counter;
+import org.apache.samza.metrics.Gauge;
+import org.apache.samza.metrics.MetricsRegistryMap;
+import org.apache.samza.metrics.MetricsVisitor;
+import org.apache.samza.metrics.Timer;
+import org.apache.samza.serializers.Serde;
+import org.apache.samza.serializers.StringSerde;
+import org.apache.samza.storage.kv.inmemory.InMemoryKeyValueStore;
+import org.junit.After;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+
+
+/**
+ * This class is used to test whether the key value size metrics in {@link SerializedKeyValueStoreMetrics} works correctly.
+ */
+public class TestKeyValueSizeHistogramMetric {
+
+  private static String storeName = "testStore";
+  private static MetricsRegistryMap metricsRegistry = new MetricsRegistryMap();
+  private static KeyValueStoreMetrics keyValueStoreMetrics = new KeyValueStoreMetrics(storeName, metricsRegistry);
+  private static SerializedKeyValueStoreMetrics serializedKeyValueStoreMetrics =
+      new SerializedKeyValueStoreMetrics(storeName, metricsRegistry);
+  private static Serde<String> stringSerde = new StringSerde();
+  private static Random random = new Random();
+
+  private KeyValueStore<String, String> store = null;
+
+  @Before
+  public void setup() {
+    KeyValueStore<byte[], byte[]> kvStore = new InMemoryKeyValueStore(keyValueStoreMetrics);
+    KeyValueStore<String, String> serializedStore =
+        new SerializedKeyValueStore<>(kvStore, stringSerde, stringSerde, serializedKeyValueStoreMetrics);
+    store = new NullSafeKeyValueStore<>(serializedStore);
+  }
+
+  /**
+   * Make sure that the histograms can record the key value size and we can use a
+   * {@link MetricsVisitor} to get access to the value store in the histograms
+   */
+  @Test
+  public void testHistogramMetric() {
+
+    List<String> keys = new ArrayList<>();
+    List<String> values = new ArrayList<>();
+
+    for (int i = 0; i < 1000; i++) {
 
 Review comment:
   Use 300 instead of 1000 in this for loop and also reduce the max length of random string to 100. This test takes less than 1s now. 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services