agresch commented on a change in pull request #3307: URL: https://github.com/apache/storm/pull/3307#discussion_r467275171
########## File path: storm-client/test/jvm/org/apache/storm/metrics2/BoltExecutorMetricsTest.java ########## @@ -0,0 +1,91 @@ +/** + * 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 + * <p/> + * http://www.apache.org/licenses/LICENSE-2.0 + * <p/> + * 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.storm.metrics2; + +import java.util.HashMap; +import java.util.Map; +import junit.framework.TestCase; +import org.apache.storm.Config; +import org.apache.storm.task.WorkerTopologyContext; +import org.junit.Assert; +import org.junit.Test; +import org.mockito.Mockito; + +public class BoltExecutorMetricsTest extends TestCase { + + @Test + public void testCounts() { + WorkerTopologyContext workerTopologyContext = Mockito.mock(WorkerTopologyContext.class); + Map<String, Object> topoConf = new HashMap<>(); + topoConf.put(Config.NUM_STAT_BUCKETS, 20); + topoConf.put(Config.TOPOLOGY_STATS_SAMPLE_RATE, 0.05); + BoltExecutorMetrics boltExecutorMetrics = new BoltExecutorMetrics(workerTopologyContext, new StormMetricRegistry(), topoConf); + + validateExecutorMetrics(boltExecutorMetrics); + + // test fail + boltExecutorMetrics.boltFailedTuple("component1", "stream1", 1); + Long stream1Count = boltExecutorMetrics.getFailTimeCounts().get("600").get("[component1, stream1]"); + Assert.assertEquals(new Long(20L),stream1Count); + Long stream2Count = boltExecutorMetrics.getFailTimeCounts().get("600").get("[component1, stream2]"); + Assert.assertNull(stream2Count); + + // test ack + boltExecutorMetrics.boltAckedTuple("component1", "stream1", 1, 10); + boltExecutorMetrics.boltAckedTuple("component1", "stream1", 1, 20); + boltExecutorMetrics.boltAckedTuple("component1", "stream2", 2, 222); + stream1Count = boltExecutorMetrics.getAckTimeCounts().get("600").get("[component1, stream1]"); + Assert.assertEquals(new Long(40L), stream1Count); Review comment: I will have to get back to you. Been a long time since I wrote this. ---------------------------------------------------------------- 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]
