Skip to content

Commit efbf6dd

Browse files
authored
Thinclient Environment Variables (Azure#43188)
* progress * add separate endpoint * progress * fix env var * progress * pr comments * cleanup * changelog * cleanup * pr comments * changelog * fix test * pr comment - fix tests
1 parent 04c8548 commit efbf6dd

File tree

3 files changed

+108
-20
lines changed

3 files changed

+108
-20
lines changed

sdk/cosmos/azure-cosmos-tests/src/test/java/com/azure/cosmos/implementation/ConfigsTests.java

Lines changed: 70 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
import io.netty.handler.ssl.SslContext;
1111
import org.testng.annotations.Test;
1212

13+
import java.net.URI;
1314
import java.util.EnumSet;
1415

1516
import static org.assertj.core.api.Assertions.assertThat;
@@ -77,71 +78,120 @@ public void httpConnectionWithoutTLSAllowed() {
7778
Configs config = new Configs();
7879
assertThat(config.isHttpConnectionWithoutTLSAllowed()).isFalse();
7980

80-
System.setProperty("COSMOS.HTTP_CONNECTION_WITHOUT_TLS_ALLOWED", "true");
81-
assertThat(config.isHttpConnectionWithoutTLSAllowed()).isTrue();
82-
8381
System.clearProperty("COSMOS.HTTP_CONNECTION_WITHOUT_TLS_ALLOWED");
82+
System.setProperty("COSMOS.HTTP_CONNECTION_WITHOUT_TLS_ALLOWED", "true");
83+
try {
84+
assertThat(config.isHttpConnectionWithoutTLSAllowed()).isTrue();
85+
} finally {
86+
System.clearProperty("COSMOS.HTTP_CONNECTION_WITHOUT_TLS_ALLOWED");
87+
}
8488
}
8589

8690
@Test(groups = { "emulator" })
8791
public void emulatorCertValidationDisabled() {
8892
Configs config = new Configs();
8993
assertThat(config.isEmulatorServerCertValidationDisabled()).isFalse();
9094

91-
System.setProperty("COSMOS.EMULATOR_SERVER_CERTIFICATE_VALIDATION_DISABLED", "true");
92-
assertThat(config.isEmulatorServerCertValidationDisabled()).isTrue();
93-
9495
System.clearProperty("COSMOS.EMULATOR_SERVER_CERTIFICATE_VALIDATION_DISABLED");
96+
System.setProperty("COSMOS.EMULATOR_SERVER_CERTIFICATE_VALIDATION_DISABLED", "true");
97+
try {
98+
assertThat(config.isEmulatorServerCertValidationDisabled()).isTrue();
99+
} finally {
100+
System.clearProperty("COSMOS.EMULATOR_SERVER_CERTIFICATE_VALIDATION_DISABLED");
101+
}
95102
}
96103

97104
@Test(groups = { "emulator" })
98105
public void emulatorHost() {
99106
Configs config = new Configs();
100107
assertThat(config.getEmulatorHost()).isEmpty();
101108

102-
System.setProperty("COSMOS.EMULATOR_HOST", "randomHost");
103-
assertThat(config.getEmulatorHost()).isEqualTo("randomHost");
104-
105109
System.clearProperty("COSMOS.EMULATOR_HOST");
110+
System.setProperty("COSMOS.EMULATOR_HOST", "randomHost");
111+
try {
112+
assertThat(config.getEmulatorHost()).isEqualTo("randomHost");
113+
} finally {
114+
System.clearProperty("COSMOS.EMULATOR_HOST");
115+
}
106116
}
107117

108118
@Test(groups = { "emulator" })
109119
public void http2Enabled() {
110120
assertThat(Configs.isHttp2Enabled()).isFalse();
111121

112-
System.setProperty("COSMOS.HTTP2_ENABLED", "true");
113-
assertThat(Configs.isHttp2Enabled()).isTrue();
114-
115122
System.clearProperty("COSMOS.HTTP2_ENABLED");
123+
System.setProperty("COSMOS.HTTP2_ENABLED", "true");
124+
try {
125+
assertThat(Configs.isHttp2Enabled()).isTrue();
126+
} finally {
127+
System.clearProperty("COSMOS.HTTP2_ENABLED");
128+
}
116129
}
117130

118131
@Test(groups = { "unit" })
119132
public void http2MaxConnectionPoolSize() {
120133
assertThat(Configs.getHttp2MaxConnectionPoolSize()).isEqualTo(1000);
121134

122-
System.setProperty("COSMOS.HTTP2_MAX_CONNECTION_POOL_SIZE", "10");
123-
assertThat(Configs.getHttp2MaxConnectionPoolSize()).isEqualTo(10);
124-
125135
System.clearProperty("COSMOS.HTTP2_MAX_CONNECTION_POOL_SIZE");
136+
System.setProperty("COSMOS.HTTP2_MAX_CONNECTION_POOL_SIZE", "10");
137+
try {
138+
assertThat(Configs.getHttp2MaxConnectionPoolSize()).isEqualTo(10);
139+
} finally {
140+
System.clearProperty("COSMOS.HTTP2_MAX_CONNECTION_POOL_SIZE");
141+
}
126142
}
127143

128144
@Test(groups = { "unit" })
129145
public void http2MinConnectionPoolSize() {
130146
assertThat(Configs.getHttp2MinConnectionPoolSize()).isEqualTo(1);
131147

132-
System.setProperty("COSMOS.HTTP2_MIN_CONNECTION_POOL_SIZE", "10");
133-
assertThat(Configs.getHttp2MinConnectionPoolSize()).isEqualTo(10);
134-
135148
System.clearProperty("COSMOS.HTTP2_MIN_CONNECTION_POOL_SIZE");
149+
System.setProperty("COSMOS.HTTP2_MIN_CONNECTION_POOL_SIZE", "10");
150+
try {
151+
assertThat(Configs.getHttp2MinConnectionPoolSize()).isEqualTo(10);
152+
} finally {
153+
System.clearProperty("COSMOS.HTTP2_MIN_CONNECTION_POOL_SIZE");
154+
}
136155
}
137156

138157
@Test(groups = { "unit" })
139158
public void http2MaxConcurrentStreams() {
140159
assertThat(Configs.getHttp2MaxConcurrentStreams()).isEqualTo(30);
141160

161+
System.clearProperty("COSMOS.HTTP2_MAX_CONCURRENT_STREAMS");
142162
System.setProperty("COSMOS.HTTP2_MAX_CONCURRENT_STREAMS", "10");
143-
assertThat(Configs.getHttp2MaxConcurrentStreams()).isEqualTo(10);
163+
try {
164+
assertThat(Configs.getHttp2MaxConcurrentStreams()).isEqualTo(10);
165+
} finally {
166+
System.clearProperty("COSMOS.HTTP2_MAX_CONCURRENT_STREAMS");
167+
}
168+
}
144169

145-
System.clearProperty("COSMOS.HTTP2_MAX_CONCURRENT_STREAMS");
170+
@Test(groups = { "unit" })
171+
public void thinClientEnabledTest() {
172+
Configs config = new Configs();
173+
assertThat(config.getThinclientEnabled()).isFalse();
174+
175+
System.clearProperty("COSMOS.THINCLIENT_ENABLED");
176+
System.setProperty("COSMOS.THINCLIENT_ENABLED", "true");
177+
try {
178+
assertThat(config.getThinclientEnabled()).isTrue();
179+
} finally {
180+
System.clearProperty("COSMOS.THINCLIENT_ENABLED");
181+
}
182+
}
183+
184+
@Test(groups = { "unit" })
185+
public void thinClientEndpointTest() {
186+
Configs config = new Configs();
187+
assertThat(config.getThinclientEndpoint()).isEqualTo(URI.create(""));
188+
189+
System.clearProperty("COSMOS.THINCLIENT_ENDPOINT");
190+
System.setProperty("COSMOS.THINCLIENT_ENDPOINT", "testThinClientEndpoint");
191+
try {
192+
assertThat(config.getThinclientEndpoint()).isEqualTo(URI.create("testThinClientEndpoint"));
193+
} finally {
194+
System.clearProperty("COSMOS.THINCLIENT_ENDPOINT");
195+
}
146196
}
147197
}

sdk/cosmos/azure-cosmos/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
#### Bugs Fixed
1010

1111
#### Other Changes
12+
* Added temporary internal-only option to enable thin client mode with system property COSMOS.THINCLIENT_ENABLED, setting the thin client endpoint with system property COSMOS.THINCLIENT_ENDPOINT, and default thin client endpoint with system property COSMOS.DEFAULT_THINCLIENT_ENDPOINT while the thin-client transport is still under development. This transport mode is not yet supported or ready to be used by external customers. Please don't use these configs in any production scenario yet. - [PR 43188](https://github.com/Azure/azure-sdk-for-java/pull/43188)
1213

1314
### 4.66.0 (2025-01-14)
1415

sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/implementation/Configs.java

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,11 @@
1414
import org.slf4j.LoggerFactory;
1515

1616
import javax.net.ssl.SSLException;
17+
import java.net.URI;
18+
import java.net.URISyntaxException;
1719
import java.time.Duration;
1820
import java.util.Locale;
21+
import java.util.Objects;
1922

2023
import static com.azure.cosmos.implementation.guava25.base.MoreObjects.firstNonNull;
2124
import static com.azure.cosmos.implementation.guava25.base.Strings.emptyToNull;
@@ -44,6 +47,12 @@ public class Configs {
4447

4548
private static final String UNAVAILABLE_LOCATIONS_EXPIRATION_TIME_IN_SECONDS = "COSMOS.UNAVAILABLE_LOCATIONS_EXPIRATION_TIME_IN_SECONDS";
4649
private static final String GLOBAL_ENDPOINT_MANAGER_INITIALIZATION_TIME_IN_SECONDS = "COSMOS.GLOBAL_ENDPOINT_MANAGER_MAX_INIT_TIME_IN_SECONDS";
50+
private static final String DEFAULT_THINCLIENT_ENDPOINT = "";
51+
private static final String THINCLIENT_ENDPOINT = "COSMOS.THINCLIENT_ENDPOINT";
52+
private static final String THINCLIENT_ENDPOINT_VARIABLE = "COSMOS_THINCLIENT_ENDPOINT";
53+
private static final boolean DEFAULT_THINCLIENT_ENABLED = false;
54+
private static final String THINCLIENT_ENABLED = "COSMOS.THINCLIENT_ENABLED";
55+
private static final String THINCLIENT_ENABLED_VARIABLE = "COSMOS_THINCLIENT_ENABLED";
4756

4857
private static final String MAX_HTTP_BODY_LENGTH_IN_BYTES = "COSMOS.MAX_HTTP_BODY_LENGTH_IN_BYTES";
4958
private static final String MAX_HTTP_INITIAL_LINE_LENGTH_IN_BYTES = "COSMOS.MAX_HTTP_INITIAL_LINE_LENGTH_IN_BYTES";
@@ -405,6 +414,34 @@ public int getGlobalEndpointManagerMaxInitializationTimeInSeconds() {
405414
return getJVMConfigAsInt(GLOBAL_ENDPOINT_MANAGER_INITIALIZATION_TIME_IN_SECONDS, DEFAULT_GLOBAL_ENDPOINT_MANAGER_INITIALIZATION_TIME_IN_SECONDS);
406415
}
407416

417+
public URI getThinclientEndpoint() {
418+
String valueFromSystemProperty = System.getProperty(THINCLIENT_ENDPOINT);
419+
if (valueFromSystemProperty != null && !valueFromSystemProperty.isEmpty()) {
420+
return URI.create(valueFromSystemProperty);
421+
}
422+
423+
String valueFromEnvVariable = System.getenv(THINCLIENT_ENDPOINT_VARIABLE);
424+
if (valueFromEnvVariable != null && !valueFromEnvVariable.isEmpty()) {
425+
return URI.create(valueFromEnvVariable);
426+
}
427+
428+
return URI.create(DEFAULT_THINCLIENT_ENDPOINT);
429+
}
430+
431+
public static boolean getThinclientEnabled() {
432+
String valueFromSystemProperty = System.getProperty(THINCLIENT_ENABLED);
433+
if (valueFromSystemProperty != null && !valueFromSystemProperty.isEmpty()) {
434+
return Boolean.parseBoolean(valueFromSystemProperty);
435+
}
436+
437+
String valueFromEnvVariable = System.getenv(THINCLIENT_ENABLED_VARIABLE);
438+
if (valueFromEnvVariable != null && !valueFromEnvVariable.isEmpty()) {
439+
return Boolean.parseBoolean(valueFromEnvVariable);
440+
}
441+
442+
return DEFAULT_THINCLIENT_ENABLED;
443+
}
444+
408445
public int getUnavailableLocationsExpirationTimeInSeconds() {
409446
return getJVMConfigAsInt(UNAVAILABLE_LOCATIONS_EXPIRATION_TIME_IN_SECONDS, DEFAULT_UNAVAILABLE_LOCATIONS_EXPIRATION_TIME_IN_SECONDS);
410447
}

0 commit comments

Comments
 (0)