use of io.confluent.kafkarest.controllers.RecordSerializer in project kafka-rest by confluentinc.
the class ProduceActionTest method getProduceAction.
private static ProduceAction getProduceAction(ProduceRateLimiters produceRateLimiters, ChunkedOutputFactory chunkedOutputFactory, int times, int producerId, boolean errorSchemaRegistry) {
Provider<SchemaManager> schemaManagerProvider = mock(Provider.class);
SchemaManager schemaManagerMock = mock(SchemaManager.class);
expect(schemaManagerProvider.get()).andReturn(schemaManagerMock);
expect(schemaManagerMock.getSchema("topicName", Optional.of(EmbeddedFormat.AVRO), Optional.empty(), Optional.empty(), Optional.empty(), Optional.empty(), Optional.of("bob"), true)).andThrow(Errors.invalidPayloadException("Schema Registry must be configured when using schemas."));
replay(schemaManagerProvider, schemaManagerMock);
Provider<ProducerMetrics> producerMetricsProvider = mock(Provider.class);
getProducerMetricsProvider(producerMetricsProvider);
Provider<RecordSerializer> recordSerializerProvider = getRecordSerializerProvider(errorSchemaRegistry);
Provider<ProduceController> produceControllerProvider = mock(Provider.class);
ProduceController produceController = getProduceControllerMock(produceControllerProvider);
setupExpectsMockCallsForProduce(produceController, times, producerId);
replay(producerMetricsProvider, produceControllerProvider, produceController);
StreamingResponseFactory streamingResponseFactory = new StreamingResponseFactory(chunkedOutputFactory);
// get the current thread so that the call counts can be seen by easy mock
ExecutorService executorService = MoreExecutors.newDirectExecutorService();
ProduceAction produceAction = new ProduceAction(schemaManagerProvider, recordSerializerProvider, produceControllerProvider, producerMetricsProvider, streamingResponseFactory, produceRateLimiters, executorService);
produceRateLimiters.clear();
return produceAction;
}
use of io.confluent.kafkarest.controllers.RecordSerializer in project kafka-rest by confluentinc.
the class ProduceActionTest method getRecordSerializerProvider.
private static Provider<RecordSerializer> getRecordSerializerProvider(boolean error) {
Provider<RecordSerializer> recordSerializerProvider = mock(Provider.class);
RecordSerializer recordSerializer = mock(RecordSerializer.class);
expect(recordSerializerProvider.get()).andReturn(recordSerializer).anyTimes();
if (!error) {
expect(recordSerializer.serialize(anyObject(), anyObject(), anyObject(), anyObject(), anyBoolean())).andReturn(Optional.empty()).anyTimes();
} else {
expect(recordSerializer.serialize(anyObject(), anyObject(), anyObject(), anyObject(), anyBoolean())).andThrow(Errors.messageSerializationException("Schema Registry not defined, no Schema Registry client available to deserialize message.")).anyTimes();
}
replay(recordSerializerProvider, recordSerializer);
EasyMock.verify(recordSerializer);
return recordSerializerProvider;
}
Aggregations