Skip to content
Merged
Changes from 1 commit
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
202f37e
apply fix
Jonas-Isr Jan 5, 2026
f04cf0b
adapt tests
Jonas-Isr Jan 5, 2026
d0edbfe
add additional lookup
Jonas-Isr Jan 5, 2026
6d66f5c
tests
Jonas-Isr Jan 5, 2026
2f474ba
release notes
Jonas-Isr Jan 5, 2026
342b049
fix DestinationNotFoundException message
Jonas-Isr Jan 5, 2026
1e85272
propagate DestinationOptions
Jonas-Isr Jan 5, 2026
09b6897
correct since tag
Jonas-Isr Jan 6, 2026
af8b3c2
add another unit test
Jonas-Isr Jan 6, 2026
7982777
remove comment
Jonas-Isr Jan 6, 2026
f22e9be
retrigger
Jonas-Isr Jan 7, 2026
bf81047
add warn log
Jonas-Isr Jan 7, 2026
64e4001
Merge branch 'refs/heads/fix-caching-getOrComputeAllDestinations' int…
Jonas-Isr Jan 7, 2026
e47b755
add skipping logic and test
Jonas-Isr Jan 7, 2026
da49da1
Merge branch 'main' into fix-caching-getOrComputeAllDestinations
Jonas-Isr Jan 8, 2026
87dd83d
improve warn messages
Jonas-Isr Jan 8, 2026
85498e1
Merge branch 'refs/heads/fix-caching-getOrComputeAllDestinations' int…
Jonas-Isr Jan 8, 2026
3697192
improve warn message
Jonas-Isr Jan 8, 2026
5473565
Merge remote-tracking branch 'origin/main' into add-preLookup-Check
newtork Jan 9, 2026
a8b7cf2
Merge remote-tracking branch 'origin/main' into add-preLookup-Check
newtork Jan 9, 2026
b969c29
Minor API adjustments
newtork Jan 9, 2026
73f2960
Apply fix
newtork Jan 9, 2026
e3b85b9
Format
newtork Jan 9, 2026
a5c89d0
Minor format
newtork Jan 9, 2026
11d0c66
Minor format
newtork Jan 9, 2026
b444fec
Add low-level test method
newtork Jan 9, 2026
6cab0ac
Format imports
newtork Jan 9, 2026
c492b6f
Fix PMD
newtork Jan 9, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
package com.sap.cloud.sdk.cloudplatform.connectivity;

import static com.sap.cloud.sdk.cloudplatform.connectivity.DestinationServiceOptionsAugmenter.getRetrievalStrategy;
import static com.sap.cloud.sdk.cloudplatform.connectivity.DestinationServiceRetrievalStrategy.CURRENT_TENANT;

import java.time.Duration;
import java.util.ArrayList;
import java.util.Arrays;
Expand All @@ -11,6 +14,7 @@
import java.util.concurrent.locks.ReentrantLock;
import java.util.function.BiFunction;
import java.util.function.Function;
import java.util.function.Predicate;
import java.util.function.Supplier;
import java.util.stream.Collectors;

Expand Down Expand Up @@ -122,17 +126,41 @@ static ResilienceConfiguration createResilienceConfiguration(
Try<Destination>
tryGetDestination( @Nonnull final String destinationName, @Nonnull final DestinationOptions options )
{
if (Cache.preLookupCheckEnabled) {
if (Cache.isUsingExperimentalFeatures(options)) {
log.warn("Using pre-lookup check together with either fragments, cross-level options, or custom headers might lead to unexpected behaviour. Pre-lookup check is skipped.");
} else if (!preLookupCheckSuccessful(destinationName, options)) {
final String msg = "Destination %s was not found among the destinations of the current tenant.";
return Try.failure(new DestinationNotFoundException(destinationName, String.format(msg, destinationName)));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(Minor)
I found the hard-coded "destinations of current tenant" misleading for cases like "always-provider". Therefore I moved the code around a little and introduced the notion of "validating destination lookup". Maybe "intercept" would've been a better word(?)

}
final Option<Exception> validationError = validateDestinationLookup(destinationName, options);
if( validationError.isDefined() ) {
return Try.failure(validationError.get());
}
return Cache.getOrComputeDestination(this, destinationName, options, this::loadAndParseDestination);
}

Option<Exception> validateDestinationLookup( String destinationName, DestinationOptions options )
{
final Option<Exception> VALID_LOOKUP = Option.none();
if( !Cache.preLookupCheckEnabled ) {
return VALID_LOOKUP;
}
if( !Cache.isEnabled() ) {
return VALID_LOOKUP;
}
if( Cache.isUsingExperimentalFeatures(options) ) {
final String msg =
"Using pre-lookup check together with either fragments, cross-level options, or custom headers might lead to unexpected behaviour. Pre-lookup check is skipped.";
log.warn(msg);
return VALID_LOOKUP;
}

final DestinationServiceRetrievalStrategy strategy = getRetrievalStrategy(options).getOrElse(CURRENT_TENANT);
final Collection<DestinationProperties> cachedDestinations = getAllDestinationProperties(strategy);
final Predicate<DestinationProperties> pred = p -> p.get(DestinationProperty.NAME).contains(destinationName);
if( cachedDestinations.stream().anyMatch(pred) ) {
return VALID_LOOKUP;
}

final String msgFormat = "Destination %s was not found among the destinations for %s.";
final String msg = String.format(msgFormat, destinationName, strategy);
return Option.some(new DestinationNotFoundException(destinationName, msg));
}

Destination loadAndParseDestination( final String destName, final DestinationOptions options )
throws DestinationAccessException,
DestinationNotFoundException
Expand Down Expand Up @@ -201,7 +229,7 @@ public Try<Iterable<Destination>> tryGetAllDestinations()
@Nonnull
public Collection<DestinationProperties> getAllDestinationProperties()
{
return getAllDestinationProperties(DestinationServiceRetrievalStrategy.CURRENT_TENANT);
return getAllDestinationProperties(CURRENT_TENANT);
}

/**
Expand Down Expand Up @@ -394,17 +422,6 @@ private static boolean hasCauseAssignableFrom( @Nonnull final Throwable t, @Nonn
return ExceptionUtils.getThrowableList(t).stream().map(Throwable::getClass).anyMatch(cls::isAssignableFrom);
}

private boolean preLookupCheckSuccessful( final String destinationName, final DestinationOptions options )
{
final DestinationServiceRetrievalStrategy retrievalStrategy =
DestinationServiceOptionsAugmenter
.getRetrievalStrategy(options)
.getOrElse(DestinationServiceRetrievalStrategy.CURRENT_TENANT);
return getAllDestinationProperties(retrievalStrategy)
.stream()
.anyMatch(properties -> properties.get(DestinationProperty.NAME).contains(destinationName));
}

/**
* Helper class that encapsulates all caching related configuration options.
*
Expand Down