|
@@ -348,24 +348,56 @@ public class TestFileSystemNodeLabelsStore extends NodeLabelTestBase {
|
|
|
|
|
|
@MethodSource("getParameters")
|
|
|
@ParameterizedTest
|
|
|
- void testRootMkdirOnInitStore(String className) throws Exception {
|
|
|
+ void testRootMkdirOnInitStoreWhenRootDirectoryAlreadyExists(String className) throws Exception {
|
|
|
initTestFileSystemNodeLabelsStore(className);
|
|
|
final FileSystem mockFs = Mockito.mock(FileSystem.class);
|
|
|
+ final FileSystemNodeLabelsStore mockStore = createMockNodeLabelsStore(mockFs);
|
|
|
+ final int expectedMkdirsCount = 0;
|
|
|
+
|
|
|
+ Mockito.when(mockStore.getFs().exists(Mockito.any(Path.class)))
|
|
|
+ .thenReturn(true);
|
|
|
+ verifyMkdirsCount(mockStore, expectedMkdirsCount);
|
|
|
+ }
|
|
|
+
|
|
|
+ @MethodSource("getParameters")
|
|
|
+ @ParameterizedTest
|
|
|
+ void testRootMkdirOnInitStoreWhenRootDirectoryNotExists(String className) throws Exception {
|
|
|
+ initTestFileSystemNodeLabelsStore(className);
|
|
|
+ final FileSystem mockFs = Mockito.mock(FileSystem.class);
|
|
|
+ final FileSystemNodeLabelsStore mockStore = createMockNodeLabelsStore(mockFs);
|
|
|
+ final int expectedMkdirsCount = 1;
|
|
|
+
|
|
|
+ Mockito.when(mockStore.getFs().exists(Mockito.any(Path.class)))
|
|
|
+ .thenReturn(false).thenReturn(true);
|
|
|
+ verifyMkdirsCount(mockStore, expectedMkdirsCount);
|
|
|
+ }
|
|
|
+
|
|
|
+ @MethodSource("getParameters")
|
|
|
+ @ParameterizedTest
|
|
|
+ void testRootMkdirOnInitStoreRetryLogic(String className) throws Exception {
|
|
|
+ initTestFileSystemNodeLabelsStore(className);
|
|
|
+ final FileSystem mockFs = Mockito.mock(FileSystem.class);
|
|
|
+ final FileSystemNodeLabelsStore mockStore = createMockNodeLabelsStore(mockFs);
|
|
|
+ final int expectedMkdirsCount = 2;
|
|
|
+
|
|
|
+ Mockito.when(mockStore.getFs().exists(Mockito.any(Path.class)))
|
|
|
+ .thenReturn(false).thenReturn(false).thenReturn(true);
|
|
|
+ verifyMkdirsCount(mockStore, expectedMkdirsCount);
|
|
|
+ }
|
|
|
+
|
|
|
+ private FileSystemNodeLabelsStore createMockNodeLabelsStore(FileSystem mockFs) {
|
|
|
FileSystemNodeLabelsStore mockStore = new FileSystemNodeLabelsStore() {
|
|
|
public void initFileSystem(Configuration config) throws IOException {
|
|
|
setFs(mockFs);
|
|
|
}
|
|
|
};
|
|
|
-
|
|
|
mockStore.setFs(mockFs);
|
|
|
- verifyMkdirsCount(mockStore, true, 1);
|
|
|
+ return mockStore;
|
|
|
}
|
|
|
|
|
|
private void verifyMkdirsCount(FileSystemNodeLabelsStore store,
|
|
|
- boolean existsRetVal, int expectedNumOfCalls)
|
|
|
+ int expectedNumOfCalls)
|
|
|
throws Exception {
|
|
|
- Mockito.when(store.getFs().exists(Mockito.any(
|
|
|
- Path.class))).thenReturn(existsRetVal);
|
|
|
store.init(conf, mgr);
|
|
|
Mockito.verify(store.getFs(), Mockito.times(
|
|
|
expectedNumOfCalls)).mkdirs(Mockito.any(Path
|