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)));
}
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();
}
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();
}
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;
}
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)));
}
Aggregations