2011-11-29 15 views

cevap

6

o size Hadoop 2.0.0 kullanıyorsanız Hadoop

0

Yaptığım şey (daha iyi bir çözüm bulana kadar) FileSystem'i genişlettim.

5

Niçin dosya sisteminizi FileSystem ile eşleştirmek için Mockito veya PowerMock gibi alaycı bir çerçeve kullanmıyorsunuz? Ünite testleriniz gerçek bir FileSystem'e bağlı olmamalıdır, ancak sadece kodunuzdaki davranışları FileSystem ile etkileşimde doğrulamalıdır.

10

olmadan test etmek ve böylece bir MiniDFSCluster ve MiniMRCluster kurmak için sınıflandırılır etti

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

Hadoop-testi kavanoz bir göz atın yukarıdaki - yerel makinede geçici HDF'ler oluşturmak ve üzerinde sizin testleri çalıştırabilirsiniz, bununla beraber

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

bir Hadoop-minicluster kullanmayı düşünün.

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(); 

Ve tearDown yönteminde Eğer mini HDF'ler küme kapatıldı olmalı ve geçici dizini kaldırın: Bir kurulum yöntem bu gibi görünebilir.

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

RawLocalFileSystem'a bir göz atmak isteyebilirsiniz. Yine de, sadece alay etsen iyi olur.

0

Sen HBaseTestingUtility kullanabilirsiniz:

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); 
     ... 
    } 
}