vtest "shard director/int key"

server s1 {
	rxreq
	txresp
} -start

server s2 {
	rxreq
	txresp
} -start

server s3 {
	rxreq
	txresp
} -start

vinyl v1 -vcl+backend {
	import std;
	import directors;

	sub vcl_init {
		new vd = directors.shard();
		if (!vd.add_backend(s1)) {
			return(fail("add s1 failed"));
		}
		if (!vd.add_backend(s2)) {
			return(fail("add s2 failed"));
		}
		if (!vd.add_backend(s3)) {
			return(fail("add s3 failed"));
		}
		if (!vd.reconfigure(replicas=25)) {
			return(fail("reconfigure failed"));
		}
	}

	sub vcl_recv {
		set req.backend_hint = vd.backend(by=KEY, key=std.integer(req.http.key));
		return(pass);
	}

	sub vcl_backend_response {
		set beresp.http.backend = beresp.backend;
	}
} -start


client c1 {
	txreq -hdr "key: 1"
	rxresp
	expect resp.http.backend == s1

	txreq -hdr "key: 2147483647"
	rxresp
	expect resp.http.backend == s2

	txreq -hdr "key: 4294967295"
	rxresp
	expect resp.http.backend == s3
} -run
