Skip to content

Commit

Permalink
pinpoint-apm#745 filter wizard bug fix. incorrect agent mapping
Browse files Browse the repository at this point in the history
 - backport pinpoint-apm#732
 - add testcase
  • Loading branch information
emeroad committed Jul 20, 2015
1 parent aa6af1c commit 08095d9
Show file tree
Hide file tree
Showing 3 changed files with 87 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -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();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,18 @@

package com.navercorp.pinpoint.web.view;

import com.navercorp.pinpoint.common.ServiceType;
import com.navercorp.pinpoint.common.bo.AgentInfoBo;
import com.navercorp.pinpoint.web.applicationmap.ServerBuilder;
import com.navercorp.pinpoint.web.applicationmap.ServerInstanceList;
import java.util.HashSet;

import org.codehaus.jackson.map.ObjectMapper;
import org.codehaus.jackson.map.ObjectWriter;
import com.navercorp.pinpoint.web.applicationmap.ServerInstanceListTest;
import org.junit.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.HashSet;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.ObjectWriter;
import com.navercorp.pinpoint.common.bo.AgentInfoBo;
import com.navercorp.pinpoint.web.applicationmap.ServerBuilder;
import com.navercorp.pinpoint.web.applicationmap.ServerInstanceList;

/**
* @author emeroad
Expand All @@ -39,18 +39,15 @@ public class ServerInstanceListSerializerTest {

@Test
public void testSerialize() throws Exception {
AgentInfoBo.Builder agentInfoBuilder = new AgentInfoBo.Builder();
agentInfoBuilder.agentId("agentId");
agentInfoBuilder.serviceType(ServiceType.TOMCAT);
agentInfoBuilder.hostName("testcomputer");
AgentInfoBo agentInfoBo = ServerInstanceListTest.createAgentInfo("agentId1", "testHost");

AgentInfoBo agentInfoBo = agentInfoBuilder.build();
HashSet<AgentInfoBo> agentInfoBoSet = new HashSet<AgentInfoBo>();
agentInfoBoSet.add(agentInfoBo);

HashSet<AgentInfoBo> set = new HashSet<AgentInfoBo>();
set.add(agentInfoBo);

ServerBuilder builder = new ServerBuilder(null);
builder.addAgentInfo(set);
builder.addAgentInfo(agentInfoBoSet);

ServerInstanceList serverInstanceList = builder.build();
ObjectWriter objectWriter = mapper.writerWithDefaultPrettyPrinter();
String json = objectWriter.writeValueAsString(serverInstanceList);
Expand Down

0 comments on commit 08095d9

Please # to comment.