Search in sources :

Example 31 with IntegerDeserializer

use of org.apache.kafka.common.serialization.IntegerDeserializer in project kafka by apache.

the class RelationalSmokeTestTest method verifySmokeTestLogic.

@Test
public void verifySmokeTestLogic() {
    try (final TopologyTestDriver driver = new TopologyTestDriver(RelationalSmokeTest.App.getTopology(), RelationalSmokeTest.App.getConfig("nothing:0", "test", "test", StreamsConfig.AT_LEAST_ONCE, TestUtils.tempDirectory().getAbsolutePath()))) {
        final TestInputTopic<Integer, RelationalSmokeTest.Article> articles = driver.createInputTopic(RelationalSmokeTest.ARTICLE_SOURCE, new IntegerSerializer(), new RelationalSmokeTest.Article.ArticleSerializer());
        final TestInputTopic<Integer, RelationalSmokeTest.Comment> comments = driver.createInputTopic(RelationalSmokeTest.COMMENT_SOURCE, new IntegerSerializer(), new RelationalSmokeTest.Comment.CommentSerializer());
        final TestOutputTopic<Integer, RelationalSmokeTest.AugmentedArticle> augmentedArticles = driver.createOutputTopic(RelationalSmokeTest.ARTICLE_RESULT_SINK, new IntegerDeserializer(), new RelationalSmokeTest.AugmentedArticle.AugmentedArticleDeserializer());
        final TestOutputTopic<Integer, RelationalSmokeTest.AugmentedComment> augmentedComments = driver.createOutputTopic(RelationalSmokeTest.COMMENT_RESULT_SINK, new IntegerDeserializer(), new RelationalSmokeTest.AugmentedComment.AugmentedCommentDeserializer());
        final RelationalSmokeTest.DataSet dataSet = RelationalSmokeTest.DataSet.generate(10, 30);
        final Map<Integer, RelationalSmokeTest.Article> articleMap = new TreeMap<>();
        for (final RelationalSmokeTest.Article article : dataSet.getArticles()) {
            articles.pipeInput(article.getKey(), article, article.getTimestamp());
            articleMap.put(article.getKey(), article);
        }
        final Map<Integer, Long> commentCounts = new TreeMap<>();
        final Map<Integer, RelationalSmokeTest.Comment> commentMap = new TreeMap<>();
        for (final RelationalSmokeTest.Comment comment : dataSet.getComments()) {
            comments.pipeInput(comment.getKey(), comment, comment.getTimestamp());
            commentMap.put(comment.getKey(), comment);
            commentCounts.put(comment.getArticleId(), commentCounts.getOrDefault(comment.getArticleId(), 0L) + 1);
        }
        final Map<Integer, RelationalSmokeTest.AugmentedArticle> augmentedArticleResults = augmentedArticles.readKeyValuesToMap();
        final Map<Integer, RelationalSmokeTest.AugmentedComment> augmentedCommentResults = augmentedComments.readKeyValuesToMap();
        assertThat(augmentedArticleResults.size(), is(dataSet.getArticles().length));
        assertThat(augmentedCommentResults.size(), is(dataSet.getComments().length));
        assertThat(RelationalSmokeTest.App.verifySync(true, articleMap, commentMap, augmentedArticleResults, augmentedCommentResults), is(true));
    }
}
Also used : TopologyTestDriver(org.apache.kafka.streams.TopologyTestDriver) IntegerSerializer(org.apache.kafka.common.serialization.IntegerSerializer) IntegerDeserializer(org.apache.kafka.common.serialization.IntegerDeserializer) TreeMap(java.util.TreeMap) Test(org.junit.Test)

Aggregations

IntegerDeserializer (org.apache.kafka.common.serialization.IntegerDeserializer)31 StringDeserializer (org.apache.kafka.common.serialization.StringDeserializer)27 Test (org.junit.Test)22 StreamsBuilder (org.apache.kafka.streams.StreamsBuilder)15 IntegrationTest (org.apache.kafka.test.IntegrationTest)13 List (java.util.List)12 Map (java.util.Map)12 StringSerializer (org.apache.kafka.common.serialization.StringSerializer)12 ArrayList (java.util.ArrayList)11 IntegerSerializer (org.apache.kafka.common.serialization.IntegerSerializer)11 KeyValue (org.apache.kafka.streams.KeyValue)11 TopologyTestDriver (org.apache.kafka.streams.TopologyTestDriver)10 HashMap (java.util.HashMap)9 Properties (java.util.Properties)8 ConsumerRecord (org.apache.kafka.clients.consumer.ConsumerRecord)8 TopicPartition (org.apache.kafka.common.TopicPartition)8 Arrays (java.util.Arrays)7 LongDeserializer (org.apache.kafka.common.serialization.LongDeserializer)7 Serdes (org.apache.kafka.common.serialization.Serdes)7 KStream (org.apache.kafka.streams.kstream.KStream)7