From 86bacb6b43706fb3b6392beaae3459524aa394ba Mon Sep 17 00:00:00 2001 From: Sanford Ryza Date: Wed, 9 Oct 2013 05:12:26 +0000 Subject: [PATCH] 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 --- .../util/TestCgroupsLCEResourcesHandler.java | 73 +++++++++++++++++++ 1 file changed, 73 insertions(+) create mode 100644 hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/test/java/org/apache/hadoop/yarn/server/nodemanager/util/TestCgroupsLCEResourcesHandler.java diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/test/java/org/apache/hadoop/yarn/server/nodemanager/util/TestCgroupsLCEResourcesHandler.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/test/java/org/apache/hadoop/yarn/server/nodemanager/util/TestCgroupsLCEResourcesHandler.java new file mode 100644 index 00000000000..55caffc430e --- /dev/null +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/test/java/org/apache/hadoop/yarn/server/nodemanager/util/TestCgroupsLCEResourcesHandler.java @@ -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())); + } + +}