use of org.apache.flink.runtime.operators.testutils.InfiniteInputIterator in project flink by apache.
the class DataSinkTaskTest method testCancelSortingDataSinkTask.
@Test
@SuppressWarnings("unchecked")
public void testCancelSortingDataSinkTask() {
double memoryFraction = 1.0;
super.initEnvironment(MEMORY_MANAGER_SIZE, NETWORK_BUFFER_SIZE);
super.addInput(new InfiniteInputIterator(), 0);
final DataSinkTask<Record> testTask = new DataSinkTask<>();
Configuration stubParams = new Configuration();
super.getTaskConfig().setStubParameters(stubParams);
// set sorting
super.getTaskConfig().setInputLocalStrategy(0, LocalStrategy.SORT);
super.getTaskConfig().setInputComparator(new RecordComparatorFactory(new int[] { 1 }, (new Class[] { IntValue.class })), 0);
super.getTaskConfig().setRelativeMemoryInput(0, memoryFraction);
super.getTaskConfig().setFilehandlesInput(0, 8);
super.getTaskConfig().setSpillingThresholdInput(0, 0.8f);
super.registerFileOutputTask(testTask, MockOutputFormat.class, new File(tempTestPath).toURI().toString());
Thread taskRunner = new Thread() {
@Override
public void run() {
try {
testTask.invoke();
} catch (Exception ie) {
ie.printStackTrace();
Assert.fail("Task threw exception although it was properly canceled");
}
}
};
taskRunner.start();
TaskCancelThread tct = new TaskCancelThread(2, taskRunner, testTask);
tct.start();
try {
tct.join();
taskRunner.join();
} catch (InterruptedException ie) {
Assert.fail("Joining threads failed");
}
}
use of org.apache.flink.runtime.operators.testutils.InfiniteInputIterator in project flink by apache.
the class DataSinkTaskTest method testCancelDataSinkTask.
@Test
public void testCancelDataSinkTask() throws Exception {
super.initEnvironment(MEMORY_MANAGER_SIZE, NETWORK_BUFFER_SIZE);
super.addInput(new InfiniteInputIterator(), 0);
final DataSinkTask<Record> testTask = new DataSinkTask<>();
Configuration stubParams = new Configuration();
super.getTaskConfig().setStubParameters(stubParams);
super.registerFileOutputTask(testTask, MockOutputFormat.class, new File(tempTestPath).toURI().toString());
Thread taskRunner = new Thread() {
@Override
public void run() {
try {
testTask.invoke();
} catch (Exception ie) {
ie.printStackTrace();
Assert.fail("Task threw exception although it was properly canceled");
}
}
};
taskRunner.start();
File tempTestFile = new File(this.tempTestPath);
// wait until the task created the file
long deadline = System.currentTimeMillis() + 60000;
while (!tempTestFile.exists() && System.currentTimeMillis() < deadline) {
Thread.sleep(10);
}
assertTrue("Task did not create file within 60 seconds", tempTestFile.exists());
// cancel the task
Thread.sleep(500);
testTask.cancel();
taskRunner.interrupt();
// wait for the canceling to complete
taskRunner.join();
// assert that temp file was created
assertFalse("Temp output file has not been removed", tempTestFile.exists());
}
use of org.apache.flink.runtime.operators.testutils.InfiniteInputIterator in project flink by apache.
the class FlatMapTaskTest method testCancelMapTask.
@Test
public void testCancelMapTask() {
addInput(new InfiniteInputIterator());
setOutput(new DiscardingOutputCollector<Record>());
final FlatMapDriver<Record, Record> testTask = new FlatMapDriver<>();
final AtomicBoolean success = new AtomicBoolean(false);
final Thread taskRunner = new Thread() {
@Override
public void run() {
try {
testDriver(testTask, MockMapStub.class);
success.set(true);
} catch (Exception ie) {
ie.printStackTrace();
}
}
};
taskRunner.start();
TaskCancelThread tct = new TaskCancelThread(1, taskRunner, this);
tct.start();
try {
tct.join();
taskRunner.join();
} catch (InterruptedException ie) {
Assert.fail("Joining threads failed");
}
Assert.assertTrue("Test threw an exception even though it was properly canceled.", success.get());
}
Aggregations