Skip to content

Commit

Permalink
Fix throughput control npe in case of defaultGroup not set (#42835)
Browse files Browse the repository at this point in the history
* Updated the minimum recommended version

* Merged latest main

* Updated min recommended versions for java sdk and updated the PR link

* Added tests for container throughput control group properties
  • Loading branch information
kushagraThapar authored Nov 8, 2024
1 parent ff9d93f commit ab2fdcc
Show file tree
Hide file tree
Showing 10 changed files with 92 additions and 57 deletions.
3 changes: 3 additions & 0 deletions sdk/cosmos/azure-cosmos-kafka-connect/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@

### 2.0.0 (2024-11-04)

#### Features Added
* General Availability release of the Source and Sink Kafka Connectors - See [PR 42785](https://github.com/Azure/azure-sdk-for-java/pull/42785)

#### Other Changes
* Improved error message when the database provided in the config does not exist - See [PR 42599](https://github.com/Azure/azure-sdk-for-java/pull/42599)

Expand Down
5 changes: 2 additions & 3 deletions sdk/cosmos/azure-cosmos-spark_3-1_2-12/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@
#### Other Changes

### 4.34.0 (2024-10-10)

> [!IMPORTANT]
> We strongly recommend our customers to use version 4.34.0 and above.
#### Bugs Fixed
* Fixed an issue to avoid transient `IllegalArgumentException` due to duplicate json properties for the `uniqueKeyPolicy` property in `DocumentCollection`. - See [PR 41608](https://github.com/Azure/azure-sdk-for-java/pull/41608) and [PR 42244](https://github.com/Azure/azure-sdk-for-java/pull/42244)

Expand Down Expand Up @@ -238,8 +239,6 @@
* Reduced the logging noise level on CancellationExceptions from `RntbdReporter.reportIssue`. - See [PR 32175](https://github.com/Azure/azure-sdk-for-java/pull/32175)

### 4.14.1 (2022-10-07)
> [!IMPORTANT]
> We strongly recommend our customers to use version 4.14.1 and above.
#### Bugs Fixed
* Fixed incorrect RU metric reporting in micrometer metrics. - See [PR 31307](https://github.com/Azure/azure-sdk-for-java/pull/31307)

Expand Down
5 changes: 2 additions & 3 deletions sdk/cosmos/azure-cosmos-spark_3-2_2-12/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@
#### Other Changes

### 4.34.0 (2024-10-10)

> [!IMPORTANT]
> We strongly recommend our customers to use version 4.34.0 and above.
#### Bugs Fixed
* Fixed an issue to avoid transient `IllegalArgumentException` due to duplicate json properties for the `uniqueKeyPolicy` property in `DocumentCollection`. - See [PR 41608](https://github.com/Azure/azure-sdk-for-java/pull/41608) and [PR 42244](https://github.com/Azure/azure-sdk-for-java/pull/42244)

Expand Down Expand Up @@ -242,8 +243,6 @@
* Reduced the logging noise level on CancellationExceptions from `RntbdReporter.reportIssue`. - See [PR 32175](https://github.com/Azure/azure-sdk-for-java/pull/32175)

### 4.14.1 (2022-10-07)
> [!IMPORTANT]
> We strongly recommend our customers to use version 4.14.1 and above.
#### Bugs Fixed
* Fixed incorrect RU metric reporting in micrometer metrics. - See [PR 31307](https://github.com/Azure/azure-sdk-for-java/pull/31307)

Expand Down
3 changes: 2 additions & 1 deletion sdk/cosmos/azure-cosmos-spark_3-3_2-12/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@
#### Other Changes

### 4.34.0 (2024-10-10)

> [!IMPORTANT]
> We strongly recommend our customers to use version 4.34.0 and above.
#### Bugs Fixed
* Fixed an issue to avoid transient `IllegalArgumentException` due to duplicate json properties for the `uniqueKeyPolicy` property in `DocumentCollection`. - See [PR 41608](https://github.com/Azure/azure-sdk-for-java/pull/41608) and [PR 42244](https://github.com/Azure/azure-sdk-for-java/pull/42244)

Expand Down
3 changes: 2 additions & 1 deletion sdk/cosmos/azure-cosmos-spark_3-4_2-12/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@
#### Other Changes

### 4.34.0 (2024-10-10)

> [!IMPORTANT]
> We strongly recommend our customers to use version 4.34.0 and above.
#### Bugs Fixed
* Fixed an issue to avoid transient `IllegalArgumentException` due to duplicate json properties for the `uniqueKeyPolicy` property in `DocumentCollection`. - See [PR 41608](https://github.com/Azure/azure-sdk-for-java/pull/41608) and [PR 42244](https://github.com/Azure/azure-sdk-for-java/pull/42244)

Expand Down
3 changes: 2 additions & 1 deletion sdk/cosmos/azure-cosmos-spark_3-5_2-12/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@
#### Other Changes

### 4.34.0 (2024-10-10)

> [!IMPORTANT]
> We strongly recommend our customers to use version 4.34.0 and above.
#### Bugs Fixed
* Fixed an issue to avoid transient `IllegalArgumentException` due to duplicate json properties for the `uniqueKeyPolicy` property in `DocumentCollection`. - See [PR 41608](https://github.com/Azure/azure-sdk-for-java/pull/41608) and [PR 42244](https://github.com/Azure/azure-sdk-for-java/pull/42244)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,12 @@
import com.azure.cosmos.CosmosAsyncClient;
import com.azure.cosmos.CosmosAsyncContainer;
import com.azure.cosmos.CosmosClientBuilder;
import com.azure.cosmos.implementation.RxDocumentServiceRequest;
import com.azure.cosmos.implementation.TestConfigurations;
import com.azure.cosmos.implementation.apachecommons.lang.tuple.Pair;
import com.azure.cosmos.implementation.throughputControl.config.LocalThroughputControlGroup;
import com.azure.cosmos.models.PriorityLevel;
import org.mockito.Mockito;
import org.testng.annotations.Test;

import java.util.UUID;
Expand All @@ -24,9 +26,9 @@ public void enableThroughputControlGroup() {
CosmosAsyncClient testClient = null;
try {
testClient = new CosmosClientBuilder()
.endpoint(TestConfigurations.HOST)
.key(TestConfigurations.MASTER_KEY)
.buildAsyncClient();
.endpoint(TestConfigurations.HOST)
.key(TestConfigurations.MASTER_KEY)
.buildAsyncClient();

ContainerThroughputControlGroupProperties throughputControlContainerProperties =
new ContainerThroughputControlGroupProperties("/testDB/testContainer");
Expand All @@ -35,13 +37,13 @@ public void enableThroughputControlGroup() {

// Test 1: add default throughput control group successfully
LocalThroughputControlGroup throughputControlDefaultGroup = new LocalThroughputControlGroup(
"test-" + UUID.randomUUID(),
container,
6,
null,
PriorityLevel.HIGH,
true,
false);
"test-" + UUID.randomUUID(),
container,
6,
null,
PriorityLevel.HIGH,
true,
false);

Pair<Integer, Boolean> stateAfterEnabling =
throughputControlContainerProperties.enableThroughputControlGroup(throughputControlDefaultGroup, null);
Expand All @@ -53,13 +55,13 @@ public void enableThroughputControlGroup() {
// Test 2: add throughput control group with same id, but different values for immutable
// properties isDefault or continueOnError
LocalThroughputControlGroup throughputControlGroupDuplicate1 = new LocalThroughputControlGroup(
throughputControlDefaultGroup.getGroupName(),
container,
6,
null,
PriorityLevel.HIGH,
false,
false);
throughputControlDefaultGroup.getGroupName(),
container,
6,
null,
PriorityLevel.HIGH,
false,
false);

assertThatThrownBy(
() -> throughputControlContainerProperties
Expand All @@ -83,26 +85,26 @@ public void enableThroughputControlGroup() {

// Test 3: add another default group
LocalThroughputControlGroup throughputControlDefaultGroup2 = new LocalThroughputControlGroup(
"test-" + UUID.randomUUID(),
container,
6,
null,
PriorityLevel.HIGH,
true,
false);
"test-" + UUID.randomUUID(),
container,
6,
null,
PriorityLevel.HIGH,
true,
false);
assertThatThrownBy(() -> throughputControlContainerProperties.enableThroughputControlGroup(throughputControlDefaultGroup2, null))
.isInstanceOf(IllegalArgumentException.class)
.hasMessage("A default group already exists");
.isInstanceOf(IllegalArgumentException.class)
.hasMessage("A default group already exists");

// Test 4: add a new group
LocalThroughputControlGroup newGroup = new LocalThroughputControlGroup(
"test-" + UUID.randomUUID(),
container,
6,
null,
PriorityLevel.HIGH,
false,
false);
"test-" + UUID.randomUUID(),
container,
6,
null,
PriorityLevel.HIGH,
false,
false);
stateAfterEnabling =
throughputControlContainerProperties.enableThroughputControlGroup(newGroup, null);
currentGroupSize = stateAfterEnabling.getLeft();
Expand All @@ -112,13 +114,13 @@ public void enableThroughputControlGroup() {

// Test 5: add a same group as step 4
LocalThroughputControlGroup newGroupDuplicate = new LocalThroughputControlGroup(
newGroup.getGroupName(),
container,
newGroup.getTargetThroughput(),
newGroup.getTargetThroughputThreshold(),
PriorityLevel.HIGH,
newGroup.isDefault(),
newGroup.isContinueOnInitError());
newGroup.getGroupName(),
container,
newGroup.getTargetThroughput(),
newGroup.getTargetThroughputThreshold(),
PriorityLevel.HIGH,
newGroup.isDefault(),
newGroup.isContinueOnInitError());
stateAfterEnabling =
throughputControlContainerProperties.enableThroughputControlGroup(newGroupDuplicate, null);
currentGroupSize = stateAfterEnabling.getLeft();
Expand All @@ -136,7 +138,8 @@ public void enableThroughputControlGroup() {
newGroup.isDefault(),
newGroup.isContinueOnInitError());
stateAfterEnabling =
throughputControlContainerProperties.enableThroughputControlGroup(newGroupDuplicateModifiedTarget, null);
throughputControlContainerProperties.enableThroughputControlGroup(newGroupDuplicateModifiedTarget,
null);
currentGroupSize = stateAfterEnabling.getLeft();
wasGroupConfigUpdated = stateAfterEnabling.getRight();
assertThat(currentGroupSize).isEqualTo(2);
Expand All @@ -147,4 +150,30 @@ public void enableThroughputControlGroup() {
}
}
}

@Test(groups = "emulator")
public void enableThroughputControlGroupWithoutDefault() {
CosmosAsyncClient testClient = null;
try {
testClient = new CosmosClientBuilder()
.endpoint(TestConfigurations.HOST)
.key(TestConfigurations.MASTER_KEY)
.buildAsyncClient();

ContainerThroughputControlGroupProperties throughputControlContainerProperties =
new ContainerThroughputControlGroupProperties("/testDB/testContainer");

// Test: Without default group and request not having the group name, allowRequestToContinueOnInitError
// should not throw NPE
boolean allowRequestToContinue =
throughputControlContainerProperties.allowRequestToContinueOnInitError(Mockito.mock(RxDocumentServiceRequest.class));

assertThat(allowRequestToContinue).isTrue();

} finally {
if (testClient != null) {
testClient.close();
}
}
}
}
6 changes: 3 additions & 3 deletions sdk/cosmos/azure-cosmos/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#### Breaking Changes

#### Bugs Fixed
* Fixed a Null Pointer Exception in `ContainerThroughputConrolGroupProperties` if defaultGroup is not set. - See [PR 42835](https://github.com/Azure/azure-sdk-for-java/pull/42835)

#### Other Changes
* Enable `JsonParser.Feature.ALLOW_UNQUOTED_CONTROL_CHARS` by default for objectMapper. - See [PR 42520](https://github.com/Azure/azure-sdk-for-java/pull/42520)
Expand All @@ -21,7 +22,8 @@
* Fixed an issue where holding onto a `CosmosException` instance would hold a strong reference to a `RxDocumentClientImpl` instance preventing garbage collection of the `RxDocumentClientImpl` instance. - See [PR 42178](https://github.com/Azure/azure-sdk-for-java/pull/42178)

### 4.64.0 (2024-10-10)

> [!IMPORTANT]
> We strongly recommend our customers to use version 4.64.0 and above.
#### Features Added
* Added an API to retrieve diagnostics from the change feed processor context. - See [PR 41738](https://github.com/Azure/azure-sdk-for-java/pull/41738)
* Added support to allow `queryChangeFeed` to complete when all changes available when the query starts have been fetched. - See [PR 42160](https://github.com/Azure/azure-sdk-for-java/pull/42160)
Expand Down Expand Up @@ -319,8 +321,6 @@
* Fixed possible `NullPointerException` issue if health-check flow kicks in before RNTBD context negotiation for a given channel - See [PR 36397](https://github.com/Azure/azure-sdk-for-java/pull/36397).

### 4.48.2 (2023-08-25)
> [!IMPORTANT]
> We strongly recommend our customers to use version 4.48.2 and above.
#### Bugs Fixed
* Fixed possible `NullPointerException` issue if health-check flow kicks in before RNTBD context negotiation for a given channel - See [PR 36397](https://github.com/Azure/azure-sdk-for-java/pull/36397).

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,10 @@ public boolean allowRequestToContinueOnInitError(RxDocumentServiceRequest reques

String requestGroupName = request.getThroughputControlGroupName();
if (StringUtils.isEmpty(requestGroupName)) {
requestGroupName = this.defaultGroup.get().getGroupName();
if (defaultGroup.get() == null) {
return true;
}
requestGroupName = defaultGroup.get().getGroupName();
}

return this.supressInitErrorGroupSet.contains(requestGroupName);
Expand Down
5 changes: 2 additions & 3 deletions sdk/spring/azure-spring-data-cosmos/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@
#### Other Changes

### 5.18.0 (2024-11-05)

> [!IMPORTANT]
> We strongly recommend our customers to use version 5.18.0 and above.
#### Other Changes
* Updated `azure-cosmos` to version `4.64.0`.

Expand Down Expand Up @@ -290,8 +291,6 @@
* Updated `azure-cosmos` to version `4.38.0`.

### 3.28.1 (2022-10-07)
> [!IMPORTANT]
> We strongly recommend our customers to use version 3.28.1 and above.
#### Other Changes
* Updated `azure-cosmos` to version `4.37.1`.

Expand Down

0 comments on commit ab2fdcc

Please sign in to comment.