Add missing file TestCgroupsLCEResourcesHandler for YARN-1284.
git-svn-id: https://svn.apache.org/repos/asf/hadoop/common/branches/branch-2@1530495 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
b57b4252bf
commit
86bacb6b43
|
@ -0,0 +1,73 @@
|
||||||
|
/**
|
||||||
|
* Licensed to the Apache Software Foundation (ASF) under one
|
||||||
|
* or more contributor license agreements. See the NOTICE file
|
||||||
|
* distributed with this work for additional information
|
||||||
|
* regarding copyright ownership. The ASF licenses this file
|
||||||
|
* to you under the Apache License, Version 2.0 (the
|
||||||
|
* "License"); you may not use this file except in compliance
|
||||||
|
* with the License. You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
package org.apache.hadoop.yarn.server.nodemanager.util;
|
||||||
|
|
||||||
|
import junit.framework.Assert;
|
||||||
|
import org.apache.hadoop.yarn.conf.YarnConfiguration;
|
||||||
|
import org.apache.hadoop.yarn.util.Clock;
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.FileOutputStream;
|
||||||
|
import java.util.UUID;
|
||||||
|
import java.util.concurrent.CountDownLatch;
|
||||||
|
|
||||||
|
public class TestCgroupsLCEResourcesHandler {
|
||||||
|
|
||||||
|
static class MockClock implements Clock {
|
||||||
|
long time;
|
||||||
|
@Override
|
||||||
|
public long getTime() {
|
||||||
|
return time;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@Test
|
||||||
|
public void testDeleteCgroup() throws Exception {
|
||||||
|
final MockClock clock = new MockClock();
|
||||||
|
clock.time = System.currentTimeMillis();
|
||||||
|
CgroupsLCEResourcesHandler handler = new CgroupsLCEResourcesHandler();
|
||||||
|
handler.setConf(new YarnConfiguration());
|
||||||
|
handler.initConfig();
|
||||||
|
handler.clock = clock;
|
||||||
|
|
||||||
|
//file exists
|
||||||
|
File file = new File("target", UUID.randomUUID().toString());
|
||||||
|
new FileOutputStream(file).close();
|
||||||
|
Assert.assertTrue(handler.deleteCgroup(file.getPath()));
|
||||||
|
|
||||||
|
//file does not exists, timing out
|
||||||
|
final CountDownLatch latch = new CountDownLatch(1);
|
||||||
|
new Thread() {
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
latch.countDown();
|
||||||
|
try {
|
||||||
|
Thread.sleep(200);
|
||||||
|
} catch (InterruptedException ex) {
|
||||||
|
//NOP
|
||||||
|
}
|
||||||
|
clock.time += YarnConfiguration.
|
||||||
|
DEFAULT_NM_LINUX_CONTAINER_CGROUPS_DELETE_TIMEOUT;
|
||||||
|
}
|
||||||
|
}.start();
|
||||||
|
latch.await();
|
||||||
|
file = new File("target", UUID.randomUUID().toString());
|
||||||
|
Assert.assertFalse(handler.deleteCgroup(file.getPath()));
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
Loading…
Reference in New Issue