Search in sources :

Example 41 with CheckedThread

use of org.apache.flink.core.testutils.CheckedThread in project flink by apache.

the class BoundedBlockingSubpartitionWriteReadTest method testRead10ConsumersConcurrent.

@Test
public void testRead10ConsumersConcurrent() throws Exception {
    final int numLongs = 15_000_000;
    // setup
    final BoundedBlockingSubpartition subpartition = createAndFillPartition(numLongs);
    // test
    final LongReader[] readerThreads = createSubpartitionLongReaders(subpartition, 10, numLongs, subpartition.getBuffersInBacklogUnsafe(), compressionEnabled);
    for (CheckedThread t : readerThreads) {
        t.start();
    }
    // check
    for (CheckedThread t : readerThreads) {
        // this propagates assertion errors out from the threads
        t.sync();
    }
    // cleanup
    subpartition.release();
}
Also used : CheckedThread(org.apache.flink.core.testutils.CheckedThread) Test(org.junit.Test)

Example 42 with CheckedThread

use of org.apache.flink.core.testutils.CheckedThread in project flink by apache.

the class ElasticsearchSinkBaseTest method testAtLeastOnceSink.

/**
 * 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>(), // use a failure handler that simply
    new DummyRetryFailureHandler());
    // 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();
    // 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();
}
Also used : OneInputStreamOperatorTestHarness(org.apache.flink.streaming.util.OneInputStreamOperatorTestHarness) IndexRequest(org.elasticsearch.action.index.IndexRequest) CheckedThread(org.apache.flink.core.testutils.CheckedThread) Test(org.junit.Test)

Example 43 with CheckedThread

use of org.apache.flink.core.testutils.CheckedThread in project flink by apache.

the class JobManagerMetricsITCase method setUp.

@Before
public void setUp() throws Exception {
    jobExecuteThread = new CheckedThread() {

        @Override
        public void go() throws Exception {
            StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment();
            env.addSource(new SourceFunction<String>() {

                @Override
                public void run(SourceContext<String> ctx) throws Exception {
                    sync.block();
                }

                @Override
                public void cancel() {
                    sync.releaseBlocker();
                }
            }).addSink(new PrintSinkFunction());
            env.execute();
        }
    };
    jobExecuteThread.start();
    sync.awaitBlocker();
}
Also used : PrintSinkFunction(org.apache.flink.streaming.api.functions.sink.PrintSinkFunction) StreamExecutionEnvironment(org.apache.flink.streaming.api.environment.StreamExecutionEnvironment) CheckedThread(org.apache.flink.core.testutils.CheckedThread) Before(org.junit.Before)

Example 44 with CheckedThread

use of org.apache.flink.core.testutils.CheckedThread in project flink by apache.

the class AccumulatorLiveITCase method submitJobAndVerifyResults.

private static void submitJobAndVerifyResults(JobGraph jobGraph) throws Exception {
    Deadline deadline = Deadline.now().plus(Duration.ofSeconds(30));
    final ClusterClient<?> client = MINI_CLUSTER_RESOURCE.getClusterClient();
    final CheckedThread submissionThread = new CheckedThread() {

        @Override
        public void go() throws Exception {
            submitJobAndWaitForResult(client, jobGraph, getClass().getClassLoader());
        }
    };
    submissionThread.start();
    try {
        NotifyingMapper.notifyLatch.await();
        // verify using the ClusterClient
        verifyResults(jobGraph, deadline, client);
        // verify using the MiniClusterJobClient
        verifyResults(jobGraph, deadline, null);
        NotifyingMapper.shutdownLatch.trigger();
    } finally {
        NotifyingMapper.shutdownLatch.trigger();
        // wait for the job to have terminated
        submissionThread.sync();
    }
}
Also used : Deadline(org.apache.flink.api.common.time.Deadline) CheckedThread(org.apache.flink.core.testutils.CheckedThread)

Example 45 with CheckedThread

use of org.apache.flink.core.testutils.CheckedThread in project flink by apache.

the class JobRetrievalITCase method testJobRetrieval.

@Test
public void testJobRetrieval() throws Exception {
    final JobVertex imalock = new JobVertex("imalock");
    imalock.setInvokableClass(SemaphoreInvokable.class);
    imalock.setParallelism(1);
    final JobGraph jobGraph = JobGraphTestUtils.streamingJobGraph(imalock);
    final JobID jobId = jobGraph.getJobID();
    // acquire the lock to make sure that the job cannot complete until the job client
    // has been attached in resumingThread
    lock.acquire();
    client.submitJob(jobGraph).get();
    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();
}
Also used : JobGraph(org.apache.flink.runtime.jobgraph.JobGraph) JobVertex(org.apache.flink.runtime.jobgraph.JobVertex) CheckedThread(org.apache.flink.core.testutils.CheckedThread) JobID(org.apache.flink.api.common.JobID) Test(org.junit.Test)

Aggregations

CheckedThread (org.apache.flink.core.testutils.CheckedThread)45 Test (org.junit.Test)41 SimpleStringSchema (org.apache.flink.api.common.serialization.SimpleStringSchema)12 HashMap (java.util.HashMap)8 LinkedList (java.util.LinkedList)8 OneInputStreamOperatorTestHarness (org.apache.flink.streaming.util.OneInputStreamOperatorTestHarness)8 TestableKinesisDataFetcher (org.apache.flink.streaming.connectors.kinesis.testutils.TestableKinesisDataFetcher)7 KinesisStreamShardState (org.apache.flink.streaming.connectors.kinesis.model.KinesisStreamShardState)6 IOException (java.io.IOException)5 Map (java.util.Map)5 CountDownLatch (java.util.concurrent.CountDownLatch)5 OneShotLatch (org.apache.flink.core.testutils.OneShotLatch)5 SequenceNumber (org.apache.flink.streaming.connectors.kinesis.model.SequenceNumber)5 Shard (com.amazonaws.services.kinesis.model.Shard)4 File (java.io.File)4 Random (java.util.Random)4 UserRecordResult (com.amazonaws.services.kinesis.producer.UserRecordResult)3 ArrayList (java.util.ArrayList)3 CompletableFuture (java.util.concurrent.CompletableFuture)3 Configuration (org.apache.flink.configuration.Configuration)3