-
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.
* add TU * fix conflicts * add TU * add TU * remove code smells * remove code smells * remove code smells * remove code smells * Update unit tests * Fix lint * Add tests for kafka Streams initializer --------- Co-authored-by: Loïc Greffier <[email protected]>
- Loading branch information
1 parent
d694d8b
commit 061a86e
Showing
28 changed files
with
1,378 additions
and
47 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
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
33 changes: 33 additions & 0 deletions
33
...plify-core/src/test/java/com/michelin/kstreamplify/converter/JsonToAvroConverterTest.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,33 @@ | ||
package com.michelin.kstreamplify.converter; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
import static org.junit.jupiter.api.Assertions.assertFalse; | ||
|
||
import com.michelin.kstreamplify.avro.KafkaTestAvro; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.junit.jupiter.api.Test; | ||
|
||
@Slf4j | ||
class JsonToAvroConverterTest { | ||
|
||
private static final String JSON = | ||
"{\"membersString\":{\"key1\":\"val1\"},\"split\":[{\"subSplit\":" | ||
+ "[{\"subSubIntField\":8,\"subSubField\":\"subSubTest\"}],\"subField\":\"subTest\"}]," | ||
+ "\"booleanField\":false,\"members\":{\"key1\":{\"mapQuantityField\":1}}," | ||
+ "\"quantityField\":10,\"stringField\":\"test\",\"listString\":[\"val1\",\"val2\"]}"; | ||
|
||
@Test | ||
void shouldConvertJsonToAvro() { | ||
KafkaTestAvro kafkaTest = (KafkaTestAvro) JsonToAvroConverter.jsonToAvro(JSON, KafkaTestAvro.getClassSchema()); | ||
assertEquals("val1", kafkaTest.getMembersString().get("key1")); | ||
assertEquals(8, kafkaTest.getSplit().get(0).getSubSplit().get(0).getSubSubIntField()); | ||
assertEquals("subSubTest", kafkaTest.getSplit().get(0).getSubSplit().get(0).getSubSubField()); | ||
assertEquals("subTest", kafkaTest.getSplit().get(0).getSubField()); | ||
assertFalse(kafkaTest.getBooleanField()); | ||
assertEquals("1.0000", kafkaTest.getMembers().get("key1").getMapQuantityField().toString()); | ||
assertEquals("10.0000", kafkaTest.getQuantityField().toString()); | ||
assertEquals("test", kafkaTest.getStringField()); | ||
assertEquals("val1", kafkaTest.getListString().get(0)); | ||
assertEquals("val2", kafkaTest.getListString().get(1)); | ||
} | ||
} |
45 changes: 45 additions & 0 deletions
45
...ify-core/src/test/java/com/michelin/kstreamplify/deduplication/DedupKeyProcessorTest.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,45 @@ | ||
package com.michelin.kstreamplify.deduplication; | ||
|
||
import static org.mockito.Mockito.any; | ||
import static org.mockito.Mockito.eq; | ||
import static org.mockito.Mockito.verify; | ||
import static org.mockito.Mockito.when; | ||
|
||
import com.michelin.kstreamplify.avro.KafkaError; | ||
import com.michelin.kstreamplify.error.ProcessingResult; | ||
import java.time.Duration; | ||
import org.apache.kafka.streams.processor.api.ProcessorContext; | ||
import org.apache.kafka.streams.processor.api.Record; | ||
import org.apache.kafka.streams.state.TimestampedKeyValueStore; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.extension.ExtendWith; | ||
import org.mockito.InjectMocks; | ||
import org.mockito.Mock; | ||
import org.mockito.junit.jupiter.MockitoExtension; | ||
|
||
@ExtendWith(MockitoExtension.class) | ||
class DedupKeyProcessorTest { | ||
|
||
@Mock | ||
private ProcessorContext<String, ProcessingResult<KafkaError, KafkaError>> context; | ||
|
||
@Mock | ||
private TimestampedKeyValueStore<String, String> dedupTimestampedStore; | ||
|
||
@Test | ||
void shouldProcessNewRecord() { | ||
String key = "some-key"; | ||
|
||
when(context.getStateStore("dedupStoreName")).thenReturn(dedupTimestampedStore); | ||
when(dedupTimestampedStore.get(key)).thenReturn(null); | ||
|
||
DedupKeyProcessor<KafkaError> dedupKeyProcessor = new DedupKeyProcessor<>("dedupStoreName", Duration.ZERO); | ||
dedupKeyProcessor.init(context); | ||
|
||
KafkaError value = new KafkaError(); | ||
Record<String, KafkaError> record = new Record<>(key, value, 0); | ||
dedupKeyProcessor.process(record); | ||
|
||
verify(dedupTimestampedStore).put(eq(key), any()); | ||
} | ||
} |
43 changes: 43 additions & 0 deletions
43
...ore/src/test/java/com/michelin/kstreamplify/deduplication/DedupKeyValueProcessorTest.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,43 @@ | ||
package com.michelin.kstreamplify.deduplication; | ||
|
||
import static org.mockito.Mockito.verify; | ||
import static org.mockito.Mockito.when; | ||
|
||
import com.michelin.kstreamplify.avro.KafkaError; | ||
import com.michelin.kstreamplify.error.ProcessingResult; | ||
import java.time.Duration; | ||
import org.apache.kafka.streams.processor.api.ProcessorContext; | ||
import org.apache.kafka.streams.processor.api.Record; | ||
import org.apache.kafka.streams.state.WindowStore; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.extension.ExtendWith; | ||
import org.mockito.InjectMocks; | ||
import org.mockito.Mock; | ||
import org.mockito.junit.jupiter.MockitoExtension; | ||
|
||
@ExtendWith(MockitoExtension.class) | ||
class DedupKeyValueProcessorTest { | ||
|
||
@Mock | ||
private ProcessorContext<String, ProcessingResult<KafkaError, KafkaError>> context; | ||
|
||
@Mock | ||
private WindowStore<String, KafkaError> windowStore; | ||
|
||
@Test | ||
void shouldProcessNewRecord() { | ||
String key = "some-key"; | ||
KafkaError value = new KafkaError(); | ||
|
||
Record<String, KafkaError> record = new Record<>(key, value, 0); | ||
|
||
when(context.getStateStore("dedupStoreName")).thenReturn(windowStore); | ||
|
||
DedupKeyValueProcessor<KafkaError> dedupKeyValueProcessor = new DedupKeyValueProcessor<>("dedupStoreName", | ||
Duration.ZERO); | ||
dedupKeyValueProcessor.init(context); | ||
dedupKeyValueProcessor.process(record); | ||
|
||
verify(windowStore).put(record.key(), record.value(), record.timestamp()); | ||
} | ||
} |
Oops, something went wrong.