Voglio eseguire unit test ma ho bisogno di un'istanza org.apache.hadoop.fs.FileSystem. Esistono finte o altre soluzioni per la creazione di FileSystem?Hadoop: Come testare l'unità FileSystem
risposta
Date un'occhiata al barattolo Hadoop-test
<dependency>
<groupId>org.apache.hadoop</groupId>
<artifactId>hadoop-test</artifactId>
<version>0.20.205.0</version>
</dependency>
si è classificato per la creazione di un MiniDFSCluster e MiniMRCluster modo da poter testare senza Hadoop
Un modo possibile sarebbe utilizzare TemporaryFolder in Junit 4.7.
Vedere: http://www.infoq.com/news/2009/07/junit-4.7-rules o http://weblogs.java.net/blog/johnsmart/archive/2009/09/29/working-temporary-files-junit-47.
Quello che ho fatto (fino a quando non troverò una soluzione migliore) ho esteso il FileSystem.
Perché non utilizzare una struttura di simulazione come Mockito o PowerMock per prendere in giro le tue interazioni con FileSystem? I test dell'unità non devono dipendere da un FileSystem effettivo, ma devono semplicemente verificare il comportamento nel codice nell'interazione con FileSystem.
Se si sta utilizzando Hadoop 2.0.0 e sopra - considerare l'utilizzo di un Hadoop-minicluster
<dependency>
<groupId>org.apache.hadoop</groupId>
<artifactId>hadoop-minicluster</artifactId>
<version>2.5.0</version>
<scope>test</scope>
</dependency>
Con esso, è possibile creare una HDFS temporanei sul computer locale, ed eseguire i test su di esso. Un metodo di impostazione può apparire come segue:
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();
E in un metodo tearDown si dovrebbe spegnere il mini gruppo HDFS, e rimuovere directory temporanea.
hdfsCluster.shutdown();
FileUtil.fullyDelete(baseDir);
Si potrebbe voler dare un'occhiata a RawLocalFileSystem. Anche se penso che faresti meglio a deriderlo.
È possibile utilizzare 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);
...
}
}
- 1. Grep su più file nel filesystem Hadoop
- 2. Hadoop: impossibile impostare FileSystem predefinito come HDFS in core-site.xml
- 3. Provare a testare le operazioni del filesystem con VFSStream
- 4. Hadoop come database archivio documenti
- 5. Readonly filesystem su Linux
- 6. Come distruggere un filesystem
- 7. Qual è il significato delle eccezioni EOF nelle connessioni hadoop namenode da hbase/filesystem?
- 8. Hadoop streaming a python utilizzando mongo-hadoop
- 9. come uccidere job hadoop
- 10. Differenze tra Hadoop-common, Hadoop-core e Hadoop-client?
- 11. Configurazione Hadoop errore
- 12. Streaming di dati e Hadoop? (non Hadoop Streaming)
- 13. Hadoop e Django, è possibile?
- 14. Come imitare os.walk in python con un filesystem temporaneo?
- 15. Filesystem virtuale in Perl
- 16. HTML5 FileSystem API
- 17. Zip FileSystem in Golang
- 18. Gettext senza un filesystem
- 19. Come monto un filesystem usando Python?
- 20. Come usare copy_file in boost :: filesystem?
- 21. Come è implementato fseek() nel filesystem?
- 22. come eseguire boost :: filesystem copy_file con sovrascrittura
- 23. Come simulare/astrarre il filesystem in go?
- 24. Come accedere a un filesystem in java?
- 25. Come implementare un filesystem molto semplice?
- 26. Come iniziare ad imparare hadoop
- 27. Come installare Hadoop su Ubuntu
- 28. Come praticare la programmazione Hadoop?
- 29. Come eseguire un programma Hadoop?
- 30. Come implementare l'ordinamento in hadoop?