source: proiecte/HadoopJUnit/hadoop-0.20.1/src/test/org/apache/hadoop/mapred/TestGetSplitHosts.java @ 120

Last change on this file since 120 was 120, checked in by (none), 14 years ago

Added the mail files for the Hadoop JUNit Project

  • Property svn:executable set to *
File size: 4.0 KB
Line 
1/**
2 * Licensed to the Apache Software Foundation (ASF) under one
3 * or more contributor license agreements.  See the NOTICE file
4 * distributed with this work for additional information
5 * regarding copyright ownership.  The ASF licenses this file
6 * to you under the Apache License, Version 2.0 (the
7 * "License"); you may not use this file except in compliance
8 * with the License.  You may obtain a copy of the License at
9 *
10 *     http://www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
17 */
18package org.apache.hadoop.mapred;
19
20import org.apache.hadoop.fs.BlockLocation;
21import org.apache.hadoop.net.NetworkTopology;
22
23import junit.framework.TestCase;
24
25public class TestGetSplitHosts extends TestCase {
26
27  public void testGetSplitHosts() throws Exception {
28
29    int numBlocks = 3;
30    int block1Size = 100, block2Size = 150, block3Size = 75;
31    int fileSize = block1Size + block2Size + block3Size;
32    int replicationFactor = 3;
33    NetworkTopology clusterMap = new NetworkTopology();
34   
35    BlockLocation[] bs = new BlockLocation[numBlocks];
36   
37    String [] block1Hosts = {"host1","host2","host3"};
38    String [] block1Names = {"host1:100","host2:100","host3:100"};
39    String [] block1Racks = {"/rack1/","/rack1/","/rack2/"};
40    String [] block1Paths = new String[replicationFactor];
41   
42    for (int i = 0; i < replicationFactor; i++) { 
43      block1Paths[i] = block1Racks[i]+block1Names[i];
44    }
45   
46    bs[0] = new BlockLocation(block1Names,block1Hosts,
47                              block1Paths,0,block1Size);
48
49
50    String [] block2Hosts = {"host4","host5","host6"};
51    String [] block2Names = {"host4:100","host5:100","host6:100"};
52    String [] block2Racks = {"/rack2/","/rack3/","/rack3/"};
53    String [] block2Paths = new String[replicationFactor];
54   
55    for (int i = 0; i < replicationFactor; i++) { 
56      block2Paths[i] = block2Racks[i]+block2Names[i];
57    }
58
59    bs[1] = new BlockLocation(block2Names,block2Hosts,
60                              block2Paths,block1Size,block2Size);
61
62    String [] block3Hosts = {"host1","host7","host8"};
63    String [] block3Names = {"host1:100","host7:100","host8:100"};
64    String [] block3Racks = {"/rack1/","/rack4/","/rack4/"};
65    String [] block3Paths = new String[replicationFactor];
66   
67    for (int i = 0; i < replicationFactor; i++) { 
68      block3Paths[i] = block3Racks[i]+block3Names[i];
69    }
70
71    bs[2] = new BlockLocation(block3Names,block3Hosts,
72                              block3Paths,block1Size+block2Size,
73                              block3Size);
74
75   
76    SequenceFileInputFormat< String, String> sif = 
77      new SequenceFileInputFormat<String,String>();
78    String [] hosts = sif.getSplitHosts(bs, 0, fileSize, clusterMap);
79
80    // Contributions By Racks are
81    // Rack1   175       
82    // Rack2   275       
83    // Rack3   150       
84    // So, Rack2 hosts, host4 and host 3 should be returned
85    // even if their individual contribution is not the highest
86
87    assertTrue (hosts.length == replicationFactor);
88    assertTrue(hosts[0].equalsIgnoreCase("host4"));
89    assertTrue(hosts[1].equalsIgnoreCase("host3"));
90    assertTrue(hosts[2].equalsIgnoreCase("host1"));
91   
92   
93    // Now Create the blocks without topology information
94    bs[0] = new BlockLocation(block1Names,block1Hosts,0,block1Size);
95    bs[1] = new BlockLocation(block2Names,block2Hosts,block1Size,block2Size);
96    bs[2] = new BlockLocation(block3Names,block3Hosts,block1Size+block2Size,
97                               block3Size);
98
99    hosts = sif.getSplitHosts(bs, 0, fileSize, clusterMap);
100   
101    // host1 makes the highest contribution among all hosts
102    // So, that should be returned before others
103   
104    assertTrue (hosts.length == replicationFactor);
105    assertTrue(hosts[0].equalsIgnoreCase("host1"));
106  }
107}
Note: See TracBrowser for help on using the repository browser.