단위 테스트를 실행하고 싶지만 org.apache.hadoop.fs.FileSystem 인스턴스가 있어야합니다. FileSystem을 만드는 모의 또는 다른 솔루션이 있습니까?Hadoop : 단위 테스트 방법 FileSystem
답변
그것은 당신이 하둡 2.0.0을 사용하는 경우 하둡
가능한 한 가지 방법은 임시 폴더 in Junit 4.7입니다.
참조 : http://www.infoq.com/news/2009/07/junit-4.7-rules 또는 http://weblogs.java.net/blog/johnsmart/archive/2009/09/29/working-temporary-files-junit-47.
필자는 (더 나은 해결책을 찾을 때까지) FileSystem을 확장했습니다.
Mockito 또는 PowerMock과 같은 조롱 프레임 워크를 사용하여 사용자의 개입을 FileSystem으로 조롱하는 것은 어떻습니까? 유닛 테스트는 실제 FileSystem에 의존해서는 안되며 FileSystem과 상호 작용할 때 코드의 동작을 검증해야합니다.
없이 테스트 할 수 있도록 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);
RawLocalFileSystem을 살펴볼 수 있습니다. 나는 당신이 그것을 조롱하는 것이 좋을 것이라고 생각하지만.
당신은 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. 단위 테스트하는 방법 Hadoop Writable
- 2. 단위 테스트 조언 - .asmx 단위 테스트 방법
- 3. 단위 테스트 작성 방법
- 4. 단위 테스트 방법 NSCoding?
- 5. 매핑 단위 테스트 방법
- 6. 단위 테스트 개인 방법
- 7. AOP 단위 테스트 방법?
- 8. 단위 테스트 작성 방법?
- 9. 단위 테스트 'SetDefaults()'방법
- 10. 단위 테스트 방법
- 11. IDictionary의 단위 테스트 방법
- 12. 단위 테스트 방법 IDataErrorInfo?
- 13. 단위 테스트 삽입 방법
- 14. 단위 테스트 TimeZones 방법?
- 15. 단위 테스트 서브 클래스 단위 방법
- 16. .NET 단위 테스트 - applicationSettings 테스트 방법
- 17. 단위 테스트 방법 Xtext에 대한 테스트
- 18. Hadoop 파일 단위 블록 크기
- 19. 단위 테스트 GWT + SmartGWT하는 방법?
- 20. 단위 테스트 코드 생성 방법
- 21. 단위 테스트 방법 BackgroundWorker C#
- 22. 단위 테스트 방법 POST를 만드시겠습니까?
- 23. Presenter, MVP의 단위 테스트 방법
- 24. T-SQL 단위 테스트 방법
- 25. CSLA의 단위 테스트? 방법? 뭐?
- 26. 캐시 계층 단위 테스트 방법
- 27. 매크로로 만든 단위 테스트 방법
- 28. 컨트롤을 액세스하는 단위 테스트 방법
- 29. 단위 테스트 방법 CodeIgniter 코드
- 30. 기본 단위 테스트 대 단위 테스트