<commit_before>#!/usr/bin/env bash
#
# Sample use of overriding parameters:
# - host, name of the host where all microservices are running
# - port, the port where the API is available
#
# $ host=myhost port=8765 ./test-all.sh
#
: ${host=localhost}
: ${port=443}

# set -e

function testUrl() {
    url=$@
    if curl $url -ks -f -o /dev/null
    then
          echo "Ok"
          return 0
    else
          echo -n "not yet"
          return 1
    fi;
}

function waitForService() {

    url=$@
    echo -n "Wait for: $url... "
    n=0
    until testUrl $url
    do
        ((n++))
        if [[ $n == 20 ]]
        then
            echo " Give up"
            exit 1
        else
            sleep 6
            echo -n ", retry #$n "
        fi
    done

}

function waitForServices() {
    waitForService $host:8761
    waitForService $host:8761/eureka/apps/config-server
    waitForService $host:8761/eureka/apps/edge-server
    waitForService $host:8761/eureka/apps/product-service
    waitForService $host:8761/eureka/apps/review-service
    waitForService $host:8761/eureka/apps/recommendation-service
    waitForService $host:8761/eureka/apps/composite-service
}


function testAPI() {
    url=$@
    echo "Is the API awake?"
    echo "$ curl -ks https://$host:$port/api/product/123 -H \"Authorization: Bearer \$TOKEN\" | jq ."
    if curl -ks https://$host:$port/api/product/123 -H "Authorization: Bearer $TOKEN" -f -o /dev/null
    then
          echo "Ok"
          return 0
    else
          echo -n "not yet"
          return 1
    fi;
}

function waitForAPI() {

    url=$@
    echo -n "Wait for API: $url... "
    n=0
    until testAPI $url
    do
        ((n++))
        if [[ $n == 20 ]]
        then
            echo " Give up"
            exit 1
        else
            sleep 6
            echo -n ", retry #$n "
        fi
    done

}

echo "Start:" `date`

if [[ $@ == *"start"* ]]
then
    echo "Restarting the test environment..."
    echo "$ docker-compose down"
    docker-compose down
    echo "$ docker-compose up -d"
    ./setup-env.sh
    docker-compose up -d
fi

waitForServices

#echo ''
#echo "Call /info on each microservice:"
#docker-compose exec composite wget -qO- localhost:8080/info | jq
#docker-compose exec pro wget -qO- localhost:8080/info | jq
#docker-compose exec rev wget -qO- localhost:8080/info | jq
#docker-compose exec rec wget -qO- localhost:8080/info | jq

<commit_msg>build-all.sh: Need to run setup-env.sh before docker-compose down as well.<commit_after>#!/usr/bin/env bash
#
# Sample use of overriding parameters:
# - host, name of the host where all microservices are running
# - port, the port where the API is available
#
# $ host=myhost port=8765 ./test-all.sh
#
: ${host=localhost}
: ${port=443}

# set -e

function testUrl() {
    url=$@
    if curl $url -ks -f -o /dev/null
    then
          echo "Ok"
          return 0
    else
          echo -n "not yet"
          return 1
    fi;
}

function waitForService() {

    url=$@
    echo -n "Wait for: $url... "
    n=0
    until testUrl $url
    do
        ((n++))
        if [[ $n == 20 ]]
        then
            echo " Give up"
            exit 1
        else
            sleep 6
            echo -n ", retry #$n "
        fi
    done

}

function waitForServices() {
    waitForService $host:8761
    waitForService $host:8761/eureka/apps/config-server
    waitForService $host:8761/eureka/apps/edge-server
    waitForService $host:8761/eureka/apps/product-service
    waitForService $host:8761/eureka/apps/review-service
    waitForService $host:8761/eureka/apps/recommendation-service
    waitForService $host:8761/eureka/apps/composite-service
}


function testAPI() {
    url=$@
    echo "Is the API awake?"
    echo "$ curl -ks https://$host:$port/api/product/123 -H \"Authorization: Bearer \$TOKEN\" | jq ."
    if curl -ks https://$host:$port/api/product/123 -H "Authorization: Bearer $TOKEN" -f -o /dev/null
    then
          echo "Ok"
          return 0
    else
          echo -n "not yet"
          return 1
    fi;
}

function waitForAPI() {

    url=$@
    echo -n "Wait for API: $url... "
    n=0
    until testAPI $url
    do
        ((n++))
        if [[ $n == 20 ]]
        then
            echo " Give up"
            exit 1
        else
            sleep 6
            echo -n ", retry #$n "
        fi
    done

}

echo "Start:" `date`

. ./setup-env.sh

if [[ $@ == *"start"* ]]
then
    echo "Restarting the test environment..."
    echo "$ docker-compose down"
    docker-compose down
    echo "$ docker-compose up -d"
    docker-compose up -d
fi

waitForServices

#echo ''
#echo "Call /info on each microservice:"
#docker-compose exec composite wget -qO- localhost:8080/info | jq
#docker-compose exec pro wget -qO- localhost:8080/info | jq
#docker-compose exec rev wget -qO- localhost:8080/info | jq
#docker-compose exec rec wget -qO- localhost:8080/info | jq


{'fraction_non_alphanumeric': 0.1271393643031785, 'fraction_numerical': 0.02893235533822331, 'mean_word_length': 1.9951189749847469, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 4, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '855203', 'n_tokens_mistral': 1796, 'n_tokens_neox': 1661, 'n_words': 485}