-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into 48-getting-started-with-a-gif-animation
# Conflicts: # kstreamplify-core-test/src/test/java/com/michelin/kstreamplify/TopologyErrorHandlerTest.java # kstreamplify-core/src/main/java/com/michelin/kstreamplify/context/KafkaStreamsExecutionContext.java # kstreamplify-core/src/main/java/com/michelin/kstreamplify/error/DlqDeserializationExceptionHandler.java # kstreamplify-core/src/main/java/com/michelin/kstreamplify/error/DlqProductionExceptionHandler.java # kstreamplify-core/src/test/java/com/michelin/kstreamplify/deduplication/DedupWithPredicateProcessorTest.java # kstreamplify-core/src/test/java/com/michelin/kstreamplify/initializer/KafkaStreamsInitializerTest.java # kstreamplify-core/src/test/java/com/michelin/kstreamplify/properties/RocksDbConfigTest.java # pom.xml
- Loading branch information
Showing
29 changed files
with
1,197 additions
and
67 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
59 changes: 59 additions & 0 deletions
59
...ore/src/test/java/com/michelin/kstreamplify/context/KafkaStreamsExecutionContextTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
package com.michelin.kstreamplify.context; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
import static org.junit.jupiter.api.Assertions.assertNull; | ||
|
||
import java.util.Properties; | ||
import org.apache.kafka.streams.StreamsConfig; | ||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.api.Test; | ||
|
||
class KafkaStreamsExecutionContextTest { | ||
|
||
@BeforeEach | ||
void setUp() { | ||
KafkaStreamsExecutionContext.setProperties(null); | ||
} | ||
|
||
@Test | ||
void shouldNotRegisterPropertiesWhenNull() { | ||
KafkaStreamsExecutionContext.registerProperties(null); | ||
assertNull(KafkaStreamsExecutionContext.getProperties()); | ||
} | ||
|
||
@Test | ||
void shouldAddPrefixToAppId() { | ||
Properties properties = new Properties(); | ||
properties.put(StreamsConfig.APPLICATION_ID_CONFIG, "appId"); | ||
properties.put("prefix.self", "abc."); | ||
|
||
KafkaStreamsExecutionContext.registerProperties(properties); | ||
|
||
assertEquals("abc.", KafkaStreamsExecutionContext.getPrefix()); | ||
assertEquals("abc.appId", KafkaStreamsExecutionContext.getProperties() | ||
.get(StreamsConfig.APPLICATION_ID_CONFIG)); | ||
} | ||
|
||
@Test | ||
void shouldNotAddPrefixToAppIdIfNoPrefix() { | ||
Properties properties = new Properties(); | ||
properties.put(StreamsConfig.APPLICATION_ID_CONFIG, "appId"); | ||
|
||
KafkaStreamsExecutionContext.registerProperties(properties); | ||
|
||
assertEquals("", KafkaStreamsExecutionContext.getPrefix()); | ||
assertEquals("appId", KafkaStreamsExecutionContext.getProperties() | ||
.get(StreamsConfig.APPLICATION_ID_CONFIG)); | ||
} | ||
|
||
@Test | ||
void shouldNotAddPrefixToAppIdIfNotAppId() { | ||
Properties properties = new Properties(); | ||
properties.put("prefix.self", "abc."); | ||
|
||
KafkaStreamsExecutionContext.registerProperties(properties); | ||
|
||
assertEquals("abc.", KafkaStreamsExecutionContext.getPrefix()); | ||
assertNull(KafkaStreamsExecutionContext.getProperties().get(StreamsConfig.APPLICATION_ID_CONFIG)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
140 changes: 140 additions & 0 deletions
140
...src/test/java/com/michelin/kstreamplify/error/DlqDeserializationExceptionHandlerTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,140 @@ | ||
package com.michelin.kstreamplify.error; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
import static org.junit.jupiter.api.Assertions.assertNull; | ||
import static org.junit.jupiter.api.Assertions.assertTrue; | ||
import static org.mockito.Mockito.when; | ||
|
||
import com.michelin.kstreamplify.avro.KafkaError; | ||
import com.michelin.kstreamplify.context.KafkaStreamsExecutionContext; | ||
import io.confluent.kafka.serializers.KafkaAvroSerializer; | ||
import io.confluent.kafka.serializers.KafkaAvroSerializerConfig; | ||
import java.nio.charset.StandardCharsets; | ||
import java.util.HashMap; | ||
import java.util.Map; | ||
import org.apache.kafka.clients.consumer.ConsumerRecord; | ||
import org.apache.kafka.clients.producer.KafkaProducer; | ||
import org.apache.kafka.clients.producer.MockProducer; | ||
import org.apache.kafka.clients.producer.Producer; | ||
import org.apache.kafka.common.KafkaException; | ||
import org.apache.kafka.common.errors.RecordTooLargeException; | ||
import org.apache.kafka.common.serialization.ByteArraySerializer; | ||
import org.apache.kafka.common.serialization.Serializer; | ||
import org.apache.kafka.streams.errors.DeserializationExceptionHandler; | ||
import org.apache.kafka.streams.processor.ProcessorContext; | ||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.extension.ExtendWith; | ||
import org.mockito.Mock; | ||
import org.mockito.junit.jupiter.MockitoExtension; | ||
|
||
@ExtendWith(MockitoExtension.class) | ||
class DlqDeserializationExceptionHandlerTest { | ||
@Mock | ||
private ConsumerRecord<byte[], byte[]> record; | ||
|
||
@Mock | ||
private ProcessorContext processorContext; | ||
|
||
private Producer<byte[], KafkaError> producer; | ||
|
||
private DlqDeserializationExceptionHandler handler; | ||
|
||
@BeforeEach | ||
void setUp() { | ||
Serializer<KafkaError> serializer = (Serializer) new KafkaAvroSerializer(); | ||
serializer.configure(Map.of(KafkaAvroSerializerConfig.SCHEMA_REGISTRY_URL_CONFIG, "mock://"), false); | ||
producer = new MockProducer<>(true, new ByteArraySerializer(), serializer); | ||
|
||
KafkaStreamsExecutionContext.setDlqTopicName(null); | ||
} | ||
|
||
@Test | ||
void shouldReturnFailIfNoDlq() { | ||
handler = new DlqDeserializationExceptionHandler(producer); | ||
|
||
DeserializationExceptionHandler.DeserializationHandlerResponse response = | ||
handler.handle(processorContext, record, new RuntimeException("Exception...")); | ||
|
||
assertEquals(DeserializationExceptionHandler.DeserializationHandlerResponse.FAIL, response); | ||
} | ||
|
||
@Test | ||
void shouldReturnFailOnExceptionDuringHandle() { | ||
handler = new DlqDeserializationExceptionHandler(producer); | ||
KafkaStreamsExecutionContext.setDlqTopicName("DlqTopic"); | ||
DeserializationExceptionHandler.DeserializationHandlerResponse response = | ||
handler.handle(processorContext, record, new KafkaException("Exception...")); | ||
|
||
assertEquals(DeserializationExceptionHandler.DeserializationHandlerResponse.FAIL, response); | ||
} | ||
|
||
@Test | ||
void shouldReturnContinueOnKafkaException() { | ||
handler = new DlqDeserializationExceptionHandler(producer); | ||
KafkaStreamsExecutionContext.setDlqTopicName("DlqTopic"); | ||
|
||
when(record.key()).thenReturn("key".getBytes(StandardCharsets.UTF_8)); | ||
when(record.value()).thenReturn("value".getBytes(StandardCharsets.UTF_8)); | ||
when(record.topic()).thenReturn("topic"); | ||
|
||
DeserializationExceptionHandler.DeserializationHandlerResponse response = | ||
handler.handle(processorContext, record, new KafkaException("Exception...")); | ||
|
||
assertEquals(DeserializationExceptionHandler.DeserializationHandlerResponse.CONTINUE, response); | ||
} | ||
|
||
@Test | ||
void shouldConfigure() { | ||
Map<String, Object> configs = new HashMap<>(); | ||
configs.put("bootstrap.servers", "localhost:9092"); | ||
configs.put("schema.registry.url", "localhost:8080"); | ||
configs.put("acks", "all"); | ||
|
||
handler = new DlqDeserializationExceptionHandler(); | ||
handler.configure(configs); | ||
|
||
assertTrue(DlqExceptionHandler.getProducer() instanceof KafkaProducer<byte[], KafkaError>); | ||
Check failure on line 97 in kstreamplify-core/src/test/java/com/michelin/kstreamplify/error/DlqDeserializationExceptionHandlerTest.java GitHub Actions / JUnit Test ReportDlqDeserializationExceptionHandlerTest.shouldConfigure
Raw output
|
||
} | ||
|
||
@Test | ||
void shouldEnrichWithException() { | ||
KafkaError.Builder kafkaError = KafkaError.newBuilder() | ||
.setTopic("topic") | ||
.setStack("stack") | ||
.setPartition(0) | ||
.setOffset(0) | ||
.setCause("cause") | ||
.setValue("value"); | ||
|
||
handler = new DlqDeserializationExceptionHandler(); | ||
KafkaError.Builder enrichedBuilder = handler.enrichWithException(kafkaError, | ||
new RuntimeException("Exception..."), "key".getBytes(StandardCharsets.UTF_8), | ||
"value".getBytes(StandardCharsets.UTF_8)); | ||
|
||
KafkaError error = enrichedBuilder.build(); | ||
assertEquals("Unknown cause", error.getCause()); | ||
assertNull(error.getContextMessage()); | ||
} | ||
|
||
@Test | ||
void shouldEnrichWithRecordTooLargeException() { | ||
KafkaError.Builder kafkaError = KafkaError.newBuilder() | ||
.setTopic("topic") | ||
.setStack("stack") | ||
.setPartition(0) | ||
.setOffset(0) | ||
.setCause("cause") | ||
.setValue("value"); | ||
|
||
handler = new DlqDeserializationExceptionHandler(); | ||
KafkaError.Builder enrichedBuilder = handler.enrichWithException(kafkaError, | ||
new RecordTooLargeException("Exception..."), "key".getBytes(StandardCharsets.UTF_8), | ||
"value".getBytes(StandardCharsets.UTF_8)); | ||
|
||
KafkaError error = enrichedBuilder.build(); | ||
assertEquals("Unknown cause", error.getCause()); | ||
assertEquals("The record is too large to be set as value (5 bytes). " | ||
+ "The key will be used instead", error.getValue()); | ||
} | ||
} |
23 changes: 23 additions & 0 deletions
23
kstreamplify-core/src/test/java/com/michelin/kstreamplify/error/DlqExceptionHandlerTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package com.michelin.kstreamplify.error; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertNotNull; | ||
|
||
import com.michelin.kstreamplify.error.DlqExceptionHandler; | ||
import java.util.HashMap; | ||
import java.util.Map; | ||
import org.junit.jupiter.api.Test; | ||
|
||
class DlqExceptionHandlerTest { | ||
|
||
@Test | ||
void shouldInstantiateProducer() { | ||
Map<String, Object> configs = new HashMap<>(); | ||
configs.put("bootstrap.servers", "localhost:9092"); | ||
configs.put("schema.registry.url", "localhost:8080"); | ||
configs.put("acks", "all"); | ||
|
||
DlqExceptionHandler.instantiateProducer("test-client", configs); | ||
|
||
assertNotNull(DlqExceptionHandler.getProducer()); | ||
} | ||
} |
Oops, something went wrong.