From 9c773516d7abb4c394ecda92b44dd1f80b4e0f6e Mon Sep 17 00:00:00 2001 From: Robert Scott Date: Sun, 6 Sep 2020 17:18:46 +0100 Subject: [PATCH] elasticmq-server-bin: add passthru.tests.elasticmqTest simply starts an elasticmq server with a queue "foobar", attempts to put a message to it from python then checks it arrives --- pkgs/servers/elasticmq-server-bin/default.nix | 66 ++++++++++--------- .../elasticmq-server-bin/elasticmq-test.nix | 47 +++++++++++++ 2 files changed, 83 insertions(+), 30 deletions(-) create mode 100644 pkgs/servers/elasticmq-server-bin/elasticmq-test.nix diff --git a/pkgs/servers/elasticmq-server-bin/default.nix b/pkgs/servers/elasticmq-server-bin/default.nix index 9688fa729b74..1b44eb2383ec 100644 --- a/pkgs/servers/elasticmq-server-bin/default.nix +++ b/pkgs/servers/elasticmq-server-bin/default.nix @@ -1,34 +1,40 @@ -{ lib, stdenv, fetchurl, jdk, jre, makeWrapper }: +{ lib, stdenv, fetchurl, jdk, jre, makeWrapper, runCommand, python3Packages, writeText }: -stdenv.mkDerivation rec { - pname = "elasticmq-server"; - version = "0.15.7"; +let + elasticmq-server = stdenv.mkDerivation rec { + pname = "elasticmq-server"; + version = "0.15.7"; - src = fetchurl { - url = "https://s3-eu-west-1.amazonaws.com/softwaremill-public/${pname}-${version}.jar"; - sha256 = "01jmb6rwh570f2y30b2if5fhcbpdnb2vkxylp9xa09c0x7a2vv4q"; + src = fetchurl { + url = "https://s3-eu-west-1.amazonaws.com/softwaremill-public/${pname}-${version}.jar"; + sha256 = "01jmb6rwh570f2y30b2if5fhcbpdnb2vkxylp9xa09c0x7a2vv4q"; + }; + + # don't do anything? + unpackPhase = "${jdk}/bin/jar xf $src favicon.png"; + + nativeBuildInputs = [ makeWrapper ]; + + installPhase = '' + mkdir -p $out/bin $out/share/elasticmq-server + + cp $src $out/share/elasticmq-server/elasticmq-server.jar + + # TODO: how to add extraArgs? current workaround is to use JAVA_TOOL_OPTIONS environment to specify properties + makeWrapper ${jre}/bin/java $out/bin/elasticmq-server \ + --add-flags "-jar $out/share/elasticmq-server/elasticmq-server.jar" + ''; + + meta = with lib; { + homepage = "https://github.com/softwaremill/elasticmq"; + description = "Message queueing system with Java, Scala and Amazon SQS-compatible interfaces"; + license = licenses.asl20; + platforms = platforms.unix; + maintainers = with maintainers; [ peterromfeldhk ]; + }; }; - - # don't do anything? - unpackPhase = "${jdk}/bin/jar xf $src favicon.png"; - - nativeBuildInputs = [ makeWrapper ]; - - installPhase = '' - mkdir -p $out/bin $out/share/elasticmq-server - - cp $src $out/share/elasticmq-server/elasticmq-server.jar - - # TODO: how to add extraArgs? current workaround is to use JAVA_TOOL_OPTIONS environment to specify properties - makeWrapper ${jre}/bin/java $out/bin/elasticmq-server \ - --add-flags "-jar $out/share/elasticmq-server/elasticmq-server.jar" - ''; - - meta = with lib; { - homepage = "https://github.com/softwaremill/elasticmq"; - description = "Message queueing system with Java, Scala and Amazon SQS-compatible interfaces"; - license = licenses.asl20; - platforms = platforms.unix; - maintainers = with maintainers; [ peterromfeldhk ]; +in elasticmq-server.overrideAttrs (_: { + passthru.tests.elasticmqTest = import ./elasticmq-test.nix { + inherit elasticmq-server runCommand python3Packages writeText; }; -} +}) diff --git a/pkgs/servers/elasticmq-server-bin/elasticmq-test.nix b/pkgs/servers/elasticmq-server-bin/elasticmq-test.nix new file mode 100644 index 000000000000..044b74508982 --- /dev/null +++ b/pkgs/servers/elasticmq-server-bin/elasticmq-test.nix @@ -0,0 +1,47 @@ +{ elasticmq-server, python3Packages, runCommand, writeText}: + +runCommand "${elasticmq-server.name}-tests" (let + commonPy = '' + import boto3 + client = boto3.resource( + "sqs", + endpoint_url="http://localhost:9324", + region_name="elasticmq", + aws_secret_access_key="x", + aws_access_key_id="x", + use_ssl=False, + ) + queue = client.get_queue_by_name(QueueName="foobar") + ''; +in { + buildInputs = with python3Packages; [ python boto3 ]; + emqConfig = writeText "emq-test.conf" '' + generate-node-address = true + + queues { + foobar {} + } + ''; + putMessagePy = writeText "put_message.py" '' + ${commonPy} + queue.send_message(MessageBody="bazqux") + ''; + checkMessagePy = writeText "check_message.py" '' + ${commonPy} + messages = queue.receive_messages() + print(f"Received {messages!r}") + assert len(messages) == 1 + assert messages[0].body == "bazqux" + ''; +}) '' + JAVA_TOOL_OPTIONS="-Dconfig.file=$emqConfig" ${elasticmq-server}/bin/elasticmq-server & + SERVER_PID=$! + sleep 10 + + python $putMessagePy + python $checkMessagePy + touch $out + + # needed on darwin + kill $SERVER_PID +''