@@ -313,6 +313,67 @@ public void wasToWasFilter_noMatch() {
313313 Assert .assertFalse (linkFilter .include (Arrays .asList (user_appA , appA_appC )));
314314 }
315315
316+ @ Test
317+ public void wasToWasFilter_noMatch_missingReceivingSpan () {
318+ final ServiceType tomcat = serviceTypeRegistryService .findServiceTypeByName (TOMCAT_TYPE_NAME );
319+
320+ final String rpcHost = "some.domain.name" ;
321+ final String rpcUrl = "http://" + rpcHost + "/some/test/path" ;
322+
323+ FilterDescriptor descriptor = new FilterDescriptor ();
324+ descriptor .setFromApplicationName ("APP_A" );
325+ descriptor .setFromServiceType (tomcat .getName ());
326+ descriptor .setToApplicationName ("APP_B" );
327+ descriptor .setToServiceType (tomcat .getName ());
328+
329+ FilterHint emptyHint = new FilterHint (Collections .emptyList ());
330+ FilterHint unmatchingHint = new FilterHint (Collections .singletonList (
331+ new RpcHint ("APP_B" , Collections .singletonList (
332+ new RpcType ("different.domain.name" , RPC_TYPE_CODE )))));
333+ FilterHint matchingHint = new FilterHint (Collections .singletonList (
334+ new RpcHint ("APP_B" , Collections .singletonList (
335+ new RpcType (rpcHost , RPC_TYPE_CODE )))));
336+
337+ LinkFilter emptyHintLinkFilter = new LinkFilter (descriptor , emptyHint , serviceTypeRegistryService , annotationKeyRegistryService );
338+ LinkFilter unmatchingHintLinkFilter = new LinkFilter (descriptor , unmatchingHint , serviceTypeRegistryService , annotationKeyRegistryService );
339+ LinkFilter matchingHintLinkFilter = new LinkFilter (descriptor , matchingHint , serviceTypeRegistryService , annotationKeyRegistryService );
340+ logger .debug ("emptyHintLinkFilter : {}" , emptyHintLinkFilter .toString ());
341+ logger .debug ("unmatchingHintLinkFilter : {}" , unmatchingHintLinkFilter .toString ());
342+ logger .debug ("matchingHintLinkFilter : {}" , matchingHintLinkFilter .toString ());
343+
344+ SpanBo fromSpan = new SpanBo ();
345+ fromSpan .setSpanId (1 );
346+ fromSpan .setParentSpanId (-1 );
347+ fromSpan .setApplicationId ("APP_A" );
348+ fromSpan .setApplicationServiceType (tomcat .getCode ());
349+ AnnotationBo rpcAnnotation = new AnnotationBo ();
350+ rpcAnnotation .setKey (RPC_ANNOTATION_CODE );
351+ rpcAnnotation .setValue (rpcUrl );
352+ SpanEventBo rpcSpanEvent = new SpanEventBo ();
353+ rpcSpanEvent .setServiceType (RPC_TYPE_CODE );
354+ rpcSpanEvent .setDestinationId (rpcHost );
355+ rpcSpanEvent .setAnnotationBoList (Collections .singletonList (rpcAnnotation ));
356+ fromSpan .addSpanEvent (rpcSpanEvent );
357+ // Reject - filter hint empty
358+ Assert .assertFalse (emptyHintLinkFilter .include (Collections .singletonList (fromSpan )));
359+ // Reject - filter hint does not match
360+ Assert .assertFalse (unmatchingHintLinkFilter .include (Collections .singletonList (fromSpan )));
361+ // Accept - filter hint matches
362+ Assert .assertTrue (matchingHintLinkFilter .include (Collections .singletonList (fromSpan )));
363+
364+ // Check rpc url as well
365+ final String unmatchingUrlPattern = "/other/test/**" ;
366+ final String matchingUrlPattern = "/some/test/**" ;
367+ // Reject - url pattern does not match
368+ descriptor .setUrl (unmatchingUrlPattern );
369+ LinkFilter matchingHintLinkFilterWithUnmatchingUrlPattern = new LinkFilter (descriptor , matchingHint , serviceTypeRegistryService , annotationKeyRegistryService );
370+ Assert .assertFalse (matchingHintLinkFilterWithUnmatchingUrlPattern .include (Collections .singletonList (fromSpan )));
371+ // Accept - url pattern matches
372+ descriptor .setUrl (encodeUrl (matchingUrlPattern ));
373+ LinkFilter matchingHintLinkFilterWithMatchingUrlPattern = new LinkFilter (descriptor , matchingHint , serviceTypeRegistryService , annotationKeyRegistryService );
374+ Assert .assertTrue (matchingHintLinkFilterWithMatchingUrlPattern .include (Collections .singletonList (fromSpan )));
375+ }
376+
316377 @ Test
317378 public void wasToBackendFilter () {
318379 final ServiceType tomcat = serviceTypeRegistryService .findServiceTypeByName (TOMCAT_TYPE_NAME );
0 commit comments