Skip to content

Commit 86b3dc8

Browse files
FabianMeiswinkelCopilotCopilotxinlian12
authored
[Internal]Enabled Netty Buffer Leak detection and left-over CosmsoClient instance detection during test execution (Azure#47211)
* Test changes to add leak detection * Update Configs.java * Update CosmosNettyLeakDetectorFactory.java * Update sdk/cosmos/azure-cosmos-encryption/src/test/java/com/azure/cosmos/encryption/CosmosNettyLeakDetectorFactory.java Co-authored-by: Copilot <[email protected]> * Update CosmosNettyLeakDetectorFactory.java * Fixes * Fixes * Update CosmosNettyLeakDetectorFactory.java * Update RxDocumentClientImpl.java * Fixes * Update CosmosNettyLeakDetectorFactory.java * Fixes * Fixes * Iterating on tests * Fixing build warning * Fixing memory leak * Reverting production changes * Iterating on test tools * Cleaning-up dummy QueryFeedRangeState properly * Update test-resources.json * Update sdk/cosmos/azure-cosmos-tests/src/test/java/com/azure/cosmos/CosmosDiagnosticsE2ETest.java Co-authored-by: Copilot <[email protected]> * [WIP] Fix Netty buffer and RxDocumentClientImpl leaks (Azure#47213) * Initial plan * Improve JavaDoc phrasing in RxDocumentClientImpl Co-authored-by: FabianMeiswinkel <[email protected]> --------- Co-authored-by: copilot-swe-agent[bot] <[email protected]> Co-authored-by: FabianMeiswinkel <[email protected]> Co-authored-by: Fabian Meiswinkel <[email protected]> * NITs * Move static block to class level in cosmos-encryption TestSuiteBase (Azure#47216) * Initial plan * Move CosmosNettyLeakDetectorFactory.ingestIntoNetty() to class-level static block Co-authored-by: FabianMeiswinkel <[email protected]> --------- Co-authored-by: copilot-swe-agent[bot] <[email protected]> Co-authored-by: FabianMeiswinkel <[email protected]> * Update SessionTest.java * Update tests.yml * Update CosmosNettyLeakDetectorFactory.java * Test config * Update CosmosNettyLeakDetectorFactory.java * Updating TestNG * Reverting TestNG to 7.9.0 (highest version still supporting Java8) * Switching back to TestNG 7.5.1 * Enabling leak detection in unit tests * Iterating on tests * Update pom.xml * Test changes (Azure#47233) * Update RntbdTransportClientTest.java * Updating netty leak detection system properties * Update CosmosNettyLeakDetectorFactory.java * Test changes * Prod memory leak fixes * Test fixes * Test fixes * Users/fabianm/portfixes (Azure#47252) * Update WebExceptionRetryPolicy.java * Update ThinClientStoreModel.java * Test fixes * Fix Netty ByteBuf leaks in StoreResponse and RetryContextOnDiagnosticTest (Azure#47266) * Initial plan * Improve logging for ByteBufInputStream close failures Change log level from debug to warn and catch Throwable instead of just IOException to make potential ByteBuf leak issues more visible. Co-authored-by: FabianMeiswinkel <[email protected]> * Fix ByteBuf leak in RetryContextOnDiagnosticTest Changed from Mono.just() to Mono.fromCallable() to defer StoreResponse creation, ensuring ByteBuf lifecycle is properly managed within each subscription rather than eagerly at mock setup time. Co-authored-by: FabianMeiswinkel <[email protected]> --------- Co-authored-by: copilot-swe-agent[bot] <[email protected]> Co-authored-by: FabianMeiswinkel <[email protected]> * Update EncryptionAsyncApiCrudTest.java * Fix ByteBuf memory leak in TcpServerMock request decoders (Azure#47269) * Initial plan * Fix memory leak in ServerRntbdRequestDecoder and ServerRntbdContextRequestDecoder When overriding channelRead() in ByteToMessageDecoder and bypassing the parent's decode logic by calling context.fireChannelRead() directly, the ByteBuf reference must be explicitly released to prevent memory leaks. Added ReferenceCountUtil.release() in try-finally blocks to properly manage buffer lifecycle. Co-authored-by: FabianMeiswinkel <[email protected]> * Replace ReferenceCountUtil.release with safeRelease * Replace ReferenceCountUtil.release with safeRelease --------- Co-authored-by: copilot-swe-agent[bot] <[email protected]> Co-authored-by: FabianMeiswinkel <[email protected]> Co-authored-by: Fabian Meiswinkel <[email protected]> * Update ThinClientStoreModel.java * Fixing test issues * Disable netty leak detection in RetrycontextOnDiagnosticTest * Test and diagnostics improvements * Test fixes and more breadcrumbs * Test fixes * Test fixes * Test fixes * Update OrderbyDocumentQueryTest.java * Test fixes * Reverting too noisy logs * Test fixes * Fixing POMs * React to code review feedback * Update pom.xml * Addresses code review feedback * Update sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/implementation/directconnectivity/rntbd/RntbdRequestDecoder.java Co-authored-by: Annie Liang <[email protected]> --------- Co-authored-by: Copilot <[email protected]> Co-authored-by: Copilot <[email protected]> Co-authored-by: FabianMeiswinkel <[email protected]> Co-authored-by: Annie Liang <[email protected]>
1 parent e758006 commit 86b3dc8

File tree

79 files changed

+3160
-1936
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

79 files changed

+3160
-1936
lines changed

sdk/cosmos/azure-cosmos-benchmark/pom.xml

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,12 @@ Licensed under the MIT License.
203203
<version>3.5.3</version> <!-- {x-version-update;org.apache.maven.plugins:maven-surefire-plugin;external_dependency} -->
204204
<configuration>
205205
<groups>unit</groups>
206+
<systemPropertyVariables>
207+
<COSMOS.CLIENT_LEAK_DETECTION_ENABLED>true</COSMOS.CLIENT_LEAK_DETECTION_ENABLED>
208+
<io.netty.leakDetection.samplingInterval>1</io.netty.leakDetection.samplingInterval>
209+
<io.netty.leakDetection.targetRecords>256</io.netty.leakDetection.targetRecords>
210+
<io.netty.leakDetection.level>paranoid</io.netty.leakDetection.level>
211+
</systemPropertyVariables>
206212
<includes>
207213
<include>%regex[.*]</include>
208214
</includes>
@@ -211,6 +217,10 @@ Licensed under the MIT License.
211217
<name>surefire.testng.verbose</name>
212218
<value>2</value>
213219
</property>
220+
<property>
221+
<name>listener</name>
222+
<value>com.azure.cosmos.CosmosNettyLeakDetectorFactory</value>
223+
</property>
214224
</properties>
215225
<skipTests>true</skipTests>
216226
</configuration>
@@ -308,6 +318,12 @@ Licensed under the MIT License.
308318
<suiteXmlFiles>
309319
<suiteXmlFile>src/test/resources/unit-testng.xml</suiteXmlFile>
310320
</suiteXmlFiles>
321+
<systemPropertyVariables>
322+
<COSMOS.CLIENT_LEAK_DETECTION_ENABLED>true</COSMOS.CLIENT_LEAK_DETECTION_ENABLED>
323+
<io.netty.leakDetection.samplingInterval>1</io.netty.leakDetection.samplingInterval>
324+
<io.netty.leakDetection.targetRecords>256</io.netty.leakDetection.targetRecords>
325+
<io.netty.leakDetection.level>paranoid</io.netty.leakDetection.level>
326+
</systemPropertyVariables>
311327
</configuration>
312328
</plugin>
313329
</plugins>
@@ -329,6 +345,12 @@ Licensed under the MIT License.
329345
<suiteXmlFiles>
330346
<suiteXmlFile>src/test/resources/fast-testng.xml</suiteXmlFile>
331347
</suiteXmlFiles>
348+
<systemPropertyVariables>
349+
<COSMOS.CLIENT_LEAK_DETECTION_ENABLED>true</COSMOS.CLIENT_LEAK_DETECTION_ENABLED>
350+
<io.netty.leakDetection.samplingInterval>1</io.netty.leakDetection.samplingInterval>
351+
<io.netty.leakDetection.targetRecords>256</io.netty.leakDetection.targetRecords>
352+
<io.netty.leakDetection.level>paranoid</io.netty.leakDetection.level>
353+
</systemPropertyVariables>
332354
</configuration>
333355
</plugin>
334356
</plugins>
@@ -350,6 +372,12 @@ Licensed under the MIT License.
350372
<suiteXmlFiles>
351373
<suiteXmlFile>src/test/resources/split-testng.xml</suiteXmlFile>
352374
</suiteXmlFiles>
375+
<systemPropertyVariables>
376+
<COSMOS.CLIENT_LEAK_DETECTION_ENABLED>true</COSMOS.CLIENT_LEAK_DETECTION_ENABLED>
377+
<io.netty.leakDetection.samplingInterval>1</io.netty.leakDetection.samplingInterval>
378+
<io.netty.leakDetection.targetRecords>256</io.netty.leakDetection.targetRecords>
379+
<io.netty.leakDetection.level>paranoid</io.netty.leakDetection.level>
380+
</systemPropertyVariables>
353381
</configuration>
354382
</plugin>
355383
</plugins>
@@ -371,6 +399,12 @@ Licensed under the MIT License.
371399
<suiteXmlFiles>
372400
<suiteXmlFile>src/test/resources/cfp-split-testng.xml</suiteXmlFile>
373401
</suiteXmlFiles>
402+
<systemPropertyVariables>
403+
<COSMOS.CLIENT_LEAK_DETECTION_ENABLED>true</COSMOS.CLIENT_LEAK_DETECTION_ENABLED>
404+
<io.netty.leakDetection.samplingInterval>1</io.netty.leakDetection.samplingInterval>
405+
<io.netty.leakDetection.targetRecords>256</io.netty.leakDetection.targetRecords>
406+
<io.netty.leakDetection.level>paranoid</io.netty.leakDetection.level>
407+
</systemPropertyVariables>
374408
</configuration>
375409
</plugin>
376410
</plugins>
@@ -392,6 +426,12 @@ Licensed under the MIT License.
392426
<suiteXmlFiles>
393427
<suiteXmlFile>src/test/resources/query-testng.xml</suiteXmlFile>
394428
</suiteXmlFiles>
429+
<systemPropertyVariables>
430+
<COSMOS.CLIENT_LEAK_DETECTION_ENABLED>true</COSMOS.CLIENT_LEAK_DETECTION_ENABLED>
431+
<io.netty.leakDetection.samplingInterval>1</io.netty.leakDetection.samplingInterval>
432+
<io.netty.leakDetection.targetRecords>256</io.netty.leakDetection.targetRecords>
433+
<io.netty.leakDetection.level>paranoid</io.netty.leakDetection.level>
434+
</systemPropertyVariables>
395435
</configuration>
396436
</plugin>
397437
</plugins>
@@ -413,6 +453,12 @@ Licensed under the MIT License.
413453
<suiteXmlFiles>
414454
<suiteXmlFile>src/test/resources/long-testng.xml</suiteXmlFile>
415455
</suiteXmlFiles>
456+
<systemPropertyVariables>
457+
<COSMOS.CLIENT_LEAK_DETECTION_ENABLED>true</COSMOS.CLIENT_LEAK_DETECTION_ENABLED>
458+
<io.netty.leakDetection.samplingInterval>1</io.netty.leakDetection.samplingInterval>
459+
<io.netty.leakDetection.targetRecords>256</io.netty.leakDetection.targetRecords>
460+
<io.netty.leakDetection.level>paranoid</io.netty.leakDetection.level>
461+
</systemPropertyVariables>
416462
</configuration>
417463
</plugin>
418464
</plugins>
@@ -434,6 +480,12 @@ Licensed under the MIT License.
434480
<suiteXmlFiles>
435481
<suiteXmlFile>src/test/resources/direct-testng.xml</suiteXmlFile>
436482
</suiteXmlFiles>
483+
<systemPropertyVariables>
484+
<COSMOS.CLIENT_LEAK_DETECTION_ENABLED>true</COSMOS.CLIENT_LEAK_DETECTION_ENABLED>
485+
<io.netty.leakDetection.samplingInterval>1</io.netty.leakDetection.samplingInterval>
486+
<io.netty.leakDetection.targetRecords>256</io.netty.leakDetection.targetRecords>
487+
<io.netty.leakDetection.level>paranoid</io.netty.leakDetection.level>
488+
</systemPropertyVariables>
437489
</configuration>
438490
</plugin>
439491
</plugins>
@@ -455,6 +507,12 @@ Licensed under the MIT License.
455507
<suiteXmlFiles>
456508
<suiteXmlFile>src/test/resources/multi-master-testng.xml</suiteXmlFile>
457509
</suiteXmlFiles>
510+
<systemPropertyVariables>
511+
<COSMOS.CLIENT_LEAK_DETECTION_ENABLED>true</COSMOS.CLIENT_LEAK_DETECTION_ENABLED>
512+
<io.netty.leakDetection.samplingInterval>1</io.netty.leakDetection.samplingInterval>
513+
<io.netty.leakDetection.targetRecords>256</io.netty.leakDetection.targetRecords>
514+
<io.netty.leakDetection.level>paranoid</io.netty.leakDetection.level>
515+
</systemPropertyVariables>
458516
</configuration>
459517
</plugin>
460518
</plugins>
@@ -476,6 +534,12 @@ Licensed under the MIT License.
476534
<suiteXmlFiles>
477535
<suiteXmlFile>src/test/resources/flaky-multi-master-testng.xml</suiteXmlFile>
478536
</suiteXmlFiles>
537+
<systemPropertyVariables>
538+
<COSMOS.CLIENT_LEAK_DETECTION_ENABLED>true</COSMOS.CLIENT_LEAK_DETECTION_ENABLED>
539+
<io.netty.leakDetection.samplingInterval>1</io.netty.leakDetection.samplingInterval>
540+
<io.netty.leakDetection.targetRecords>256</io.netty.leakDetection.targetRecords>
541+
<io.netty.leakDetection.level>paranoid</io.netty.leakDetection.level>
542+
</systemPropertyVariables>
479543
</configuration>
480544
</plugin>
481545
</plugins>
@@ -497,6 +561,12 @@ Licensed under the MIT License.
497561
<suiteXmlFiles>
498562
<suiteXmlFile>src/test/resources/fi-multi-master-testng.xml</suiteXmlFile>
499563
</suiteXmlFiles>
564+
<systemPropertyVariables>
565+
<COSMOS.CLIENT_LEAK_DETECTION_ENABLED>true</COSMOS.CLIENT_LEAK_DETECTION_ENABLED>
566+
<io.netty.leakDetection.samplingInterval>1</io.netty.leakDetection.samplingInterval>
567+
<io.netty.leakDetection.targetRecords>256</io.netty.leakDetection.targetRecords>
568+
<io.netty.leakDetection.level>paranoid</io.netty.leakDetection.level>
569+
</systemPropertyVariables>
500570
</configuration>
501571
</plugin>
502572
</plugins>
@@ -519,6 +589,12 @@ Licensed under the MIT License.
519589
<suiteXmlFiles>
520590
<suiteXmlFile>src/test/resources/examples-testng.xml</suiteXmlFile>
521591
</suiteXmlFiles>
592+
<systemPropertyVariables>
593+
<COSMOS.CLIENT_LEAK_DETECTION_ENABLED>true</COSMOS.CLIENT_LEAK_DETECTION_ENABLED>
594+
<io.netty.leakDetection.samplingInterval>1</io.netty.leakDetection.samplingInterval>
595+
<io.netty.leakDetection.targetRecords>256</io.netty.leakDetection.targetRecords>
596+
<io.netty.leakDetection.level>paranoid</io.netty.leakDetection.level>
597+
</systemPropertyVariables>
522598
</configuration>
523599
<executions>
524600
<execution>
@@ -548,6 +624,12 @@ Licensed under the MIT License.
548624
<suiteXmlFiles>
549625
<suiteXmlFile>src/test/resources/emulator-testng.xml</suiteXmlFile>
550626
</suiteXmlFiles>
627+
<systemPropertyVariables>
628+
<COSMOS.CLIENT_LEAK_DETECTION_ENABLED>true</COSMOS.CLIENT_LEAK_DETECTION_ENABLED>
629+
<io.netty.leakDetection.samplingInterval>1</io.netty.leakDetection.samplingInterval>
630+
<io.netty.leakDetection.targetRecords>256</io.netty.leakDetection.targetRecords>
631+
<io.netty.leakDetection.level>paranoid</io.netty.leakDetection.level>
632+
</systemPropertyVariables>
551633
</configuration>
552634
</plugin>
553635
</plugins>
@@ -569,6 +651,12 @@ Licensed under the MIT License.
569651
<suiteXmlFiles>
570652
<suiteXmlFile>src/test/resources/e2e-testng.xml</suiteXmlFile>
571653
</suiteXmlFiles>
654+
<systemPropertyVariables>
655+
<COSMOS.CLIENT_LEAK_DETECTION_ENABLED>true</COSMOS.CLIENT_LEAK_DETECTION_ENABLED>
656+
<io.netty.leakDetection.samplingInterval>1</io.netty.leakDetection.samplingInterval>
657+
<io.netty.leakDetection.targetRecords>256</io.netty.leakDetection.targetRecords>
658+
<io.netty.leakDetection.level>paranoid</io.netty.leakDetection.level>
659+
</systemPropertyVariables>
572660
</configuration>
573661
</plugin>
574662
</plugins>

sdk/cosmos/azure-cosmos-benchmark/src/main/java/com/azure/cosmos/benchmark/ReadMyWriteWorkflow.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -498,4 +498,13 @@ protected String getDocumentLink(Document doc) {
498498
return doc.getSelfLink();
499499
}
500500
}
501+
502+
@Override
503+
void shutdown() {
504+
if (this.client != null) {
505+
this.client.close();
506+
}
507+
508+
super.shutdown();
509+
}
501510
}

sdk/cosmos/azure-cosmos-encryption/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ The Azure Cosmos Encryption Plugin is used for encrypting data with a user-provi
1212
<dependency>
1313
<groupId>com.azure</groupId>
1414
<artifactId>azure-cosmos-encryption</artifactId>
15-
<version>2.24.0</version>
15+
<version>2.25.0-beta.1</version>
1616
</dependency>
1717
```
1818
[//]: # ({x-version-update-end})

sdk/cosmos/azure-cosmos-encryption/pom.xml

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,8 @@ Licensed under the MIT License.
4949
--add-opens com.azure.cosmos.encryption/com.azure.cosmos.encryption.util=ALL-UNNAMED
5050
--add-opens com.azure.cosmos.encryption/com.azure.cosmos.encryption.models=ALL-UNNAMED
5151
--add-opens com.azure.cosmos/com.azure.cosmos.implementation=ALL-UNNAMED
52+
--add-modules java.management
53+
--add-reads com.azure.cosmos.encryption=java.management
5254
</javaModulesSurefireArgLine>
5355
<doclintMissingInclusion>-</doclintMissingInclusion>
5456
<spotless.skip>true</spotless.skip>
@@ -217,6 +219,12 @@ Licensed under the MIT License.
217219
<version>3.5.3</version> <!-- {x-version-update;org.apache.maven.plugins:maven-surefire-plugin;external_dependency} -->
218220
<configuration>
219221
<groups>unit</groups>
222+
<systemPropertyVariables>
223+
<COSMOS.CLIENT_LEAK_DETECTION_ENABLED>true</COSMOS.CLIENT_LEAK_DETECTION_ENABLED>
224+
<io.netty.leakDetection.samplingInterval>1</io.netty.leakDetection.samplingInterval>
225+
<io.netty.leakDetection.targetRecords>256</io.netty.leakDetection.targetRecords>
226+
<io.netty.leakDetection.level>paranoid</io.netty.leakDetection.level>
227+
</systemPropertyVariables>
220228
<includes>
221229
<include>%regex[.*]</include>
222230
</includes>
@@ -225,6 +233,10 @@ Licensed under the MIT License.
225233
<name>surefire.testng.verbose</name>
226234
<value>2</value>
227235
</property>
236+
<property>
237+
<name>listener</name>
238+
<value>com.azure.cosmos.encryption.CosmosNettyLeakDetectorFactory</value>
239+
</property>
228240
</properties>
229241
<skipTests>true</skipTests>
230242
</configuration>
@@ -263,6 +275,12 @@ Licensed under the MIT License.
263275
<suiteXmlFiles>
264276
<suiteXmlFile>src/test/resources/unit-testng.xml</suiteXmlFile>
265277
</suiteXmlFiles>
278+
<systemPropertyVariables>
279+
<COSMOS.CLIENT_LEAK_DETECTION_ENABLED>true</COSMOS.CLIENT_LEAK_DETECTION_ENABLED>
280+
<io.netty.leakDetection.samplingInterval>1</io.netty.leakDetection.samplingInterval>
281+
<io.netty.leakDetection.targetRecords>256</io.netty.leakDetection.targetRecords>
282+
<io.netty.leakDetection.level>paranoid</io.netty.leakDetection.level>
283+
</systemPropertyVariables>
266284
</configuration>
267285
</plugin>
268286
</plugins>
@@ -284,7 +302,12 @@ Licensed under the MIT License.
284302
<suiteXmlFiles>
285303
<suiteXmlFile>src/test/resources/encryption-testng.xml</suiteXmlFile>
286304
</suiteXmlFiles>
287-
305+
<systemPropertyVariables>
306+
<COSMOS.CLIENT_LEAK_DETECTION_ENABLED>true</COSMOS.CLIENT_LEAK_DETECTION_ENABLED>
307+
<io.netty.leakDetection.samplingInterval>1</io.netty.leakDetection.samplingInterval>
308+
<io.netty.leakDetection.targetRecords>256</io.netty.leakDetection.targetRecords>
309+
<io.netty.leakDetection.level>paranoid</io.netty.leakDetection.level>
310+
</systemPropertyVariables>
288311
</configuration>
289312
</plugin>
290313
</plugins>

sdk/cosmos/azure-cosmos-encryption/src/test/java/com/azure/cosmos/encryption/CosmosEncryptionAsyncClientTest.java

Lines changed: 2 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
import org.testng.annotations.AfterMethod;
2121
import org.testng.annotations.BeforeClass;
2222
import org.testng.annotations.BeforeMethod;
23+
import org.testng.annotations.Listeners;
2324

2425
import java.lang.management.BufferPoolMXBean;
2526
import java.lang.management.ManagementFactory;
@@ -29,16 +30,15 @@
2930
import java.util.Map;
3031
import java.util.concurrent.atomic.AtomicInteger;
3132

33+
@Listeners({TestNGLogListener.class, CosmosNettyLeakDetectorFactory.class})
3234
public abstract class CosmosEncryptionAsyncClientTest implements ITest {
3335
protected static Logger logger = LoggerFactory.getLogger(CosmosEncryptionAsyncClientTest.class.getSimpleName());
3436
protected static final int SUITE_SETUP_TIMEOUT = 120000;
3537
private static final ImplementationBridgeHelpers.CosmosClientBuilderHelper.CosmosClientBuilderAccessor cosmosClientBuilderAccessor =
3638
ImplementationBridgeHelpers.CosmosClientBuilderHelper.getCosmosClientBuilderAccessor();
37-
private final static AtomicInteger instancesUsed = new AtomicInteger(0);
3839

3940
private final CosmosClientBuilder clientBuilder;
4041
private String testName;
41-
private volatile Map<Integer, String> activeClientsAtBegin = new HashMap<>();
4242

4343
public CosmosEncryptionAsyncClientTest() {
4444
this(new CosmosClientBuilder());
@@ -52,78 +52,6 @@ public final CosmosClientBuilder getClientBuilder() {
5252
return this.clientBuilder;
5353
}
5454

55-
@BeforeClass(groups = {"fast", "long", "direct", "multi-master", "encryption"}, timeOut = SUITE_SETUP_TIMEOUT)
56-
57-
public void beforeClassSetupLeakDetection() {
58-
if (instancesUsed.getAndIncrement() == 0) {
59-
this.activeClientsAtBegin = RxDocumentClientImpl.getActiveClientsSnapshot();
60-
this.logMemoryUsage("BEFORE");
61-
}
62-
}
63-
64-
private void logMemoryUsage(String name) {
65-
long pooledDirectBytes = PooledByteBufAllocator.DEFAULT.metric()
66-
.directArenas().stream()
67-
.mapToLong(io.netty.buffer.PoolArenaMetric::numActiveBytes)
68-
.sum();
69-
70-
long used = PlatformDependent.usedDirectMemory();
71-
long max = PlatformDependent.maxDirectMemory();
72-
logger.info("MEMORY USAGE: {}:{}", this.getClass().getCanonicalName(), name);
73-
logger.info("Netty Direct Memory: {}/{}/{} bytes", used, pooledDirectBytes, max);
74-
for (BufferPoolMXBean pool : ManagementFactory.getPlatformMXBeans(BufferPoolMXBean.class)) {
75-
logger.info("Pool {}: used={} bytes, capacity={} bytes, count={}",
76-
pool.getName(), pool.getMemoryUsed(), pool.getTotalCapacity(), pool.getCount());
77-
}
78-
}
79-
80-
@AfterClass(groups = {"fast", "long", "direct", "multi-master", "encryption"}, timeOut = SUITE_SETUP_TIMEOUT)
81-
public void afterClassSetupLeakDetection() {
82-
if (instancesUsed.decrementAndGet() == 0) {
83-
Map<Integer, String> leakedClientSnapshotNow = RxDocumentClientImpl.getActiveClientsSnapshot();
84-
StringBuilder sb = new StringBuilder();
85-
Map<Integer, String> leakedClientSnapshotAtBegin = activeClientsAtBegin;
86-
87-
for (Integer clientId : leakedClientSnapshotNow.keySet()) {
88-
if (!leakedClientSnapshotAtBegin.containsKey(clientId)) {
89-
// this client was leaked in this class
90-
sb
91-
.append("CosmosClient [")
92-
.append(clientId)
93-
.append("] leaked. Callstack of initialization:\n")
94-
.append(leakedClientSnapshotNow.get(clientId))
95-
.append("\n\n");
96-
}
97-
}
98-
99-
if (sb.length() > 0) {
100-
String msg = "COSMOS CLIENT LEAKS detected in test class: "
101-
+ this.getClass().getCanonicalName()
102-
+ "\n\n"
103-
+ sb;
104-
105-
logger.error(msg);
106-
// fail(msg);
107-
}
108-
109-
List<String> nettyLeaks = CosmosNettyLeakDetectorFactory.resetIdentifiedLeaks();
110-
if (nettyLeaks.size() > 0) {
111-
sb.append("\n");
112-
for (String leak : nettyLeaks) {
113-
sb.append(leak).append("\n");
114-
}
115-
116-
String msg = "NETTY LEAKS detected in test class: "
117-
+ this.getClass().getCanonicalName()
118-
+ sb;
119-
120-
logger.error(msg);
121-
// fail(msg);
122-
}
123-
this.logMemoryUsage("AFTER");
124-
}
125-
}
126-
12755
@Override
12856
public final String getTestName() {
12957
return this.testName;

0 commit comments

Comments
 (0)