From 90a880ef9099efc7555eddf175a6be7a7331dff6 Mon Sep 17 00:00:00 2001 From: Tim Swast Date: Thu, 28 Apr 2016 21:21:04 -0700 Subject: [PATCH] Add Datastore indexes samples. (#214) Samples are moved from: https://cloud.google.com/appengine/docs/java/datastore/indexes Note: I add a new script `test-devserver.sh` to the testing config. This script runs the `mvn appengine:devserver` plugin, waits for it to start, then verifies that it gets a non-error response from the `/` path. I use this to verify that the `datastore-indexes.xml` files are correct (by disabling autoGenerate, the local devserver throws an error when a query is used without the correct index defined, just as production does). We should probably add any "hello world" or other projects to this check, as well. Anywhere we say to run `mvn appengine:devserver`, it would be good to test that it is correct. --- test-devserver.sh | 52 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100755 test-devserver.sh diff --git a/test-devserver.sh b/test-devserver.sh new file mode 100755 index 00000000000..62b3dfefef7 --- /dev/null +++ b/test-devserver.sh @@ -0,0 +1,52 @@ +#!/usr/bin/env bash +# Copyright 2016 Google Inc. All Rights Reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +# Usage: +# test-devserver.sh path/to/project +# +# This script runs the local appengine:devserver Maven plugin and verifies that +# a request to http://localhost:8080/ does not return an error code. +# +# As an example, this is useful for verifying that datastore-indexes.xml is +# correct (only if autoGenerate=false and the / handler does all queries used), +# as an example. + +set -e +set -x + +if [ -z "$1" ]; then + echo "Missing directory parameter." + echo "Usage:" + echo " $0 path/to/project" + exit 1 +fi + +( +cd "$1" +expect -c ' + spawn mvn --batch-mode clean appengine:devserver -DskipTests + set timeout 600 + expect localhost:8080 + sleep 10 + spawn curl --silent --output /dev/stderr --write-out "%{http_code}" http://localhost:8080/ + expect { + "200" { + exit + } + } + exit 1 + ' +) +