Skip to content

Commit e47b755

Browse files
committed
add skipping logic and test
1 parent 64e4001 commit e47b755

2 files changed

Lines changed: 70 additions & 4 deletions

File tree

cloudplatform/connectivity-destination-service/src/main/java/com/sap/cloud/sdk/cloudplatform/connectivity/DestinationService.java

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -121,9 +121,13 @@ static ResilienceConfiguration createResilienceConfiguration(
121121
Try<Destination>
122122
tryGetDestination( @Nonnull final String destinationName, @Nonnull final DestinationOptions options )
123123
{
124-
if( Cache.preLookupCheckEnabled && !preLookupCheckSuccessful(destinationName, options) ) {
125-
final String msg = "Destination %s was not found among the destinations of the current tenant.";
126-
return Try.failure(new DestinationNotFoundException(destinationName, String.format(msg, destinationName)));
124+
if (Cache.preLookupCheckEnabled) {
125+
if (Cache.isUsingExperimentalFeatures(options)) {
126+
log.warn("Using cache/change detection together with either fragments, cross-level options, or custom headers is discouraged. PreLookup check is skipped.");
127+
} else if (!preLookupCheckSuccessful(destinationName, options)) {
128+
final String msg = "Destination %s was not found among the destinations of the current tenant.";
129+
return Try.failure(new DestinationNotFoundException(destinationName, String.format(msg, destinationName)));
130+
}
127131
}
128132
return Cache.getOrComputeDestination(this, destinationName, options, this::loadAndParseDestination);
129133
}

cloudplatform/connectivity-destination-service/src/test/java/com/sap/cloud/sdk/cloudplatform/connectivity/DestinationServiceTest.java

Lines changed: 63 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@
4949
import java.util.concurrent.atomic.AtomicReference;
5050
import java.util.concurrent.locks.ReentrantLock;
5151
import java.util.function.Function;
52+
import java.util.stream.Stream;
5253

5354
import org.apache.http.HttpVersion;
5455
import org.apache.http.client.HttpClient;
@@ -62,6 +63,9 @@
6263
import org.junit.jupiter.api.Timeout;
6364
import org.junit.jupiter.api.extension.RegisterExtension;
6465
import org.junit.jupiter.api.parallel.Isolated;
66+
import org.junit.jupiter.params.ParameterizedTest;
67+
import org.junit.jupiter.params.provider.Arguments;
68+
import org.junit.jupiter.params.provider.MethodSource;
6569
import org.mockito.stubbing.Answer;
6670

6771
import com.auth0.jwt.JWT;
@@ -1944,7 +1948,7 @@ void testPrependGetAllDestinationsCall()
19441948
.when(destinationServiceAdapter)
19451949
.getConfigurationAsJson(eq("/v1/subaccountDestinations"), any());
19461950

1947-
Destination result = loader.tryGetDestination(destinationName).get();
1951+
loader.tryGetDestination(destinationName).get();
19481952

19491953
verify(destinationServiceAdapter, times(1)).getConfigurationAsJson(eq("/v1/instanceDestinations"), any());
19501954
verify(destinationServiceAdapter, times(1)).getConfigurationAsJson(eq("/v1/subaccountDestinations"), any());
@@ -2003,4 +2007,62 @@ void testPrependGetAllDestinationsCallUsesCorrectRetrievalStrategy()
20032007
Destination result = loader.tryGetDestination(destinationName, options).get();
20042008
assertThat(result.asHttp().getUri()).isEqualTo(URI.create(providerUrl));
20052009
}
2010+
2011+
@ParameterizedTest
2012+
@MethodSource("provideTestData")
2013+
void testPrependGetAllDestinationsCallSkipped(DestinationOptions options, String expectedPath) {
2014+
// Reset Cache to re-enable the PreLookupCheck
2015+
DestinationService.Cache.reset();
2016+
2017+
// additional mock for cross level test case
2018+
final String responseWithCrossLevel = """
2019+
{
2020+
"destinationConfiguration": {
2021+
"Name": "%s",
2022+
"Type": "HTTP",
2023+
"URL": "https://foo.com",
2024+
"Description": "%s level destination"
2025+
}
2026+
}
2027+
""";
2028+
doReturn(responseWithCrossLevel.formatted(destinationName, "subaccount"))
2029+
.when(destinationServiceAdapter)
2030+
.getConfigurationAsJson(eq(expectedPath), any());
2031+
2032+
// call single destination with options
2033+
loader.tryGetDestination(destinationName, options).get();
2034+
2035+
// verify that there was no call to all-destination endpoints
2036+
verify(destinationServiceAdapter, times(0)).getConfigurationAsJson(eq("/v1/instanceDestinations"), any());
2037+
verify(destinationServiceAdapter, times(0)).getConfigurationAsJson(eq("/v1/subaccountDestinations"), any());
2038+
verify(destinationServiceAdapter, times(1)).getConfigurationAsJson(eq(expectedPath), any());
2039+
verifyNoMoreInteractions(destinationServiceAdapter);
2040+
}
2041+
2042+
private static Stream<Arguments> provideTestData() {
2043+
final Header h1 = new Header("X-Custom-Header-1", "value-1");
2044+
final DestinationOptions optionsWithHeader =
2045+
DestinationOptions.builder().augmentBuilder(augmenter().customHeaders(h1)).build();
2046+
2047+
final DestinationOptions optionsWithSubaccount =
2048+
DestinationOptions
2049+
.builder()
2050+
.augmentBuilder(
2051+
DestinationServiceOptionsAugmenter
2052+
.augmenter()
2053+
.crossLevelConsumption(DestinationServiceOptionsAugmenter.CrossLevelScope.SUBACCOUNT))
2054+
.build();
2055+
2056+
final DestinationOptions optionsWithFragment = DestinationOptions
2057+
.builder()
2058+
.augmentBuilder(DestinationServiceOptionsAugmenter.augmenter().fragmentName("a-fragment"))
2059+
.build();
2060+
2061+
2062+
return Stream.of(
2063+
Arguments.of(optionsWithHeader, "/v1/destinations/" + destinationName),
2064+
Arguments.of(optionsWithSubaccount, "/v2/destinations/" + destinationName + "@subaccount"),
2065+
Arguments.of(optionsWithFragment, "/v1/destinations/" + destinationName)
2066+
);
2067+
}
20062068
}

0 commit comments

Comments
 (0)