Comments (4)
The way that we solve that is by using the TestTopology constructor that takes a function to create the topology.
public TestTopology(final Function<? super Properties, ? extends Topology> topologyFactory,
final Map<?, ?> properties)
This topologyFactory function feeds back the properties in the second parameter with all automatically populated entries, such as SR url.
So if you have some createTopology(Properties properties)
in your main application, you can retrieve the SR url with properties.get(AbstractKafkaAvroSerDeConfig.SCHEMA_REGISTRY_URL_CONFIG)
or try to directly pass the properties to the configure method of the AvroSerde.
from fluent-kafka-streams-tests.
Thanks for this Pointer. I've got it to work in this way as well now.
Our app is part of a Spring Boot application which requires slightly more effort to allow us to configure it in this way, but its doable :-)
The issue can be closed then. Thanks for the super fast reply!
from fluent-kafka-streams-tests.
Can you share a snippet on how this works? I also have a same scenario, but different to the sample codes, I use @Autowired in my unit test because my Kafka Streams implementation is also @Autowired due to Spring Kafka library.
I am confused right now as to how my @Autowired implementation can reach the mock schema registry URL when overriding Avro Serdes. Hope you guys can guide me on this 🙏🏻
@SpringBootTest
public class HourlyLoginCountProcessorTests {
private SchemaRegistryMock schemaRegistryMock = new SchemaRegistryMock();
@Autowired
HourlyLoginCountProcessor hourlyLoginCountProcessor;
TestTopology<Object, Object> testTopology = null;
@BeforeEach
public void setUp() throws IOException {
this.schemaRegistryMock.start();
StreamsBuilder streamsBuilder = new StreamsBuilder();
this.hourlyLoginCountProcessor.buildPipeline(streamsBuilder);
Topology topology = streamsBuilder.build();
this.testTopology = new TestTopology<>(topology, this.getStreamsConfiguration("http://dummy"))
.withSchemaRegistryMock(this.schemaRegistryMock);
this.testTopology.start();
}
@Test
void HourlyLoginCountProcessorTest() {
LoginRaw loginRaw = this.generateLoginRawForSauyo();
LoginRaw loginRawNullLocation = this.generateLoginRawWithNullLocation();
// try inserting data into the LOGIN_RAW_STREAM stream / topic
this.testTopology.input()
.add("", loginRaw)
.add("", loginRawNullLocation);
this.testTopology.input()
.at(TimeUnit.SECONDS.toMillis(1)).add("", loginRaw)
.at(TimeUnit.SECONDS.toMillis(2)).add("", loginRawNullLocation);
// .at(System.currentTimeMillis()).add(dummyInput); // flush KTable
// see the output of the stream based on input
ProducerRecord<Object, LoginCount> record =
this.testTopology.tableOutput().withValueType(LoginCount.class).readOneRecord();
// should use .toString() method because the field is in CharSequence
System.out.println("haha");
}
private LoginRaw generateLoginRawWithNullLocation() {
// omitted for brevity
}
private LoginRaw generateLoginRawForSauyo() {
// omitted for brevity
}
private Properties getStreamsConfiguration(String url) {
final Properties streamsConfiguration = new Properties();
streamsConfiguration.put(StreamsConfig.APPLICATION_ID_CONFIG, "TopologyTestDriver");
streamsConfiguration.put(StreamsConfig.BOOTSTRAP_SERVERS_CONFIG, "mock:9092");
streamsConfiguration.put(StreamsConfig.DEFAULT_KEY_SERDE_CLASS_CONFIG, Serdes.String().getClass());
streamsConfiguration.put(StreamsConfig.DEFAULT_VALUE_SERDE_CLASS_CONFIG, SpecificAvroSerde.class);
// giving any value to SCHEMA_REGISTRY_URL_CONFIG will activate a mocked Schema Registry.
// actual value is ignored
streamsConfiguration.put(AbstractKafkaSchemaSerDeConfig.SCHEMA_REGISTRY_URL_CONFIG, url);
return streamsConfiguration;
}
}
from fluent-kafka-streams-tests.
Hi @kensixx, can you please elaborate what the error is you are getting or what exactly is not working?
from fluent-kafka-streams-tests.
Related Issues (20)
- StateStore Configuration HOT 2
- Bump kafka version to 2.2.0 HOT 1
- Schema Registry List and Get subject versions HOT 1
- [schema-registry] Use with Java 8 tests HOT 3
- Not listening on HTTP port. The WireMock server is most likely stopped HOT 5
- java.lang.ClassNotFoundException: com.fasterxml.jackson.annotation.JsonMerge HOT 3
- Add support for JUnit4 HOT 2
- [schema-registry] MockedSchemaRegistry 5.2.1 returns Schema id -1 for some Schema registrations HOT 3
- Support topic pattern HOT 2
- fluent-kafka-streams-tests-junit4 for JDK 8 HOT 2
- No records returned when using Suppression HOT 1
- Code example on how to use schema registry client for standalone spring test HOT 1
- Allow checking output value contents using matchers (e.g. AssertJ matchers) HOT 2
- NullPointerException thrown when using TopicNameExtractor for sinks in topology HOT 2
- Support JsonSchema and Protobuf providers on SchemaRegistryMock HOT 4
- How to enable SchemaRegistryMock when using Spring Kafka + @Autowired + manual overriding of Avro Serdes? HOT 14
- Upgrade Kafka, Confluent and Protobuf dependencies HOT 3
- Version 2.8.0 no longer works with Spring Boot 3x due to the dependency of wiremock still using javax instead of jakarta HOT 4
- 500 errors on server result in JSON serialiser exceptions rather than the expected error as the return is in HTML HOT 7
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from fluent-kafka-streams-tests.