DefaultCollectionService extends DefaultJPAService implements CollectionService { @Override public void submitAnnotations(PrincipalUser submitter, List<Annotation> annotations) { requireNotDisposed(); requireArgument(submitter != null, "Submitting user cannot be null."); requireArgument(annotations != null, "The list of annotations to submit cannot be null."); checkSubmitAnnotationPolicyRequirementsMet(submitter, annotations); List<Annotation> putAnnotationList = new LinkedList<>(); for (Annotation annotation : annotations) { if (annotation.computeSizeBytes() > MAX_ANNOTATION_SIZE_BYTES) { _logger.debug("Annotation size of {} bytes exceeded max size {} allowed for annotation {}.", annotation.computeSizeBytes(), MAX_ANNOTATION_SIZE_BYTES, annotation); Map<String, String> tags = new HashMap<>(); tags.put("source", annotation.getSource()); _monitorService.modifyCounter(Counter.ANNOTATION_DROPS_MAXSIZEEXCEEDED, 1, tags); } else { annotation.setScope(TSDBEntity.replaceUnsupportedChars(annotation.getScope())); annotation.setMetric(TSDBEntity.replaceUnsupportedChars(annotation.getMetric())); Map<String, String> filteredTags = new HashMap<>(); for (String tagKey : annotation.getTags().keySet()) { filteredTags.put(TSDBEntity.replaceUnsupportedChars(tagKey), TSDBEntity.replaceUnsupportedChars(annotation.getTags().get(tagKey))); } annotation.setTags(filteredTags); putAnnotationList.add(annotation); } } _monitorService.modifyCounter(Counter.ANNOTATION_WRITES, putAnnotationList.size(), null); if (!putAnnotationList.isEmpty()) { _mqService.enqueue(ANNOTATION.getQueueName(), putAnnotationList); } } @Inject  DefaultCollectionService(MQService mqService, TSDBService tsdbService, AuditService auditService,
            AnnotationStorageService annotationStorageService, SystemConfiguration configuration, SchemaService schemaService, WardenService wardenService,
            MonitorService monitorService, NamespaceService namespaceService); @Override void submitMetric(PrincipalUser submitter, Metric metric); @Override void submitMetrics(PrincipalUser submitter, List<Metric> metrics); @Override void submitAnnotation(PrincipalUser submitter, Annotation annotation); @Override void submitAnnotations(PrincipalUser submitter, List<Annotation> annotations); @Override List<Metric> commitMetrics(int messageCount, int timeout); @Override int commitMetricSchema(int messageCount, int timeout); @Override int commitAnnotations(int annotationCount, int timeout); @Override int commitHistograms(int histogramCount, int timeout); @Override void submitHistogram(PrincipalUser submitter, Histogram histogram); @Override void submitHistograms(PrincipalUser submitter, List<Histogram> histograms); @Override void dispose();  }
@Test public void submitAnnotations_testAnnotationSizeLessThanMax() { Annotation a = TestUtils.createAnnotation(); collectionService.submitAnnotations(user, ImmutableList.of(a)); verify(monitorService).modifyCounter(Counter.ANNOTATION_WRITES, 1, null); ArgumentCaptor<List> annotationListCaptor = ArgumentCaptor.forClass(List.class); verify(mqService).enqueue(eq(ANNOTATION.getQueueName()), annotationListCaptor.capture()); assertEquals(1, annotationListCaptor.getValue().size()); assertTrue(annotationListCaptor.getValue().contains(a)); }
@Test public void submitAnnotations_testListContainingOneAnnotationSizeGreaterThanMax() { Annotation a = TestUtils.createAnnotation(); Annotation tooLargeAnnotation = createAnnotationWithSizeTooLarge(); collectionService.submitAnnotations(user, ImmutableList.of(a, tooLargeAnnotation)); verify(monitorService).modifyCounter(Counter.ANNOTATION_DROPS_MAXSIZEEXCEEDED, 1, ImmutableMap.of("source", tooLargeAnnotation.getSource())); verify(monitorService).modifyCounter(Counter.ANNOTATION_WRITES, 1, null); ArgumentCaptor<List> annotationListCaptor = ArgumentCaptor.forClass(List.class); verify(mqService).enqueue(eq(ANNOTATION.getQueueName()), annotationListCaptor.capture()); assertEquals(1, annotationListCaptor.getValue().size()); }
@Test public void updateAnnotations_testOnlyOneAnnotationSizeGreaterThanMax() { Annotation tooLargeAnnotation = createAnnotationWithSizeTooLarge(); collectionService.submitAnnotations(user, ImmutableList.of(tooLargeAnnotation)); verify(monitorService).modifyCounter(Counter.ANNOTATION_DROPS_MAXSIZEEXCEEDED, 1, ImmutableMap.of("source", tooLargeAnnotation.getSource())); verify(monitorService).modifyCounter(Counter.ANNOTATION_WRITES, 0, null); verify(mqService, never()).enqueue(any(), (List)any()); }