Skip to content
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

allowUsingHttp2 #42947

Merged
merged 14 commits into from
Nov 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,10 @@
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.node.ArrayNode;
import com.fasterxml.jackson.databind.node.ObjectNode;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.reflect.FieldUtils;
import org.mockito.Mockito;
import org.testng.SkipException;
import org.testng.annotations.AfterClass;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.DataProvider;
Expand Down Expand Up @@ -410,8 +412,19 @@ public void gatewayDiagnosticsOnException() throws Exception {
}

@Test(groups = {"fast"}, timeOut = TIMEOUT)
public void gatewayDiagnostgiticsOnNonCosmosException() {
public void gatewayDiagnosticsOnNonCosmosException() {
CosmosAsyncClient testClient = null;

// TODO[Http2]: Re-evaluate this test with http2 public API
boolean isHttp2Enabled = false;
if (!System.getProperty("COSMOS.HTTP2_ENABLED", StringUtils.EMPTY).isEmpty()) {
isHttp2Enabled = Boolean.parseBoolean(System.getProperty("COSMOS.HTTP2_ENABLED"));
}

if (isHttp2Enabled) {
throw new SkipException("Test gatewayDiagnosticsOnNonCosmosException only with http1.1");
}

try {
GatewayConnectionConfig gatewayConnectionConfig = new GatewayConnectionConfig();
gatewayConnectionConfig.setMaxConnectionPoolSize(1); // using a small value to force pendingAcquisitionTimeout happen
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,12 +106,42 @@ public void emulatorHost() {
}

@Test(groups = { "emulator" })
public void sslContextTest() {
Configs config = new Configs();
SslContext sslContext = config.getSslContext(false);
assertThat(sslContext).isEqualTo(ReflectionUtils.getSslContext(config));
public void http2Enabled() {
assertThat(Configs.isHttp2Enabled()).isFalse();

System.setProperty("COSMOS.HTTP2_ENABLED", "true");
assertThat(Configs.isHttp2Enabled()).isTrue();

System.clearProperty("COSMOS.HTTP2_ENABLED");
}

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

System.setProperty("COSMOS.HTTP2_MAX_CONNECTION_POOL_SIZE", "10");
assertThat(Configs.getHttp2MaxConnectionPoolSize()).isEqualTo(10);

System.clearProperty("COSMOS.HTTP2_MAX_CONNECTION_POOL_SIZE");
}

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

System.setProperty("COSMOS.HTTP2_MIN_CONNECTION_POOL_SIZE", "10");
assertThat(Configs.getHttp2MinConnectionPoolSize()).isEqualTo(10);

System.clearProperty("COSMOS.HTTP2_MIN_CONNECTION_POOL_SIZE");
}

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

System.setProperty("COSMOS.HTTP2_MAX_CONCURRENT_STREAMS", "10");
assertThat(Configs.getHttp2MaxConcurrentStreams()).isEqualTo(10);

sslContext = config.getSslContext(true);
assertThat(sslContext).isEqualTo(ReflectionUtils.getSslContextWithCertValidationDisabled(config));
System.clearProperty("COSMOS.HTTP2_MAX_CONCURRENT_STREAMS");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ public void connectionStateListener_OnConnectionEvent(
SslContext sslContext = SslContextUtils.CreateSslContext("client.jks", false);

Configs config = Mockito.mock(Configs.class);
Mockito.doReturn(sslContext).when(config).getSslContext(false);
Mockito.doReturn(sslContext).when(config).getSslContext(false, false);

RntbdTransportClient client = new RntbdTransportClient(
config,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import com.azure.cosmos.CosmosAsyncClient;
import com.azure.cosmos.CosmosAsyncContainer;
import com.azure.cosmos.CosmosClientBuilder;
import com.azure.cosmos.implementation.Configs;
import com.azure.cosmos.implementation.InternalObjectNode;
import com.azure.cosmos.implementation.directconnectivity.ReflectionUtils;
import com.azure.cosmos.implementation.http.ReactorNettyClient;
Expand Down Expand Up @@ -35,10 +36,11 @@
public class LogLevelTest extends TestSuiteBase {
public final static String COSMOS_DB_LOGGING_CATEGORY = "com.azure.cosmos";
public final static String NETWORK_LOGGING_CATEGORY = "com.azure.cosmos.netty-network";
public final static String LOG_PATTERN_1 = "HTTP/1.1 201";
public final static String LOG_PATTERN_2 = "| 0 1 2 3 4 5 6 7 8 9 a b c d e f |";
public final static String LOG_PATTERN_3 = "USER_EVENT: SslHandshakeCompletionEvent(SUCCESS)";
public final static String LOG_PATTERN_4 = "CONNECT: ";
public final static String LOG_PATTERN_HTTP_1_1 = "HTTP/1.1 201";
public final static String LOG_PATTERN_HTTP_2 = "HTTP/2";
public final static String LOG_PATTERN_1 = "| 0 1 2 3 4 5 6 7 8 9 a b c d e f |";
public final static String LOG_PATTERN_2 = "USER_EVENT: SslHandshakeCompletionEvent(SUCCESS)";
public final static String LOG_PATTERN_3 = "CONNECT: ";

private static final String APPENDER_NAME = "StringWriterAppender";
private static CosmosAsyncContainer createdCollection;
Expand Down Expand Up @@ -70,10 +72,9 @@ public void after_LogLevelTest() {
* This test will try to create document with netty wire DEBUG logging and
* validate it.
*
* @throws Exception
*/
@Test(groups = { "fast" }, timeOut = TIMEOUT)
public void createDocumentWithDebugLevel() throws Exception {
public void createDocumentWithDebugLevel() {
final StringWriter consoleWriter = new StringWriter();

addAppenderAndLogger(NETWORK_LOGGING_CATEGORY, Level.DEBUG, APPENDER_NAME, consoleWriter);
Expand All @@ -90,17 +91,16 @@ public void createDocumentWithDebugLevel() throws Exception {
assertThat(consoleWriter.toString()).contains(LOG_PATTERN_1);
assertThat(consoleWriter.toString()).contains(LOG_PATTERN_2);
assertThat(consoleWriter.toString()).contains(LOG_PATTERN_3);
assertThat(consoleWriter.toString()).contains(LOG_PATTERN_4);
validateHttpProtocol(consoleWriter);
}

/**
* This test will try to create document with netty wire WARN logging and
* validate it.
*
* @throws Exception
*/
@Test(groups = { "fast" }, timeOut = TIMEOUT)
public void createDocumentWithWarningLevel() throws Exception {
public void createDocumentWithWarningLevel() {
final StringWriter consoleWriter = new StringWriter();
addAppenderAndLogger(NETWORK_LOGGING_CATEGORY, Level.WARN, APPENDER_NAME, consoleWriter);

Expand All @@ -116,17 +116,16 @@ public void createDocumentWithWarningLevel() throws Exception {
assertThat(consoleWriter.toString()).contains(LOG_PATTERN_1);
assertThat(consoleWriter.toString()).contains(LOG_PATTERN_2);
assertThat(consoleWriter.toString()).contains(LOG_PATTERN_3);
assertThat(consoleWriter.toString()).contains(LOG_PATTERN_4);
validateHttpProtocol(consoleWriter);
}

/**
* This test will try to create document with netty wire TRACE logging and
* validate it.
*
* @throws Exception
*/
@Test(groups = { "fast" }, timeOut = TIMEOUT)
public void createDocumentWithTraceLevel() throws Exception {
public void createDocumentWithTraceLevel() {
final StringWriter consoleWriter = new StringWriter();

addAppenderAndLogger(NETWORK_LOGGING_CATEGORY, Level.TRACE, APPENDER_NAME, consoleWriter);
Expand All @@ -143,11 +142,11 @@ public void createDocumentWithTraceLevel() throws Exception {
assertThat(consoleWriter.toString()).contains(LOG_PATTERN_1);
assertThat(consoleWriter.toString()).contains(LOG_PATTERN_2);
assertThat(consoleWriter.toString()).contains(LOG_PATTERN_3);
assertThat(consoleWriter.toString()).contains(LOG_PATTERN_4);
validateHttpProtocol(consoleWriter);
}

@Test(groups = { "fast" }, timeOut = TIMEOUT, enabled = false)
public void createDocumentWithTraceLevelAtRoot() throws Exception {
public void createDocumentWithTraceLevelAtRoot() {
final StringWriter consoleWriter = new StringWriter();

addAppenderAndLogger(COSMOS_DB_LOGGING_CATEGORY, Level.TRACE, APPENDER_NAME, consoleWriter);
Expand All @@ -164,11 +163,11 @@ public void createDocumentWithTraceLevelAtRoot() throws Exception {
assertThat(consoleWriter.toString()).contains(LOG_PATTERN_1);
assertThat(consoleWriter.toString()).contains(LOG_PATTERN_2);
assertThat(consoleWriter.toString()).contains(LOG_PATTERN_3);
assertThat(consoleWriter.toString()).contains(LOG_PATTERN_4);
validateHttpProtocol(consoleWriter);
}

@Test(groups = { "fast" }, timeOut = TIMEOUT, enabled = false)
public void createDocumentWithDebugLevelAtRoot() throws Exception {
public void createDocumentWithDebugLevelAtRoot() {
final StringWriter consoleWriter = new StringWriter();

addAppenderAndLogger(COSMOS_DB_LOGGING_CATEGORY, Level.DEBUG, APPENDER_NAME, consoleWriter);
Expand All @@ -185,17 +184,16 @@ public void createDocumentWithDebugLevelAtRoot() throws Exception {
assertThat(consoleWriter.toString()).contains(LOG_PATTERN_1);
assertThat(consoleWriter.toString()).contains(LOG_PATTERN_2);
assertThat(consoleWriter.toString()).contains(LOG_PATTERN_3);
assertThat(consoleWriter.toString()).contains(LOG_PATTERN_4);
validateHttpProtocol(consoleWriter);
}

/**
* This test will try to create document with netty wire ERROR logging and
* validate it.
*
* @throws Exception
*/
@Test(groups = { "fast" }, timeOut = TIMEOUT)
public void createDocumentWithErrorLevel() throws Exception {
public void createDocumentWithErrorLevel() {
final StringWriter consoleWriter = new StringWriter();

addAppenderAndLogger(NETWORK_LOGGING_CATEGORY, Level.ERROR, APPENDER_NAME, consoleWriter);
Expand All @@ -211,17 +209,16 @@ public void createDocumentWithErrorLevel() throws Exception {
assertThat(consoleWriter.toString()).contains(LOG_PATTERN_1);
assertThat(consoleWriter.toString()).contains(LOG_PATTERN_2);
assertThat(consoleWriter.toString()).contains(LOG_PATTERN_3);
assertThat(consoleWriter.toString()).contains(LOG_PATTERN_4);
validateHttpProtocol(consoleWriter);
}

/**
* This test will try to create document with netty wire INFO logging and
* validate it.
*
* @throws Exception
*/
@Test(groups = { "fast" }, timeOut = TIMEOUT)
public void createDocumentWithInfoLevel() throws Exception {
public void createDocumentWithInfoLevel() {
final StringWriter consoleWriter = new StringWriter();

addAppenderAndLogger(NETWORK_LOGGING_CATEGORY, Level.INFO, APPENDER_NAME, consoleWriter);
Expand All @@ -237,7 +234,16 @@ public void createDocumentWithInfoLevel() throws Exception {
assertThat(consoleWriter.toString()).contains(LOG_PATTERN_1);
assertThat(consoleWriter.toString()).contains(LOG_PATTERN_2);
assertThat(consoleWriter.toString()).contains(LOG_PATTERN_3);
assertThat(consoleWriter.toString()).contains(LOG_PATTERN_4);
validateHttpProtocol(consoleWriter);
}

private void validateHttpProtocol(StringWriter consoleWriter) {
boolean isHttp2Enabled = Configs.isHttp2Enabled();
if (isHttp2Enabled) {
assertThat(consoleWriter.toString()).contains(LOG_PATTERN_HTTP_2);
} else {
assertThat(consoleWriter.toString()).contains(LOG_PATTERN_HTTP_1_1);
}
}

private InternalObjectNode getDocumentDefinition() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ public void conflictResolutionPolicyCRUD() {
// when (e.StatusCode == HttpStatusCode.BadRequest)
CosmosException dce = Utils.as(e, CosmosException.class);
if (dce != null && dce.getStatusCode() == 400) {
assertThat(dce.getMessage()).contains("Invalid path '\\\\/a\\\\/b' for last writer wins conflict resolution");
assertThat(dce.getMessage()).contains("Invalid path '/a/b' for last writer wins conflict resolution");
} else {
throw e;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import com.azure.cosmos.CosmosAsyncDatabase;
import com.azure.cosmos.CosmosClientBuilder;
import com.azure.cosmos.GatewayConnectionConfig;
import com.azure.cosmos.implementation.Configs;
import com.azure.cosmos.implementation.InternalObjectNode;
import com.azure.cosmos.implementation.TestConfigurations;
import com.azure.cosmos.models.CosmosItemRequestOptions;
Expand Down Expand Up @@ -96,10 +97,9 @@ public void createDocumentWithValidHttpProxy() throws Exception {
/**
* This test will try to create document via http proxy server with netty wire logging and validate it.
*
* @throws Exception
*/
@Test(groups = { "fast" }, timeOut = TIMEOUT)
public void createDocumentWithValidHttpProxyWithNettyWireLogging() throws Exception {
public void createDocumentWithValidHttpProxyWithNettyWireLogging() {
CosmosAsyncClient clientWithRightProxy = null;
try {
final StringWriter consoleWriter = new StringWriter();
Expand All @@ -125,7 +125,13 @@ public void createDocumentWithValidHttpProxyWithNettyWireLogging() throws Except

assertThat(consoleWriter.toString()).contains(LogLevelTest.LOG_PATTERN_1);
assertThat(consoleWriter.toString()).contains(LogLevelTest.LOG_PATTERN_2);
assertThat(consoleWriter.toString()).contains(LogLevelTest.LOG_PATTERN_3);
boolean isHttp2Enabled = Configs.isHttp2Enabled();
if (isHttp2Enabled) {
assertThat(consoleWriter.toString()).contains(LogLevelTest.LOG_PATTERN_HTTP_2);
} else {
assertThat(consoleWriter.toString()).contains(LogLevelTest.LOG_PATTERN_HTTP_1_1);
}

} finally {
safeClose(clientWithRightProxy);
}
Expand Down
4 changes: 4 additions & 0 deletions sdk/cosmos/azure-cosmos/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@
#### Bugs Fixed

#### Other Changes
* Added support to enable http2 for gateway mode with system property `COSMOS.HTTP2_ENABLED` and system variable `COSMOS_HTTP2_ENABLED`. - [PR 42947](https://github.com/Azure/azure-sdk-for-java/pull/42947)
xinlian12 marked this conversation as resolved.
Show resolved Hide resolved
* Added support to allow changing http2 max connection pool size with system property `COSMOS.HTTP2_MAX_CONNECTION_POOL_SIZE` and system variable `COSMOS_HTTP2_MAX_CONNECTION_POOL_SIZE`. - [PR 42947](https://github.com/Azure/azure-sdk-for-java/pull/42947)
* Added support to allow changing http2 max connection pool size with system property `COSMOS.HTTP2_MIN_CONNECTION_POOL_SIZE` and system variable `COSMOS_HTTP2_MIN_CONNECTION_POOL_SIZE`. - [PR 42947](https://github.com/Azure/azure-sdk-for-java/pull/42947)
* Added support to allow changing http2 max connection pool size with system property `COSMOS.HTTP2_MAX_CONCURRENT_STREAMS` and system variable `COSMOS_HTTP2_MAX_CONCURRENT_STREAMS`. - [PR 42947](https://github.com/Azure/azure-sdk-for-java/pull/42947)

### 4.65.0 (2024-11-19)

Expand Down
Loading
Loading