Backport von Verbesserungen / Erweiterungen der Tests:
[demos/kafka/training] / src / test / java / de / juplo / kafka / ApplicationTests.java
index 51d579e..1781b1d 100644 (file)
@@ -1,16 +1,13 @@
 package de.juplo.kafka;
 
-import org.apache.kafka.clients.consumer.ConsumerRecord;
 import org.apache.kafka.clients.producer.ProducerRecord;
 import org.apache.kafka.common.serialization.LongSerializer;
 import org.apache.kafka.common.serialization.StringSerializer;
 import org.apache.kafka.common.utils.Bytes;
 import org.springframework.boot.test.context.TestConfiguration;
 import org.springframework.context.annotation.Bean;
-import org.springframework.context.annotation.Primary;
 import org.springframework.test.context.ContextConfiguration;
 
-import java.util.Set;
 import java.util.function.Consumer;
 
 
@@ -27,29 +24,30 @@ public class ApplicationTests extends GenericApplicationTests<String, Long>
 
 
           @Override
-          public void generate(
-              int numberOfMessagesToGenerate,
-              Set<Integer> poisonPills,
-              Set<Integer> logicErrors,
+          public int generate(
+              boolean poisonPills,
+              boolean logicErrors,
               Consumer<ProducerRecord<Bytes, Bytes>> messageSender)
           {
             int i = 0;
 
             for (int partition = 0; partition < 10; partition++)
             {
-              for (int key = 0; key < 10; key++)
+              for (int key = 0; key < 10000; key++)
               {
-                if (++i > numberOfMessagesToGenerate)
-                  return;
+                i++;
 
                 Bytes value = new Bytes(longSerializer.serialize(TOPIC, (long)i));
-                if (logicErrors.contains(i))
+                if (i == 99977)
                 {
-                  value = new Bytes(longSerializer.serialize(TOPIC, Long.MIN_VALUE));
-                }
-                if (poisonPills.contains(i))
-                {
-                  value = new Bytes(stringSerializer.serialize(TOPIC, "BOOM (Poison-Pill)!"));
+                  if (logicErrors)
+                  {
+                    value = new Bytes(longSerializer.serialize(TOPIC, Long.MIN_VALUE));
+                  }
+                  if (poisonPills)
+                  {
+                    value = new Bytes(stringSerializer.serialize(TOPIC, "BOOM (Poison-Pill)!"));
+                  }
                 }
 
                 ProducerRecord<Bytes, Bytes> record =
@@ -62,6 +60,8 @@ public class ApplicationTests extends GenericApplicationTests<String, Long>
                 messageSender.accept(record);
               }
             }
+
+            return i;
           }
         });
   }
@@ -70,9 +70,8 @@ public class ApplicationTests extends GenericApplicationTests<String, Long>
   @TestConfiguration
   public static class Configuration
   {
-    @Primary
     @Bean
-    public Consumer<ConsumerRecord<String, Long>> consumer()
+    public RecordHandler<String, Long> recordHandler()
     {
       return (record) ->
       {