Birim testini çalıştırmak istiyorum ancak org.apache.hadoop.fs.FileSystem örneğim olması gerekiyor. Dosya sistemi oluşturmak için herhangi bir sahte veya başka bir çözüm var mı?Hadoop: Birim testi nasıl yapılır FileSystem
cevap
o size Hadoop 2.0.0 kullanıyorsanız Hadoop
Olası bir yol, TemporaryFolder'un Junit 4.7'de kullanılmasıdır.
Bkz .: http://www.infoq.com/news/2009/07/junit-4.7-rules veya http://weblogs.java.net/blog/johnsmart/archive/2009/09/29/working-temporary-files-junit-47.
Yaptığım şey (daha iyi bir çözüm bulana kadar) FileSystem'i genişlettim.
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.
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);
RawLocalFileSystem'a bir göz atmak isteyebilirsiniz. Yine de, sadece alay etsen iyi olur.
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);
...
}
}
- 1. NSCoding nasıl birim testi yapılır?
- 2. Birim web testi nasıl yapılır - JavaScript
- 3. Çeşitli veri kaynaklarıyla Birim testi nasıl yapılır?
- 4. Birim testi nasıl tanımlanabilir?
- 5. Temel Birim Testi ve Birim Testi
- 6. Birim testi
- 7. Birim testi nasıl yapılır React Component shouldComponentUpdate yöntemi
- 8. Python unittest kullanarak dosya yazma fonksiyonlarının birim testi nasıl yapılır
- 9. Python'da alaylı bir dosya nesnesiyle birim testi nasıl yapılır?
- 10. Android'de gerçek HttpURLConnection ile birim testi nasıl yapılır?
- 11. Windows Phone 8.1 biriminde birim testi nasıl yapılır?
- 12. JMS (ActiveMQ) ile birim testi
- 13. iPhone'da birim testi nasıl çalışır?
- 14. Otomatik C birim testi
- 15. Javascript Sandbox birim testi
- 16. Silverlight 4 Birim Testi
- 17. Birim testi özel sınıflar
- 18. Birim Testi CacheManager
- 19. symfony2 birim testi doğrulama
- 20. C++ Birim Testi
- 21. Birim Testi ASP.net Page_Load
- 22. TaskScheduler.FromCurrentSynchronizationContext - birim testi
- 23. Birim testi Activity.startService() çağrısı?
- 24. Denetleyici birim testi, thin3
- 25. Birim testi NHibernate UserTypes
- 26. Oracle ile birim testi
- 27. CXF birim testi
- 28. Vbscript otomatik/birim testi
- 29. ASP.NET Birim Testi
- 30. Birim testi RavenDb sorguları