Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
81 commits
Select commit Hold shift + click to select a range
446ca0b
Test changes to add leak detection
FabianMeiswinkel Nov 7, 2025
0e2032b
Update Configs.java
FabianMeiswinkel Nov 7, 2025
1a7985b
Merge branch 'main' into users/fabianm/TestImprovements
FabianMeiswinkel Nov 7, 2025
455b8bc
Update CosmosNettyLeakDetectorFactory.java
FabianMeiswinkel Nov 7, 2025
8360f49
Update sdk/cosmos/azure-cosmos-encryption/src/test/java/com/azure/cos…
FabianMeiswinkel Nov 7, 2025
f9f263c
Update CosmosNettyLeakDetectorFactory.java
FabianMeiswinkel Nov 7, 2025
8e3a2d3
Fixes
FabianMeiswinkel Nov 7, 2025
13370c8
Fixes
FabianMeiswinkel Nov 7, 2025
b59e147
Update CosmosNettyLeakDetectorFactory.java
FabianMeiswinkel Nov 7, 2025
d3aa922
Update RxDocumentClientImpl.java
FabianMeiswinkel Nov 7, 2025
6c66864
Fixes
FabianMeiswinkel Nov 7, 2025
4dbfe6a
Update CosmosNettyLeakDetectorFactory.java
FabianMeiswinkel Nov 7, 2025
de7ecde
Fixes
FabianMeiswinkel Nov 7, 2025
bb9493d
Fixes
FabianMeiswinkel Nov 7, 2025
2e9c533
Iterating on tests
FabianMeiswinkel Nov 7, 2025
6ac7997
Fixing build warning
FabianMeiswinkel Nov 7, 2025
190b9e3
Fixing memory leak
FabianMeiswinkel Nov 8, 2025
8c70464
Reverting production changes
FabianMeiswinkel Nov 10, 2025
5c3dac3
Merge branch 'main' of https://github.com/Azure/azure-sdk-for-java in…
FabianMeiswinkel Nov 10, 2025
bca461f
Iterating on test tools
FabianMeiswinkel Nov 10, 2025
1046b1d
Cleaning-up dummy QueryFeedRangeState properly
FabianMeiswinkel Nov 10, 2025
3ad7a16
Update test-resources.json
FabianMeiswinkel Nov 10, 2025
f8643a3
Update sdk/cosmos/azure-cosmos-tests/src/test/java/com/azure/cosmos/C…
FabianMeiswinkel Nov 10, 2025
b4c2a91
[WIP] Fix Netty buffer and RxDocumentClientImpl leaks (#47213)
Copilot Nov 10, 2025
639b41e
NITs
FabianMeiswinkel Nov 10, 2025
68bb25e
Move static block to class level in cosmos-encryption TestSuiteBase (…
Copilot Nov 10, 2025
b5ac806
Merge branch 'main' of https://github.com/Azure/azure-sdk-for-java in…
FabianMeiswinkel Nov 10, 2025
6f12a81
Update SessionTest.java
FabianMeiswinkel Nov 10, 2025
1d19eae
Merge branch 'users/fabianm/NettyBufferLeakFixes' of https://github.c…
FabianMeiswinkel Nov 10, 2025
3caade1
Update tests.yml
FabianMeiswinkel Nov 10, 2025
8a798ff
Update CosmosNettyLeakDetectorFactory.java
FabianMeiswinkel Nov 11, 2025
8059e0e
Test config
FabianMeiswinkel Nov 11, 2025
5ea5a92
Update CosmosNettyLeakDetectorFactory.java
FabianMeiswinkel Nov 11, 2025
82216f9
Updating TestNG
FabianMeiswinkel Nov 11, 2025
c60f309
Reverting TestNG to 7.9.0 (highest version still supporting Java8)
FabianMeiswinkel Nov 11, 2025
f9ecf9e
Switching back to TestNG 7.5.1
FabianMeiswinkel Nov 11, 2025
e6f5109
Merge branch 'main' of https://github.com/Azure/azure-sdk-for-java in…
FabianMeiswinkel Nov 11, 2025
f71d7b5
Enabling leak detection in unit tests
FabianMeiswinkel Nov 11, 2025
59a71a6
Merge branch 'main' of https://github.com/Azure/azure-sdk-for-java in…
FabianMeiswinkel Nov 11, 2025
e842124
Iterating on tests
FabianMeiswinkel Nov 12, 2025
2d13133
Merge branch 'main' into users/fabianm/NettyBufferLeakFixes
FabianMeiswinkel Nov 12, 2025
1e4bb36
Update pom.xml
FabianMeiswinkel Nov 12, 2025
bb5ba74
Test changes (#47233)
FabianMeiswinkel Nov 12, 2025
8835846
Update RntbdTransportClientTest.java
FabianMeiswinkel Nov 12, 2025
7fcacf2
Updating netty leak detection system properties
FabianMeiswinkel Nov 12, 2025
2b4dc18
Update CosmosNettyLeakDetectorFactory.java
FabianMeiswinkel Nov 12, 2025
03dea1d
Merge branch 'main' of https://github.com/Azure/azure-sdk-for-java in…
FabianMeiswinkel Nov 12, 2025
c7e7360
Test changes
FabianMeiswinkel Nov 12, 2025
65c9b27
Merge branch 'main' of https://github.com/Azure/azure-sdk-for-java in…
FabianMeiswinkel Nov 12, 2025
3fd46ae
Prod memory leak fixes
FabianMeiswinkel Nov 13, 2025
5c0d021
Test fixes
FabianMeiswinkel Nov 13, 2025
e5ea5de
Merge branch 'main' of https://github.com/Azure/azure-sdk-for-java in…
FabianMeiswinkel Nov 13, 2025
117a4e2
Test fixes
FabianMeiswinkel Nov 13, 2025
77a0514
Merge branch 'main' of https://github.com/Azure/azure-sdk-for-java in…
FabianMeiswinkel Nov 13, 2025
7a30b0e
Users/fabianm/portfixes (#47252)
FabianMeiswinkel Nov 13, 2025
ce25798
Merge branch 'users/fabianm/NettyBufferLeakFixes' of https://github.c…
FabianMeiswinkel Nov 13, 2025
4b97eff
Test fixes
FabianMeiswinkel Nov 13, 2025
b008d62
Merge branch 'main' into users/fabianm/NettyBufferLeakFixes
FabianMeiswinkel Nov 13, 2025
06425eb
Fix Netty ByteBuf leaks in StoreResponse and RetryContextOnDiagnostic…
Copilot Nov 13, 2025
daa8fd3
Update EncryptionAsyncApiCrudTest.java
FabianMeiswinkel Nov 13, 2025
7d09f9c
Merge branch 'users/fabianm/NettyBufferLeakFixes' of https://github.c…
FabianMeiswinkel Nov 13, 2025
ad522f1
Fix ByteBuf memory leak in TcpServerMock request decoders (#47269)
Copilot Nov 13, 2025
738d186
Update ThinClientStoreModel.java
FabianMeiswinkel Nov 13, 2025
625d295
Merge branch 'main' of https://github.com/Azure/azure-sdk-for-java in…
FabianMeiswinkel Nov 13, 2025
db3fb79
Fixing test issues
FabianMeiswinkel Nov 13, 2025
3b2a74f
Disable netty leak detection in RetrycontextOnDiagnosticTest
FabianMeiswinkel Nov 13, 2025
3e53ed7
Test and diagnostics improvements
FabianMeiswinkel Nov 14, 2025
1f6d624
Merge branch 'main' of https://github.com/Azure/azure-sdk-for-java in…
FabianMeiswinkel Nov 14, 2025
33a680e
Test fixes and more breadcrumbs
FabianMeiswinkel Nov 14, 2025
f216f74
Merge branch 'main' into users/fabianm/NettyBufferLeakFixes
FabianMeiswinkel Nov 14, 2025
02ee9f3
Test fixes
FabianMeiswinkel Nov 14, 2025
a058028
Merge branch 'main' into users/fabianm/NettyBufferLeakFixes
FabianMeiswinkel Nov 14, 2025
a54d1ba
Test fixes
FabianMeiswinkel Nov 14, 2025
b56a020
Test fixes
FabianMeiswinkel Nov 15, 2025
6d59331
Merge branch 'main' into users/fabianm/NettyBufferLeakFixes
FabianMeiswinkel Nov 15, 2025
5b07ba2
Update OrderbyDocumentQueryTest.java
FabianMeiswinkel Nov 15, 2025
4835f8b
Merge branch 'main' into users/fabianm/NettyBufferLeakFixes
FabianMeiswinkel Nov 15, 2025
d99560a
Test fixes
FabianMeiswinkel Nov 17, 2025
616f8c4
Merge branch 'main' of https://github.com/Azure/azure-sdk-for-java in…
FabianMeiswinkel Nov 17, 2025
f73d4e0
Reverting too noisy logs
FabianMeiswinkel Nov 17, 2025
146636a
Merge branch 'main' of https://github.com/Azure/azure-sdk-for-java in…
FabianMeiswinkel Nov 17, 2025
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
88 changes: 88 additions & 0 deletions sdk/cosmos/azure-cosmos-benchmark/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,12 @@ Licensed under the MIT License.
<version>3.5.3</version> <!-- {x-version-update;org.apache.maven.plugins:maven-surefire-plugin;external_dependency} -->
<configuration>
<groups>unit</groups>
<systemPropertyVariables>
<COSMOS.CLIENT_LEAK_DETECTION_ENABLED>true</COSMOS.CLIENT_LEAK_DETECTION_ENABLED>
<io.netty.leakDetection.samplingInterval>1</io.netty.leakDetection.samplingInterval>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

io.netty.leakDetection.samplingInterval is being defined twice?

<io.netty.leakDetection.samplingInterval>256</io.netty.leakDetection.samplingInterval>
<io.netty.leakDetection.level>paranoid</io.netty.leakDetection.level>
</systemPropertyVariables>
<includes>
<include>%regex[.*]</include>
</includes>
Expand All @@ -211,6 +217,10 @@ Licensed under the MIT License.
<name>surefire.testng.verbose</name>
<value>2</value>
</property>
<property>
<name>listener</name>
<value>com.azure.cosmos.CosmosNettyLeakDetectorFactory</value>
</property>
</properties>
<skipTests>true</skipTests>
</configuration>
Expand Down Expand Up @@ -308,6 +318,12 @@ Licensed under the MIT License.
<suiteXmlFiles>
<suiteXmlFile>src/test/resources/unit-testng.xml</suiteXmlFile>
</suiteXmlFiles>
<systemPropertyVariables>
<COSMOS.CLIENT_LEAK_DETECTION_ENABLED>true</COSMOS.CLIENT_LEAK_DETECTION_ENABLED>
<io.netty.leakDetection.samplingInterval>1</io.netty.leakDetection.samplingInterval>
<io.netty.leakDetection.samplingInterval>256</io.netty.leakDetection.samplingInterval>
<io.netty.leakDetection.level>paranoid</io.netty.leakDetection.level>
</systemPropertyVariables>
</configuration>
</plugin>
</plugins>
Expand All @@ -329,6 +345,12 @@ Licensed under the MIT License.
<suiteXmlFiles>
<suiteXmlFile>src/test/resources/fast-testng.xml</suiteXmlFile>
</suiteXmlFiles>
<systemPropertyVariables>
<COSMOS.CLIENT_LEAK_DETECTION_ENABLED>true</COSMOS.CLIENT_LEAK_DETECTION_ENABLED>
<io.netty.leakDetection.samplingInterval>1</io.netty.leakDetection.samplingInterval>
<io.netty.leakDetection.samplingInterval>256</io.netty.leakDetection.samplingInterval>
<io.netty.leakDetection.level>paranoid</io.netty.leakDetection.level>
</systemPropertyVariables>
</configuration>
</plugin>
</plugins>
Expand All @@ -350,6 +372,12 @@ Licensed under the MIT License.
<suiteXmlFiles>
<suiteXmlFile>src/test/resources/split-testng.xml</suiteXmlFile>
</suiteXmlFiles>
<systemPropertyVariables>
<COSMOS.CLIENT_LEAK_DETECTION_ENABLED>true</COSMOS.CLIENT_LEAK_DETECTION_ENABLED>
<io.netty.leakDetection.samplingInterval>1</io.netty.leakDetection.samplingInterval>
<io.netty.leakDetection.samplingInterval>256</io.netty.leakDetection.samplingInterval>
<io.netty.leakDetection.level>paranoid</io.netty.leakDetection.level>
</systemPropertyVariables>
</configuration>
</plugin>
</plugins>
Expand All @@ -371,6 +399,12 @@ Licensed under the MIT License.
<suiteXmlFiles>
<suiteXmlFile>src/test/resources/cfp-split-testng.xml</suiteXmlFile>
</suiteXmlFiles>
<systemPropertyVariables>
<COSMOS.CLIENT_LEAK_DETECTION_ENABLED>true</COSMOS.CLIENT_LEAK_DETECTION_ENABLED>
<io.netty.leakDetection.samplingInterval>1</io.netty.leakDetection.samplingInterval>
<io.netty.leakDetection.samplingInterval>256</io.netty.leakDetection.samplingInterval>
<io.netty.leakDetection.level>paranoid</io.netty.leakDetection.level>
</systemPropertyVariables>
</configuration>
</plugin>
</plugins>
Expand All @@ -392,6 +426,12 @@ Licensed under the MIT License.
<suiteXmlFiles>
<suiteXmlFile>src/test/resources/query-testng.xml</suiteXmlFile>
</suiteXmlFiles>
<systemPropertyVariables>
<COSMOS.CLIENT_LEAK_DETECTION_ENABLED>true</COSMOS.CLIENT_LEAK_DETECTION_ENABLED>
<io.netty.leakDetection.samplingInterval>1</io.netty.leakDetection.samplingInterval>
<io.netty.leakDetection.samplingInterval>256</io.netty.leakDetection.samplingInterval>
<io.netty.leakDetection.level>paranoid</io.netty.leakDetection.level>
</systemPropertyVariables>
</configuration>
</plugin>
</plugins>
Expand All @@ -413,6 +453,12 @@ Licensed under the MIT License.
<suiteXmlFiles>
<suiteXmlFile>src/test/resources/long-testng.xml</suiteXmlFile>
</suiteXmlFiles>
<systemPropertyVariables>
<COSMOS.CLIENT_LEAK_DETECTION_ENABLED>true</COSMOS.CLIENT_LEAK_DETECTION_ENABLED>
<io.netty.leakDetection.samplingInterval>1</io.netty.leakDetection.samplingInterval>
<io.netty.leakDetection.samplingInterval>256</io.netty.leakDetection.samplingInterval>
<io.netty.leakDetection.level>paranoid</io.netty.leakDetection.level>
</systemPropertyVariables>
</configuration>
</plugin>
</plugins>
Expand All @@ -434,6 +480,12 @@ Licensed under the MIT License.
<suiteXmlFiles>
<suiteXmlFile>src/test/resources/direct-testng.xml</suiteXmlFile>
</suiteXmlFiles>
<systemPropertyVariables>
<COSMOS.CLIENT_LEAK_DETECTION_ENABLED>true</COSMOS.CLIENT_LEAK_DETECTION_ENABLED>
<io.netty.leakDetection.samplingInterval>1</io.netty.leakDetection.samplingInterval>
<io.netty.leakDetection.samplingInterval>256</io.netty.leakDetection.samplingInterval>
<io.netty.leakDetection.level>paranoid</io.netty.leakDetection.level>
</systemPropertyVariables>
</configuration>
</plugin>
</plugins>
Expand All @@ -455,6 +507,12 @@ Licensed under the MIT License.
<suiteXmlFiles>
<suiteXmlFile>src/test/resources/multi-master-testng.xml</suiteXmlFile>
</suiteXmlFiles>
<systemPropertyVariables>
<COSMOS.CLIENT_LEAK_DETECTION_ENABLED>true</COSMOS.CLIENT_LEAK_DETECTION_ENABLED>
<io.netty.leakDetection.samplingInterval>1</io.netty.leakDetection.samplingInterval>
<io.netty.leakDetection.samplingInterval>256</io.netty.leakDetection.samplingInterval>
<io.netty.leakDetection.level>paranoid</io.netty.leakDetection.level>
</systemPropertyVariables>
</configuration>
</plugin>
</plugins>
Expand All @@ -476,6 +534,12 @@ Licensed under the MIT License.
<suiteXmlFiles>
<suiteXmlFile>src/test/resources/flaky-multi-master-testng.xml</suiteXmlFile>
</suiteXmlFiles>
<systemPropertyVariables>
<COSMOS.CLIENT_LEAK_DETECTION_ENABLED>true</COSMOS.CLIENT_LEAK_DETECTION_ENABLED>
<io.netty.leakDetection.samplingInterval>1</io.netty.leakDetection.samplingInterval>
<io.netty.leakDetection.samplingInterval>256</io.netty.leakDetection.samplingInterval>
<io.netty.leakDetection.level>paranoid</io.netty.leakDetection.level>
</systemPropertyVariables>
</configuration>
</plugin>
</plugins>
Expand All @@ -497,6 +561,12 @@ Licensed under the MIT License.
<suiteXmlFiles>
<suiteXmlFile>src/test/resources/fi-multi-master-testng.xml</suiteXmlFile>
</suiteXmlFiles>
<systemPropertyVariables>
<COSMOS.CLIENT_LEAK_DETECTION_ENABLED>true</COSMOS.CLIENT_LEAK_DETECTION_ENABLED>
<io.netty.leakDetection.samplingInterval>1</io.netty.leakDetection.samplingInterval>
<io.netty.leakDetection.samplingInterval>256</io.netty.leakDetection.samplingInterval>
<io.netty.leakDetection.level>paranoid</io.netty.leakDetection.level>
</systemPropertyVariables>
</configuration>
</plugin>
</plugins>
Expand All @@ -519,6 +589,12 @@ Licensed under the MIT License.
<suiteXmlFiles>
<suiteXmlFile>src/test/resources/examples-testng.xml</suiteXmlFile>
</suiteXmlFiles>
<systemPropertyVariables>
<COSMOS.CLIENT_LEAK_DETECTION_ENABLED>true</COSMOS.CLIENT_LEAK_DETECTION_ENABLED>
<io.netty.leakDetection.samplingInterval>1</io.netty.leakDetection.samplingInterval>
<io.netty.leakDetection.samplingInterval>256</io.netty.leakDetection.samplingInterval>
<io.netty.leakDetection.level>paranoid</io.netty.leakDetection.level>
</systemPropertyVariables>
</configuration>
<executions>
<execution>
Expand Down Expand Up @@ -548,6 +624,12 @@ Licensed under the MIT License.
<suiteXmlFiles>
<suiteXmlFile>src/test/resources/emulator-testng.xml</suiteXmlFile>
</suiteXmlFiles>
<systemPropertyVariables>
<COSMOS.CLIENT_LEAK_DETECTION_ENABLED>true</COSMOS.CLIENT_LEAK_DETECTION_ENABLED>
<io.netty.leakDetection.samplingInterval>1</io.netty.leakDetection.samplingInterval>
<io.netty.leakDetection.samplingInterval>256</io.netty.leakDetection.samplingInterval>
<io.netty.leakDetection.level>paranoid</io.netty.leakDetection.level>
</systemPropertyVariables>
</configuration>
</plugin>
</plugins>
Expand All @@ -569,6 +651,12 @@ Licensed under the MIT License.
<suiteXmlFiles>
<suiteXmlFile>src/test/resources/e2e-testng.xml</suiteXmlFile>
</suiteXmlFiles>
<systemPropertyVariables>
<COSMOS.CLIENT_LEAK_DETECTION_ENABLED>true</COSMOS.CLIENT_LEAK_DETECTION_ENABLED>
<io.netty.leakDetection.samplingInterval>1</io.netty.leakDetection.samplingInterval>
<io.netty.leakDetection.samplingInterval>256</io.netty.leakDetection.samplingInterval>
<io.netty.leakDetection.level>paranoid</io.netty.leakDetection.level>
</systemPropertyVariables>
</configuration>
</plugin>
</plugins>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -498,4 +498,13 @@ protected String getDocumentLink(Document doc) {
return doc.getSelfLink();
}
}

@Override
void shutdown() {
if (this.client != null) {
this.client.close();
}

super.shutdown();
}
}
2 changes: 1 addition & 1 deletion sdk/cosmos/azure-cosmos-encryption/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ The Azure Cosmos Encryption Plugin is used for encrypting data with a user-provi
<dependency>
<groupId>com.azure</groupId>
<artifactId>azure-cosmos-encryption</artifactId>
<version>2.24.0</version>
<version>2.25.0-beta.1</version>
</dependency>
```
[//]: # ({x-version-update-end})
Expand Down
25 changes: 24 additions & 1 deletion sdk/cosmos/azure-cosmos-encryption/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ Licensed under the MIT License.
--add-opens com.azure.cosmos.encryption/com.azure.cosmos.encryption.util=ALL-UNNAMED
--add-opens com.azure.cosmos.encryption/com.azure.cosmos.encryption.models=ALL-UNNAMED
--add-opens com.azure.cosmos/com.azure.cosmos.implementation=ALL-UNNAMED
--add-modules java.management
--add-reads com.azure.cosmos.encryption=java.management
</javaModulesSurefireArgLine>
<doclintMissingInclusion>-</doclintMissingInclusion>
<spotless.skip>true</spotless.skip>
Expand Down Expand Up @@ -217,6 +219,12 @@ Licensed under the MIT License.
<version>3.5.3</version> <!-- {x-version-update;org.apache.maven.plugins:maven-surefire-plugin;external_dependency} -->
<configuration>
<groups>unit</groups>
<systemPropertyVariables>
<COSMOS.CLIENT_LEAK_DETECTION_ENABLED>true</COSMOS.CLIENT_LEAK_DETECTION_ENABLED>
<io.netty.leakDetection.samplingInterval>1</io.netty.leakDetection.samplingInterval>
<io.netty.leakDetection.samplingInterval>256</io.netty.leakDetection.samplingInterval>
<io.netty.leakDetection.level>paranoid</io.netty.leakDetection.level>
</systemPropertyVariables>
<includes>
<include>%regex[.*]</include>
</includes>
Expand All @@ -225,6 +233,10 @@ Licensed under the MIT License.
<name>surefire.testng.verbose</name>
<value>2</value>
</property>
<property>
<name>listener</name>
<value>com.azure.cosmos.encryption.CosmosNettyLeakDetectorFactory</value>
</property>
</properties>
<skipTests>true</skipTests>
</configuration>
Expand Down Expand Up @@ -263,6 +275,12 @@ Licensed under the MIT License.
<suiteXmlFiles>
<suiteXmlFile>src/test/resources/unit-testng.xml</suiteXmlFile>
</suiteXmlFiles>
<systemPropertyVariables>
<COSMOS.CLIENT_LEAK_DETECTION_ENABLED>true</COSMOS.CLIENT_LEAK_DETECTION_ENABLED>
<io.netty.leakDetection.samplingInterval>1</io.netty.leakDetection.samplingInterval>
<io.netty.leakDetection.samplingInterval>256</io.netty.leakDetection.samplingInterval>
<io.netty.leakDetection.level>paranoid</io.netty.leakDetection.level>
</systemPropertyVariables>
</configuration>
</plugin>
</plugins>
Expand All @@ -284,7 +302,12 @@ Licensed under the MIT License.
<suiteXmlFiles>
<suiteXmlFile>src/test/resources/encryption-testng.xml</suiteXmlFile>
</suiteXmlFiles>

<systemPropertyVariables>
<COSMOS.CLIENT_LEAK_DETECTION_ENABLED>true</COSMOS.CLIENT_LEAK_DETECTION_ENABLED>
<io.netty.leakDetection.samplingInterval>1</io.netty.leakDetection.samplingInterval>
<io.netty.leakDetection.samplingInterval>256</io.netty.leakDetection.samplingInterval>
<io.netty.leakDetection.level>paranoid</io.netty.leakDetection.level>
</systemPropertyVariables>
</configuration>
</plugin>
</plugins>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import org.testng.annotations.AfterMethod;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Listeners;

import java.lang.management.BufferPoolMXBean;
import java.lang.management.ManagementFactory;
Expand All @@ -29,16 +30,15 @@
import java.util.Map;
import java.util.concurrent.atomic.AtomicInteger;

@Listeners({TestNGLogListener.class, CosmosNettyLeakDetectorFactory.class})
public abstract class CosmosEncryptionAsyncClientTest implements ITest {
protected static Logger logger = LoggerFactory.getLogger(CosmosEncryptionAsyncClientTest.class.getSimpleName());
protected static final int SUITE_SETUP_TIMEOUT = 120000;
private static final ImplementationBridgeHelpers.CosmosClientBuilderHelper.CosmosClientBuilderAccessor cosmosClientBuilderAccessor =
ImplementationBridgeHelpers.CosmosClientBuilderHelper.getCosmosClientBuilderAccessor();
private final static AtomicInteger instancesUsed = new AtomicInteger(0);

private final CosmosClientBuilder clientBuilder;
private String testName;
private volatile Map<Integer, String> activeClientsAtBegin = new HashMap<>();

public CosmosEncryptionAsyncClientTest() {
this(new CosmosClientBuilder());
Expand All @@ -52,78 +52,6 @@ public final CosmosClientBuilder getClientBuilder() {
return this.clientBuilder;
}

@BeforeClass(groups = {"fast", "long", "direct", "multi-master", "encryption"}, timeOut = SUITE_SETUP_TIMEOUT)

public void beforeClassSetupLeakDetection() {
if (instancesUsed.getAndIncrement() == 0) {
this.activeClientsAtBegin = RxDocumentClientImpl.getActiveClientsSnapshot();
this.logMemoryUsage("BEFORE");
}
}

private void logMemoryUsage(String name) {
long pooledDirectBytes = PooledByteBufAllocator.DEFAULT.metric()
.directArenas().stream()
.mapToLong(io.netty.buffer.PoolArenaMetric::numActiveBytes)
.sum();

long used = PlatformDependent.usedDirectMemory();
long max = PlatformDependent.maxDirectMemory();
logger.info("MEMORY USAGE: {}:{}", this.getClass().getCanonicalName(), name);
logger.info("Netty Direct Memory: {}/{}/{} bytes", used, pooledDirectBytes, max);
for (BufferPoolMXBean pool : ManagementFactory.getPlatformMXBeans(BufferPoolMXBean.class)) {
logger.info("Pool {}: used={} bytes, capacity={} bytes, count={}",
pool.getName(), pool.getMemoryUsed(), pool.getTotalCapacity(), pool.getCount());
}
}

@AfterClass(groups = {"fast", "long", "direct", "multi-master", "encryption"}, timeOut = SUITE_SETUP_TIMEOUT)
public void afterClassSetupLeakDetection() {
if (instancesUsed.decrementAndGet() == 0) {
Map<Integer, String> leakedClientSnapshotNow = RxDocumentClientImpl.getActiveClientsSnapshot();
StringBuilder sb = new StringBuilder();
Map<Integer, String> leakedClientSnapshotAtBegin = activeClientsAtBegin;

for (Integer clientId : leakedClientSnapshotNow.keySet()) {
if (!leakedClientSnapshotAtBegin.containsKey(clientId)) {
// this client was leaked in this class
sb
.append("CosmosClient [")
.append(clientId)
.append("] leaked. Callstack of initialization:\n")
.append(leakedClientSnapshotNow.get(clientId))
.append("\n\n");
}
}

if (sb.length() > 0) {
String msg = "COSMOS CLIENT LEAKS detected in test class: "
+ this.getClass().getCanonicalName()
+ "\n\n"
+ sb;

logger.error(msg);
// fail(msg);
}

List<String> nettyLeaks = CosmosNettyLeakDetectorFactory.resetIdentifiedLeaks();
if (nettyLeaks.size() > 0) {
sb.append("\n");
for (String leak : nettyLeaks) {
sb.append(leak).append("\n");
}

String msg = "NETTY LEAKS detected in test class: "
+ this.getClass().getCanonicalName()
+ sb;

logger.error(msg);
// fail(msg);
}
this.logMemoryUsage("AFTER");
}
}

@Override
public final String getTestName() {
return this.testName;
Expand Down
Loading
Loading