/** * Test equal restriction with field navigation. */ @Test public void equalsTrueNavigation() { HttpTimerData httpData = new HttpTimerData(); httpData.getHttpInfo().setId(1L); List<IIndexQueryRestriction> restrictions = Collections.singletonList(IndexQueryRestrictionFactory.equal("httpInfo.id", 1L)); boolean result = processor.areAllRestrictionsFulfilled(httpData, restrictions); assertThat(result, is(true)); }
@Override public boolean matches(Object object) { if (!HttpTimerData.class.isInstance(object)) { return false; } HttpTimerData other = (HttpTimerData) object; assertThat(data.getHttpInfo().getUri(), is(equalTo(other.getHttpInfo().getUri()))); assertThat(data.getHttpInfo().getRequestMethod(), is(equalTo(other.getHttpInfo().getRequestMethod()))); assertThat(data.getAttributes(), is(equalTo(other.getAttributes()))); assertThat(data.getHeaders(), is(equalTo(other.getHeaders()))); assertThat(data.getSessionAttributes(), is(equalTo(other.getSessionAttributes()))); assertThat(data.getParameters(), is(equalTo(other.getParameters()))); assertThat(data.isCharting(), is(equalTo(other.isCharting()))); assertThat(data.getHttpResponseStatus(), is(equalTo(other.getHttpResponseStatus()))); return true; } }
return emptyStyledString; case TAG_VALUE: return new StyledString(data.getHttpInfo().getInspectItTaggingHeaderValue()); case HTTP_METHOD: return new StyledString(data.getHttpInfo().getRequestMethod()); case INVOCATION_AFFILLIATION: int percentage = (int) (data.getInvocationAffiliationPercentage() * 100); int invocations = 0; if (null != data.getInvocationParentsIdSet()) { invocations = data.getInvocationParentsIdSet().size(); return new StyledString(String.valueOf(data.getCount())); case AVERAGE: if (data.isTimeDataAvailable()) { return new StyledString(NumberFormatter.formatDouble(data.getAverage(), timeDecimalPlaces)); } else { return emptyStyledString; if (data.isTimeDataAvailable()) { return new StyledString(NumberFormatter.formatDouble(data.getMin(), timeDecimalPlaces)); } else { return emptyStyledString; if (data.isTimeDataAvailable()) { return new StyledString(NumberFormatter.formatDouble(data.getMax(), timeDecimalPlaces)); } else { return emptyStyledString; if (data.isTimeDataAvailable()) {
/** * {@inheritDoc} */ @Override protected void addFields(HttpTimerData data, Builder builder) { builder.addField(Series.Http.FIELD_DURATION, data.getDuration()); if (HttpTimerDataHelper.hasResponseCode(data)) { builder.addField(Series.Http.FIELD_HTTP_RESPONSE_CODE, data.getHttpResponseStatus()); } }
Root<? extends HttpTimerData> root = criteria.from(HttpTimerData.class); Predicate platformId = builder.equal(root.get("platformIdent"), templates.iterator().next().getPlatformIdent()); Predicate timestamp = builder.between(root.<Timestamp> get("timeStamp"), new Timestamp(fromDate.getTime()), new Timestamp(toDate.getTime())); Predicate condition = null; Set<String> uris = new HashSet<>(); for (HttpTimerData httpTimerData : templates) { if (!HttpInfo.UNDEFINED.equals(httpTimerData.getHttpInfo().getUri())) { uris.add(httpTimerData.getHttpInfo().getUri()); if (httpTimerData.getHttpInfo().hasInspectItTaggingHeader()) { tags.add(httpTimerData.getHttpInfo().getInspectItTaggingHeaderValue());
/** * {@inheritDoc} */ @Override public void setInputDefinition(InputDefinition inputDefinition) { super.setInputDefinition(inputDefinition); template = new HttpTimerData(); template.setPlatformIdent(inputDefinition.getIdDefinition().getPlatformId()); httptimerDataAccessService = inputDefinition.getRepositoryDefinition().getHttpTimerDataAccessService(); }
HttpTimerData data = new HttpTimerData(); data.setPlatformIdent(platformId); data.setMethodIdent(methodId); data.setSensorTypeIdent(sensorTypeId); data.setTimeStamp(timestamp); data.setDuration(duration); data.calculateMin(duration); data.calculateMax(duration); data.setCpuDuration(cpuDuration); data.calculateCpuMax(cpuDuration); data.calculateCpuMin(cpuDuration); data.setCount(1L); data.getHttpInfo().setUri(extractor.getRequestUri(servletRequestClass, httpServletRequest)); data.getHttpInfo().setRequestMethod(extractor.getRequestMethod(servletRequestClass, httpServletRequest)); data.getHttpInfo().setScheme(extractor.getScheme(servletRequestClass, httpServletRequest)); data.getHttpInfo().setServerName(extractor.getServerName(servletRequestClass, httpServletRequest)); data.getHttpInfo().setServerPort(extractor.getServerPort(servletRequestClass, httpServletRequest)); data.getHttpInfo().setQueryString(extractor.getQueryString(servletRequestClass, httpServletRequest)); data.setHeaders(extractor.getHeaders(servletRequestClass, httpServletRequest)); data.setAttributes(extractor.getAttributes(servletRequestClass, httpServletRequest)); data.setParameters(extractor.getParameterMap(servletRequestClass, httpServletRequest)); data.setSessionAttributes(extractor.getSessionAttributes(servletRequestClass, httpServletRequest));
/** * {@inheritDoc} */ @Override public Object getAggregationKey(HttpTimerData httpData) { final int prime = 31; int result = 0; if (uriBased) { result = (prime * result) + ((httpData.getHttpInfo().getUri() == null) ? 0 : httpData.getHttpInfo().getUri().hashCode()); } else { result = (prime * result) + ((httpData.getHttpInfo().getInspectItTaggingHeaderValue() == null) ? 0 : httpData.getHttpInfo().getInspectItTaggingHeaderValue().hashCode()); } if (includeRequestMethod) { result = (prime * result) + ((httpData.getHttpInfo().getRequestMethod() == null) ? 0 : httpData.getHttpInfo().getRequestMethod().hashCode()); } return result; }
@Test public void aggregationWithInspectITHeader() { final HttpTimerData data = new HttpTimerData(); Map<String, String> map = new HashMap<>(); MapUtils.putAll(map, new String[][] { { HttpTimerData.INSPECTIT_TAGGING_HEADER, "tag1" } }); data.setHeaders(map); data.getHttpInfo().setUri("URI"); data.getHttpInfo().setRequestMethod("GET"); data.setDuration(100d); data.setCpuDuration(10d); data.calculateCpuMin(10d); data.calculateCpuMax(10d); data.setCpuDuration(10d); final HttpTimerData data2 = new HttpTimerData(); data2.setHeaders(new HashMap<String, String>() { private static final long serialVersionUID = 6328525502662081826L; data2.getHttpInfo().setUri("URI"); data2.getHttpInfo().setRequestMethod("GET"); data2.setDuration(500d); data2.calculateCpuMin(20d); data2.calculateCpuMax(20d); data2.setCpuDuration(20d); assertThat(output.size(), is(equalTo(1))); HttpTimerData result = output.get(0); assertThat(result.getHttpInfo().getUri(), is(equalTo(HttpInfo.UNDEFINED))); assertThat(result.getHttpInfo().hasInspectItTaggingHeader(), is(equalTo(true)));
@Test public void noTag() throws Exception { when(cachedDataService.getPlatformIdentForId(PLATFORM_ID)).thenReturn(platformIdent); long time = RandomUtils.nextLong(); when(data.getPlatformIdent()).thenReturn(PLATFORM_ID); when(data.getTimeStamp()).thenReturn(new Timestamp(time)); when(data.getHttpInfo()).thenReturn(httpInfo); when(httpInfo.getUri()).thenReturn(URI); when(httpInfo.hasInspectItTaggingHeader()).thenReturn(false); when(httpInfo.getInspectItTaggingHeaderValue()).thenReturn(null); Collection<Builder> pointBuilderCol = builder.createBuilders(data); assertThat(pointBuilderCol.size(), is(1)); Builder pointBuilder = pointBuilderCol.iterator().next(); assertThat(getMeasurement(pointBuilder), is(Series.Http.NAME)); assertThat(getTime(pointBuilder), is(time)); assertThat(getPrecision(pointBuilder), is(TimeUnit.MILLISECONDS)); assertThat(getTags(pointBuilder), not(hasKey(Series.Http.TAG_INSPECTIT_TAGGING_HEADER))); assertThat(getFields(pointBuilder), hasEntry(Series.Http.FIELD_DURATION, (Object) data.getDuration())); }
@Test public void aggregationURI() { final HttpTimerData data = new HttpTimerData(); data.getHttpInfo().setUri("URI"); data.getHttpInfo().setRequestMethod("GET"); data.setDuration(100d); data.setCpuDuration(10d); data.calculateCpuMin(10d); data.calculateCpuMax(10d); data.setCpuDuration(10d); final HttpTimerData data2 = new HttpTimerData(); data2.getHttpInfo().setUri("URI"); data2.getHttpInfo().setRequestMethod("POST"); data2.setDuration(500d); data2.calculateCpuMin(20d); data2.calculateCpuMax(20d); data2.setCpuDuration(20d); final List<HttpTimerData> input = new ArrayList<>(); Collections.addAll(input, data, data2); AggregationPerformer<HttpTimerData> aggregationPerformer = new AggregationPerformer<>(new HttpTimerDataAggregator(true, false)); aggregationPerformer.processCollection(input); final List<HttpTimerData> output = aggregationPerformer.getResultList(); assertThat(output, is(notNullValue())); assertThat(output.size(), is(equalTo(1))); HttpTimerData result = output.get(0); assertThat(result.getHttpInfo().getUri(), is(equalTo("URI"))); assertThat(result.getHttpInfo().hasInspectItTaggingHeader(), is(equalTo(false))); assertThat(result.getDuration(), is(equalTo(600d))); assertThat(result.getCpuDuration(), is(equalTo(30d))); }
Long secondCpuTimerValue = 6872L; HttpTimerData tmp = new HttpTimerData(null, platformId, sensorTypeId, methodId); tmp.getHttpInfo().setRequestMethod(method); tmp.getHttpInfo().setUri(uri); Map<String, String> attributeMap = new HashMap<String, String>(); MapUtils.putAll(attributeMap, new Object[][] { { att1, att1Value }, { att2, att2Value } }); tmp.setAttributes(attributeMap); tmp.setParameters(parameterMap); tmp.setHeaders(headerMap); tmp.setSessionAttributes(sessionAtrMap); tmp.setHttpResponseStatus(responseStatus);
HttpTimerData httpData = new HttpTimerData(); httpData.setMethodIdent(1L); httpData.getHttpInfo().setInspectItTaggingHeaderValue("blaha"); searchCriteria.setCaseSensitive(false); assertThat(SearchFactory.isSearchCompatible(httpData, searchCriteria, repositoryDefinition), is(equalTo(true))); httpData.getHttpInfo().setInspectItTaggingHeaderValue(""); httpData.getHttpInfo().setUri("ablah"); searchCriteria.setCaseSensitive(false); assertThat(SearchFactory.isSearchCompatible(httpData, searchCriteria, repositoryDefinition), is(equalTo(true))); httpData.getHttpInfo().setUri(""); httpData.getHttpInfo().setRequestMethod("ablaha"); searchCriteria.setCaseSensitive(false); assertThat(SearchFactory.isSearchCompatible(httpData, searchCriteria, repositoryDefinition), is(equalTo(true))); httpData.getHttpInfo().setRequestMethod(""); httpData.setAttributes(map); searchCriteria.setCaseSensitive(false); assertThat(SearchFactory.isSearchCompatible(httpData, searchCriteria, repositoryDefinition), is(equalTo(true))); httpData.setAttributes(Collections.<String, String> emptyMap()); httpData.setSessionAttributes(map); searchCriteria.setCaseSensitive(false); assertThat(SearchFactory.isSearchCompatible(httpData, searchCriteria, repositoryDefinition), is(equalTo(true))); httpData.setSessionAttributes(Collections.<String, String> emptyMap()); map.clear();
@Test public void aggregationURIRequestMethods() { final HttpTimerData data = new HttpTimerData(); data.getHttpInfo().setUri("URI"); data.getHttpInfo().setRequestMethod("GET"); data.setDuration(100d); data.setCpuDuration(10d); data.calculateCpuMin(10d); data.calculateCpuMax(10d); data.setCpuDuration(10d); final HttpTimerData data2 = new HttpTimerData(); data2.getHttpInfo().setUri("URI"); data2.getHttpInfo().setRequestMethod("POST"); data2.setDuration(500d); data2.calculateCpuMin(20d); data2.calculateCpuMax(20d); data2.setCpuDuration(20d); final List<HttpTimerData> input = new ArrayList<>(); Collections.addAll(input, data, data2); AggregationPerformer<HttpTimerData> aggregationPerformer = new AggregationPerformer<>(new HttpTimerDataAggregator(true, true)); aggregationPerformer.processCollection(input); final List<HttpTimerData> output = aggregationPerformer.getResultList(); assertThat(output, is(notNullValue())); assertThat(output.size(), is(equalTo(2))); }
@Test private void musteReturnAnObjectWithAPairLongStringIfTheTimerDataHasHttpTimerData() { InvocationSequenceData invocationSequenceData = new InvocationSequenceData(new Timestamp(10L), 10L, 20L, 108L); HttpTimerData timerData = new HttpTimerData(new Timestamp(10), 10, 10, 108L); HttpInfo httpInfo = new HttpInfo("URI", "requestMethod", "headerValue"); timerData.setHttpInfo(httpInfo); invocationSequenceData.setTimerData(timerData); Pair<Long, String> aggregationKey = (Pair<Long, String>) DiagnosisDataAggregator.getInstance().getAggregationKey(invocationSequenceData); assertThat("The string of the pair must be the sql data", aggregationKey.getSecond(), is(timerData.getHttpInfo().getUri())); }
case URL: if (InvocationSequenceDataHelper.hasHttpTimerData(o1) && InvocationSequenceDataHelper.hasHttpTimerData(o2)) { String uri1 = ((HttpTimerData) o1.getTimerData()).getHttpInfo().getUrl(); String uri2 = ((HttpTimerData) o2.getTimerData()).getHttpInfo().getUrl(); return ObjectUtils.compare(uri1, uri2); } else if (InvocationSequenceDataHelper.hasHttpTimerData(o1)) { int status1 = ((HttpTimerData) o1.getTimerData()).getHttpResponseStatus(); int status2 = ((HttpTimerData) o2.getTimerData()).getHttpResponseStatus(); return ObjectUtils.compare(status1, status2); } else if (InvocationSequenceDataHelper.hasHttpTimerData(o1)) { case USE_CASE: if (InvocationSequenceDataHelper.hasHttpTimerData(o1) && InvocationSequenceDataHelper.hasHttpTimerData(o2)) { String useCase1 = ((HttpTimerData) o1.getTimerData()).getHttpInfo().getInspectItTaggingHeaderValue(); String useCase2 = ((HttpTimerData) o2.getTimerData()).getHttpInfo().getInspectItTaggingHeaderValue(); return ObjectUtils.compare(useCase1, useCase2); } else if (InvocationSequenceDataHelper.hasHttpTimerData(o1)) {
@Test public void aggregationWithInspectITHeaderTwoDifferent() { final HttpTimerData data = new HttpTimerData(); Map<String, String> map1 = new HashMap<>(); MapUtils.putAll(map1, new String[][] { { HttpTimerData.INSPECTIT_TAGGING_HEADER, "tag1" } }); data.setHeaders(map1); data.getHttpInfo().setUri("URI"); data.getHttpInfo().setRequestMethod("GET"); final HttpTimerData data2 = new HttpTimerData(); Map<String, String> map2 = new HashMap<>(); MapUtils.putAll(map2, new String[][] { { HttpTimerData.INSPECTIT_TAGGING_HEADER, "tag2" } }); data2.setHeaders(map2); data2.getHttpInfo().setUri("URI"); data2.getHttpInfo().setRequestMethod("GET"); final List<HttpTimerData> input = new ArrayList<>(); Collections.addAll(input, data, data2); AggregationPerformer<HttpTimerData> aggregationPerformer = new AggregationPerformer<>(new HttpTimerDataAggregator(false, false)); aggregationPerformer.processCollection(input); final List<HttpTimerData> output = aggregationPerformer.getResultList(); assertThat(output, is(notNullValue())); assertThat(output.size(), is(equalTo(2))); }
/** * {@inheritDoc} */ @Override public IAggregatedData<HttpTimerData> getClone(HttpTimerData httpData) { AggregatedHttpTimerData clone = new AggregatedHttpTimerData(); clone.setPlatformIdent(httpData.getPlatformIdent()); clone.setSensorTypeIdent(httpData.getSensorTypeIdent()); clone.setMethodIdent(httpData.getMethodIdent()); clone.setCharting(httpData.isCharting()); if (uriBased) { clone.getHttpInfo().setUri(httpData.getHttpInfo().getUri()); } else { // Aggregation based on Usecase. We reset the URI so that we can easily know // that use case aggregation is used. clone.getHttpInfo().setUri(HttpInfo.UNDEFINED); clone.getHttpInfo().setInspectItTaggingHeaderValue(httpData.getHttpInfo().getInspectItTaggingHeaderValue()); } clone.getHttpInfo().setRequestMethod(httpData.getHttpInfo().getRequestMethod()); return clone; }
@Test private void musteReturnAnInstanceWithHttpSourceTypeDataIfTheTimerDataIsHttpTimerData() { InvocationSequenceData invocationSequenceData = new InvocationSequenceData(new Timestamp(10L), 10L, 20L, 108L); HttpTimerData timerData = new HttpTimerData(); invocationSequenceData.setTimerData(timerData); AggregatedDiagnosisData aggregatedDiagnosisData = DiagnosisDataAggregator.getInstance().getAggregatedDiagnosisData(invocationSequenceData); assertThat("The object must have HTTP as source type", aggregatedDiagnosisData.getSourceType(), is(SourceType.HTTP)); }
HttpInfo originalInfo = mock(HttpInfo.class, RETURNS_SMART_NULLS); HttpTimerData httpTimerData = mock(HttpTimerData.class); when(httpTimerData.getHttpInfo()).thenReturn(originalInfo); HttpTimerData clone = mock(HttpTimerData.class); when(serializationManager.copy(Matchers.<HttpTimerData> any())).thenReturn(clone); when(httpTimerData.isCharting()).thenReturn(false); processor.process(timerData, entityManager); processor.process(httpTimerData, entityManager); when(httpTimerData.isCharting()).thenReturn(true); processor.process(timerData, entityManager); processor.process(httpTimerData, entityManager); verify(clone, times(1)).setHttpInfo(httpInfo); verify(entityManager, times(1)).persist(clone); verifyNoMoreInteractions(timerDataAggregator); verify(clone, times(1)).setId(0); verify(httpTimerData, times(0)).setId(0);