Remove AVRO message converters in 4.0.x
Since we are migrating Schema Registry to Spring Cloud Stream, the AVRO message converters in Spring Cloud Function could reside in Spring Cloud Stream as part of its Schema Registry. Resolves https://github.com/spring-cloud/spring-cloud-function/issues/921 Resolves #922
This commit is contained in:
committed by
Oleg Zhurakousky
parent
e83b0dfabe
commit
c8109270d2
@@ -17,7 +17,6 @@
|
||||
package org.springframework.cloud.function.context.config;
|
||||
|
||||
import io.cloudevents.spring.messaging.CloudEventMessageConverter;
|
||||
import org.apache.avro.Schema;
|
||||
import org.junit.jupiter.api.Nested;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
@@ -26,8 +25,6 @@ import org.springframework.boot.test.context.FilteredClassLoader;
|
||||
import org.springframework.boot.test.context.runner.ApplicationContextRunner;
|
||||
import org.springframework.cloud.function.context.FunctionCatalog;
|
||||
import org.springframework.cloud.function.context.FunctionRegistry;
|
||||
import org.springframework.cloud.function.context.converter.avro.AvroSchemaMessageConverter;
|
||||
import org.springframework.cloud.function.context.converter.avro.AvroSchemaServiceManager;
|
||||
import org.springframework.cloud.function.context.scan.TestFunction;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
@@ -49,37 +46,6 @@ public class ContextFunctionCatalogAutoConfigurationConditionalLoadingTests {
|
||||
.run((context) -> assertThat(context).doesNotHaveBean(FunctionRegistry.class));
|
||||
}
|
||||
|
||||
@Nested
|
||||
class AvroSchemaMessageConverterConfig {
|
||||
|
||||
@Test
|
||||
void avroSchemaMessageConverterBeansLoadedWhenAvroOnClasspath() {
|
||||
contextRunner.run((context) -> assertThat(context).hasSingleBean(AvroSchemaServiceManager.class)
|
||||
.hasSingleBean(AvroSchemaMessageConverter.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
void avroSchemaMessageConverterBeansNotLoadedWhenAvroNotOnClasspath() {
|
||||
contextRunner.withClassLoader(new FilteredClassLoader(Schema.class)).run((context) ->
|
||||
assertThat(context).doesNotHaveBean(AvroSchemaServiceManager.class)
|
||||
.doesNotHaveBean(AvroSchemaMessageConverter.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
void customAvroSchemaServiceManagerIsRespected() {
|
||||
AvroSchemaServiceManager customManager = mock(AvroSchemaServiceManager.class);
|
||||
contextRunner.withBean(AvroSchemaServiceManager.class, () -> customManager)
|
||||
.run((context) -> assertThat(context).getBean(AvroSchemaServiceManager.class).isSameAs(customManager));
|
||||
}
|
||||
|
||||
@Test
|
||||
void customAvroSchemaMessageConverterIsRespected() {
|
||||
AvroSchemaMessageConverter customConverter = mock(AvroSchemaMessageConverter.class);
|
||||
contextRunner.withBean(AvroSchemaMessageConverter.class, () -> customConverter)
|
||||
.run((context) -> assertThat(context).getBean(AvroSchemaMessageConverter.class).isSameAs(customConverter));
|
||||
}
|
||||
}
|
||||
|
||||
@Nested
|
||||
class CloudEventsMessageConverterConfig {
|
||||
|
||||
|
||||
@@ -1,83 +0,0 @@
|
||||
/*
|
||||
* Copyright 2021-2021 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.cloud.function.context.converter.avro;
|
||||
|
||||
import java.util.Random;
|
||||
import java.util.UUID;
|
||||
import java.util.function.Function;
|
||||
|
||||
import com.example.Sensor;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import org.springframework.boot.WebApplicationType;
|
||||
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
|
||||
import org.springframework.boot.builder.SpringApplicationBuilder;
|
||||
import org.springframework.cloud.function.context.FunctionCatalog;
|
||||
import org.springframework.cloud.function.context.catalog.SimpleFunctionRegistry;
|
||||
import org.springframework.context.ConfigurableApplicationContext;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.messaging.Message;
|
||||
import org.springframework.messaging.MessageHeaders;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
/**
|
||||
* @author Soby Chacko
|
||||
*/
|
||||
public class AvroSchemaMessageConverterTests {
|
||||
|
||||
@Test
|
||||
public void testAvroSchemaMessageConverter() {
|
||||
try (ConfigurableApplicationContext context = new SpringApplicationBuilder(
|
||||
SampleFunctionConfiguration.class).web(WebApplicationType.NONE).run(
|
||||
"--spring.main.lazy-initialization=true")) {
|
||||
|
||||
FunctionCatalog functionCatalog = context.getBean(FunctionCatalog.class);
|
||||
SimpleFunctionRegistry.FunctionInvocationWrapper function = functionCatalog.lookup("avroSensor");
|
||||
|
||||
Random random = new Random();
|
||||
Sensor sensor = new Sensor();
|
||||
sensor.setId(UUID.randomUUID().toString() + "-v1");
|
||||
sensor.setAcceleration(random.nextFloat() * 10);
|
||||
sensor.setVelocity(random.nextFloat() * 100);
|
||||
sensor.setTemperature(random.nextFloat() * 50);
|
||||
|
||||
final AvroSchemaMessageConverter bean = context.getBean(AvroSchemaMessageConverter.class);
|
||||
// Explicitly convert the Sensor to byte[]
|
||||
final Message<?> message = bean.toMessage(sensor, new MessageHeaders(null));
|
||||
// Now send with the sensor->byte[] converted payload.
|
||||
final Sensor enrichedSensor = (Sensor) function.apply(message);
|
||||
|
||||
assertThat(enrichedSensor.getTemperature()).isEqualTo(sensor.getTemperature() + 5);
|
||||
}
|
||||
}
|
||||
|
||||
@EnableAutoConfiguration
|
||||
@Configuration
|
||||
protected static class SampleFunctionConfiguration {
|
||||
|
||||
@Bean
|
||||
public Function<Sensor, Sensor> avroSensor() {
|
||||
return s -> {
|
||||
s.setTemperature(s.getTemperature() + 5);
|
||||
return s;
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user