Search in sources :

Example 6 with NoOpFailureHandler

use of org.apache.flink.streaming.connectors.elasticsearch.util.NoOpFailureHandler in project flink by apache.

the class ElasticsearchSinkBaseTest method testBulkFailureRethrownOnInvoke.

/** Tests that any bulk failure in the listener callbacks is rethrown on an immediately following invoke call. */
@Test
public void testBulkFailureRethrownOnInvoke() throws Throwable {
    final DummyElasticsearchSink<String> sink = new DummyElasticsearchSink<>(new HashMap<String, String>(), new SimpleSinkFunction<String>(), new NoOpFailureHandler());
    final OneInputStreamOperatorTestHarness<String, Object> testHarness = new OneInputStreamOperatorTestHarness<>(new StreamSink<>(sink));
    testHarness.open();
    // setup the next bulk request, and let the whole bulk request fail
    sink.setFailNextBulkRequestCompletely(new Exception("artificial failure for bulk request"));
    testHarness.processElement(new StreamRecord<>("msg"));
    verify(sink.getMockBulkProcessor(), times(1)).add(any(ActionRequest.class));
    // manually execute the next bulk request
    sink.manualBulkRequestWithAllPendingRequests();
    try {
        testHarness.processElement(new StreamRecord<>("next msg"));
    } catch (Exception e) {
        // the invoke should have failed with the bulk request failure
        Assert.assertTrue(e.getCause().getMessage().contains("artificial failure for bulk request"));
        // test succeeded
        return;
    }
    Assert.fail();
}
Also used : NoOpFailureHandler(org.apache.flink.streaming.connectors.elasticsearch.util.NoOpFailureHandler) OneInputStreamOperatorTestHarness(org.apache.flink.streaming.util.OneInputStreamOperatorTestHarness) ActionRequest(org.elasticsearch.action.ActionRequest) Test(org.junit.Test)

Aggregations

NoOpFailureHandler (org.apache.flink.streaming.connectors.elasticsearch.util.NoOpFailureHandler)6 OneInputStreamOperatorTestHarness (org.apache.flink.streaming.util.OneInputStreamOperatorTestHarness)6 ActionRequest (org.elasticsearch.action.ActionRequest)6 Test (org.junit.Test)6 CheckedThread (org.apache.flink.core.testutils.CheckedThread)2 ArrayList (java.util.ArrayList)1