diff --git a/contrib/scripts/test-bulk-schema.sh b/contrib/scripts/test-bulk-schema.sh new file mode 100755 index 00000000000..c9fa8d1d215 --- /dev/null +++ b/contrib/scripts/test-bulk-schema.sh @@ -0,0 +1,227 @@ +#!/bin/bash +# verify fix of https://github.com/dgraph-io/dgraph/issues/2616 + +readonly ME=${0##*/} +readonly SRCDIR=$(readlink -f ${BASH_SOURCE[0]%/*}) + +declare -ri PORT_OFFSET=$((RANDOM % 1000)) +declare -ri ZERO_PORT=$((5080+PORT_OFFSET)) +declare -ri ALPHA_PORT=$((7080+PORT_OFFSET)) HTTP_PORT=$((8080+PORT_OFFSET)) + +INFO() { echo "$ME: $@"; } +ERROR() { echo >&2 "$ME: $@"; } +FATAL() { ERROR "$@"; exit 1; } + +set -e + +INFO "running bulk load schema test" + +WORKDIR=$(mktemp --tmpdir -d $ME.tmp-XXXXXX) +INFO "using workdir $WORKDIR" +cd $WORKDIR + +function StartZero +{ + INFO "starting zero server on port $ZERO_PORT" + dgraph zero -o $PORT_OFFSET --my=localhost:$ZERO_PORT \ + >zero.log 2>&1 1million.schema <> 1million.rdf.gz & + dgraph bulk -z localhost:$ZERO_PORT -s 1million.schema -r 1million.rdf.gz \ + >bulk.log 2>&1 alpha.log 2>&1 /dev/null + + curl localhost:$HTTP_PORT/mutate -X POST -H 'X-Dgraph-CommitNow: true' -d $' +{ + set { + _:company1 "CompanyABC" . + } +} +' &>/dev/null +} + +function QuerySchema +{ + INFO "running schema query" + local out_file=${1:?no out file} + curl -sS localhost:$HTTP_PORT/query -XPOST -d'schema {}' | python -c "import json,sys; d=json.load(sys.stdin); json.dump(d['data'],sys.stdout,sort_keys=True,indent=2,separators=(',',': '))" > $out_file + echo >> $out_file + #INFO "schema is: " && cat $out_file +} + +function DoExport +{ + INFO "running export" + curl localhost:$HTTP_PORT/admin/export &>/dev/null + sleep 1 +} + +function BulkLoadExportedData +{ + INFO "bulk loading exported data" + dgraph bulk -z localhost:$ZERO_PORT \ + -s ../dir1/export/*/g01.schema.gz \ + -r ../dir1/export/*/g01.rdf.gz \ + >bulk.log 2>&1 fixture.schema <fixture.rdf < "E.T. the Extra-Terrestrial" . +_:et "Science Fiction" . +_:et "792.9" . +EOF + + dgraph bulk -z localhost:$ZERO_PORT -s fixture.schema -r fixture.rdf \ + >bulk.log 2>&1 /dev/null + +StartZero +BulkLoadSampleData +StartAlpha +UpdateDatabase +QuerySchema "schema.out" +DoExport +StopServers + +popd >/dev/null +mkdir dir2 +pushd dir2 >/dev/null + +StartZero +BulkLoadExportedData +StartAlpha +QuerySchema "schema.out" +StopServers + +popd >/dev/null + +INFO "verifing schema is same before export and after bulk import" +diff dir1/schema.out dir2/schema.out || FATAL "schema incorrect" +INFO "schema is correct" + +mkdir dir3 +pushd dir3 >/dev/null + +StartZero +BulkLoadFixtureData +StartAlpha +QuerySchema "schema.out" +StopServers + +popd >/dev/null + +# final schema should include *all* predicates regardless of whether they were +# introduced by the schema or rdf file, used or not used, or of default type +# or non-default type +INFO "verifying schema contains all predicates" +diff - dir3/schema.out <