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_r389123442
 
 

 ##########
 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++) {
+      keys.add(getRandomString());
+      values.add(getRandomString());
+    }
+
+    Collections.shuffle(keys);
+    Collections.shuffle(values);
+
 
 Review comment:
   At the beginning I didn't use a random way to generate keys and values so I 
had to shuffle them. I forgot to delete the shuffle code later on. I modified 
the test case and deleted them 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:
[email protected]


With regards,
Apache Git Services

Reply via email to