use of org.apache.hadoop.yarn.server.sharedcachemanager.metrics.CleanerMetrics in project hadoop by apache.
the class TestCleanerTask method testProcessEvictableResource.
@Test
public void testProcessEvictableResource() throws Exception {
FileSystem fs = mock(FileSystem.class);
CleanerMetrics metrics = mock(CleanerMetrics.class);
SCMStore store = mock(SCMStore.class);
CleanerTask task = createSpiedTask(fs, store, metrics, new ReentrantLock());
// mock an evictable resource
when(store.isResourceEvictable(isA(String.class), isA(FileStatus.class))).thenReturn(true);
FileStatus status = mock(FileStatus.class);
when(status.getPath()).thenReturn(new Path(ROOT + "/a/b/c/abc"));
when(store.removeResource(isA(String.class))).thenReturn(true);
// rename succeeds
when(fs.rename(isA(Path.class), isA(Path.class))).thenReturn(true);
// delete returns true
when(fs.delete(isA(Path.class), anyBoolean())).thenReturn(true);
// process the resource
task.processSingleResource(status);
// the directory should be renamed
verify(fs).rename(eq(status.getPath()), isA(Path.class));
// metrics should record a deleted file
verify(metrics).reportAFileDelete();
verify(metrics, never()).reportAFileProcess();
}
use of org.apache.hadoop.yarn.server.sharedcachemanager.metrics.CleanerMetrics in project hadoop by apache.
the class TestCleanerTask method testProcessFreshResource.
@Test
public void testProcessFreshResource() throws Exception {
FileSystem fs = mock(FileSystem.class);
CleanerMetrics metrics = mock(CleanerMetrics.class);
SCMStore store = mock(SCMStore.class);
CleanerTask task = createSpiedTask(fs, store, metrics, new ReentrantLock());
// mock a resource that is not evictable
when(store.isResourceEvictable(isA(String.class), isA(FileStatus.class))).thenReturn(false);
FileStatus status = mock(FileStatus.class);
when(status.getPath()).thenReturn(new Path(ROOT + "/a/b/c/abc"));
// process the resource
task.processSingleResource(status);
// the directory should not be renamed
verify(fs, never()).rename(eq(status.getPath()), isA(Path.class));
// metrics should record a processed file (but not delete)
verify(metrics).reportAFileProcess();
verify(metrics, never()).reportAFileDelete();
}
use of org.apache.hadoop.yarn.server.sharedcachemanager.metrics.CleanerMetrics in project hadoop by apache.
the class TestCleanerTask method testResourceIsInUseHasAnActiveApp.
@Test
public void testResourceIsInUseHasAnActiveApp() throws Exception {
FileSystem fs = mock(FileSystem.class);
CleanerMetrics metrics = mock(CleanerMetrics.class);
SCMStore store = mock(SCMStore.class);
FileStatus resource = mock(FileStatus.class);
when(resource.getPath()).thenReturn(new Path(ROOT + "/a/b/c/abc"));
// resource is stale
when(store.isResourceEvictable(isA(String.class), isA(FileStatus.class))).thenReturn(true);
// but still has appIds
when(store.removeResource(isA(String.class))).thenReturn(false);
CleanerTask task = createSpiedTask(fs, store, metrics, new ReentrantLock());
// process the resource
task.processSingleResource(resource);
// metrics should record a processed file (but not delete)
verify(metrics).reportAFileProcess();
verify(metrics, never()).reportAFileDelete();
}
use of org.apache.hadoop.yarn.server.sharedcachemanager.metrics.CleanerMetrics in project hadoop by apache.
the class TestCleanerTask method testNonExistentRoot.
@Test
public void testNonExistentRoot() throws Exception {
FileSystem fs = mock(FileSystem.class);
CleanerMetrics metrics = mock(CleanerMetrics.class);
SCMStore store = mock(SCMStore.class);
CleanerTask task = createSpiedTask(fs, store, metrics, new ReentrantLock());
// the shared cache root does not exist
when(fs.exists(task.getRootPath())).thenReturn(false);
task.run();
// process() should not be called
verify(task, never()).process();
}
Aggregations