use of org.apache.hadoop.yarn.api.records.ApplicationId in project hadoop by apache.
the class TestInMemorySCMStore method testAddResourceRefAddResourceConcurrency.
@Test
public void testAddResourceRefAddResourceConcurrency() throws Exception {
startEmptyStore();
final String key = "key1";
final String fileName = "foo.jar";
final String user = "user";
final ApplicationId id = createAppId(1, 1L);
// add the resource and add the resource ref at the same time
ExecutorService exec = HadoopExecutors.newFixedThreadPool(2);
final CountDownLatch start = new CountDownLatch(1);
Callable<String> addKeyTask = new Callable<String>() {
public String call() throws Exception {
start.await();
return store.addResource(key, fileName);
}
};
Callable<String> addAppIdTask = new Callable<String>() {
public String call() throws Exception {
start.await();
return store.addResourceReference(key, new SharedCacheResourceReference(id, user));
}
};
Future<String> addAppIdFuture = exec.submit(addAppIdTask);
Future<String> addKeyFuture = exec.submit(addKeyTask);
// start them at the same time
start.countDown();
// get the results
String addKeyResult = addKeyFuture.get();
String addAppIdResult = addAppIdFuture.get();
assertEquals(fileName, addKeyResult);
System.out.println("addAppId() result: " + addAppIdResult);
// it may be null or the fileName depending on the timing
assertTrue(addAppIdResult == null || addAppIdResult.equals(fileName));
exec.shutdown();
}
use of org.apache.hadoop.yarn.api.records.ApplicationId in project hadoop by apache.
the class TestInMemorySCMStore method testAddResourceRefNonExistentResource.
@Test
public void testAddResourceRefNonExistentResource() throws Exception {
startEmptyStore();
String key = "key1";
ApplicationId id = createAppId(1, 1L);
// try adding an app id without adding the key first
assertNull(store.addResourceReference(key, new SharedCacheResourceReference(id, "user")));
}
use of org.apache.hadoop.yarn.api.records.ApplicationId in project hadoop by apache.
the class TestRemoteAppChecker method testNonExistentApp.
@Test
public void testNonExistentApp() throws Exception {
YarnClient client = createCheckerWithMockedClient();
ApplicationId id = ApplicationId.newInstance(1, 1);
// test for null
doReturn(null).when(client).getApplicationReport(id);
assertFalse(checker.isApplicationActive(id));
// test for ApplicationNotFoundException
doThrow(new ApplicationNotFoundException("Throw!")).when(client).getApplicationReport(id);
assertFalse(checker.isApplicationActive(id));
}
use of org.apache.hadoop.yarn.api.records.ApplicationId in project hadoop by apache.
the class TestInMemorySCMStore method startEmptyStore.
private void startEmptyStore() throws Exception {
doReturn(new ArrayList<ApplicationId>()).when(checker).getActiveApplications();
doReturn(new HashMap<String, String>()).when(store).getInitialCachedResources(isA(FileSystem.class), isA(Configuration.class));
this.store.init(new Configuration());
this.store.start();
}
use of org.apache.hadoop.yarn.api.records.ApplicationId in project hadoop by apache.
the class TestInMemorySCMStore method testRemoveRef.
@Test
public void testRemoveRef() throws Exception {
startEmptyStore();
String key = "key1";
String fileName = "foo.jar";
String user = "user";
// first add the resource
store.addResource(key, fileName);
// add a ref
ApplicationId id = createAppId(1, 1L);
SharedCacheResourceReference myRef = new SharedCacheResourceReference(id, user);
String result = store.addResourceReference(key, myRef);
assertEquals(fileName, result);
Collection<SharedCacheResourceReference> refs = store.getResourceReferences(key);
assertSame(1, refs.size());
assertEquals(Collections.singleton(myRef), refs);
// remove the same ref
store.removeResourceReferences(key, Collections.singleton(myRef), true);
Collection<SharedCacheResourceReference> newRefs = store.getResourceReferences(key);
assertTrue(newRefs == null || newRefs.isEmpty());
}
Aggregations