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 5A158F892 for ; Mon, 8 Apr 2013 19:57:48 +0000 (UTC) Received: (qmail 48228 invoked by uid 500); 8 Apr 2013 19:57:48 -0000 Delivered-To: apmail-hadoop-common-commits-archive@hadoop.apache.org Received: (qmail 48174 invoked by uid 500); 8 Apr 2013 19:57:48 -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 48165 invoked by uid 99); 8 Apr 2013 19:57:48 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 08 Apr 2013 19:57:48 +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; Mon, 08 Apr 2013 19:57:45 +0000 Received: from eris.apache.org (localhost [127.0.0.1]) by eris.apache.org (Postfix) with ESMTP id E5A9F23888EA; Mon, 8 Apr 2013 19:57:24 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r1465752 - /hadoop/common/branches/branch-2/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/test/MockitoUtil.java Date: Mon, 08 Apr 2013 19:57:24 -0000 To: common-commits@hadoop.apache.org From: todd@apache.org X-Mailer: svnmailer-1.0.8-patched Message-Id: <20130408195724.E5A9F23888EA@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: todd Date: Mon Apr 8 19:57:24 2013 New Revision: 1465752 URL: http://svn.apache.org/r1465752 Log: HDFS-3981. Fix handling of FSN lock in getBlockLocations. Contributed by Xiaobo Peng and Todd Lipcon. Modified: hadoop/common/branches/branch-2/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/test/MockitoUtil.java Modified: hadoop/common/branches/branch-2/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/test/MockitoUtil.java URL: http://svn.apache.org/viewvc/hadoop/common/branches/branch-2/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/test/MockitoUtil.java?rev=1465752&r1=1465751&r2=1465752&view=diff ============================================================================== --- hadoop/common/branches/branch-2/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/test/MockitoUtil.java (original) +++ hadoop/common/branches/branch-2/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/test/MockitoUtil.java Mon Apr 8 19:57:24 2013 @@ -20,6 +20,9 @@ package org.apache.hadoop.test; import java.io.Closeable; import org.mockito.Mockito; +import org.mockito.invocation.InvocationOnMock; +import org.mockito.stubbing.Answer; +import org.mockito.stubbing.Stubber; public abstract class MockitoUtil { @@ -33,4 +36,29 @@ public abstract class MockitoUtil { return Mockito.mock(clazz, Mockito.withSettings().extraInterfaces(Closeable.class)); } + + /** + * Throw an exception from the mock/spy only in the case that the + * call stack at the time the method has a line which matches the given + * pattern. + * + * @param t the Throwable to throw + * @param pattern the pattern against which to match the call stack trace + * @return the stub in progress + */ + public static Stubber doThrowWhenCallStackMatches( + final Throwable t, final String pattern) { + return Mockito.doAnswer(new Answer() { + @Override + public Object answer(InvocationOnMock invocation) throws Throwable { + t.setStackTrace(Thread.currentThread().getStackTrace()); + for (StackTraceElement elem : t.getStackTrace()) { + if (elem.toString().matches(pattern)) { + throw t; + } + } + return invocation.callRealMethod(); + } + }); + } }