2011-11-29 5 views

답변

6

그것은 당신이 하둡 2.0.0을 사용하는 경우 하둡

0

필자는 (더 나은 해결책을 찾을 때까지) FileSystem을 확장했습니다.

5

Mockito 또는 PowerMock과 같은 조롱 프레임 워크를 사용하여 사용자의 개입을 FileSystem으로 조롱하는 것은 어떻습니까? 유닛 테스트는 실제 FileSystem에 의존해서는 안되며 FileSystem과 상호 작용할 때 코드의 동작을 검증해야합니다.

10

없이 테스트 할 수 있도록 MiniDFSCluster 및 MiniMRCluster를 설정하는 분류했다

<dependency> 
    <groupId>org.apache.hadoop</groupId> 
    <artifactId>hadoop-test</artifactId> 
    <version>0.20.205.0</version> 
</dependency> 

하둡 테스트 항아리를 살펴 보자 위 - 당신은 당신의 로컬 컴퓨터에 임시 HDFS를 만들고, 그것에 당신의 테스트를 실행할 수 있습니다, 그것은으로

<dependency> 
    <groupId>org.apache.hadoop</groupId> 
    <artifactId>hadoop-minicluster</artifactId> 
    <version>2.5.0</version> 
    <scope>test</scope> 
</dependency> 

하둡 - minicluster을 사용하는 것이 좋습니다.

baseDir = Files.createTempDirectory("test_hdfs").toFile().getAbsoluteFile(); 
Configuration conf = new Configuration(); 
conf.set(MiniDFSCluster.HDFS_MINIDFS_BASEDIR, baseDir.getAbsolutePath()); 
MiniDFSCluster.Builder builder = new MiniDFSCluster.Builder(conf); 
hdfsCluster = builder.build(); 

String hdfsURI = "hdfs://localhost:"+ hdfsCluster.getNameNodePort() + "/"; 
DistributedFileSystem fileSystem = hdfsCluster.getFileSystem(); 

을 그리고 해체 방법에 당신은 당신의 미니 HDFS 클러스터를 종료해야하며, 임시 디렉토리를 제거합니다 설정 방법은 다음과 같이 보일 수 있습니다.

hdfsCluster.shutdown(); 
FileUtil.fullyDelete(baseDir); 
0

RawLocalFileSystem을 살펴볼 수 있습니다. 나는 당신이 그것을 조롱하는 것이 좋을 것이라고 생각하지만.

0

당신은 HBaseTestingUtility 사용할 수 있습니다

public class SomeTest { 
    private HBaseTestingUtility testingUtil = new HBaseTestingUtility(); 

    @Before 
    public void setup() throws Exception { 
     testingUtil.startMiniDFSCluster(1); 
    } 

    @After 
    public void tearDown() throws IOException { 
     testingUtil.shutdownMiniDFSCluster(); 
    } 

    @Test 
    public void test() throws Exception { 
     DistributedFileSystem fs = testingUtil.getDFSCluster().getFileSystem(); 
     final Path dstPath = new Path("/your/path/file.txt); 
     final Path srcPath = new Path(SomeTest.class.getResource("file.txt").toURI()); 
     fs.copyFromLocalFile(srcPath, dstPath); 
     ... 
    } 
}