Skip to content

Commit

Permalink
Fixing unit tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
jeet1995 committed Feb 1, 2025
1 parent bf2a3b9 commit 93a590a
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 45 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -480,9 +480,9 @@ public void validateAsync(boolean useMultipleWriteEndpoints,
@Test(groups = "long")
public void validateWriteEndpointOrderWithClientSideDisableMultipleWriteLocation() throws Exception {
this.initialize(false, true, false);
assertThat(this.cache.getWriteEndpoints().get(0)).isEqualTo(LocationCacheTest.Location1Endpoint);
assertThat(this.cache.getWriteEndpoints().get(1)).isEqualTo(LocationCacheTest.Location2Endpoint);
assertThat(this.cache.getWriteEndpoints().get(2)).isEqualTo(LocationCacheTest.Location3Endpoint);
assertThat(this.cache.getWriteEndpoints().get(0)).isEqualTo(new LocationCache.ConsolidatedRegionalEndpoint(LocationCacheTest.Location1Endpoint, null));
assertThat(this.cache.getWriteEndpoints().get(1)).isEqualTo(new LocationCache.ConsolidatedRegionalEndpoint(LocationCacheTest.Location2Endpoint, null));
assertThat(this.cache.getWriteEndpoints().get(2)).isEqualTo(new LocationCache.ConsolidatedRegionalEndpoint(LocationCacheTest.Location3Endpoint, null));
}

@Test(groups = "unit", dataProvider = "excludedRegionsTestConfigs")
Expand Down Expand Up @@ -900,17 +900,17 @@ private void validateRequestEndpointResolution(
// ALL write requests flip-flop between current write and alternate write endpoint
UnmodifiableList<LocationCache.ConsolidatedRegionalEndpoint> writeEndpoints = this.cache.getWriteEndpoints();

assertThat(firstAvailableWriteEndpoint).isEqualTo(writeEndpoints.get(0));
assertThat(secondAvailableWriteEndpoint).isEqualTo(this.resolveEndpointForWriteRequest(ResourceType.Document, true));
assertThat(firstAvailableWriteEndpoint).isEqualTo(this.resolveEndpointForWriteRequest(ResourceType.Document, false));
assertThat(new LocationCache.ConsolidatedRegionalEndpoint(firstAvailableWriteEndpoint, null)).isEqualTo(writeEndpoints.get(0));
assertThat(new LocationCache.ConsolidatedRegionalEndpoint(secondAvailableWriteEndpoint, null)).isEqualTo(this.resolveEndpointForWriteRequest(ResourceType.Document, true));
assertThat(new LocationCache.ConsolidatedRegionalEndpoint(firstAvailableWriteEndpoint, null)).isEqualTo(this.resolveEndpointForWriteRequest(ResourceType.Document, false));

// Writes to other resource types should be directed to first/second write getEndpoint
assertThat(firstWriteEnpoint).isEqualTo(this.resolveEndpointForWriteRequest(ResourceType.Database, false));
assertThat(secondWriteEnpoint).isEqualTo(this.resolveEndpointForWriteRequest(ResourceType.Database, true));
assertThat(new LocationCache.ConsolidatedRegionalEndpoint(firstWriteEnpoint, null)).isEqualTo(this.resolveEndpointForWriteRequest(ResourceType.Database, false));
assertThat(new LocationCache.ConsolidatedRegionalEndpoint(secondWriteEnpoint, null)).isEqualTo(this.resolveEndpointForWriteRequest(ResourceType.Database, true));

// Reads should be directed to available read endpoints regardless of resource type
assertThat(firstAvailableReadEndpoint).isEqualTo(this.resolveEndpointForReadRequest(true));
assertThat(firstAvailableReadEndpoint).isEqualTo(this.resolveEndpointForReadRequest(false));
assertThat(new LocationCache.ConsolidatedRegionalEndpoint(firstAvailableReadEndpoint, null)).isEqualTo(this.resolveEndpointForReadRequest(true));
assertThat(new LocationCache.ConsolidatedRegionalEndpoint(firstAvailableReadEndpoint, null)).isEqualTo(this.resolveEndpointForReadRequest(false));
}

private LocationCache.ConsolidatedRegionalEndpoint resolveEndpointForReadRequest(boolean masterResourceType) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -491,10 +491,8 @@ private RxDocumentClientImpl(URI serviceEndpoint,
this.connectionSharingAcrossClientsEnabled = connectionSharingAcrossClientsEnabled;
this.configs = configs;
this.masterKeyOrResourceToken = masterKeyOrResourceToken;
this.isThinClientEnabled = this.configs.isThinClientEnabled();
// TODO: we have a default thinclient endpoint in configs, but it is not set to anything - need
// to figure out what default will be
this.serviceEndpoint = this.isThinClientEnabled ? this.configs.getThinclientEndpoint() : serviceEndpoint;
this.isThinClientEnabled = Configs.isThinClientEnabled();
this.serviceEndpoint = serviceEndpoint;
this.credential = credential;
this.tokenCredential = tokenCredential;
this.contentResponseOnWriteEnabled = contentResponseOnWriteEnabled;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -686,50 +686,54 @@ private void addEndpoints(
Map<ConsolidatedRegionalEndpoint, String> regionByEndpoint,
List<String> parsedLocations) {

for (DatabaseAccountLocation gatewayDbAccountLocation : gatewayDbAccountLocations) {
if (!Strings.isNullOrEmpty(gatewayDbAccountLocation.getName())) {
try {
if (gatewayDbAccountLocations != null) {
for (DatabaseAccountLocation gatewayDbAccountLocation : gatewayDbAccountLocations) {
if (!Strings.isNullOrEmpty(gatewayDbAccountLocation.getName())) {
try {

String location = gatewayDbAccountLocation.getName().toLowerCase(Locale.ROOT);
URI endpoint = new URI(gatewayDbAccountLocation.getEndpoint().toLowerCase(Locale.ROOT));
String location = gatewayDbAccountLocation.getName().toLowerCase(Locale.ROOT);
URI endpoint = new URI(gatewayDbAccountLocation.getEndpoint().toLowerCase(Locale.ROOT));

ConsolidatedRegionalEndpoint consolidatedRegionalEndpoint = new ConsolidatedRegionalEndpoint(endpoint, null);
ConsolidatedRegionalEndpoint consolidatedRegionalEndpoint = new ConsolidatedRegionalEndpoint(endpoint, null);

if (!endpointsByLocation.containsKey(location)) {
endpointsByLocation.put(location, consolidatedRegionalEndpoint);
}
if (!endpointsByLocation.containsKey(location)) {
endpointsByLocation.put(location, consolidatedRegionalEndpoint);
}

if (!regionByEndpoint.containsKey(consolidatedRegionalEndpoint)) {
regionByEndpoint.put(consolidatedRegionalEndpoint, location);
}
if (!regionByEndpoint.containsKey(consolidatedRegionalEndpoint)) {
regionByEndpoint.put(consolidatedRegionalEndpoint, location);
}

parsedLocations.add(gatewayDbAccountLocation.getName());
} catch (Exception e) {
logger.warn("GetAvailableEndpointsByLocation() - skipping add for location = [{}] as its location name is either empty or endpoint is malformed [{}]",
gatewayDbAccountLocation.getName(),
gatewayDbAccountLocation.getEndpoint());
parsedLocations.add(gatewayDbAccountLocation.getName());
} catch (Exception e) {
logger.warn("GetAvailableEndpointsByLocation() - skipping add for location = [{}] as its location name is either empty or endpoint is malformed [{}]",
gatewayDbAccountLocation.getName(),
gatewayDbAccountLocation.getEndpoint());
}
}
}
}

for (DatabaseAccountLocation thinClientDbAccountLocation: thinClientDbAccountLocations) {
if (!Strings.isNullOrEmpty(thinClientDbAccountLocation.getName())) {
try {
String location = thinClientDbAccountLocation.getName().toLowerCase(Locale.ROOT);
URI endpoint = new URI(thinClientDbAccountLocation.getEndpoint().toLowerCase(Locale.ROOT));
if (thinClientDbAccountLocations != null) {
for (DatabaseAccountLocation thinClientDbAccountLocation: thinClientDbAccountLocations) {
if (!Strings.isNullOrEmpty(thinClientDbAccountLocation.getName())) {
try {
String location = thinClientDbAccountLocation.getName().toLowerCase(Locale.ROOT);
URI endpoint = new URI(thinClientDbAccountLocation.getEndpoint().toLowerCase(Locale.ROOT));

ConsolidatedRegionalEndpoint consolidatedRegionalEndpoint = endpointsByLocation.get(location);
ConsolidatedRegionalEndpoint consolidatedRegionalEndpoint = endpointsByLocation.get(location);

if (consolidatedRegionalEndpoint == null) {
throw new IllegalStateException(String.format("Gateway location endpoint doesn't exist while thin client location endpoint exists for location %s", location));
}
if (consolidatedRegionalEndpoint == null) {
throw new IllegalStateException(String.format("Gateway location endpoint doesn't exist while thin client location endpoint exists for location %s", location));
}

consolidatedRegionalEndpoint.thinClientLocationEndpoint = endpoint;
consolidatedRegionalEndpoint.thinClientLocationEndpoint = endpoint;

} catch (Exception e) {
logger.warn("GetAvailableEndpointsByLocation() - skipping add for location = [{}] as its location name is either empty or endpoint is malformed [{}]",
thinClientDbAccountLocation.getName(),
thinClientDbAccountLocation.getEndpoint());
} catch (Exception e) {
logger.warn("GetAvailableEndpointsByLocation() - skipping add for location = [{}] as its location name is either empty or endpoint is malformed [{}]",
thinClientDbAccountLocation.getName(),
thinClientDbAccountLocation.getEndpoint());
}
}
}
}
Expand Down

0 comments on commit 93a590a

Please sign in to comment.