github.com/m3db/m3@v1.5.0/scripts/docker-integration-tests/cold_writes_simple/test.sh (about) 1 #!/usr/bin/env bash 2 3 set -xe 4 5 source "$M3_PATH"/scripts/docker-integration-tests/common.sh 6 REVISION=$(git rev-parse HEAD) 7 SCRIPT_PATH="$M3_PATH"/scripts/docker-integration-tests/cold_writes_simple 8 COMPOSE_FILE=$SCRIPT_PATH/docker-compose.yml 9 export REVISION 10 11 echo "Run m3dbnode and m3coordinator containers" 12 docker-compose -f ${COMPOSE_FILE} up -d --renew-anon-volumes dbnode01 13 docker-compose -f ${COMPOSE_FILE} up -d --renew-anon-volumes coordinator01 14 15 # Think of this as a defer func() in golang 16 function defer { 17 docker-compose -f ${COMPOSE_FILE} down || echo "unable to shutdown containers" # CI fails to stop all containers sometimes 18 } 19 trap defer EXIT 20 21 setup_single_m3db_node 22 23 function write_data { 24 namespace=$1 25 id=$2 26 timestamp=$3 27 value=$4 28 29 respCode=$(curl -s -o /dev/null -X POST -w "%{http_code}" 0.0.0.0:9003/write -d '{ 30 "namespace": "'"$namespace"'", 31 "id": "'"$id"'", 32 "datapoint": { 33 "timestamp":'"$timestamp"', 34 "value": '"$value"' 35 } 36 }') 37 38 if [[ $respCode -eq "200" ]]; then 39 return 0 40 else 41 return 1 42 fi 43 } 44 45 function read_all { 46 namespace=$1 47 id=$2 48 expected_datapoints=$3 49 50 received_datapoints=$(curl -sSf -X POST 0.0.0.0:9003/fetch -d '{ 51 "namespace": "'"$namespace"'", 52 "id": "'"$id"'", 53 "rangeStart": 0, 54 "rangeEnd":'"$(date +"%s")"' 55 }' | jq '.datapoints | length') 56 57 if [[ $expected_datapoints -eq $received_datapoints ]]; then 58 return 0 59 else 60 return 1 61 fi 62 } 63 64 echo "Write data for 'now - 2 * bufferPast' (testing cold writes from memory)" 65 write_data "coldWritesRepairAndNoIndex" "foo" "$(($(date +"%s") - 60 * 10 * 2))" 12.3456789 66 67 echo "Expect to read 1 datapoint" 68 read_all "coldWritesRepairAndNoIndex" "foo" 1 69 70 echo "Write data for 'now - 2 * blockSize' (testing compaction to disk)" 71 write_data "coldWritesRepairAndNoIndex" "foo" "$(($(date +"%s") - 60 * 60 * 2))" 98.7654321 72 73 echo "Wait until cold writes are flushed" 74 ATTEMPTS=10 MAX_TIMEOUT=4 TIMEOUT=1 retry_with_backoff \ 75 '[ -n "$(docker-compose -f ${COMPOSE_FILE} exec dbnode01 find /var/lib/m3db/data/coldWritesRepairAndNoIndex -name "*1-checkpoint.db")" ]' 76 77 echo "Restart DB (test bootstrapping cold writes)" 78 docker-compose -f ${COMPOSE_FILE} restart dbnode01 79 80 echo "Wait until bootstrapped" 81 ATTEMPTS=10 TIMEOUT=2 retry_with_backoff \ 82 '[ "$(curl -sSf 0.0.0.0:9002/health | jq .bootstrapped)" == true ]' 83 84 echo "Expect to read 2 datapoints" 85 read_all "coldWritesRepairAndNoIndex" "foo" 2