Search in sources :

Example 1 with CleanerMetrics

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();
}
Also used : ReentrantLock(java.util.concurrent.locks.ReentrantLock) Path(org.apache.hadoop.fs.Path) FileStatus(org.apache.hadoop.fs.FileStatus) SCMStore(org.apache.hadoop.yarn.server.sharedcachemanager.store.SCMStore) FileSystem(org.apache.hadoop.fs.FileSystem) CleanerMetrics(org.apache.hadoop.yarn.server.sharedcachemanager.metrics.CleanerMetrics) Test(org.junit.Test)

Example 2 with CleanerMetrics

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();
}
Also used : ReentrantLock(java.util.concurrent.locks.ReentrantLock) Path(org.apache.hadoop.fs.Path) FileStatus(org.apache.hadoop.fs.FileStatus) SCMStore(org.apache.hadoop.yarn.server.sharedcachemanager.store.SCMStore) FileSystem(org.apache.hadoop.fs.FileSystem) CleanerMetrics(org.apache.hadoop.yarn.server.sharedcachemanager.metrics.CleanerMetrics) Test(org.junit.Test)

Example 3 with CleanerMetrics

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();
}
Also used : Path(org.apache.hadoop.fs.Path) ReentrantLock(java.util.concurrent.locks.ReentrantLock) FileStatus(org.apache.hadoop.fs.FileStatus) SCMStore(org.apache.hadoop.yarn.server.sharedcachemanager.store.SCMStore) FileSystem(org.apache.hadoop.fs.FileSystem) CleanerMetrics(org.apache.hadoop.yarn.server.sharedcachemanager.metrics.CleanerMetrics) Test(org.junit.Test)

Example 4 with CleanerMetrics

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();
}
Also used : ReentrantLock(java.util.concurrent.locks.ReentrantLock) SCMStore(org.apache.hadoop.yarn.server.sharedcachemanager.store.SCMStore) FileSystem(org.apache.hadoop.fs.FileSystem) CleanerMetrics(org.apache.hadoop.yarn.server.sharedcachemanager.metrics.CleanerMetrics) Test(org.junit.Test)

Aggregations

ReentrantLock (java.util.concurrent.locks.ReentrantLock)4 FileSystem (org.apache.hadoop.fs.FileSystem)4 CleanerMetrics (org.apache.hadoop.yarn.server.sharedcachemanager.metrics.CleanerMetrics)4 SCMStore (org.apache.hadoop.yarn.server.sharedcachemanager.store.SCMStore)4 Test (org.junit.Test)4 FileStatus (org.apache.hadoop.fs.FileStatus)3 Path (org.apache.hadoop.fs.Path)3