Search in sources :

Example 11 with RecordComparatorFactory

use of org.apache.flink.runtime.testutils.recordutils.RecordComparatorFactory in project flink by apache.

the class DataSinkTaskTest method testFailingSortingDataSinkTask.

@Test
@SuppressWarnings("unchecked")
public void testFailingSortingDataSinkTask() {
    int keyCnt = 100;
    int valCnt = 20;
    double memoryFraction = 1.0;
    super.initEnvironment(MEMORY_MANAGER_SIZE, NETWORK_BUFFER_SIZE);
    super.addInput(new UniformRecordGenerator(keyCnt, valCnt, true), 0);
    DataSinkTask<Record> testTask = new DataSinkTask<>(this.mockEnv);
    Configuration stubParams = new Configuration();
    // 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);
    File tempTestFile = new File(tempFolder.getRoot(), UUID.randomUUID().toString());
    super.registerFileOutputTask(MockFailingOutputFormat.class, tempTestFile.toURI().toString(), stubParams);
    boolean stubFailed = false;
    try {
        testTask.invoke();
    } catch (Exception e) {
        stubFailed = true;
    }
    Assert.assertTrue("Function exception was not forwarded.", stubFailed);
    // assert that temp file was removed
    Assert.assertFalse("Temp output file has not been removed", tempTestFile.exists());
}
Also used : RecordComparatorFactory(org.apache.flink.runtime.testutils.recordutils.RecordComparatorFactory) Configuration(org.apache.flink.configuration.Configuration) Record(org.apache.flink.types.Record) UniformRecordGenerator(org.apache.flink.runtime.operators.testutils.UniformRecordGenerator) File(java.io.File) IOException(java.io.IOException) FileNotFoundException(java.io.FileNotFoundException) Test(org.junit.Test)

Aggregations

RecordComparatorFactory (org.apache.flink.runtime.testutils.recordutils.RecordComparatorFactory)11 Record (org.apache.flink.types.Record)11 Test (org.junit.Test)9 SerializationDelegate (org.apache.flink.runtime.plugable.SerializationDelegate)8 RecordSerializerFactory (org.apache.flink.runtime.testutils.recordutils.RecordSerializerFactory)8 IntValue (org.apache.flink.types.IntValue)7 OutputEmitter (org.apache.flink.runtime.operators.shipping.OutputEmitter)4 File (java.io.File)3 FileNotFoundException (java.io.FileNotFoundException)3 IOException (java.io.IOException)3 Configuration (org.apache.flink.configuration.Configuration)3 StringValue (org.apache.flink.types.StringValue)3 UniformRecordGenerator (org.apache.flink.runtime.operators.testutils.UniformRecordGenerator)2 DoubleValue (org.apache.flink.types.DoubleValue)2 NullKeyFieldException (org.apache.flink.types.NullKeyFieldException)2 BufferedReader (java.io.BufferedReader)1 FileReader (java.io.FileReader)1 PipedInputStream (java.io.PipedInputStream)1 PipedOutputStream (java.io.PipedOutputStream)1 HashSet (java.util.HashSet)1