31
31
32
32
import org .junit .Test ;
33
33
import org .yaml .snakeyaml .Yaml ;
34
+ import org .yaml .snakeyaml .constructor .SafeConstructor ;
34
35
35
36
import org .apache .heron .common .basics .Pair ;
36
37
@@ -49,7 +50,7 @@ public void testCreateOverrides() throws IOException {
49
50
final String overridesPath = ConfigUtils .createOverrideConfiguration (overrideProperties );
50
51
try (Reader reader = Files .newBufferedReader (Paths .get (overridesPath ))) {
51
52
final Map <String , Object > overrides =
52
- (Map <String , Object >) new Yaml ().loadAs (reader , Map .class );
53
+ (Map <String , Object >) new Yaml (new SafeConstructor () ).loadAs (reader , Map .class );
53
54
assertEquals (overrides .size (), overrideProperties .size ());
54
55
for (String key : overrides .keySet ()) {
55
56
assertEquals (overrides .get (key ), overrideProperties .getProperty (key ));
@@ -73,15 +74,15 @@ public void testStateManagerFileOverrides() throws IOException {
73
74
try (Writer writer = Files .newBufferedWriter (stateManagerPath )) {
74
75
final Map <String , String > config = new HashMap <>();
75
76
config .put ("heron.statemgr.connection.string" , "<host>:<port>" );
76
- new Yaml ().dump (config , writer );
77
+ new Yaml (new SafeConstructor () ).dump (config , writer );
77
78
}
78
79
79
80
// apply the overrides
80
81
ConfigUtils .applyOverridesToStateManagerConfig (Paths .get (overridesPath ), stateManagerPath );
81
82
82
83
try (Reader reader = Files .newBufferedReader (stateManagerPath )) {
83
84
final Map <String , Object > stateManagerWithOverrides =
84
- (Map <String , Object >) new Yaml ().loadAs (reader , Map .class );
85
+ (Map <String , Object >) new Yaml (new SafeConstructor () ).loadAs (reader , Map .class );
85
86
assertEquals (stateManagerWithOverrides .size (), 1 );
86
87
assertEquals (stateManagerWithOverrides .get ("heron.statemgr.connection.string" ),
87
88
"zookeeper:2181" );
@@ -103,15 +104,15 @@ public void testNoOverridesAppliedToStateManager() throws IOException {
103
104
try (Writer writer = Files .newBufferedWriter (stateManagerPath )) {
104
105
final Map <String , String > config = new HashMap <>();
105
106
config .put ("heron.statemgr.connection.string" , "<host>:<port>" );
106
- new Yaml ().dump (config , writer );
107
+ new Yaml (new SafeConstructor () ).dump (config , writer );
107
108
}
108
109
109
110
// apply the overrides
110
111
ConfigUtils .applyOverridesToStateManagerConfig (Paths .get (overridesPath ), stateManagerPath );
111
112
112
113
try (Reader reader = Files .newBufferedReader (stateManagerPath )) {
113
114
final Map <String , Object > stateManagerWithOverrides =
114
- (Map <String , Object >) new Yaml ().loadAs (reader , Map .class );
115
+ (Map <String , Object >) new Yaml (new SafeConstructor () ).loadAs (reader , Map .class );
115
116
assertEquals (stateManagerWithOverrides .size (), 1 );
116
117
assertEquals (stateManagerWithOverrides .get ("heron.statemgr.connection.string" ),
117
118
"<host>:<port>" );
@@ -142,7 +143,7 @@ public void testApplyOverrides() throws IOException {
142
143
143
144
try (Reader reader = Files .newBufferedReader (Paths .get (overridesPath ))) {
144
145
final Map <String , Object > newOverrides =
145
- (Map <String , Object >) new Yaml ().loadAs (reader , Map .class );
146
+ (Map <String , Object >) new Yaml (new SafeConstructor () ).loadAs (reader , Map .class );
146
147
assertEquals (newOverrides , combinedOverrides );
147
148
}
148
149
}
@@ -166,7 +167,7 @@ public void testApplyEmptyOverrides() throws IOException {
166
167
167
168
try (Reader reader = Files .newBufferedReader (Paths .get (overridesPath ))) {
168
169
final Map <String , Object > newOverrides =
169
- (Map <String , Object >) new Yaml ().loadAs (reader , Map .class );
170
+ (Map <String , Object >) new Yaml (new SafeConstructor () ).loadAs (reader , Map .class );
170
171
assertEquals (newOverrides , overrides );
171
172
}
172
173
}
0 commit comments