Java Code Examples for org.apache.flink.core.testutils.CheckedThread#getState()
The following examples show how to use
org.apache.flink.core.testutils.CheckedThread#getState() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: JobRetrievalITCase.java From flink with Apache License 2.0 | 5 votes |
@Test public void testJobRetrieval() throws Exception { final JobID jobID = new JobID(); final JobVertex imalock = new JobVertex("imalock"); imalock.setInvokableClass(SemaphoreInvokable.class); final JobGraph jobGraph = new JobGraph(jobID, "testjob", imalock); // acquire the lock to make sure that the job cannot complete until the job client // has been attached in resumingThread lock.acquire(); ClientUtils.submitJob(client, jobGraph); final CheckedThread resumingThread = new CheckedThread("Flink-Job-Retriever") { @Override public void go() throws Exception { assertNotNull(client.requestJobResult(jobID).get()); } }; // wait until the job is running while (client.listJobs().get().isEmpty()) { Thread.sleep(50); } // kick off resuming resumingThread.start(); // wait for client to connect while (resumingThread.getState() != Thread.State.WAITING) { Thread.sleep(10); } // client has connected, we can release the lock lock.release(); resumingThread.sync(); }
Example 2
Source File: ElasticsearchSinkBaseTest.java From Flink-CEPplus with Apache License 2.0 | 4 votes |
/** * Tests that any item failure in the listener callbacks due to flushing on an immediately following checkpoint * is rethrown; we set a timeout because the test will not finish if the logic is broken. */ @Test(timeout = 5000) public void testItemFailureRethrownOnCheckpointAfterFlush() 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 its mock item failures List<Exception> mockResponsesList = new ArrayList<>(2); mockResponsesList.add(null); // the first request in a bulk will succeed mockResponsesList.add(new Exception("artificial failure for record")); // the second request in a bulk will fail sink.setMockItemFailuresListForNextBulkItemResponses(mockResponsesList); testHarness.processElement(new StreamRecord<>("msg-1")); verify(sink.getMockBulkProcessor(), times(1)).add(any(IndexRequest.class)); // manually execute the next bulk request (1 request only, thus should succeed) sink.manualBulkRequestWithAllPendingRequests(); // setup the requests to be flushed in the snapshot testHarness.processElement(new StreamRecord<>("msg-2")); testHarness.processElement(new StreamRecord<>("msg-3")); verify(sink.getMockBulkProcessor(), times(3)).add(any(IndexRequest.class)); CheckedThread snapshotThread = new CheckedThread() { @Override public void go() throws Exception { testHarness.snapshot(1L, 1000L); } }; snapshotThread.start(); // the snapshot should eventually be blocked before snapshot triggers flushing while (snapshotThread.getState() != Thread.State.WAITING) { Thread.sleep(10); } // let the snapshot-triggered flush continue (2 records in the bulk, so the 2nd one should fail) sink.continueFlush(); try { snapshotThread.sync(); } catch (Exception e) { // the snapshot should have failed with the failure from the 2nd request Assert.assertTrue(e.getCause().getCause().getMessage().contains("artificial failure for record")); // test succeeded return; } Assert.fail(); }
Example 3
Source File: ElasticsearchSinkBaseTest.java From Flink-CEPplus with Apache License 2.0 | 4 votes |
/** * Tests that any bulk failure in the listener callbacks due to flushing on an immediately following checkpoint * is rethrown; we set a timeout because the test will not finish if the logic is broken. */ @Test(timeout = 5000) public void testBulkFailureRethrownOnOnCheckpointAfterFlush() 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 bulk request succeed sink.setMockItemFailuresListForNextBulkItemResponses(Collections.singletonList((Exception) null)); testHarness.processElement(new StreamRecord<>("msg-1")); verify(sink.getMockBulkProcessor(), times(1)).add(any(IndexRequest.class)); // manually execute the next bulk request sink.manualBulkRequestWithAllPendingRequests(); // setup the requests to be flushed in the snapshot testHarness.processElement(new StreamRecord<>("msg-2")); testHarness.processElement(new StreamRecord<>("msg-3")); verify(sink.getMockBulkProcessor(), times(3)).add(any(IndexRequest.class)); CheckedThread snapshotThread = new CheckedThread() { @Override public void go() throws Exception { testHarness.snapshot(1L, 1000L); } }; snapshotThread.start(); // the snapshot should eventually be blocked before snapshot triggers flushing while (snapshotThread.getState() != Thread.State.WAITING) { Thread.sleep(10); } // for the snapshot-triggered flush, we let the bulk request fail completely sink.setFailNextBulkRequestCompletely(new Exception("artificial failure for bulk request")); // let the snapshot-triggered flush continue (bulk request should fail completely) sink.continueFlush(); try { snapshotThread.sync(); } catch (Exception e) { // the snapshot should have failed with the bulk request failure Assert.assertTrue(e.getCause().getCause().getMessage().contains("artificial failure for bulk request")); // test succeeded return; } Assert.fail(); }
Example 4
Source File: ElasticsearchSinkBaseTest.java From Flink-CEPplus with Apache License 2.0 | 4 votes |
/** * Tests that the sink correctly waits for pending requests (including re-added requests) on checkpoints; * we set a timeout because the test will not finish if the logic is broken. */ @Test(timeout = 5000) public void testAtLeastOnceSink() throws Throwable { final DummyElasticsearchSink<String> sink = new DummyElasticsearchSink<>( new HashMap<String, String>(), new SimpleSinkFunction<String>(), new DummyRetryFailureHandler()); // use a failure handler that simply re-adds requests final OneInputStreamOperatorTestHarness<String, Object> testHarness = new OneInputStreamOperatorTestHarness<>(new StreamSink<>(sink)); testHarness.open(); // setup the next bulk request, and its mock item failures; // it contains 1 request, which will fail and re-added to the next bulk request sink.setMockItemFailuresListForNextBulkItemResponses(Collections.singletonList(new Exception("artificial failure for record"))); testHarness.processElement(new StreamRecord<>("msg")); verify(sink.getMockBulkProcessor(), times(1)).add(any(IndexRequest.class)); CheckedThread snapshotThread = new CheckedThread() { @Override public void go() throws Exception { testHarness.snapshot(1L, 1000L); } }; snapshotThread.start(); // the snapshot should eventually be blocked before snapshot triggers flushing while (snapshotThread.getState() != Thread.State.WAITING) { Thread.sleep(10); } sink.continueFlush(); // since the previous flush should have resulted in a request re-add from the failure handler, // we should have flushed again, and eventually be blocked before snapshot triggers the 2nd flush while (snapshotThread.getState() != Thread.State.WAITING) { Thread.sleep(10); } // current number of pending request should be 1 due to the re-add Assert.assertEquals(1, sink.getNumPendingRequests()); // this time, let the bulk request succeed, so no-more requests are re-added sink.setMockItemFailuresListForNextBulkItemResponses(Collections.singletonList((Exception) null)); sink.continueFlush(); // the snapshot should finish with no exceptions snapshotThread.sync(); testHarness.close(); }
Example 5
Source File: JobRetrievalITCase.java From Flink-CEPplus with Apache License 2.0 | 4 votes |
@Test public void testJobRetrieval() throws Exception { final JobID jobID = new JobID(); final JobVertex imalock = new JobVertex("imalock"); imalock.setInvokableClass(SemaphoreInvokable.class); final JobGraph jobGraph = new JobGraph(jobID, "testjob", imalock); // acquire the lock to make sure that the job cannot complete until the job client // has been attached in resumingThread lock.acquire(); client.setDetached(true); client.submitJob(jobGraph, JobRetrievalITCase.class.getClassLoader()); final CheckedThread resumingThread = new CheckedThread("Flink-Job-Retriever") { @Override public void go() throws Exception { assertNotNull(client.requestJobResult(jobID).get()); } }; // wait until the job is running while (client.listJobs().get().isEmpty()) { Thread.sleep(50); } // kick off resuming resumingThread.start(); // wait for client to connect while (resumingThread.getState() != Thread.State.WAITING) { Thread.sleep(10); } // client has connected, we can release the lock lock.release(); resumingThread.sync(); }
Example 6
Source File: ElasticsearchSinkBaseTest.java From flink with Apache License 2.0 | 4 votes |
/** * Tests that any item failure in the listener callbacks due to flushing on an immediately following checkpoint * is rethrown; we set a timeout because the test will not finish if the logic is broken. */ @Test(timeout = 5000) public void testItemFailureRethrownOnCheckpointAfterFlush() 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 its mock item failures List<Exception> mockResponsesList = new ArrayList<>(2); mockResponsesList.add(null); // the first request in a bulk will succeed mockResponsesList.add(new Exception("artificial failure for record")); // the second request in a bulk will fail sink.setMockItemFailuresListForNextBulkItemResponses(mockResponsesList); testHarness.processElement(new StreamRecord<>("msg-1")); verify(sink.getMockBulkProcessor(), times(1)).add(any(IndexRequest.class)); // manually execute the next bulk request (1 request only, thus should succeed) sink.manualBulkRequestWithAllPendingRequests(); // setup the requests to be flushed in the snapshot testHarness.processElement(new StreamRecord<>("msg-2")); testHarness.processElement(new StreamRecord<>("msg-3")); verify(sink.getMockBulkProcessor(), times(3)).add(any(IndexRequest.class)); CheckedThread snapshotThread = new CheckedThread() { @Override public void go() throws Exception { testHarness.snapshot(1L, 1000L); } }; snapshotThread.start(); // the snapshot should eventually be blocked before snapshot triggers flushing while (snapshotThread.getState() != Thread.State.WAITING) { Thread.sleep(10); } // let the snapshot-triggered flush continue (2 records in the bulk, so the 2nd one should fail) sink.continueFlush(); try { snapshotThread.sync(); } catch (Exception e) { // the snapshot should have failed with the failure from the 2nd request Assert.assertTrue(e.getCause().getCause().getMessage().contains("artificial failure for record")); // test succeeded return; } Assert.fail(); }
Example 7
Source File: ElasticsearchSinkBaseTest.java From flink with Apache License 2.0 | 4 votes |
/** * Tests that any bulk failure in the listener callbacks due to flushing on an immediately following checkpoint * is rethrown; we set a timeout because the test will not finish if the logic is broken. */ @Test(timeout = 5000) public void testBulkFailureRethrownOnOnCheckpointAfterFlush() 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 bulk request succeed sink.setMockItemFailuresListForNextBulkItemResponses(Collections.singletonList((Exception) null)); testHarness.processElement(new StreamRecord<>("msg-1")); verify(sink.getMockBulkProcessor(), times(1)).add(any(IndexRequest.class)); // manually execute the next bulk request sink.manualBulkRequestWithAllPendingRequests(); // setup the requests to be flushed in the snapshot testHarness.processElement(new StreamRecord<>("msg-2")); testHarness.processElement(new StreamRecord<>("msg-3")); verify(sink.getMockBulkProcessor(), times(3)).add(any(IndexRequest.class)); CheckedThread snapshotThread = new CheckedThread() { @Override public void go() throws Exception { testHarness.snapshot(1L, 1000L); } }; snapshotThread.start(); // the snapshot should eventually be blocked before snapshot triggers flushing while (snapshotThread.getState() != Thread.State.WAITING) { Thread.sleep(10); } // for the snapshot-triggered flush, we let the bulk request fail completely sink.setFailNextBulkRequestCompletely(new Exception("artificial failure for bulk request")); // let the snapshot-triggered flush continue (bulk request should fail completely) sink.continueFlush(); try { snapshotThread.sync(); } catch (Exception e) { // the snapshot should have failed with the bulk request failure Assert.assertTrue(e.getCause().getCause().getMessage().contains("artificial failure for bulk request")); // test succeeded return; } Assert.fail(); }
Example 8
Source File: ElasticsearchSinkBaseTest.java From flink with Apache License 2.0 | 4 votes |
/** * Tests that the sink correctly waits for pending requests (including re-added requests) on checkpoints; * we set a timeout because the test will not finish if the logic is broken. */ @Test(timeout = 5000) public void testAtLeastOnceSink() throws Throwable { final DummyElasticsearchSink<String> sink = new DummyElasticsearchSink<>( new HashMap<String, String>(), new SimpleSinkFunction<String>(), new DummyRetryFailureHandler()); // use a failure handler that simply re-adds requests final OneInputStreamOperatorTestHarness<String, Object> testHarness = new OneInputStreamOperatorTestHarness<>(new StreamSink<>(sink)); testHarness.open(); // setup the next bulk request, and its mock item failures; // it contains 1 request, which will fail and re-added to the next bulk request sink.setMockItemFailuresListForNextBulkItemResponses(Collections.singletonList(new Exception("artificial failure for record"))); testHarness.processElement(new StreamRecord<>("msg")); verify(sink.getMockBulkProcessor(), times(1)).add(any(IndexRequest.class)); CheckedThread snapshotThread = new CheckedThread() { @Override public void go() throws Exception { testHarness.snapshot(1L, 1000L); } }; snapshotThread.start(); // the snapshot should eventually be blocked before snapshot triggers flushing while (snapshotThread.getState() != Thread.State.WAITING) { Thread.sleep(10); } sink.continueFlush(); // since the previous flush should have resulted in a request re-add from the failure handler, // we should have flushed again, and eventually be blocked before snapshot triggers the 2nd flush while (snapshotThread.getState() != Thread.State.WAITING) { Thread.sleep(10); } // current number of pending request should be 1 due to the re-add Assert.assertEquals(1, sink.getNumPendingRequests()); // this time, let the bulk request succeed, so no-more requests are re-added sink.setMockItemFailuresListForNextBulkItemResponses(Collections.singletonList((Exception) null)); sink.continueFlush(); // the snapshot should finish with no exceptions snapshotThread.sync(); testHarness.close(); }
Example 9
Source File: JobRetrievalITCase.java From flink with Apache License 2.0 | 4 votes |
@Test public void testJobRetrieval() throws Exception { final JobID jobID = new JobID(); final JobVertex imalock = new JobVertex("imalock"); imalock.setInvokableClass(SemaphoreInvokable.class); final JobGraph jobGraph = new JobGraph(jobID, "testjob", imalock); // acquire the lock to make sure that the job cannot complete until the job client // has been attached in resumingThread lock.acquire(); client.setDetached(true); client.submitJob(jobGraph, JobRetrievalITCase.class.getClassLoader()); final CheckedThread resumingThread = new CheckedThread("Flink-Job-Retriever") { @Override public void go() throws Exception { assertNotNull(client.requestJobResult(jobID).get()); } }; // wait until the job is running while (client.listJobs().get().isEmpty()) { Thread.sleep(50); } // kick off resuming resumingThread.start(); // wait for client to connect while (resumingThread.getState() != Thread.State.WAITING) { Thread.sleep(10); } // client has connected, we can release the lock lock.release(); resumingThread.sync(); }
Example 10
Source File: ElasticsearchSinkBaseTest.java From flink with Apache License 2.0 | 4 votes |
/** * Tests that any item failure in the listener callbacks due to flushing on an immediately following checkpoint * is rethrown; we set a timeout because the test will not finish if the logic is broken. */ @Test(timeout = 5000) public void testItemFailureRethrownOnCheckpointAfterFlush() 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 its mock item failures List<Exception> mockResponsesList = new ArrayList<>(2); mockResponsesList.add(null); // the first request in a bulk will succeed mockResponsesList.add(new Exception("artificial failure for record")); // the second request in a bulk will fail sink.setMockItemFailuresListForNextBulkItemResponses(mockResponsesList); testHarness.processElement(new StreamRecord<>("msg-1")); verify(sink.getMockBulkProcessor(), times(1)).add(any(IndexRequest.class)); // manually execute the next bulk request (1 request only, thus should succeed) sink.manualBulkRequestWithAllPendingRequests(); // setup the requests to be flushed in the snapshot testHarness.processElement(new StreamRecord<>("msg-2")); testHarness.processElement(new StreamRecord<>("msg-3")); verify(sink.getMockBulkProcessor(), times(3)).add(any(IndexRequest.class)); CheckedThread snapshotThread = new CheckedThread() { @Override public void go() throws Exception { testHarness.snapshot(1L, 1000L); } }; snapshotThread.start(); // the snapshot should eventually be blocked before snapshot triggers flushing while (snapshotThread.getState() != Thread.State.WAITING) { Thread.sleep(10); } // let the snapshot-triggered flush continue (2 records in the bulk, so the 2nd one should fail) sink.continueFlush(); try { snapshotThread.sync(); } catch (Exception e) { // the snapshot should have failed with the failure from the 2nd request Assert.assertTrue(e.getCause().getCause().getMessage().contains("artificial failure for record")); // test succeeded return; } Assert.fail(); }
Example 11
Source File: ElasticsearchSinkBaseTest.java From flink with Apache License 2.0 | 4 votes |
/** * Tests that any bulk failure in the listener callbacks due to flushing on an immediately following checkpoint * is rethrown; we set a timeout because the test will not finish if the logic is broken. */ @Test(timeout = 5000) public void testBulkFailureRethrownOnOnCheckpointAfterFlush() 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 bulk request succeed sink.setMockItemFailuresListForNextBulkItemResponses(Collections.singletonList((Exception) null)); testHarness.processElement(new StreamRecord<>("msg-1")); verify(sink.getMockBulkProcessor(), times(1)).add(any(IndexRequest.class)); // manually execute the next bulk request sink.manualBulkRequestWithAllPendingRequests(); // setup the requests to be flushed in the snapshot testHarness.processElement(new StreamRecord<>("msg-2")); testHarness.processElement(new StreamRecord<>("msg-3")); verify(sink.getMockBulkProcessor(), times(3)).add(any(IndexRequest.class)); CheckedThread snapshotThread = new CheckedThread() { @Override public void go() throws Exception { testHarness.snapshot(1L, 1000L); } }; snapshotThread.start(); // the snapshot should eventually be blocked before snapshot triggers flushing while (snapshotThread.getState() != Thread.State.WAITING) { Thread.sleep(10); } // for the snapshot-triggered flush, we let the bulk request fail completely sink.setFailNextBulkRequestCompletely(new Exception("artificial failure for bulk request")); // let the snapshot-triggered flush continue (bulk request should fail completely) sink.continueFlush(); try { snapshotThread.sync(); } catch (Exception e) { // the snapshot should have failed with the bulk request failure Assert.assertTrue(e.getCause().getCause().getMessage().contains("artificial failure for bulk request")); // test succeeded return; } Assert.fail(); }
Example 12
Source File: ElasticsearchSinkBaseTest.java From flink with Apache License 2.0 | 4 votes |
/** * Tests that the sink correctly waits for pending requests (including re-added requests) on checkpoints; * we set a timeout because the test will not finish if the logic is broken. */ @Test(timeout = 5000) public void testAtLeastOnceSink() throws Throwable { final DummyElasticsearchSink<String> sink = new DummyElasticsearchSink<>( new HashMap<String, String>(), new SimpleSinkFunction<String>(), new DummyRetryFailureHandler()); // use a failure handler that simply re-adds requests final OneInputStreamOperatorTestHarness<String, Object> testHarness = new OneInputStreamOperatorTestHarness<>(new StreamSink<>(sink)); testHarness.open(); // setup the next bulk request, and its mock item failures; // it contains 1 request, which will fail and re-added to the next bulk request sink.setMockItemFailuresListForNextBulkItemResponses(Collections.singletonList(new Exception("artificial failure for record"))); testHarness.processElement(new StreamRecord<>("msg")); verify(sink.getMockBulkProcessor(), times(1)).add(any(IndexRequest.class)); CheckedThread snapshotThread = new CheckedThread() { @Override public void go() throws Exception { testHarness.snapshot(1L, 1000L); } }; snapshotThread.start(); // the snapshot should eventually be blocked before snapshot triggers flushing while (snapshotThread.getState() != Thread.State.WAITING) { Thread.sleep(10); } sink.continueFlush(); // since the previous flush should have resulted in a request re-add from the failure handler, // we should have flushed again, and eventually be blocked before snapshot triggers the 2nd flush while (snapshotThread.getState() != Thread.State.WAITING) { Thread.sleep(10); } // current number of pending request should be 1 due to the re-add Assert.assertEquals(1, sink.getNumPendingRequests()); // this time, let the bulk request succeed, so no-more requests are re-added sink.setMockItemFailuresListForNextBulkItemResponses(Collections.singletonList((Exception) null)); sink.continueFlush(); // the snapshot should finish with no exceptions snapshotThread.sync(); testHarness.close(); }