-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Read database account properties using CosmosClient and CosmosAsyncClient #45789
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
jeet1995
wants to merge
20
commits into
Azure:main
Choose a base branch
from
jeet1995:ExposeDatabaseAccountProperties
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
20 commits
Select commit
Hold shift + click to select a range
865617c
Adding public API to expose `CosmosDatabaseAccount`.
jeet1995 f00294b
Expose database account metadata (perform I/O call).
jeet1995 7d8b950
Expose database account metadata (perform I/O call).
jeet1995 f78793b
Expose database account metadata (perform I/O call).
jeet1995 fca2ab8
Use static helper.
jeet1995 dd5d645
Use cache if necessary.
jeet1995 6f03a6f
Merge branch 'main' of github.com:jeet1995/azure-sdk-for-java into Ex…
jeet1995 3eb76ca
Merge branch 'main' of github.com:Azure/azure-sdk-for-java into Expos…
jeet1995 5b650e8
Use cache if necessary.
jeet1995 459d15d
Use cache if necessary.
jeet1995 562817d
Wire up to use database account resolution method which goes through …
jeet1995 201071a
Wire up to use database account resolution method which goes through …
jeet1995 63c0c12
Wire up to use database account resolution method which goes through …
jeet1995 e1576d9
Wire up to use database account resolution method which goes through …
jeet1995 4367183
Wire up to use database account resolution method which goes through …
jeet1995 cee11fc
Wire up to use database account resolution method which goes through …
jeet1995 2c25134
Modify docs.
jeet1995 e2aaf0a
Refactoring
jeet1995 325edf1
Merge branch 'main' of github.com:jeet1995/azure-sdk-for-java into Ex…
jeet1995 207a80e
Refactoring
jeet1995 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
91 changes: 91 additions & 0 deletions
91
...cosmos-tests/src/test/java/com/azure/cosmos/models/CosmosDatabaseAccountResponseTest.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT License. | ||
|
||
package com.azure.cosmos.models; | ||
|
||
import com.azure.cosmos.CosmosAsyncClient; | ||
import com.azure.cosmos.CosmosClient; | ||
import com.azure.cosmos.CosmosClientBuilder; | ||
import com.azure.cosmos.rx.TestSuiteBase; | ||
import org.testng.annotations.AfterClass; | ||
import org.testng.annotations.BeforeClass; | ||
import org.testng.annotations.Factory; | ||
import org.testng.annotations.Test; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
public class CosmosDatabaseAccountResponseTest extends TestSuiteBase { | ||
private CosmosClient client; | ||
private CosmosAsyncClient asyncClient; | ||
|
||
@Factory(dataProvider = "clientBuilders") | ||
public CosmosDatabaseAccountResponseTest(CosmosClientBuilder clientBuilder) { | ||
super(clientBuilder); | ||
} | ||
|
||
@BeforeClass(groups = {"fast"}, timeOut = SETUP_TIMEOUT) | ||
public void before_CosmosDatabaseAccountTest() { | ||
assertThat(this.client).isNull(); | ||
assertThat(this.asyncClient).isNull(); | ||
|
||
this.client = getClientBuilder().buildClient(); | ||
this.asyncClient = getClientBuilder().buildAsyncClient(); | ||
} | ||
|
||
@AfterClass(groups = {"fast"}, timeOut = SHUTDOWN_TIMEOUT, alwaysRun = true) | ||
public void afterClass() { | ||
assertThat(this.client).isNotNull(); | ||
assertThat(this.asyncClient).isNotNull(); | ||
|
||
this.client.close(); | ||
this.asyncClient.close(); | ||
} | ||
|
||
@Test(groups = {"fast"}, timeOut = TIMEOUT) | ||
public void readCosmosDatabaseAccountWithClient() { | ||
CosmosDatabaseAccountResponse latestDatabaseAccountResponse = client.readDatabaseAccount(false); | ||
|
||
assertThat(latestDatabaseAccountResponse).isNotNull(); | ||
validateDatabaseAccountResponse(latestDatabaseAccountResponse); | ||
|
||
CosmosDatabaseAccountResponse cachedResponse = client.readDatabaseAccount(true); | ||
|
||
assertThat(cachedResponse).isNotNull(); | ||
validateDatabaseAccountResponse(cachedResponse); | ||
|
||
validateEquality(latestDatabaseAccountResponse, cachedResponse); | ||
} | ||
|
||
@Test(groups = {"fast"}, timeOut = TIMEOUT) | ||
public void readCosmosDatabaseAccountWithAsyncClient() { | ||
CosmosDatabaseAccountResponse latestDatabaseAccountResponse = asyncClient.readDatabaseAccount(false).block(); | ||
|
||
assertThat(latestDatabaseAccountResponse).isNotNull(); | ||
validateDatabaseAccountResponse(latestDatabaseAccountResponse); | ||
|
||
CosmosDatabaseAccountResponse cachedResponse = asyncClient.readDatabaseAccount(true).block(); | ||
|
||
assertThat(cachedResponse).isNotNull(); | ||
validateDatabaseAccountResponse(cachedResponse); | ||
|
||
validateEquality(latestDatabaseAccountResponse, cachedResponse); | ||
} | ||
|
||
private void validateDatabaseAccountResponse(CosmosDatabaseAccountResponse response) { | ||
assertThat(response).isNotNull(); | ||
assertThat(response.getId()).isNotNull(); | ||
assertThat(response.getId()).isNotEmpty(); | ||
assertThat(response.getReadRegions()).isNotEmpty(); | ||
assertThat(response.getWriteRegions()).isNotEmpty(); | ||
assertThat(response.isMultiWriteAccount()).isNotNull(); | ||
assertThat(response.getAccountLevelConsistency()).isNotNull(); | ||
} | ||
|
||
private void validateEquality(CosmosDatabaseAccountResponse response1, CosmosDatabaseAccountResponse response2) { | ||
assertThat(response1.getId()).isEqualTo(response2.getId()); | ||
assertThat(response1.getReadRegions()).isEqualTo(response2.getReadRegions()); | ||
assertThat(response1.getWriteRegions()).isEqualTo(response2.getWriteRegions()); | ||
assertThat(response1.isMultiWriteAccount()).isEqualTo(response2.isMultiWriteAccount()); | ||
assertThat(response1.getAccountLevelConsistency()).isEqualTo(response2.getAccountLevelConsistency()); | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
NIT: I would probably prefer the name to ensure false is the default behavior - so shouldSkipCache or somethig like that