Unit test for startup metrics parsing, refactoring.
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
/*******************************************************************************
|
||||
* Copyright (c) 2017, 2019 Pivotal, Inc.
|
||||
* Copyright (c) 2017, 2020 Pivotal, Inc.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Eclipse Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
@@ -187,8 +187,8 @@ public abstract class AbstractInjectedIntoHoverProvider implements HoverProvider
|
||||
AutowiredHoverProvider.createHoverContentForBeans(sourceLinks, project, hover, wiredBeans);
|
||||
}
|
||||
|
||||
if (liveData.getStartup() != null) {
|
||||
Duration instanciationTime = liveData.getStartup().getBeanInstanciationTime(definedBean.getId());
|
||||
if (liveData.getStartupMetrics() != null) {
|
||||
Duration instanciationTime = liveData.getStartupMetrics().getBeanInstanciationTime(definedBean.getId());
|
||||
if (instanciationTime != null) {
|
||||
hover.append("Instanciation Time: ");
|
||||
hover.append(instanciationTime.toMillis());
|
||||
|
||||
@@ -1,3 +1,13 @@
|
||||
/*******************************************************************************
|
||||
* Copyright (c) 2020 Pivotal, Inc.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Eclipse Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* https://www.eclipse.org/legal/epl-v10.html
|
||||
*
|
||||
* Contributors:
|
||||
* Pivotal, Inc. - initial API and implementation
|
||||
*******************************************************************************/
|
||||
package org.springframework.ide.vscode.boot.java.livehover.v2;
|
||||
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*******************************************************************************
|
||||
* Copyright (c) 2019 Pivotal, Inc.
|
||||
* Copyright (c) 2019, 2020 Pivotal, Inc.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Eclipse Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
@@ -29,12 +29,12 @@ public class SpringProcessLiveData {
|
||||
private final LiveConditional[] conditionals;
|
||||
private final LiveProperties properties;
|
||||
private final LiveMetricsModel metrics;
|
||||
private StartupModel startup;
|
||||
private StartupMetricsModel startup;
|
||||
|
||||
public SpringProcessLiveData(String processName, String processID, String contextPath, String urlScheme,
|
||||
String port, String host, LiveBeansModel beansModel, String[] activeProfiles,
|
||||
LiveRequestMapping[] requestMappings, LiveConditional[] conditionals, LiveProperties properties,
|
||||
LiveMetricsModel metrics, StartupModel startup) {
|
||||
LiveMetricsModel metrics, StartupMetricsModel startup) {
|
||||
super();
|
||||
this.processName = processName;
|
||||
this.processID = processID;
|
||||
@@ -100,7 +100,7 @@ public class SpringProcessLiveData {
|
||||
return this.metrics;
|
||||
}
|
||||
|
||||
public StartupModel getStartup() {
|
||||
public StartupMetricsModel getStartupMetrics() {
|
||||
return startup;
|
||||
}
|
||||
|
||||
|
||||
@@ -93,7 +93,7 @@ public class SpringProcessLiveDataExtractorOverJMX {
|
||||
LiveRequestMapping[] requestMappings = getRequestMappings(connection, domain);
|
||||
LiveBeansModel beans = getBeans(connection, domain);
|
||||
LiveMetricsModel metrics = getMetrics(connection, domain);
|
||||
StartupModel startup = getStartup(connection, domain, currentData == null ? null : currentData.getStartup());
|
||||
StartupMetricsModel startup = getStartupMetrics(connection, domain, currentData == null ? null : currentData.getStartupMetrics());
|
||||
|
||||
if (contextPath == null) {
|
||||
contextPath = getContextPath(connection, domain, environment);
|
||||
@@ -164,14 +164,14 @@ public class SpringProcessLiveDataExtractorOverJMX {
|
||||
};
|
||||
}
|
||||
|
||||
private StartupModel getStartup(MBeanServerConnection connection, String domain, StartupModel currentStartup) {
|
||||
private StartupMetricsModel getStartupMetrics(MBeanServerConnection connection, String domain, StartupMetricsModel currentStartup) {
|
||||
if (currentStartup != null) {
|
||||
return currentStartup;
|
||||
}
|
||||
try {
|
||||
Map<?,?> result = (Map<?,?>) getActuatorDataFromOperation(connection, getObjectName(domain, "type=Endpoint,name=Startup"), "startup");
|
||||
if (result != null) {
|
||||
return StartupModel.parse(result);
|
||||
return StartupMetricsModel.parse(result);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
log.error("", e);
|
||||
|
||||
@@ -1,3 +1,13 @@
|
||||
/*******************************************************************************
|
||||
* Copyright (c) 2020 Pivotal, Inc.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Eclipse Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* https://www.eclipse.org/legal/epl-v10.html
|
||||
*
|
||||
* Contributors:
|
||||
* Pivotal, Inc. - initial API and implementation
|
||||
*******************************************************************************/
|
||||
package org.springframework.ide.vscode.boot.java.livehover.v2;
|
||||
|
||||
import java.time.Duration;
|
||||
@@ -11,7 +21,13 @@ import com.google.gson.GsonBuilder;
|
||||
import com.google.gson.JsonDeserializer;
|
||||
import com.google.gson.reflect.TypeToken;
|
||||
|
||||
public class StartupModel {
|
||||
/**
|
||||
* POJO for Startup metrics data
|
||||
*
|
||||
* @author Alex Boyko
|
||||
*
|
||||
*/
|
||||
public class StartupMetricsModel {
|
||||
|
||||
private static final String BEAN_INSTANCIATION_EVENT = "spring.beans.instantiate";
|
||||
|
||||
@@ -106,13 +122,14 @@ public class StartupModel {
|
||||
}
|
||||
}
|
||||
|
||||
public static StartupModel parse(Map<?, ?> mapContent) {
|
||||
public static StartupMetricsModel parse(Map<?, ?> mapContent) {
|
||||
Object timeline = mapContent.get("timeline");
|
||||
if (timeline instanceof Map) {
|
||||
Object events = ((Map<?,?>) timeline).get("events");
|
||||
if (events instanceof List) {
|
||||
List<StartupEvent> fromJson = gson.fromJson(gson.toJson(events), new TypeToken<List<StartupEvent>>() {}.getType());
|
||||
return new StartupModel(fromJson);
|
||||
String json = gson.toJson(events);
|
||||
List<StartupEvent> fromJson = gson.fromJson(json, new TypeToken<List<StartupEvent>>() {}.getType());
|
||||
return new StartupMetricsModel(fromJson);
|
||||
}
|
||||
}
|
||||
return null;
|
||||
@@ -122,7 +139,7 @@ public class StartupModel {
|
||||
|
||||
private Map<String, Duration> beanInstanciationTimes;
|
||||
|
||||
public StartupModel(List<StartupEvent> startupEvents) {
|
||||
public StartupMetricsModel(List<StartupEvent> startupEvents) {
|
||||
this.startupEvents = startupEvents;
|
||||
beanInstanciationTimes = createbeanInstanciationTimes();
|
||||
}
|
||||
@@ -1,3 +1,13 @@
|
||||
/*******************************************************************************
|
||||
* Copyright (c) 2020 Pivotal, Inc.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Eclipse Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* https://www.eclipse.org/legal/epl-v10.html
|
||||
*
|
||||
* Contributors:
|
||||
* Pivotal, Inc. - initial API and implementation
|
||||
*******************************************************************************/
|
||||
package org.springframework.ide.vscode.boot.java.metrics.test;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
|
||||
@@ -1,5 +1,37 @@
|
||||
/*******************************************************************************
|
||||
* Copyright (c) 2020 Pivotal, Inc.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Eclipse Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* https://www.eclipse.org/legal/epl-v10.html
|
||||
*
|
||||
* Contributors:
|
||||
* Pivotal, Inc. - initial API and implementation
|
||||
*******************************************************************************/
|
||||
package org.springframework.ide.vscode.boot.java.metrics.test;
|
||||
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
|
||||
import java.io.InputStreamReader;
|
||||
import java.time.Duration;
|
||||
import java.util.Map;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.springframework.ide.vscode.boot.java.livehover.v2.StartupMetricsModel;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
|
||||
public class StartupMetricsTest {
|
||||
|
||||
@Test
|
||||
public void testParser() throws Exception {
|
||||
Gson gson = new Gson();
|
||||
Map<?,?> mapContent = gson.fromJson(new InputStreamReader(getClass().getResourceAsStream("/test-files/startup.json")), Map.class);
|
||||
StartupMetricsModel startupMetricsModel = StartupMetricsModel.parse(mapContent);
|
||||
assertNotNull(startupMetricsModel);
|
||||
assertEquals(419, startupMetricsModel.getStartupEvents().size());
|
||||
assertEquals(Duration.ofNanos(10298253), startupMetricsModel.getBeanInstanciationTime("ownerController"));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*******************************************************************************
|
||||
* Copyright (c) 2019 Pivotal, Inc.
|
||||
* Copyright (c) 2019, 2020 Pivotal, Inc.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Eclipse Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
@@ -23,7 +23,7 @@ import org.springframework.ide.vscode.boot.java.livehover.v2.LiveMetricsModel;
|
||||
import org.springframework.ide.vscode.boot.java.livehover.v2.LiveProperties;
|
||||
import org.springframework.ide.vscode.boot.java.livehover.v2.LiveRequestMapping;
|
||||
import org.springframework.ide.vscode.boot.java.livehover.v2.LiveRequestMappingBoot1xRequestMapping;
|
||||
import org.springframework.ide.vscode.boot.java.livehover.v2.StartupModel;
|
||||
import org.springframework.ide.vscode.boot.java.livehover.v2.StartupMetricsModel;
|
||||
import org.springframework.ide.vscode.boot.java.livehover.v2.SpringProcessLiveData;
|
||||
|
||||
/**
|
||||
@@ -45,7 +45,7 @@ public class SpringProcessLiveDataBuilder {
|
||||
private LiveConditional[] conditionals;
|
||||
private LiveProperties properties;
|
||||
private LiveMetricsModel metrics;
|
||||
private StartupModel startup;
|
||||
private StartupMetricsModel startup;
|
||||
|
||||
public SpringProcessLiveDataBuilder processName(String processName) {
|
||||
this.processName = processName;
|
||||
@@ -131,7 +131,7 @@ public class SpringProcessLiveDataBuilder {
|
||||
return this;
|
||||
}
|
||||
|
||||
public SpringProcessLiveDataBuilder liveStartup(StartupModel startup) {
|
||||
public SpringProcessLiveDataBuilder liveStartup(StartupMetricsModel startup) {
|
||||
this.startup = startup;
|
||||
return this;
|
||||
}
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user