Search in sources :

Example 11 with Subscriber

use of java.util.concurrent.Flow.Subscriber in project helidon by oracle.

the class MultiPartEncoderTest method testRequests.

@Test
public void testRequests() throws Exception {
    MultiPartEncoder enc = MultiPartEncoder.create("boundary", MEDIA_CONTEXT.writerContext());
    Multi.create(LongStream.range(1, 500).mapToObj(i -> WriteableBodyPart.builder().entity("part" + i).build())).subscribe(enc);
    final CountDownLatch latch = new CountDownLatch(3);
    Subscriber<DataChunk> subscriber = new Subscriber<DataChunk>() {

        @Override
        public void onSubscribe(final Flow.Subscription subscription) {
            subscription.request(3L);
        }

        @Override
        public void onNext(final DataChunk item) {
            latch.countDown();
        }

        @Override
        public void onComplete() {
        }

        @Override
        public void onError(Throwable throwable) {
        }
    };
    enc.subscribe(subscriber);
    waitOnLatch(latch);
}
Also used : DataChunkSubscriber(io.helidon.media.multipart.MultiPartDecoderTest.DataChunkSubscriber) Subscriber(java.util.concurrent.Flow.Subscriber) DataChunk(io.helidon.common.http.DataChunk) CountDownLatch(java.util.concurrent.CountDownLatch) Test(org.junit.jupiter.api.Test)

Aggregations

Subscriber (java.util.concurrent.Flow.Subscriber)11 Test (org.junit.jupiter.api.Test)11 DataChunk (io.helidon.common.http.DataChunk)10 Subscription (java.util.concurrent.Flow.Subscription)10 CompletableFuture (java.util.concurrent.CompletableFuture)9 CountDownLatch (java.util.concurrent.CountDownLatch)9 List (java.util.List)8 TimeUnit (java.util.concurrent.TimeUnit)8 TimeoutException (java.util.concurrent.TimeoutException)8 CoreMatchers.is (org.hamcrest.CoreMatchers.is)8 MatcherAssert.assertThat (org.hamcrest.MatcherAssert.assertThat)8 Multi (io.helidon.common.reactive.Multi)7 CompletionException (java.util.concurrent.CompletionException)7 CompletionStage (java.util.concurrent.CompletionStage)7 Publisher (java.util.concurrent.Flow.Publisher)7 Consumer (java.util.function.Consumer)7 CoreMatchers.hasItems (org.hamcrest.CoreMatchers.hasItems)7 CoreMatchers.notNullValue (org.hamcrest.CoreMatchers.notNullValue)7 CoreMatchers.nullValue (org.hamcrest.CoreMatchers.nullValue)7 Matchers.equalTo (org.hamcrest.Matchers.equalTo)7