summary refs log tree commit diff
path: root/nixos/tests/cassandra.nix
blob: b729e6b158bcbfd2ddf4a18bdc55326cd25c9766 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
import ./make-test.nix ({ pkgs, ...}:
let
  user = "cassandra";
  nodeCfg = nodes: selfIP: cassandraOpts:
    {
      services.cassandra = {
        enable = true;
        listenAddress = selfIP;
        rpcAddress = "0.0.0.0";
        seeds = [ "192.168.1.1" ];
        package = pkgs.cassandra_2_0;
        jre = pkgs.openjdk;
        clusterName = "ci ahoy";
        authenticator = "PasswordAuthenticator";
        authorizer = "CassandraAuthorizer";
        user = user;
      } // cassandraOpts;
      nixpkgs.config.allowUnfree = true;
      virtualisation.memorySize = 1024;
    };

in
{
  name = "cassandra-ci";

  nodes = {
    cass0 = {pkgs, config, nodes, ...}: nodeCfg nodes "192.168.1.1" {};
    cass1 = {pkgs, config, nodes, ...}: nodeCfg nodes "192.168.1.2" {};
    cass2 = {pkgs, config, nodes, ...}: nodeCfg nodes "192.168.1.3" {
      extraParams = [
        ''JVM_OPTS="$JVM_OPTS -Dcassandra.replace_address=192.168.1.2"''
      ];
      listenAddress = "192.168.1.3";
    };
  };

  testScript = ''
    subtest "start seed", sub {
      $cass0->waitForUnit("cassandra.service");
      $cass0->waitForOpenPort(9160);
      $cass0->execute("echo show version | cqlsh localhost -u cassandra -p cassandra");
      sleep 2;
      $cass0->succeed("echo show version | cqlsh localhost -u cassandra -p cassandra");
      $cass1->start;
    };
    subtest "cassandra user/group", sub {
      $cass0->succeed("id \"${user}\" >/dev/null");
      $cass1->succeed("id \"${user}\" >/dev/null");
    };
    subtest "bring up cassandra cluster", sub {
      $cass1->waitForUnit("cassandra.service");
      $cass0->waitUntilSucceeds("nodetool status | grep -c UN  | grep 2");
    };
    subtest "break and fix node", sub {
      $cass0->block;
      $cass0->waitUntilSucceeds("nodetool status | grep -c DN  | grep 1");
      $cass0->unblock;
      $cass0->waitUntilSucceeds("nodetool status | grep -c UN  | grep 2");
    };
    subtest "replace crashed node", sub {
      $cass1->crash;
      $cass2->start;
      $cass2->waitForUnit("cassandra.service");
      $cass0->waitUntilFails("nodetool status | grep UN  | grep 192.168.1.2");
      $cass0->waitUntilSucceeds("nodetool status | grep UN | grep 192.168.1.3");
    };
  '';
})