2018-11-11 08:41:11 +00:00
|
|
|
{ system ? builtins.currentSystem,
|
|
|
|
config ? {},
|
|
|
|
pkgs ? import ../.. { inherit system config; }
|
|
|
|
}:
|
|
|
|
|
2018-05-12 00:16:25 +00:00
|
|
|
with pkgs.lib;
|
|
|
|
|
|
|
|
let
|
2023-04-05 12:45:26 +00:00
|
|
|
makeKafkaTest = name: { kafkaPackage, mode ? "zookeeper" }: (import ./make-test-python.nix ({
|
2018-05-12 00:16:25 +00:00
|
|
|
inherit name;
|
2021-01-10 19:08:30 +00:00
|
|
|
meta = with pkgs.lib.maintainers; {
|
2018-05-12 00:16:25 +00:00
|
|
|
maintainers = [ nequissimus ];
|
|
|
|
};
|
|
|
|
|
|
|
|
nodes = {
|
2023-04-05 12:45:26 +00:00
|
|
|
kafka = { ... }: {
|
|
|
|
services.apache-kafka = mkMerge [
|
|
|
|
({
|
|
|
|
enable = true;
|
|
|
|
package = kafkaPackage;
|
|
|
|
settings = {
|
|
|
|
"offsets.topic.replication.factor" = 1;
|
|
|
|
"log.dirs" = [
|
|
|
|
"/var/lib/kafka/logdir1"
|
|
|
|
"/var/lib/kafka/logdir2"
|
|
|
|
];
|
|
|
|
};
|
|
|
|
})
|
|
|
|
(mkIf (mode == "zookeeper") {
|
|
|
|
settings = {
|
|
|
|
"zookeeper.session.timeout.ms" = 600000;
|
|
|
|
"zookeeper.connect" = [ "zookeeper1:2181" ];
|
|
|
|
};
|
|
|
|
})
|
|
|
|
(mkIf (mode == "kraft") {
|
|
|
|
clusterId = "ak2fIHr4S8WWarOF_ODD0g";
|
|
|
|
formatLogDirs = true;
|
|
|
|
settings = {
|
|
|
|
"node.id" = 1;
|
|
|
|
"process.roles" = [
|
|
|
|
"broker"
|
|
|
|
"controller"
|
|
|
|
];
|
|
|
|
"listeners" = [
|
|
|
|
"PLAINTEXT://:9092"
|
|
|
|
"CONTROLLER://:9093"
|
|
|
|
];
|
|
|
|
"listener.security.protocol.map" = [
|
|
|
|
"PLAINTEXT:PLAINTEXT"
|
|
|
|
"CONTROLLER:PLAINTEXT"
|
|
|
|
];
|
|
|
|
"controller.quorum.voters" = [
|
|
|
|
"1@kafka:9093"
|
|
|
|
];
|
|
|
|
"controller.listener.names" = [ "CONTROLLER" ];
|
|
|
|
};
|
|
|
|
})
|
|
|
|
];
|
|
|
|
|
|
|
|
networking.firewall.allowedTCPPorts = [ 9092 9093 ];
|
|
|
|
# i686 tests: qemu-system-i386 can simulate max 2047MB RAM (not 2048)
|
|
|
|
virtualisation.memorySize = 2047;
|
|
|
|
};
|
|
|
|
} // optionalAttrs (mode == "zookeeper") {
|
2018-07-20 20:56:59 +00:00
|
|
|
zookeeper1 = { ... }: {
|
2018-05-12 00:16:25 +00:00
|
|
|
services.zookeeper = {
|
|
|
|
enable = true;
|
|
|
|
};
|
|
|
|
|
|
|
|
networking.firewall.allowedTCPPorts = [ 2181 ];
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
testScript = ''
|
2020-01-08 09:39:29 +00:00
|
|
|
start_all()
|
2018-05-12 00:16:25 +00:00
|
|
|
|
2023-04-05 12:45:26 +00:00
|
|
|
${optionalString (mode == "zookeeper") ''
|
2020-01-08 09:39:29 +00:00
|
|
|
zookeeper1.wait_for_unit("default.target")
|
|
|
|
zookeeper1.wait_for_unit("zookeeper.service")
|
|
|
|
zookeeper1.wait_for_open_port(2181)
|
2023-04-05 12:45:26 +00:00
|
|
|
''}
|
2018-05-12 00:16:25 +00:00
|
|
|
|
2020-01-08 09:39:29 +00:00
|
|
|
kafka.wait_for_unit("default.target")
|
|
|
|
kafka.wait_for_unit("apache-kafka.service")
|
|
|
|
kafka.wait_for_open_port(9092)
|
2018-05-12 00:16:25 +00:00
|
|
|
|
2020-01-08 09:39:29 +00:00
|
|
|
kafka.wait_until_succeeds(
|
|
|
|
"${kafkaPackage}/bin/kafka-topics.sh --create "
|
2022-10-26 08:41:53 +00:00
|
|
|
+ "--bootstrap-server localhost:9092 --partitions 1 "
|
2020-01-08 09:39:29 +00:00
|
|
|
+ "--replication-factor 1 --topic testtopic"
|
|
|
|
)
|
|
|
|
kafka.succeed(
|
|
|
|
"echo 'test 1' | "
|
|
|
|
+ "${kafkaPackage}/bin/kafka-console-producer.sh "
|
|
|
|
+ "--broker-list localhost:9092 --topic testtopic"
|
|
|
|
)
|
|
|
|
assert "test 1" in kafka.succeed(
|
|
|
|
"${kafkaPackage}/bin/kafka-console-consumer.sh "
|
|
|
|
+ "--bootstrap-server localhost:9092 --topic testtopic "
|
|
|
|
+ "--from-beginning --max-messages 1"
|
|
|
|
)
|
2022-10-26 08:41:53 +00:00
|
|
|
'';
|
2020-04-07 15:50:58 +00:00
|
|
|
}) { inherit system; });
|
2018-05-12 00:16:25 +00:00
|
|
|
|
|
|
|
in with pkgs; {
|
2023-04-05 12:45:26 +00:00
|
|
|
kafka_2_8 = makeKafkaTest "kafka_2_8" { kafkaPackage = apacheKafka_2_8; };
|
|
|
|
kafka_3_0 = makeKafkaTest "kafka_3_0" { kafkaPackage = apacheKafka_3_0; };
|
|
|
|
kafka_3_1 = makeKafkaTest "kafka_3_1" { kafkaPackage = apacheKafka_3_1; };
|
|
|
|
kafka_3_2 = makeKafkaTest "kafka_3_2" { kafkaPackage = apacheKafka_3_2; };
|
|
|
|
kafka_3_3 = makeKafkaTest "kafka_3_3" { kafkaPackage = apacheKafka_3_3; };
|
|
|
|
kafka_3_4 = makeKafkaTest "kafka_3_4" { kafkaPackage = apacheKafka_3_4; };
|
|
|
|
kafka_3_5 = makeKafkaTest "kafka_3_5" { kafkaPackage = apacheKafka_3_5; };
|
|
|
|
kafka = makeKafkaTest "kafka" { kafkaPackage = apacheKafka; };
|
|
|
|
kafka_kraft = makeKafkaTest "kafka_kraft" { kafkaPackage = apacheKafka; mode = "kraft"; };
|
2018-05-12 00:16:25 +00:00
|
|
|
}
|