Return-Path: X-Original-To: apmail-hadoop-common-commits-archive@www.apache.org Delivered-To: apmail-hadoop-common-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 3C360D57E for ; Sun, 18 Nov 2012 21:36:42 +0000 (UTC) Received: (qmail 6240 invoked by uid 500); 18 Nov 2012 21:36:42 -0000 Delivered-To: apmail-hadoop-common-commits-archive@hadoop.apache.org Received: (qmail 6177 invoked by uid 500); 18 Nov 2012 21:36:41 -0000 Mailing-List: contact common-commits-help@hadoop.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: common-dev@hadoop.apache.org Delivered-To: mailing list common-commits@hadoop.apache.org Received: (qmail 6170 invoked by uid 99); 18 Nov 2012 21:36:41 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Sun, 18 Nov 2012 21:36:41 +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; Sun, 18 Nov 2012 21:36:39 +0000 Received: from eris.apache.org (localhost [127.0.0.1]) by eris.apache.org (Postfix) with ESMTP id D3FF623888CD for ; Sun, 18 Nov 2012 21:36:17 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r1410993 - in /hadoop/common/branches/branch-1-win: CHANGES.txt src/test/org/apache/hadoop/metrics2/impl/TestSinkQueue.java Date: Sun, 18 Nov 2012 21:36:17 -0000 To: common-commits@hadoop.apache.org From: suresh@apache.org X-Mailer: svnmailer-1.0.8-patched Message-Id: <20121118213617.D3FF623888CD@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: suresh Date: Sun Nov 18 21:36:16 2012 New Revision: 1410993 URL: http://svn.apache.org/viewvc?rev=1410993&view=rev Log: HADOOP-9036. Merge change 1410992 from branch-1 Modified: hadoop/common/branches/branch-1-win/CHANGES.txt hadoop/common/branches/branch-1-win/src/test/org/apache/hadoop/metrics2/impl/TestSinkQueue.java Modified: hadoop/common/branches/branch-1-win/CHANGES.txt URL: http://svn.apache.org/viewvc/hadoop/common/branches/branch-1-win/CHANGES.txt?rev=1410993&r1=1410992&r2=1410993&view=diff ============================================================================== --- hadoop/common/branches/branch-1-win/CHANGES.txt (original) +++ hadoop/common/branches/branch-1-win/CHANGES.txt Sun Nov 18 21:36:16 2012 @@ -30,6 +30,9 @@ Release 1.2.0 - unreleased HADOOP-8900. BuiltInGzipDecompressor throws IOException - stored gzip size doesn't match decompressed size. (Andy Isaacson via suresh) + HADOOP-9036. Fix racy test case TestSinkQueue (Backport HADOOP-7292). + (Luke Lu backport by suresh) + Release 1.1.1 - Unreleased INCOMPATIBLE CHANGES Modified: hadoop/common/branches/branch-1-win/src/test/org/apache/hadoop/metrics2/impl/TestSinkQueue.java URL: http://svn.apache.org/viewvc/hadoop/common/branches/branch-1-win/src/test/org/apache/hadoop/metrics2/impl/TestSinkQueue.java?rev=1410993&r1=1410992&r2=1410993&view=diff ============================================================================== --- hadoop/common/branches/branch-1-win/src/test/org/apache/hadoop/metrics2/impl/TestSinkQueue.java (original) +++ hadoop/common/branches/branch-1-win/src/test/org/apache/hadoop/metrics2/impl/TestSinkQueue.java Sun Nov 18 21:36:16 2012 @@ -24,13 +24,13 @@ import org.apache.commons.logging.LogFac import org.junit.Test; import static org.junit.Assert.*; import static org.mockito.Mockito.*; +import java.util.concurrent.CountDownLatch; /** * Test the half-blocking metrics sink queue */ public class TestSinkQueue { - - private final Log LOG = LogFactory.getLog(TestSinkQueue.class); + private static final Log LOG = LogFactory.getLog(TestSinkQueue.class); /** * Test common use case @@ -61,6 +61,11 @@ public class TestSinkQueue { * @throws Exception */ @Test public void testEmptyBlocking() throws Exception { + testEmptyBlocking(0); + testEmptyBlocking(100); + } + + private void testEmptyBlocking(int awhile) throws Exception { final SinkQueue q = new SinkQueue(2); final Runnable trigger = mock(Runnable.class); // try consuming emtpy equeue and blocking @@ -81,7 +86,10 @@ public class TestSinkQueue { } }; t.start(); - Thread.yield(); // Let the other block + // Should work with or without sleep + if (awhile > 0) { + Thread.sleep(awhile); + } q.enqueue(1); q.enqueue(2); t.join(); @@ -226,21 +234,25 @@ public class TestSinkQueue { LOG.info(e); return; } - fail("should've thrown"); + LOG.error("should've thrown CME"); + fail("should've thrown CME"); } - private SinkQueue - newSleepingConsumerQueue(int capacity, int... values) { + private SinkQueue newSleepingConsumerQueue(int capacity, + int... values) throws Exception { final SinkQueue q = new SinkQueue(capacity); for (int i : values) { q.enqueue(i); } + final CountDownLatch barrier = new CountDownLatch(1); Thread t = new Thread() { @Override public void run() { try { + Thread.sleep(10); // causes failure without barrier q.consume(new Consumer() { public void consume(Integer e) throws InterruptedException { LOG.info("sleeping"); + barrier.countDown(); Thread.sleep(1000 * 86400); // a long time } }); @@ -253,7 +265,7 @@ public class TestSinkQueue { t.setName("Sleeping consumer"); t.setDaemon(true); // so jvm can exit t.start(); - Thread.yield(); // Let the consumer consume + barrier.await(); LOG.debug("Returning new sleeping consumer queue"); return q; }