/*
* 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.runtime.webmonitor.metrics;
import akka.actor.ActorSystem;
import org.apache.flink.runtime.webmonitor.JobManagerRetriever;
import org.apache.flink.runtime.webmonitor.handlers.JobVertexAccumulatorsHandler;
import org.apache.flink.util.TestLogger;
import org.junit.Assert;
import org.junit.Test;
import scala.concurrent.ExecutionContext;
import java.util.HashMap;
import java.util.Map;
import static org.apache.flink.runtime.webmonitor.handlers.TaskManagersHandler.TASK_MANAGER_ID_KEY;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNull;
import static org.powermock.api.mockito.PowerMockito.mock;
public class TaskManagerMetricsHandlerTest extends TestLogger {
@Test
public void testGetPaths() {
TaskManagerMetricsHandler handler = new TaskManagerMetricsHandler(mock(MetricFetcher.class));
String[] paths = handler.getPaths();
Assert.assertEquals(1, paths.length);
Assert.assertEquals("/taskmanagers/:taskmanagerid/metrics", paths[0]);
}
@Test
public void getMapFor() throws Exception {
MetricFetcher fetcher = new MetricFetcher(mock(ActorSystem.class), mock(JobManagerRetriever.class), mock(ExecutionContext.class));
MetricStore store = MetricStoreTest.setupStore(fetcher.getMetricStore());
TaskManagerMetricsHandler handler = new TaskManagerMetricsHandler(fetcher);
Map<String, String> pathParams = new HashMap<>();
pathParams.put(TASK_MANAGER_ID_KEY, "tmid");
Map<String, String> metrics = handler.getMapFor(pathParams, store);
assertEquals("1", metrics.get("abc.metric2"));
}
@Test
public void getMapForNull() {
MetricFetcher fetcher = new MetricFetcher(mock(ActorSystem.class), mock(JobManagerRetriever.class), mock(ExecutionContext.class));
MetricStore store = fetcher.getMetricStore();
TaskManagerMetricsHandler handler = new TaskManagerMetricsHandler(fetcher);
Map<String, String> pathParams = new HashMap<>();
Map<String, String> metrics = handler.getMapFor(pathParams, store);
assertNull(metrics);
}
}