zentol commented on a change in pull request #6814: [FLINK-10423][rocksdb][metrics] rocksdb native metrics monitor URL: https://github.com/apache/flink/pull/6814#discussion_r223872647
########## File path: flink-state-backends/flink-statebackend-rocksdb/src/test/java/org/apache/flink/contrib/streaming/state/RocksDBNativeMetricTest.java ########## @@ -0,0 +1,160 @@ +/* + * 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.flink.contrib.streaming.state; + +import org.apache.flink.api.java.tuple.Tuple2; +import org.apache.flink.metrics.MetricGroup; +import org.apache.flink.util.ResourceGuard; + +import org.junit.Assert; +import org.junit.Rule; +import org.junit.Test; +import org.rocksdb.ColumnFamilyHandle; +import org.rocksdb.RocksDB; +import org.rocksdb.RocksDBException; + +import java.io.IOException; +import java.util.ArrayList; +import java.util.Collections; +import java.util.Map; +import java.util.concurrent.ConcurrentLinkedQueue; + +import static org.mockito.Matchers.any; +import static org.mockito.Mockito.eq; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.times; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; + +/** + * Tests that native metrics can be pulled from RocksDB. + */ +public class RocksDBNativeMetricTest { + + private static final String COLUMN_FAMILY_NAME = "test-cf"; + + private static final String PROPERTY = "property"; + + @Rule public RocksDBResource rocksDBResource = new RocksDBResource(); + + @Test + public void testMessageCollector() throws IOException { + ConcurrentLinkedQueue<Tuple2<String, ColumnFamilyHandle>> messageQueue = new ConcurrentLinkedQueue<>(); + + RocksDBNativeMetricMonitor.RocksDBNativeMetricTask task = new RocksDBNativeMetricMonitor.RocksDBNativeMetricTask( + mock(RocksDB.class), + new ResourceGuard(), + new ArrayList<>(), + mock(MetricGroup.class), + messageQueue + ); + + messageQueue.add(Tuple2.of("", mock(ColumnFamilyHandle.class))); + task.collectNewMessages(); + + Assert.assertEquals("failed to removed pending messages from queue", 0, messageQueue.size()); + Assert.assertEquals("failed to add message to kv state", 1, task.numberOfColumnFamilies()); + } + + @Test + public void testGaugeRegistration() throws IOException { + MetricGroup metricGroup = mock(MetricGroup.class); + MetricGroup innerGroup = mock(MetricGroup.class); Review comment: there are various utility classes to not require mocking for metric group related stuff. `UnregisteredMetricGroups` can be used to create safe default implementations where specific methods can be overridden. You can pass a custom MetricRegistry to check for specific metrics instead. ---------------------------------------------------------------- This is an automated message from the Apache Git Service. To respond to the message, please log on 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
