From 70db2ec417366890a17af8374eb5075bf68f3028 Mon Sep 17 00:00:00 2001 From: Andrew Wang Date: Fri, 13 Jun 2014 19:00:03 +0000 Subject: [PATCH] HDFS-6470. TestBPOfferService.testBPInitErrorHandling is flaky. Contributed by Ming Ma. git-svn-id: https://svn.apache.org/repos/asf/hadoop/common/trunk@1602490 13f79535-47bb-0310-9956-ffa450edef68 --- hadoop-hdfs-project/hadoop-hdfs/CHANGES.txt | 3 ++ .../server/datanode/TestBPOfferService.java | 38 +++++++++++++++---- 2 files changed, 34 insertions(+), 7 deletions(-) diff --git a/hadoop-hdfs-project/hadoop-hdfs/CHANGES.txt b/hadoop-hdfs-project/hadoop-hdfs/CHANGES.txt index 035aaa35025..cf84105d77b 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/CHANGES.txt +++ b/hadoop-hdfs-project/hadoop-hdfs/CHANGES.txt @@ -437,6 +437,9 @@ Release 2.5.0 - UNRELEASED HDFS-6330. Move mkdirs() to FSNamesystem. (wheat9) + HDFS-6470. TestBPOfferService.testBPInitErrorHandling is flaky. + (Ming Ma via wang) + OPTIMIZATIONS HDFS-6214. Webhdfs has poor throughput for files >2GB (daryn) diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/datanode/TestBPOfferService.java b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/datanode/TestBPOfferService.java index c2d8698127b..704d0996353 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/datanode/TestBPOfferService.java +++ b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/datanode/TestBPOfferService.java @@ -325,15 +325,14 @@ public class TestBPOfferService { } }).when(mockDn).initBlockPool(Mockito.any(BPOfferService.class)); BPOfferService bpos = setupBPOSForNNs(mockDn, mockNN1, mockNN2); + List actors = bpos.getBPServiceActors(); + assertEquals(2, actors.size()); bpos.start(); try { waitForInitialization(bpos); - List actors = bpos.getBPServiceActors(); - // even if one of the actor initialization fails also other will be - // running until both failed. - assertEquals(2, actors.size()); - BPServiceActor actor = actors.get(0); - waitForBlockReport(actor.getNameNodeProxy()); + // even if one of the actor initialization fails, the other one will be + // finish block report. + waitForBlockReport(mockNN1, mockNN2); } finally { bpos.stop(); } @@ -409,7 +408,32 @@ public class TestBPOfferService { } }, 500, 10000); } - + + private void waitForBlockReport( + final DatanodeProtocolClientSideTranslatorPB mockNN1, + final DatanodeProtocolClientSideTranslatorPB mockNN2) + throws Exception { + GenericTestUtils.waitFor(new Supplier() { + @Override + public Boolean get() { + return get(mockNN1) || get(mockNN2); + } + + private Boolean get(DatanodeProtocolClientSideTranslatorPB mockNN) { + try { + Mockito.verify(mockNN).blockReport( + Mockito.anyObject(), + Mockito.eq(FAKE_BPID), + Mockito.anyObject()); + return true; + } catch (Throwable t) { + LOG.info("waiting on block report: " + t.getMessage()); + return false; + } + } + }, 500, 10000); + } + private ReceivedDeletedBlockInfo[] waitForBlockReceived( ExtendedBlock fakeBlock, DatanodeProtocolClientSideTranslatorPB mockNN) throws Exception {