Skip to content

Commit 4db598e

Browse files
YARN-9999. TestFSSchedulerConfigurationStore: Extend from ConfigurationStoreBaseTest, general code cleanup. Contributed by Benjamin Teke
1 parent 94f7470 commit 4db598e

File tree

3 files changed

+91
-96
lines changed

3 files changed

+91
-96
lines changed

hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/capacity/conf/ConfigurationStoreBaseTest.java

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -78,13 +78,24 @@ public void testNullConfigurationUpdate() throws Exception {
7878
confStore.close();
7979
}
8080

81-
YarnConfigurationStore.LogMutation prepareLogMutation(String key,
82-
String value)
81+
YarnConfigurationStore.LogMutation prepareLogMutation(String... values)
8382
throws Exception {
84-
Map<String, String> update = new HashMap<>();
85-
update.put(key, value);
83+
Map<String, String> updates = new HashMap<>();
84+
String key;
85+
String value;
86+
87+
if (values.length % 2 != 0) {
88+
throw new IllegalArgumentException("The number of parameters should be " +
89+
"even.");
90+
}
91+
92+
for (int i = 1; i <= values.length; i += 2) {
93+
key = values[i - 1];
94+
value = values[i];
95+
updates.put(key, value);
96+
}
8697
YarnConfigurationStore.LogMutation mutation =
87-
new YarnConfigurationStore.LogMutation(update, TEST_USER);
98+
new YarnConfigurationStore.LogMutation(updates, TEST_USER);
8899
confStore.logMutation(mutation);
89100

90101
return mutation;

hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/capacity/conf/PersistentConfigurationStoreBaseTest.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525

2626
import static org.junit.Assert.assertEquals;
2727
import static org.junit.Assert.assertNull;
28+
import static org.junit.Assume.assumeFalse;
2829

2930
/**
3031
* Base class for the persistent {@link YarnConfigurationStore}
@@ -94,6 +95,9 @@ public void testVersion() throws Exception {
9495

9596
@Test
9697
public void testMaxLogs() throws Exception {
98+
assumeFalse("test should be skipped for TestFSSchedulerConfigurationStore",
99+
this instanceof TestFSSchedulerConfigurationStore);
100+
97101
conf.setLong(YarnConfiguration.RM_SCHEDCONF_MAX_LOGS, 2);
98102
confStore.initialize(conf, schedConf, rmContext);
99103
LinkedList<YarnConfigurationStore.LogMutation> logs = confStore.getLogs();

hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/capacity/conf/TestFSSchedulerConfigurationStore.java

Lines changed: 71 additions & 91 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020

2121
import java.io.File;
2222
import java.io.IOException;
23-
import java.util.HashMap;
2423
import java.util.Map;
2524

2625
import org.apache.commons.io.FileUtils;
@@ -31,36 +30,34 @@
3130
import org.apache.hadoop.hdfs.HdfsConfiguration;
3231
import org.apache.hadoop.hdfs.MiniDFSCluster;
3332
import org.apache.hadoop.yarn.conf.YarnConfiguration;
34-
import org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.conf.YarnConfigurationStore.LogMutation;
33+
import org.apache.hadoop.yarn.server.records.Version;
3534
import org.hamcrest.CoreMatchers;
3635
import org.junit.After;
3736
import org.junit.Before;
3837
import org.junit.Test;
3938

4039
import static org.junit.Assert.assertEquals;
41-
import static org.junit.Assert.fail;
4240
import static org.junit.Assert.assertNull;
41+
import static org.junit.Assert.fail;
4342
import static org.junit.Assert.assertThat;
4443

4544

4645
/**
4746
* Tests {@link FSSchedulerConfigurationStore}.
4847
*/
49-
public class TestFSSchedulerConfigurationStore {
50-
private static final String TEST_USER = "test";
51-
private FSSchedulerConfigurationStore configurationStore;
52-
private Configuration conf;
48+
public class TestFSSchedulerConfigurationStore extends
49+
PersistentConfigurationStoreBaseTest {
5350
private File testSchedulerConfigurationDir;
5451

5552
@Before
53+
@Override
5654
public void setUp() throws Exception {
57-
configurationStore = new FSSchedulerConfigurationStore();
55+
super.setUp();
5856
testSchedulerConfigurationDir = new File(
5957
TestFSSchedulerConfigurationStore.class.getResource("").getPath()
6058
+ FSSchedulerConfigurationStore.class.getSimpleName());
6159
testSchedulerConfigurationDir.mkdirs();
6260

63-
conf = new Configuration();
6461
conf.set(YarnConfiguration.SCHEDULER_CONFIGURATION_FS_PATH,
6562
testSchedulerConfigurationDir.getAbsolutePath());
6663
}
@@ -81,34 +78,41 @@ public void tearDown() throws Exception {
8178
FileUtils.deleteDirectory(testSchedulerConfigurationDir);
8279
}
8380

81+
@Test
82+
public void checkVersion() {
83+
try {
84+
confStore.checkVersion();
85+
} catch (Exception e) {
86+
fail("checkVersion throw exception");
87+
}
88+
}
89+
8490
@Test
8591
public void confirmMutationWithValid() throws Exception {
8692
conf.setInt(
87-
YarnConfiguration.SCHEDULER_CONFIGURATION_FS_MAX_VERSION, 2);
93+
YarnConfiguration.SCHEDULER_CONFIGURATION_FS_MAX_VERSION, 2);
8894
conf.set("a", "a");
8995
conf.set("b", "b");
9096
conf.set("c", "c");
9197
writeConf(conf);
92-
configurationStore.initialize(conf, conf, null);
93-
Configuration storeConf = configurationStore.retrieve();
98+
confStore.initialize(conf, conf, null);
99+
Configuration storeConf = confStore.retrieve();
94100
compareConfig(conf, storeConf);
95101

96102
Configuration expectConfig = new Configuration(conf);
97103
expectConfig.unset("a");
98104
expectConfig.set("b", "bb");
99105

100-
prepareParameterizedLogMutation(configurationStore, true,
101-
"a", null, "b", "bb");
102-
storeConf = configurationStore.retrieve();
106+
confStore.confirmMutation(prepareLogMutation("a", null, "b", "bb"), true);
107+
storeConf = confStore.retrieve();
103108
assertNull(storeConf.get("a"));
104109
assertEquals("bb", storeConf.get("b"));
105110
assertEquals("c", storeConf.get("c"));
106111

107112
compareConfig(expectConfig, storeConf);
108113

109-
prepareParameterizedLogMutation(configurationStore, true,
110-
"a", null, "b", "bbb");
111-
storeConf = configurationStore.retrieve();
114+
confStore.confirmMutation(prepareLogMutation("a", null, "b", "bbb"), true);
115+
storeConf = confStore.retrieve();
112116
assertNull(storeConf.get("a"));
113117
assertEquals("bbb", storeConf.get("b"));
114118
assertEquals("c", storeConf.get("c"));
@@ -120,17 +124,51 @@ public void confirmMutationWithInvalid() throws Exception {
120124
conf.set("b", "b");
121125
conf.set("c", "c");
122126
writeConf(conf);
123-
configurationStore.initialize(conf, conf, null);
124-
Configuration storeConf = configurationStore.retrieve();
127+
confStore.initialize(conf, conf, null);
128+
Configuration storeConf = confStore.retrieve();
125129
compareConfig(conf, storeConf);
126130

127-
prepareParameterizedLogMutation(configurationStore, false,
128-
"a", null, "b", "bb");
129-
storeConf = configurationStore.retrieve();
131+
confStore.confirmMutation(prepareLogMutation("a", null, "b", "bb"), false);
132+
storeConf = confStore.retrieve();
130133

131134
compareConfig(conf, storeConf);
132135
}
133136

137+
@Test
138+
public void testConfigRetrieval() throws Exception {
139+
Configuration schedulerConf = new Configuration();
140+
schedulerConf.set("a", "a");
141+
schedulerConf.setLong("long", 1L);
142+
schedulerConf.setBoolean("boolean", true);
143+
writeConf(schedulerConf);
144+
145+
confStore.initialize(conf, conf, null);
146+
Configuration storedConfig = confStore.retrieve();
147+
148+
compareConfig(schedulerConf, storedConfig);
149+
}
150+
151+
@Test
152+
public void testFormatConfiguration() throws Exception {
153+
Configuration persistedSchedConf = new Configuration();
154+
persistedSchedConf.set("a", "a");
155+
writeConf(persistedSchedConf);
156+
confStore.initialize(conf, conf, null);
157+
Configuration storedConfig = confStore.retrieve();
158+
assertEquals("Retrieved config should match the stored one", "a",
159+
storedConfig.get("a"));
160+
confStore.format();
161+
try {
162+
confStore.retrieve();
163+
fail("Expected an IOException with message containing \"no capacity " +
164+
"scheduler file in\" to be thrown");
165+
} catch (IOException e) {
166+
assertThat("Exception message should contain the predefined string.",
167+
e.getMessage(),
168+
CoreMatchers.containsString("no capacity scheduler file in"));
169+
}
170+
}
171+
134172
@Test
135173
public void testFileSystemClose() throws Exception {
136174
MiniDFSCluster hdfsCluster = null;
@@ -146,18 +184,15 @@ public void testFileSystemClose() throws Exception {
146184
fs.mkdirs(path);
147185
}
148186

149-
FSSchedulerConfigurationStore configStore =
150-
new FSSchedulerConfigurationStore();
151187
hdfsConfig.set(YarnConfiguration.SCHEDULER_CONFIGURATION_FS_PATH,
152188
path.toString());
153-
configStore.initialize(hdfsConfig, hdfsConfig, null);
189+
confStore.initialize(hdfsConfig, hdfsConfig, null);
154190

155191
// Close the FileSystem object and validate
156192
fs.close();
157193

158194
try {
159-
prepareParameterizedLogMutation(configStore, true,
160-
"testkey", "testvalue");
195+
confStore.confirmMutation(prepareLogMutation("key", "val"), true);
161196
} catch (IOException e) {
162197
if (e.getMessage().contains("Filesystem closed")) {
163198
fail("FSSchedulerConfigurationStore failed to handle " +
@@ -176,50 +211,8 @@ public void testFileSystemClose() throws Exception {
176211
}
177212
}
178213

179-
@Test
180-
public void testFormatConfiguration() throws Exception {
181-
Configuration schedulerConf = new Configuration();
182-
schedulerConf.set("a", "a");
183-
writeConf(schedulerConf);
184-
configurationStore.initialize(conf, conf, null);
185-
Configuration storedConfig = configurationStore.retrieve();
186-
assertEquals("a", storedConfig.get("a"));
187-
configurationStore.format();
188-
try {
189-
configurationStore.retrieve();
190-
fail("Expected an IOException with message containing \"no capacity " +
191-
"scheduler file in\" to be thrown");
192-
} catch (IOException e) {
193-
assertThat(e.getMessage(),
194-
CoreMatchers.containsString("no capacity scheduler file in"));
195-
}
196-
}
197-
198-
@Test
199-
public void retrieve() throws Exception {
200-
Configuration schedulerConf = new Configuration();
201-
schedulerConf.set("a", "a");
202-
schedulerConf.setLong("long", 1L);
203-
schedulerConf.setBoolean("boolean", true);
204-
writeConf(schedulerConf);
205-
206-
configurationStore.initialize(conf, conf, null);
207-
Configuration storedConfig = configurationStore.retrieve();
208-
209-
compareConfig(schedulerConf, storedConfig);
210-
}
211-
212-
@Test
213-
public void checkVersion() {
214-
try {
215-
configurationStore.checkVersion();
216-
} catch (Exception e) {
217-
fail("checkVersion throw exception");
218-
}
219-
}
220-
221214
private void compareConfig(Configuration schedulerConf,
222-
Configuration storedConfig) {
215+
Configuration storedConfig) {
223216
for (Map.Entry<String, String> entry : schedulerConf) {
224217
assertEquals(entry.getKey(), schedulerConf.get(entry.getKey()),
225218
storedConfig.get(entry.getKey()));
@@ -231,26 +224,13 @@ private void compareConfig(Configuration schedulerConf,
231224
}
232225
}
233226

234-
private void prepareParameterizedLogMutation(
235-
FSSchedulerConfigurationStore configStore,
236-
boolean validityFlag, String... values) throws Exception {
237-
Map<String, String> updates = new HashMap<>();
238-
String key;
239-
String value;
240-
241-
if (values.length % 2 != 0) {
242-
throw new IllegalArgumentException("The number of parameters should be " +
243-
"even.");
244-
}
245-
246-
for (int i = 1; i <= values.length; i += 2) {
247-
key = values[i - 1];
248-
value = values[i];
249-
updates.put(key, value);
250-
}
227+
@Override
228+
public YarnConfigurationStore createConfStore() {
229+
return new FSSchedulerConfigurationStore();
230+
}
251231

252-
LogMutation logMutation = new LogMutation(updates, TEST_USER);
253-
configStore.logMutation(logMutation);
254-
configStore.confirmMutation(logMutation, validityFlag);
232+
@Override
233+
Version getVersion() {
234+
return null;
255235
}
256236
}

0 commit comments

Comments
 (0)