use of org.apache.apex.malhar.lib.wal.FSWindowDataManager in project apex-malhar by apache.
the class AbstractFileInputOperatorTest method testIdempotencyWithMultipleEmitTuples.
@Test
public void testIdempotencyWithMultipleEmitTuples() throws Exception {
FileContext.getLocalFSFileContext().delete(new Path(new File(testMeta.dir).getAbsolutePath()), true);
List<String> allLines = Lists.newArrayList();
for (int file = 0; file < 2; file++) {
List<String> lines = Lists.newArrayList();
for (int line = 0; line < 2; line++) {
lines.add("f" + file + "l" + line);
}
allLines.addAll(lines);
FileUtils.write(new File(testMeta.dir, "file" + file), StringUtils.join(lines, '\n'));
}
LineByLineFileInputOperator oper = new LineByLineFileInputOperator();
FSWindowDataManager manager = new FSWindowDataManager();
manager.setStatePath(testMeta.dir + "/recovery");
oper.setWindowDataManager(manager);
CollectorTestSink<String> queryResults = new CollectorTestSink<String>();
TestUtils.setSink(oper.output, queryResults);
oper.setDirectory(testMeta.dir);
oper.getScanner().setFilePatternRegexp(".*file[\\d]");
oper.setup(testMeta.context);
oper.beginWindow(0);
for (int i = 0; i < 3; i++) {
oper.emitTuples();
}
oper.endWindow();
oper.teardown();
List<String> beforeRecovery = Lists.newArrayList(queryResults.collectedTuples);
queryResults.clear();
// idempotency part
oper.setup(testMeta.context);
oper.beginWindow(0);
oper.endWindow();
Assert.assertEquals("number tuples", 4, queryResults.collectedTuples.size());
Assert.assertEquals("lines", beforeRecovery, queryResults.collectedTuples);
oper.teardown();
}
use of org.apache.apex.malhar.lib.wal.FSWindowDataManager in project apex-malhar by apache.
the class AbstractFileInputOperatorTest method testWindowDataManagerPartitioning.
@Test
public void testWindowDataManagerPartitioning() throws Exception {
LineByLineFileInputOperator oper = new LineByLineFileInputOperator();
oper.getScanner().setFilePatternRegexp(".*partition([\\d]*)");
oper.setDirectory(new File(testMeta.dir).getAbsolutePath());
oper.setWindowDataManager(new FSWindowDataManager());
oper.operatorId = 7;
Path path = new Path(new File(testMeta.dir).getAbsolutePath());
FileContext.getLocalFSFileContext().delete(path, true);
for (int file = 0; file < 4; file++) {
FileUtils.write(new File(testMeta.dir, "partition00" + file), "");
}
List<Partition<AbstractFileInputOperator<String>>> partitions = Lists.newArrayList();
partitions.add(new DefaultPartition<AbstractFileInputOperator<String>>(oper));
Collection<Partition<AbstractFileInputOperator<String>>> newPartitions = oper.definePartitions(partitions, new PartitioningContextImpl(null, 2));
Assert.assertEquals(2, newPartitions.size());
Assert.assertEquals(1, oper.getCurrentPartitions());
List<FSWindowDataManager> storageManagers = Lists.newLinkedList();
for (Partition<AbstractFileInputOperator<String>> p : newPartitions) {
storageManagers.add((FSWindowDataManager) p.getPartitionedInstance().getWindowDataManager());
}
Assert.assertEquals("count of storage managers", 2, storageManagers.size());
int countOfDeleteManagers = 0;
FSWindowDataManager deleteManager = null;
for (FSWindowDataManager storageManager : storageManagers) {
if (storageManager.getDeletedOperators() != null) {
countOfDeleteManagers++;
deleteManager = storageManager;
}
}
Assert.assertEquals("count of delete managers", 1, countOfDeleteManagers);
Assert.assertNotNull("deleted operators manager", deleteManager);
Assert.assertEquals("deleted operators", Sets.newHashSet(7), deleteManager.getDeletedOperators());
}
use of org.apache.apex.malhar.lib.wal.FSWindowDataManager in project apex-malhar by apache.
the class AbstractFileInputOperatorTest method testStateWithIdempotency.
@Test
public void testStateWithIdempotency() throws Exception {
FileContext.getLocalFSFileContext().delete(new Path(new File(testMeta.dir).getAbsolutePath()), true);
HashSet<String> allLines = Sets.newHashSet();
for (int file = 0; file < 3; file++) {
HashSet<String> lines = Sets.newHashSet();
for (int line = 0; line < 2; line++) {
lines.add("f" + file + "l" + line);
}
allLines.addAll(lines);
FileUtils.write(new File(testMeta.dir, "file" + file), StringUtils.join(lines, '\n'));
}
LineByLineFileInputOperator oper = new LineByLineFileInputOperator();
FSWindowDataManager manager = new FSWindowDataManager();
manager.setStatePath(testMeta.dir + "/recovery");
oper.setWindowDataManager(manager);
CollectorTestSink<String> queryResults = new CollectorTestSink<String>();
@SuppressWarnings({ "unchecked", "rawtypes" }) CollectorTestSink<Object> sink = (CollectorTestSink) queryResults;
oper.output.setSink(sink);
oper.setDirectory(testMeta.dir);
oper.getScanner().setFilePatternRegexp(".*file[\\d]");
oper.setup(testMeta.context);
for (long wid = 0; wid < 4; wid++) {
oper.beginWindow(wid);
oper.emitTuples();
oper.endWindow();
}
oper.teardown();
sink.clear();
// idempotency part
oper.pendingFiles.add(new File(testMeta.dir, "file0").getAbsolutePath());
oper.failedFiles.add(new AbstractFileInputOperator.FailedFile(new File(testMeta.dir, "file1").getAbsolutePath(), 0));
oper.unfinishedFiles.add(new AbstractFileInputOperator.FailedFile(new File(testMeta.dir, "file2").getAbsolutePath(), 0));
oper.setup(testMeta.context);
for (long wid = 0; wid < 4; wid++) {
oper.beginWindow(wid);
oper.endWindow();
}
Assert.assertTrue("pending state", !oper.pendingFiles.contains("file0"));
for (AbstractFileInputOperator.FailedFile failedFile : oper.failedFiles) {
Assert.assertTrue("failed state", !failedFile.path.equals("file1"));
}
for (AbstractFileInputOperator.FailedFile unfinishedFile : oper.unfinishedFiles) {
Assert.assertTrue("unfinished state", !unfinishedFile.path.equals("file2"));
}
oper.teardown();
}
use of org.apache.apex.malhar.lib.wal.FSWindowDataManager in project apex-malhar by apache.
the class AbstractKuduOutputOperator method setup.
@Override
public void setup(Context.OperatorContext context) {
super.setup(context);
windowDataManager = getWindowDataManager();
if (windowDataManager == null) {
windowDataManager = new FSWindowDataManager();
}
windowDataManager.setup(context);
}
use of org.apache.apex.malhar.lib.wal.FSWindowDataManager 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();
}
Aggregations