use of org.apache.apex.malhar.lib.io.block.BlockMetadata in project apex-malhar by apache.
the class FileSplitterInputTest method testIdempotency.
@Test
public void testIdempotency() throws InterruptedException {
FSWindowDataManager fsIdempotentStorageManager = new FSWindowDataManager();
testMeta.fileSplitterInput.setWindowDataManager(fsIdempotentStorageManager);
testMeta.fileSplitterInput.setup(testMeta.context);
// will emit window 1 from data directory
validateFileMetadataInWindow1();
testMeta.fileMetadataSink.clear();
testMeta.blockMetadataSink.clear();
testMeta.fileSplitterInput.teardown();
testMeta.fileSplitterInput = KryoCloneUtils.cloneObject(testMeta.fileSplitterInput);
testMeta.resetSinks();
testMeta.fileSplitterInput.setup(testMeta.context);
testMeta.fileSplitterInput.beginWindow(1);
Assert.assertEquals("Blocks", 12, testMeta.blockMetadataSink.collectedTuples.size());
for (Object blockMetadata : testMeta.blockMetadataSink.collectedTuples) {
BlockMetadata.FileBlockMetadata metadata = (BlockMetadata.FileBlockMetadata) blockMetadata;
Assert.assertTrue("path: " + metadata.getFilePath(), testMeta.filePaths.contains(metadata.getFilePath()));
}
testMeta.fileSplitterInput.teardown();
}
use of org.apache.apex.malhar.lib.io.block.BlockMetadata in project apex-malhar by apache.
the class FileSplitterInputTest method testRecoveryOfPartialFile.
@Test
public void testRecoveryOfPartialFile() throws InterruptedException {
FSWindowDataManager fsIdempotentStorageManager = new FSWindowDataManager();
testMeta.updateConfig(fsIdempotentStorageManager, 500L, 2L, 2);
FileSplitterInput checkpointedInput = KryoCloneUtils.cloneObject(testMeta.fileSplitterInput);
testMeta.fileSplitterInput.setup(testMeta.context);
testMeta.fileSplitterInput.beginWindow(1);
testMeta.scanner.semaphore.acquire(12);
testMeta.fileSplitterInput.emitTuples();
testMeta.fileSplitterInput.endWindow();
// fileX.txt has just 6 blocks. Since blocks threshold is 2, only 2 are emitted.
Assert.assertEquals("Files", 1, testMeta.fileMetadataSink.collectedTuples.size());
Assert.assertEquals("Blocks", 2, testMeta.blockMetadataSink.collectedTuples.size());
AbstractFileSplitter.FileMetadata fileX = testMeta.fileMetadataSink.collectedTuples.get(0);
testMeta.fileMetadataSink.clear();
testMeta.blockMetadataSink.clear();
testMeta.fileSplitterInput.teardown();
// there was a failure and the operator was re-deployed
testMeta.fileSplitterInput = checkpointedInput;
testMeta.resetSinks();
testMeta.fileSplitterInput.setup(testMeta.context);
testMeta.fileSplitterInput.beginWindow(1);
// fileX is recovered and first two blocks are repeated.
Assert.assertEquals("Recovered Files", 1, testMeta.fileMetadataSink.collectedTuples.size());
AbstractFileSplitter.FileMetadata fileXRecovered = testMeta.fileMetadataSink.collectedTuples.get(0);
Assert.assertEquals("recovered file-metadata", fileX.getFileName(), fileXRecovered.getFileName());
Assert.assertEquals("Recovered Blocks", 2, testMeta.blockMetadataSink.collectedTuples.size());
testMeta.fileSplitterInput.endWindow();
testMeta.fileMetadataSink.clear();
testMeta.blockMetadataSink.clear();
testMeta.fileSplitterInput.beginWindow(2);
// next 2 blocks of fileX
testMeta.fileSplitterInput.emitTuples();
testMeta.fileSplitterInput.endWindow();
testMeta.fileSplitterInput.beginWindow(3);
// next 2 blocks of fileX
testMeta.fileSplitterInput.emitTuples();
testMeta.fileSplitterInput.endWindow();
// Next 2 blocks of fileX
Assert.assertEquals("File", 0, testMeta.fileMetadataSink.collectedTuples.size());
Assert.assertEquals("Blocks", 4, testMeta.blockMetadataSink.collectedTuples.size());
testMeta.fileMetadataSink.clear();
testMeta.blockMetadataSink.clear();
testMeta.fileSplitterInput.beginWindow(4);
((MockScanner) testMeta.fileSplitterInput.getScanner()).semaphore.acquire(11);
testMeta.fileSplitterInput.emitTuples();
testMeta.fileSplitterInput.endWindow();
// 2 blocks of a different file
Assert.assertEquals("New file", 1, testMeta.fileMetadataSink.collectedTuples.size());
Assert.assertEquals("Blocks", 2, testMeta.blockMetadataSink.collectedTuples.size());
AbstractFileSplitter.FileMetadata fileY = testMeta.fileMetadataSink.collectedTuples.get(0);
for (BlockMetadata.FileBlockMetadata blockMetadata : testMeta.blockMetadataSink.collectedTuples) {
Assert.assertTrue("Block file name", blockMetadata.getFilePath().endsWith(fileY.getFileName()));
testMeta.fileSplitterInput.teardown();
}
}
use of org.apache.apex.malhar.lib.io.block.BlockMetadata in project apex-malhar by apache.
the class FileSplitterTest method testIdempotency.
@Test
public void testIdempotency() throws InterruptedException {
FSWindowDataManager fsWindowDataManager = new FSWindowDataManager();
testMeta.fileSplitter.setWindowDataManager(fsWindowDataManager);
testMeta.fileSplitter.setup(testMeta.context);
// will emit window 1 from data directory
testFileMetadata();
testMeta.fileMetadataSink.clear();
testMeta.blockMetadataSink.clear();
testMeta.fileSplitter.setup(testMeta.context);
testMeta.fileSplitter.beginWindow(1);
Assert.assertEquals("Blocks", 12, testMeta.blockMetadataSink.collectedTuples.size());
for (Object blockMetadata : testMeta.blockMetadataSink.collectedTuples) {
BlockMetadata.FileBlockMetadata metadata = (BlockMetadata.FileBlockMetadata) blockMetadata;
Assert.assertTrue("path: " + metadata.getFilePath(), testMeta.filePaths.contains(metadata.getFilePath()));
}
}
Aggregations