@@ -50,3 +50,103 @@ pub fn construct_history_jvm_args(
5050 . context ( MergeJvmArgumentOverridesSnafu ) ?;
5151 Ok ( merged. effective_jvm_config_after_merging ( ) . join ( "\n " ) )
5252}
53+ #[ cfg( test) ]
54+ mod tests {
55+ use indoc:: indoc;
56+
57+ use crate :: crd:: history:: v1alpha1:: SparkHistoryServer ;
58+
59+ use super :: * ;
60+
61+ #[ test]
62+ fn test_construct_jvm_arguments_defaults ( ) {
63+ let input = r#"
64+ apiVersion: spark.stackable.tech/v1alpha1
65+ kind: SparkHistoryServer
66+ metadata:
67+ name: spark-history
68+ spec:
69+ image:
70+ productVersion: 3.5.2
71+ logFileDirectory:
72+ s3:
73+ prefix: eventlogs/
74+ bucket:
75+ reference: spark-history-s3-bucket
76+ nodes:
77+ roleGroups:
78+ default:
79+ replicas: 1
80+ config:
81+ cleaner: true
82+ "# ;
83+
84+ let jvm_config = construct_jvm_config_for_test ( input) ;
85+
86+ assert_eq ! (
87+ jvm_config,
88+ indoc! { "
89+ -Dlog4j.configurationFile=/stackable/log_config/log4j2.properties
90+ -Djava.security.properties=/stackable/spark/conf/security.properties
91+ -javaagent:/stackable/jmx/jmx_prometheus_javaagent.jar=18081:/stackable/jmx/config.yaml" }
92+ ) ;
93+ }
94+
95+ #[ test]
96+ fn test_construct_jvm_argument_overrides ( ) {
97+ let input = r#"
98+ apiVersion: spark.stackable.tech/v1alpha1
99+ kind: SparkHistoryServer
100+ metadata:
101+ name: spark-history
102+ spec:
103+ image:
104+ productVersion: 3.5.2
105+ logFileDirectory:
106+ s3:
107+ prefix: eventlogs/
108+ bucket:
109+ reference: spark-history-s3-bucket
110+ nodes:
111+ jvmArgumentOverrides:
112+ add:
113+ - -Dhttps.proxyHost=proxy.my.corp
114+ - -Dhttps.proxyPort=8080
115+ - -Djava.net.preferIPv4Stack=true
116+ roleGroups:
117+ default:
118+ replicas: 1
119+ jvmArgumentOverrides:
120+ removeRegex:
121+ - -Dhttps.proxyPort=.*
122+ add:
123+ - -Dhttps.proxyPort=1234
124+ config:
125+ cleaner: true
126+ "# ;
127+
128+ let jvm_config = construct_jvm_config_for_test ( input) ;
129+
130+ assert_eq ! (
131+ jvm_config,
132+ indoc! { "
133+ -Dlog4j.configurationFile=/stackable/log_config/log4j2.properties
134+ -Djava.security.properties=/stackable/spark/conf/security.properties
135+ -javaagent:/stackable/jmx/jmx_prometheus_javaagent.jar=18081:/stackable/jmx/config.yaml
136+ -Dhttps.proxyHost=proxy.my.corp
137+ -Djava.net.preferIPv4Stack=true
138+ -Dhttps.proxyPort=1234" }
139+ ) ;
140+ }
141+
142+ fn construct_jvm_config_for_test ( history_server : & str ) -> String {
143+ let deserializer = serde_yaml:: Deserializer :: from_str ( history_server) ;
144+ let history_server: SparkHistoryServer =
145+ serde_yaml:: with:: singleton_map_recursive:: deserialize ( deserializer) . unwrap ( ) ;
146+
147+ let role = history_server. role ( ) ;
148+ let resolved_log_dir = ResolvedLogDir :: Custom ( "local:/tmp/foo" . to_owned ( ) ) ;
149+
150+ construct_history_jvm_args ( role, "default" , & resolved_log_dir) . unwrap ( )
151+ }
152+ }
0 commit comments