Search in sources :

Example 21 with Buffer

use of io.servicetalk.buffer.api.Buffer in project servicetalk by apple.

the class DefaultSerializerSerializationTest method serializeSingleWithSize.

@Test
void serializeSingleWithSize() {
    final Buffer buffer = factory.serialize("Hello", allocator, 1);
    verify(allocator).newBuffer(1);
    assertThat("Unexpected created buffers.", createdBuffers, hasSize(1));
    verify(provider).serialize("Hello", createdBuffers.get(0));
    assertThat("Unexpected serialized buffers.", buffer, equalTo(createdBuffers.get(0)));
}
Also used : Buffer(io.servicetalk.buffer.api.Buffer) Test(org.junit.jupiter.api.Test)

Example 22 with Buffer

use of io.servicetalk.buffer.api.Buffer in project servicetalk by apple.

the class DefaultSerializerSerializationTest method applySerializationForPublisherWithTypeAndEstimator.

@Test
void applySerializationForPublisherWithTypeAndEstimator() {
    TestPublisher<String> source = new TestPublisher<>();
    final Publisher<Buffer> serialized = factory.serialize(source, allocator, String.class, sizeEstimator);
    TestPublisherSubscriber<Buffer> subscriber = new TestPublisherSubscriber<>();
    toSource(serialized).subscribe(subscriber);
    subscriber.awaitSubscription().request(2);
    verify(provider).getSerializer(String.class);
    Buffer expected1 = verifySerializedBufferWithSizes(source, "Hello", 1);
    assertThat(subscriber.takeOnNext(), is(expected1));
    Buffer expected2 = verifySerializedBufferWithSizes(source, "Hello", 2);
    assertThat(subscriber.takeOnNext(), is(expected2));
    source.onComplete();
    subscriber.awaitOnComplete();
}
Also used : Buffer(io.servicetalk.buffer.api.Buffer) TestPublisherSubscriber(io.servicetalk.concurrent.test.internal.TestPublisherSubscriber) TestPublisher(io.servicetalk.concurrent.api.TestPublisher) Test(org.junit.jupiter.api.Test)

Example 23 with Buffer

use of io.servicetalk.buffer.api.Buffer in project servicetalk by apple.

the class DefaultSerializerSerializationTest method drainBlockingIteratorAndVerify.

private <T> void drainBlockingIteratorAndVerify(final Iterable<T> data, final BlockingIterator<T> mockIterator, final BlockingIterable<Buffer> buffers) throws Exception {
    final BlockingIterator<Buffer> iterator = buffers.iterator();
    int index = 0;
    for (T datum : data) {
        assertThat("Incomplete data at index: " + index, iterator.hasNext(1, TimeUnit.MILLISECONDS), is(true));
        final Buffer next = iterator.next(1, TimeUnit.MILLISECONDS);
        assertThat("Unexpected created buffers.", createdBuffers, hasSize(index + 1));
        verify(serializer).serialize(datum, createdBuffers.get(index));
        assertThat("Unexpected data at index: " + index, next, is(createdBuffers.get(index)));
        index++;
    }
    iterator.close();
    verify(mockIterator).close();
}
Also used : Buffer(io.servicetalk.buffer.api.Buffer)

Example 24 with Buffer

use of io.servicetalk.buffer.api.Buffer in project servicetalk by apple.

the class DefaultSerializerSerializationTest method verifySerializedBufferWithSizes.

private <T> Buffer verifySerializedBufferWithSizes(final TestPublisher<T> source, T item, final int sizeEstimate) {
    when(sizeEstimator.applyAsInt(anyInt())).thenReturn(sizeEstimate);
    source.onNext(item);
    verify(allocator).newBuffer(sizeEstimate);
    assertThat("Unexpected created buffers.", createdBuffers, hasSize(1));
    final Buffer serialized = createdBuffers.remove(0);
    verify(sizeEstimator).applyAsInt(sizeEstimate - 1);
    verify(serializer).serialize(item, serialized);
    return serialized;
}
Also used : Buffer(io.servicetalk.buffer.api.Buffer)

Example 25 with Buffer

use of io.servicetalk.buffer.api.Buffer in project servicetalk by apple.

the class DefaultSerializerSerializationTest method serializeSingle.

@Test
void serializeSingle() {
    final Buffer buffer = factory.serialize("Hello", allocator);
    assertThat("Unexpected created buffers.", createdBuffers, hasSize(1));
    verify(provider).serialize("Hello", createdBuffers.get(0));
    assertThat("Unexpected serialized buffers.", buffer, equalTo(createdBuffers.get(0)));
}
Also used : Buffer(io.servicetalk.buffer.api.Buffer) Test(org.junit.jupiter.api.Test)

Aggregations

Buffer (io.servicetalk.buffer.api.Buffer)243 Test (org.junit.jupiter.api.Test)117 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)83 MethodSource (org.junit.jupiter.params.provider.MethodSource)56 StreamingHttpResponse (io.servicetalk.http.api.StreamingHttpResponse)39 StreamingHttpRequest (io.servicetalk.http.api.StreamingHttpRequest)30 StreamingHttpClient (io.servicetalk.http.api.StreamingHttpClient)29 HttpHeaders (io.servicetalk.http.api.HttpHeaders)26 Nullable (javax.annotation.Nullable)24 List (java.util.List)23 EmbeddedChannel (io.netty.channel.embedded.EmbeddedChannel)22 Publisher (io.servicetalk.concurrent.api.Publisher)21 CountDownLatch (java.util.concurrent.CountDownLatch)21 AtomicReference (java.util.concurrent.atomic.AtomicReference)20 CompositeBuffer (io.servicetalk.buffer.api.CompositeBuffer)18 Single (io.servicetalk.concurrent.api.Single)18 InputStream (java.io.InputStream)18 ArrayList (java.util.ArrayList)17 MatcherAssert.assertThat (org.hamcrest.MatcherAssert.assertThat)16 BufferAllocator (io.servicetalk.buffer.api.BufferAllocator)15