Return-Path: X-Original-To: apmail-hadoop-yarn-commits-archive@minotaur.apache.org Delivered-To: apmail-hadoop-yarn-commits-archive@minotaur.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id E4F39109DB for ; Wed, 9 Oct 2013 05:10:15 +0000 (UTC) Received: (qmail 24888 invoked by uid 500); 9 Oct 2013 05:08:26 -0000 Delivered-To: apmail-hadoop-yarn-commits-archive@hadoop.apache.org Received: (qmail 24822 invoked by uid 500); 9 Oct 2013 05:08:22 -0000 Mailing-List: contact yarn-commits-help@hadoop.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: yarn-commits@hadoop.apache.org Delivered-To: mailing list yarn-commits@hadoop.apache.org Received: (qmail 24659 invoked by uid 99); 9 Oct 2013 05:08:05 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 09 Oct 2013 05:08:05 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=5.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 09 Oct 2013 05:08:03 +0000 Received: from eris.apache.org (localhost [127.0.0.1]) by eris.apache.org (Postfix) with ESMTP id E54D7238889B; Wed, 9 Oct 2013 05:07:41 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r1530493 - /hadoop/common/trunk/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/test/java/org/apache/hadoop/yarn/server/nodemanager/util/TestCgroupsLCEResourcesHandler.java Date: Wed, 09 Oct 2013 05:07:41 -0000 To: yarn-commits@hadoop.apache.org From: sandy@apache.org X-Mailer: svnmailer-1.0.9 Message-Id: <20131009050741.E54D7238889B@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: sandy Date: Wed Oct 9 05:07:41 2013 New Revision: 1530493 URL: http://svn.apache.org/r1530493 Log: Add missing file TestCgroupsLCEResourcesHandler for YARN-1284. Added: hadoop/common/trunk/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/test/java/org/apache/hadoop/yarn/server/nodemanager/util/TestCgroupsLCEResourcesHandler.java Added: hadoop/common/trunk/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/test/java/org/apache/hadoop/yarn/server/nodemanager/util/TestCgroupsLCEResourcesHandler.java URL: http://svn.apache.org/viewvc/hadoop/common/trunk/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/test/java/org/apache/hadoop/yarn/server/nodemanager/util/TestCgroupsLCEResourcesHandler.java?rev=1530493&view=auto ============================================================================== --- hadoop/common/trunk/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/test/java/org/apache/hadoop/yarn/server/nodemanager/util/TestCgroupsLCEResourcesHandler.java (added) +++ hadoop/common/trunk/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/test/java/org/apache/hadoop/yarn/server/nodemanager/util/TestCgroupsLCEResourcesHandler.java Wed Oct 9 05:07:41 2013 @@ -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())); + } + +}