#377 support depth-limited search

- add testcase
This commit is contained in:
Woonduk Kang
2015-05-13 10:43:46 +09:00
parent 7a6923bd76
commit d56eeede0f
3 changed files with 117 additions and 11 deletions
@@ -37,6 +37,7 @@ import org.slf4j.LoggerFactory;
import java.util.*;
/**
* Breadth-first link search
* not thread safe
* @author emeroad
*/
@@ -58,7 +59,7 @@ public class BFSLinkSelector implements LinkSelector {
private final Queue nextQueue = new Queue();
public BFSLinkSelector(MapStatisticsCalleeDao mapStatisticsCalleeDao, MapStatisticsCallerDao mapStatisticsCallerDao, HostApplicationMapDao hostApplicationMapDao) {
public BFSLinkSelector(MapStatisticsCallerDao mapStatisticsCallerDao, MapStatisticsCalleeDao mapStatisticsCalleeDao, HostApplicationMapDao hostApplicationMapDao) {
if (mapStatisticsCalleeDao == null) {
throw new NullPointerException("mapStatisticsCalleeDao must not be null");
}
@@ -74,7 +75,7 @@ public class BFSLinkSelector implements LinkSelector {
}
/**
* Queries for all applications(callee) called by the targetApplication
* Queries for all applications(caller&callee) called by the targetApplicationList
*
* @param targetApplicationList
* @param range
@@ -18,7 +18,6 @@ package com.navercorp.pinpoint.web.service;
import java.util.*;
import com.navercorp.pinpoint.common.service.ServiceTypeRegistryService;
import com.navercorp.pinpoint.common.trace.ServiceType;
import com.navercorp.pinpoint.web.applicationmap.ApplicationMap;
import com.navercorp.pinpoint.web.applicationmap.ApplicationMapBuilder;
@@ -63,10 +62,6 @@ public class MapServiceImpl implements MapService {
@Autowired(required=false)
private MatcherGroup matcherGroup;
@Autowired()
private ServiceTypeRegistryService registry;
/**
* Used in the main UI - draws the server map by querying the timeslot by time.
*/
@@ -82,8 +77,8 @@ public class MapServiceImpl implements MapService {
StopWatch watch = new StopWatch("ApplicationMap");
watch.start("ApplicationMap Hbase Io Fetch(Caller,Callee) Time");
// LinkSelector linkSelector = new DFSLinkSelector(this.mapStatisticsCalleeDao, this.mapStatisticsCallerDao, hostApplicationMapDao);
LinkSelector linkSelector = new BFSLinkSelector(this.mapStatisticsCalleeDao, this.mapStatisticsCallerDao, hostApplicationMapDao);
LinkSelector linkSelector = new BFSLinkSelector(this.mapStatisticsCallerDao, this.mapStatisticsCalleeDao, hostApplicationMapDao);
LinkDataDuplexMap linkDataDuplexMap = linkSelector.select(sourceApplication, range, searchOption);
watch.stop();
@@ -91,8 +86,9 @@ public class MapServiceImpl implements MapService {
ApplicationMapBuilder builder = new ApplicationMapBuilder(range, matcherGroup);
ApplicationMap map = builder.build(linkDataDuplexMap, agentInfoService, this.mapResponseDao);
watch.stop();
logger.info("ApplicationMap BuildTime: {}", watch.prettyPrint());
if (logger.isInfoEnabled()) {
logger.info("ApplicationMap BuildTime: {}", watch.prettyPrint());
}
return map;
}
@@ -0,0 +1,109 @@
/*
* 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.service;
import com.navercorp.pinpoint.common.trace.HistogramSchema;
import com.navercorp.pinpoint.common.trace.ServiceType;
import com.navercorp.pinpoint.web.applicationmap.rawdata.LinkDataDuplexMap;
import com.navercorp.pinpoint.web.applicationmap.rawdata.LinkDataMap;
import com.navercorp.pinpoint.web.dao.HostApplicationMapDao;
import com.navercorp.pinpoint.web.dao.MapStatisticsCalleeDao;
import com.navercorp.pinpoint.web.dao.MapStatisticsCallerDao;
import com.navercorp.pinpoint.web.service.map.AcceptApplication;
import com.navercorp.pinpoint.web.vo.Application;
import com.navercorp.pinpoint.web.vo.Range;
import com.navercorp.pinpoint.web.vo.SearchOption;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import java.util.HashSet;
import static org.mockito.Matchers.anyObject;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
/**
* @author emeroad
*/
public class BFSLinkSelectorTest {
private MapStatisticsCallerDao callerDao;
private MapStatisticsCalleeDao calleeDao;
private HostApplicationMapDao hostApplicationMapDao;
Application APP_A = new Application("APP_A", ServiceType.STAND_ALONE);
Application APP_B = new Application("APP_B", ServiceType.STAND_ALONE);
Application APP_C = new Application("APP_B", ServiceType.STAND_ALONE);
// APP_A ->
Range range = new Range(0, 100);
SearchOption option = new SearchOption(1, 1);
@Before
public void setUp() throws Exception {
this.callerDao = mock(MapStatisticsCallerDao.class);
this.calleeDao = mock(MapStatisticsCalleeDao.class);
this.hostApplicationMapDao = mock(HostApplicationMapDao.class);
}
@Test
public void testEmpty() throws Exception {
when(callerDao.selectCaller((Application) anyObject(), (Range) anyObject())).thenReturn(new LinkDataMap());
when(calleeDao.selectCallee((Application) anyObject(), (Range) anyObject())).thenReturn(new LinkDataMap());
when(hostApplicationMapDao.findAcceptApplicationName((Application) anyObject(), (Range) anyObject())).thenReturn(new HashSet<AcceptApplication>());
BFSLinkSelector bfsLinkSelector = new BFSLinkSelector(this.callerDao, this.calleeDao, hostApplicationMapDao);
LinkDataDuplexMap select = bfsLinkSelector.select(APP_A, range, option);
Assert.assertEquals(select.size(), 1);
}
@Test
public void testCaller() throws Exception {
Application sourceApp = new Application("APP_A", ServiceType.STAND_ALONE);
Application targetApp = new Application("APP_B", ServiceType.STAND_ALONE);
LinkDataMap linkDataMap = new LinkDataMap();
linkDataMap.addLinkData(sourceApp, "agentA", targetApp, "agentB", 1000, HistogramSchema.FAST_SCHEMA.getNormalSlot().getSlotTime(), 1);
when(callerDao.selectCaller((Application) anyObject(), (Range) anyObject())).thenReturn(linkDataMap);
when(calleeDao.selectCallee((Application) anyObject(), (Range) anyObject())).thenReturn(new LinkDataMap());
when(hostApplicationMapDao.findAcceptApplicationName((Application) anyObject(), (Range) anyObject())).thenReturn(new HashSet<AcceptApplication>());
BFSLinkSelector bfsLinkSelector = new BFSLinkSelector(this.callerDao, this.calleeDao, hostApplicationMapDao);
Range range = new Range(0, 100);
SearchOption option = new SearchOption(1, 1);
LinkDataDuplexMap select = bfsLinkSelector.select(sourceApp, range, option);
Assert.assertEquals(select.size(), 1);
Assert.assertEquals(select.getSourceLinkDataList().size(), 1);
}
}