@@ -7,6 +7,98 @@ plugins {
77
88apply from : ' ../gradle/coverage/java-coverage.gradle'
99
10+ // Memory profile configuration - supports environment variable GRADLE_MEMORY_PROFILE or system property
11+ // Values: "low" (8GB systems), "default" (16GB+ systems), "high" (32GB+ systems)
12+ // Auto-detects system memory if not explicitly set
13+ def detectMemoryProfile () {
14+ // Check if explicitly set via environment variable or system property
15+ def explicitProfile = System . getenv(" GRADLE_MEMORY_PROFILE" ) ?: System . getProperty(" gradle.memory.profile" )
16+ if (explicitProfile) {
17+ return explicitProfile
18+ }
19+
20+ // Auto-detect based on actual system memory (total RAM) using OperatingSystemMXBean
21+ try {
22+ def osBean = java.lang.management.ManagementFactory . getOperatingSystemMXBean()
23+ def sunOsBean = Class . forName(" com.sun.management.OperatingSystemMXBean" )
24+ if (! sunOsBean. isInstance(osBean)) {
25+ throw new Exception (" OperatingSystemMXBean does not support getTotalPhysicalMemorySize()" )
26+ }
27+
28+ def method = sunOsBean. getMethod(" getTotalPhysicalMemorySize" )
29+ def totalMemoryBytes = method. invoke(osBean) as Long
30+ def totalMemoryGB = totalMemoryBytes / (1024.0 * 1024.0 * 1024.0 )
31+
32+ def detectedProfile
33+ if (totalMemoryGB < 12 ) {
34+ detectedProfile = " low" // < 12GB: use low profile (8GB systems)
35+ } else if (totalMemoryGB < 24 ) {
36+ detectedProfile = " default" // 12-24GB: use default profile (16GB+ systems)
37+ } else {
38+ detectedProfile = " high" // >= 24GB: use high profile (32GB+ systems)
39+ }
40+
41+ println " Auto-detected memory profile: ${ detectedProfile} (System RAM: ${ String.format("%.1f", totalMemoryGB)} GB)"
42+ return detectedProfile
43+ } catch (Exception e) {
44+ // Fallback to default if detection fails
45+ println " Warning: Could not detect system memory (${ e.message} ), using 'default' profile"
46+ return " default"
47+ }
48+ }
49+
50+ def memoryProfile = detectMemoryProfile()
51+
52+ // Define memory configurations per profile
53+ // since it's read before build.gradle runs
54+ def memoryConfigs = [
55+ " low" : [
56+ testHeap : " 1g" ,
57+ testMinHeap : " 256m" ,
58+ testMetaspace : " 384m" ,
59+ // Docker container memory settings (for ES/OS/Cassandra/Neo4j) - applied via system properties
60+ elasticsearchHeap : " 256m" ,
61+ opensearchHeap : " 512m" ,
62+ cassandraHeap : " 128m" ,
63+ neo4jHeap : " 256m"
64+ ],
65+ " default" : [
66+ testHeap : " 2g" ,
67+ testMinHeap : " 512m" ,
68+ testMetaspace : " 512m" ,
69+ elasticsearchHeap : " 512m" ,
70+ opensearchHeap : " 1024m" ,
71+ cassandraHeap : " 128m" ,
72+ neo4jHeap : " 512m"
73+ ],
74+ " high" : [
75+ testHeap : " 3g" ,
76+ testMinHeap : " 1g" ,
77+ testMetaspace : " 768m" ,
78+ elasticsearchHeap : " 768m" ,
79+ opensearchHeap : " 1536m" ,
80+ cassandraHeap : " 256m" ,
81+ neo4jHeap : " 768m"
82+ ]
83+ ]
84+
85+ def memoryConfig = memoryConfigs[memoryProfile] ?: memoryConfigs[" low" ]
86+ println " Using memory profile: ${ memoryProfile} "
87+ println " Test processes: ${ memoryConfig.testHeap} heap (min ${ memoryConfig.testMinHeap} ), ${ memoryConfig.testMetaspace} metaspace"
88+ println " Docker containers:"
89+ println " - Elasticsearch: ${ memoryConfig.elasticsearchHeap} "
90+ println " - OpenSearch: ${ memoryConfig.opensearchHeap} "
91+ println " - Cassandra: ${ memoryConfig.cassandraHeap} "
92+ println " - Neo4j: ${ memoryConfig.neo4jHeap} "
93+ println " Note: Gradle daemon memory is set in gradle.properties (see file for details)"
94+ println " Override: Set GRADLE_MEMORY_PROFILE environment variable or -Dgradle.memory.profile system property"
95+
96+ // Set system properties for container memory configuration (containers read these at runtime)
97+ System . setProperty(" testcontainers.elasticsearch.heap" , memoryConfig. elasticsearchHeap)
98+ System . setProperty(" testcontainers.opensearch.heap" , memoryConfig. opensearchHeap)
99+ System . setProperty(" testcontainers.cassandra.heap" , memoryConfig. cassandraHeap)
100+ System . setProperty(" testcontainers.neo4j.heap" , memoryConfig. neo4jHeap)
101+
10102configurations {
11103 enhance
12104}
@@ -151,12 +243,84 @@ test {
151243 environment ' STRICT_URN_VALIDATION_ENABLED' , ' true'
152244}
153245
246+ task testEs7CassandraNeo4j (type : Test ) {
247+ doFirst {
248+ maxParallelForks = 1
249+ }
250+ useTestNG() {
251+ suites ' src/test/resources/testng-es7-cassandra-neo4j.xml'
252+ }
253+ testLogging {
254+ events " failed" , " skipped" , " passed"
255+ exceptionFormat " full"
256+ showStandardStreams = true
257+ }
258+
259+ environment ' STRICT_URN_VALIDATION_ENABLED' , ' true'
260+
261+ group = ' verification'
262+ description = ' Runs only the testng-es7-cassandra-neo4j.xml test suite'
263+ }
264+
265+ task testOpenSearch (type : Test ) {
266+ doFirst {
267+ maxParallelForks = 1
268+ }
269+ useTestNG() {
270+ suites ' src/test/resources/testng-opensearch.xml'
271+ }
272+ testLogging {
273+ events " failed" , " skipped" , " passed"
274+ exceptionFormat " full"
275+ showStandardStreams = true
276+ }
277+
278+ environment ' STRICT_URN_VALIDATION_ENABLED' , ' true'
279+
280+ group = ' verification'
281+ description = ' Runs only the testng-opensearch.xml test suite'
282+ }
283+
284+ task testOther (type : Test ) {
285+ doFirst {
286+ maxParallelForks = 1
287+ }
288+ useTestNG() {
289+ suites ' src/test/resources/testng-other.xml'
290+ }
291+ testLogging {
292+ events " failed" , " skipped" , " passed" , " started"
293+ exceptionFormat " full"
294+ showStandardStreams = true
295+ }
296+
297+ environment ' STRICT_URN_VALIDATION_ENABLED' , ' true'
298+
299+ group = ' verification'
300+ description = ' Runs only other test suite to debug the failing tests'
301+ }
302+
154303ebean {
155304 debugLevel = 1 // 0 - 9
156305}
157306
158307tasks. withType(Test ) {
159308 enableAssertions = false
309+ // Set heap size for test JVM processes based on memory profile
310+ // This is separate from gradle.properties which only sets memory for the Gradle daemon
311+ maxHeapSize = memoryConfig. testHeap
312+ minHeapSize = memoryConfig. testMinHeap
313+
314+ // Add JVM args for memory efficiency and to prevent OOM kills
315+ // -XX:MaxMetaspaceSize: Limit metaspace to prevent unbounded growth
316+ // -XX:+UseG1GC: Use G1 garbage collector for better memory efficiency
317+ // -XX:MaxGCPauseMillis: Target pause time for GC (higher for low-memory systems)
318+ def gcPauseMillis = memoryProfile == " low" ? " 1000" : " 500"
319+ jvmArgs = [
320+ " -XX:MaxMetaspaceSize=${ memoryConfig.testMetaspace} " ,
321+ " -XX:+UseG1GC" ,
322+ " -XX:MaxGCPauseMillis=${ gcPauseMillis} "
323+ ]
160324}
161325
162326clean {
0 commit comments