at 21.11-pre 2.5 kB view raw
1{ system ? builtins.currentSystem, 2 config ? {}, 3 pkgs ? import ../.. { inherit system config; } 4}: 5 6with pkgs.lib; 7 8let 9 makeKafkaTest = name: kafkaPackage: (import ./make-test-python.nix ({ 10 inherit name; 11 meta = with pkgs.lib.maintainers; { 12 maintainers = [ nequissimus ]; 13 }; 14 15 nodes = { 16 zookeeper1 = { ... }: { 17 services.zookeeper = { 18 enable = true; 19 }; 20 21 networking.firewall.allowedTCPPorts = [ 2181 ]; 22 virtualisation.memorySize = 1024; 23 }; 24 kafka = { ... }: { 25 services.apache-kafka = { 26 enable = true; 27 extraProperties = '' 28 offsets.topic.replication.factor = 1 29 zookeeper.session.timeout.ms = 600000 30 ''; 31 package = kafkaPackage; 32 zookeeper = "zookeeper1:2181"; 33 }; 34 35 networking.firewall.allowedTCPPorts = [ 9092 ]; 36 # i686 tests: qemu-system-i386 can simulate max 2047MB RAM (not 2048) 37 virtualisation.memorySize = 2047; 38 }; 39 }; 40 41 testScript = '' 42 start_all() 43 44 zookeeper1.wait_for_unit("default.target") 45 zookeeper1.wait_for_unit("zookeeper.service") 46 zookeeper1.wait_for_open_port(2181) 47 48 kafka.wait_for_unit("default.target") 49 kafka.wait_for_unit("apache-kafka.service") 50 kafka.wait_for_open_port(9092) 51 52 kafka.wait_until_succeeds( 53 "${kafkaPackage}/bin/kafka-topics.sh --create " 54 + "--zookeeper zookeeper1:2181 --partitions 1 " 55 + "--replication-factor 1 --topic testtopic" 56 ) 57 kafka.succeed( 58 "echo 'test 1' | " 59 + "${kafkaPackage}/bin/kafka-console-producer.sh " 60 + "--broker-list localhost:9092 --topic testtopic" 61 ) 62 '' + (if name == "kafka_0_9" then '' 63 assert "test 1" in kafka.succeed( 64 "${kafkaPackage}/bin/kafka-console-consumer.sh " 65 + "--zookeeper zookeeper1:2181 --topic testtopic " 66 + "--from-beginning --max-messages 1" 67 ) 68 '' else '' 69 assert "test 1" in kafka.succeed( 70 "${kafkaPackage}/bin/kafka-console-consumer.sh " 71 + "--bootstrap-server localhost:9092 --topic testtopic " 72 + "--from-beginning --max-messages 1" 73 ) 74 ''); 75 }) { inherit system; }); 76 77in with pkgs; { 78 kafka_2_4 = makeKafkaTest "kafka_2_4" apacheKafka_2_4; 79 kafka_2_5 = makeKafkaTest "kafka_2_5" apacheKafka_2_5; 80 kafka_2_6 = makeKafkaTest "kafka_2_6" apacheKafka_2_6; 81}