3232import org .apache .hadoop .hdfs .MiniDFSCluster .DataNodeProperties ;
3333import org .apache .hadoop .util .ThreadUtil ;
3434
35+ import org .junit .After ;
36+ import org .junit .Before ;
3537import org .junit .Test ;
3638
3739
4143 */
4244public class TestDFSClientExcludedNodes {
4345
44- @ Test (timeout =10000 )
46+ private MiniDFSCluster cluster ;
47+ private Configuration conf ;
48+
49+ @ Before
50+ public void setUp () {
51+ cluster = null ;
52+ conf = new HdfsConfiguration ();
53+ }
54+
55+ @ After
56+ public void tearDown () {
57+ if (cluster != null ) {
58+ cluster .shutdown ();
59+ }
60+ }
61+
62+ @ Test (timeout =60000 )
4563 public void testExcludedNodes () throws IOException {
46- Configuration conf = new HdfsConfiguration ();
47- MiniDFSCluster cluster = new MiniDFSCluster .Builder (conf ).numDataNodes (3 ).build ();
64+ cluster = new MiniDFSCluster .Builder (conf ).numDataNodes (3 ).build ();
4865 FileSystem fs = cluster .getFileSystem ();
4966 Path filePath = new Path ("/testExcludedNodes" );
5067
@@ -67,17 +84,16 @@ public void testExcludedNodes() throws IOException {
6784 }
6885 }
6986
70- @ Test (timeout =10000 )
87+ @ Test (timeout =60000 )
7188 public void testExcludedNodesForgiveness () throws IOException {
72- Configuration conf = new HdfsConfiguration ();
73- // Forgive nodes in under 1s for this test case.
89+ // Forgive nodes in under 2.5s for this test case.
7490 conf .setLong (
7591 DFSConfigKeys .DFS_CLIENT_WRITE_EXCLUDE_NODES_CACHE_EXPIRY_INTERVAL ,
76- 1000 );
92+ 2500 );
7793 // We'll be using a 512 bytes block size just for tests
7894 // so making sure the checksum bytes too match it.
7995 conf .setInt ("io.bytes.per.checksum" , 512 );
80- MiniDFSCluster cluster = new MiniDFSCluster .Builder (conf ).numDataNodes (3 ).build ();
96+ cluster = new MiniDFSCluster .Builder (conf ).numDataNodes (3 ).build ();
8197 List <DataNodeProperties > props = cluster .dataNodes ;
8298 FileSystem fs = cluster .getFileSystem ();
8399 Path filePath = new Path ("/testForgivingExcludedNodes" );
@@ -112,11 +128,11 @@ public void testExcludedNodesForgiveness() throws IOException {
112128 Assert .assertEquals (true , cluster .restartDataNode (two , true ));
113129 cluster .waitActive ();
114130
115- // Sleep for 2s , to let the excluded nodes be expired
131+ // Sleep for 5s , to let the excluded nodes be expired
116132 // from the excludes list (i.e. forgiven after the configured wait period).
117- // [Sleeping just in case the restart of the DNs completed < 2s cause
133+ // [Sleeping just in case the restart of the DNs completed < 5s cause
118134 // otherwise, we'll end up quickly excluding those again.]
119- ThreadUtil .sleepAtLeastIgnoreInterrupts (2000 );
135+ ThreadUtil .sleepAtLeastIgnoreInterrupts (5000 );
120136
121137 // Terminate the last good DN, to assert that there's no
122138 // single-DN-available scenario, caused by not forgiving the other
0 commit comments