Search in sources :

Example 1 with AnnotatedDataSetCallback

use of org.apache.camel.component.flink.annotations.AnnotatedDataSetCallback in project camel by apache.

the class FlinkProducerTest method shouldExecuteAnnotatedCallback.

@Test
public void shouldExecuteAnnotatedCallback() {
    DataSetCallback dataSetCallback = new AnnotatedDataSetCallback(new Object() {

        @org.apache.camel.component.flink.annotations.DataSetCallback
        Long countLines(DataSet<String> textFile) {
            try {
                return textFile.count();
            } catch (Exception e) {
                return null;
            }
        }
    });
    long pomLinesCount = template.requestBodyAndHeader(flinkDataSetUri, null, FlinkConstants.FLINK_DATASET_CALLBACK_HEADER, dataSetCallback, Long.class);
    Truth.assertThat(pomLinesCount).isEqualTo(19);
}
Also used : AnnotatedDataSetCallback(org.apache.camel.component.flink.annotations.AnnotatedDataSetCallback) AnnotatedDataSetCallback(org.apache.camel.component.flink.annotations.AnnotatedDataSetCallback) IOException(java.io.IOException) Test(org.junit.Test)

Example 2 with AnnotatedDataSetCallback

use of org.apache.camel.component.flink.annotations.AnnotatedDataSetCallback in project camel by apache.

the class FlinkProducerTest method shouldExecuteAnnotatedVoidCallback.

@Test
public void shouldExecuteAnnotatedVoidCallback() throws IOException {
    final File output = File.createTempFile("camel", "flink");
    output.delete();
    DataSetCallback dataSetCallback = new AnnotatedDataSetCallback(new Object() {

        @org.apache.camel.component.flink.annotations.DataSetCallback
        void countLines(DataSet<String> textFile) {
            textFile.writeAsText(output.getAbsolutePath());
        }
    });
    template.sendBodyAndHeader(flinkDataSetUri, null, FlinkConstants.FLINK_DATASET_CALLBACK_HEADER, dataSetCallback);
    Truth.assertThat(output.length()).isAtLeast(0L);
}
Also used : AnnotatedDataSetCallback(org.apache.camel.component.flink.annotations.AnnotatedDataSetCallback) AnnotatedDataSetCallback(org.apache.camel.component.flink.annotations.AnnotatedDataSetCallback) File(java.io.File) Test(org.junit.Test)

Example 3 with AnnotatedDataSetCallback

use of org.apache.camel.component.flink.annotations.AnnotatedDataSetCallback in project camel by apache.

the class FlinkProducerTest method shouldExecuteAnnotatedCallbackWithParameters.

@Test
public void shouldExecuteAnnotatedCallbackWithParameters() {
    DataSetCallback dataSetCallback = new AnnotatedDataSetCallback(new Object() {

        @org.apache.camel.component.flink.annotations.DataSetCallback
        Long countLines(DataSet<String> textFile, int first, int second) {
            try {
                return textFile.count() * first * second;
            } catch (Exception e) {
                return null;
            }
        }
    });
    long pomLinesCount = template.requestBodyAndHeader(flinkDataSetUri, Arrays.<Integer>asList(10, 10), FlinkConstants.FLINK_DATASET_CALLBACK_HEADER, dataSetCallback, Long.class);
    Truth.assertThat(pomLinesCount).isEqualTo(numberOfLinesInTestFile * 10 * 10);
}
Also used : AnnotatedDataSetCallback(org.apache.camel.component.flink.annotations.AnnotatedDataSetCallback) AnnotatedDataSetCallback(org.apache.camel.component.flink.annotations.AnnotatedDataSetCallback) IOException(java.io.IOException) Test(org.junit.Test)

Aggregations

AnnotatedDataSetCallback (org.apache.camel.component.flink.annotations.AnnotatedDataSetCallback)3 Test (org.junit.Test)3 IOException (java.io.IOException)2 File (java.io.File)1