#732 filter wizard bug fix. incorrect agent mapping

- add testcase
This commit is contained in:
Woonduk Kang
2015-07-17 19:29:57 +09:00
parent 6edcbb995c
commit a370ea49f6
3 changed files with 83 additions and 17 deletions
@@ -37,11 +37,17 @@ public class ServerBuilder {
private final AgentHistogramList agentHistogramList;
private final Set<AgentInfoBo> agentSet;
private MatcherGroup matcherGroup = null;
private final MatcherGroup matcherGroup;
public ServerBuilder() {
// TODO FIX
this(null);
}
public ServerBuilder(MatcherGroup matcherGroup) {
this.agentHistogramList = new AgentHistogramList();
this.agentSet = new HashSet<AgentInfoBo>();
// TODO avoid null
this.matcherGroup = matcherGroup;
}
@@ -0,0 +1,68 @@
/*
* Copyright 2014 NAVER Corp.
*
* Licensed 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 com.navercorp.pinpoint.web.applicationmap;
import com.navercorp.pinpoint.common.bo.AgentInfoBo;
import com.navercorp.pinpoint.common.trace.ServiceType;
import org.junit.Assert;
import org.junit.Test;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import static org.junit.Assert.*;
/**
* @author emeroad
*/
public class ServerInstanceListTest {
@Test
public void testGetAgentIdList() throws Exception {
AgentInfoBo agentInfoBo1 = createAgentInfo("agentId1", "testHost");
AgentInfoBo agentInfoBo2 = createAgentInfo("agentId2", "testHost");
Set<AgentInfoBo> agentInfoBoSet = new HashSet<AgentInfoBo>();
agentInfoBoSet.add(agentInfoBo1);
agentInfoBoSet.add(agentInfoBo2);
ServerBuilder builder = new ServerBuilder();
builder.addAgentInfo(agentInfoBoSet);
ServerInstanceList serverInstanceList = builder.build();
List<String> agentIdList = serverInstanceList.getAgentIdList();
Assert.assertEquals(agentIdList.size(), 2);
Assert.assertEquals(agentIdList.get(0), "agentId1");
Assert.assertEquals(agentIdList.get(1), "agentId2");
}
public static AgentInfoBo createAgentInfo(String agentId, String hostName) {
AgentInfoBo.Builder agentInfoBuilder = new AgentInfoBo.Builder();
agentInfoBuilder.setAgentId(agentId);
ServiceType serviceType = ServiceType.TEST_STAND_ALONE;
agentInfoBuilder.setServiceTypeCode(serviceType.getCode());
// TODO FIX api
agentInfoBuilder.setServiceType(serviceType);
agentInfoBuilder.setHostName(hostName);
return agentInfoBuilder.build();
}
}
@@ -18,18 +18,17 @@ package com.navercorp.pinpoint.web.view;
import java.util.HashSet;
import com.navercorp.pinpoint.web.applicationmap.ServerInstanceListTest;
import org.junit.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.context.support.GenericXmlApplicationContext;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.ObjectWriter;
import com.navercorp.pinpoint.common.bo.AgentInfoBo;
import com.navercorp.pinpoint.common.trace.ServiceType;
import com.navercorp.pinpoint.web.applicationmap.ServerBuilder;
import com.navercorp.pinpoint.web.applicationmap.ServerInstanceList;
/**
* @author emeroad
*/
@@ -42,26 +41,19 @@ public class ServerInstanceListSerializerTest {
PinpointObjectMapper mapper = new PinpointObjectMapper();
mapper.afterPropertiesSet();
AgentInfoBo.Builder agentInfoBuilder = new AgentInfoBo.Builder();
agentInfoBuilder.setAgentId("agentId");
agentInfoBuilder.setServiceTypeCode(ServiceType.TEST_STAND_ALONE.getCode());
// TODO FIX api
agentInfoBuilder.setServiceType(ServiceType.TEST_STAND_ALONE);
AgentInfoBo agentInfoBo = ServerInstanceListTest.createAgentInfo("agentId1", "testHost");
agentInfoBuilder.setHostName("testcomputer");
HashSet<AgentInfoBo> agentInfoBoSet = new HashSet<AgentInfoBo>();
agentInfoBoSet.add(agentInfoBo);
AgentInfoBo agentInfoBo = agentInfoBuilder.build();
ServerBuilder builder = new ServerBuilder();
builder.addAgentInfo(agentInfoBoSet);
HashSet<AgentInfoBo> set = new HashSet<AgentInfoBo>();
set.add(agentInfoBo);
ServerBuilder builder = new ServerBuilder(null);
builder.addAgentInfo(set);
ServerInstanceList serverInstanceList = builder.build();
ObjectWriter objectWriter = mapper.writerWithDefaultPrettyPrinter();
String json = objectWriter.writeValueAsString(serverInstanceList);
logger.debug(json);
}
}