Skip to content

Conversation

@coryan
Copy link
Contributor

@coryan coryan commented Dec 6, 2017

This fixes #37. It implements an integration test for Table::Apply() against the Cloud Bigtable Emulator.

I think both @sduskis and @mbrukman will have opinions on the need for such integration tests. I want to hear from them if this is good enough. @garye and @DanielMahu please check the code too!

This is part of the fixes for googleapis#37.  The script starts up the
emulator and runs the integration test against it.
Also run the integration tests as part of the CI builds.
Copy link
Contributor

@mbrukman mbrukman left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some thoughts for your consideration.

wget \
zlib-devel

# Install the bigtable emulator and the bigtable command-line client. They
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

s/bigtable/Bigtable/g

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

g++-4.8 \
|| /bin/true

# Install the bigtable emulator and the bigtable command-line client. They
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

s/bigtable/Bigtable/

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.


int main() try {
bigtable::Client client("emulated", "emulated");
std::unique_ptr<bigtable::Table> table = client.Open("test-table");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we have the Admin API available yet? If so, it should create and delete the table itself. Same for the column family.

Otherwise, it's a bunch of magic strings here: both table and column family are set up via script, and must match here, but it's not stated anywhere either in the shell script or this C++ test.

Some options:

  1. document the implicit dependency (easy and cheesy)
  2. set env vars in the script, read those env vars in C++ so that it's clear it's an external input (preferred, unless option 3 is coming soon)
  3. once Admin API is available, just create/delete table + column family in the script (defer)

Thoughts?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nope, there is no Admin API, nor is the Admin API part of the MVP. I have created #79 for this. I am inclined to do (2) because it will make this program reusable for testing against production too. I used command-line args for the first cut.

mutation.emplace_back(bigtable::SetCell("fam", "col0", 0, "value-1-0"));
mutation.emplace_back(bigtable::SetCell("fam", "col1", 0, "value-1-1"));
table->Apply(std::move(mutation));
std::cout << "row-key-1 mutated successfully\n";
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this also do a read after each write to ensure it actually wrote what it thinks it did?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It should, but we do not have any APIs to read yet. #32 #29

set -eu

function kill_emulator {
kill ${EMULATOR_PID}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

2- or 4-space indent for shell scripts?

ARG GOPATH=/var/tmp/build/cbt
WORKDIR ${GOPATH}
RUN if grep -q 14.04 /etc/lsb-release; then \
echo "Skip cloud bigtable client install, go version too old in Ubuntu 14.04."; \
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

s/go/Go/g

ARG GOPATH=/var/tmp/build/cbt
WORKDIR ${GOPATH}
RUN if grep -q 14.04 /etc/lsb-release; then \
echo "Skip cloud bigtable client install, go version too old in Ubuntu 14.04."; \
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

s/Skip/Skipping/ ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.


WORKDIR /var/tmp/build/gccpp/build-output/bigtable
RUN if grep -q 14.04 /etc/lsb-release; then \
echo "Skip integration tests, go version too old in Ubuntu 14.04."; \
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

s/Skip/Skipping/ ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

"${GOPATH}/bin/emulator" >emulator.log 2>&1 </dev/null &
EMULATOR_PID=$!
if [ $? -ne 0 ]; then
echo "emulator failed, aborting"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about:

echo "Cloud Bigtable emulator failed; aborting test." >&2

?


trap kill_emulator EXIT

export BIGTABLE_EMULATOR_HOST=localhost:9000
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is 9000 the default port on which the emulator listens on? Is this running inside a container so we're guaranteed that 9000 is not taken already? Is it worthwhile to document where this magic number comes from? Is it worthwhile to choose a specific port explicitly and use a var so the connection is clear?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.


echo "Launching Cloud Bigtable emulator in the background"
"${GOPATH}/bin/emulator" >emulator.log 2>&1 </dev/null &
# The tests typically run on a docker container, where the ports are largely
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

s/on a docker/in a Docker/ ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

echo "Launching Cloud Bigtable emulator in the background"
"${GOPATH}/bin/emulator" >emulator.log 2>&1 </dev/null &
# The tests typically run on a docker container, where the ports are largely
# free, when using in manual tests you can set EMULATOR_PORT.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

s/free,/free;/

s/manual tests/manual tests,/

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done, thanks!

WORKDIR ${GOPATH}
RUN if grep -q 14.04 /etc/lsb-release; then \
echo "Skip cloud bigtable client install, go version too old in Ubuntu 14.04."; \
echo "Skipping cloud bigtable client install, Go version too old in Ubuntu 14.04."; \
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

s/cloud bigtable client/cbt/ ?

or if you want to be more descriptive, "cbt CLI"?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

@coryan
Copy link
Contributor Author

coryan commented Dec 7, 2017

PTAL.

Copy link
Contributor

@mbrukman mbrukman left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM


echo "Creating test-table in the emulator."
"${GOPATH}/bin/cbt" $CBT_ARGS createtable test-table
echo "Creating family in test-table."
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

s/family/column family/

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Argh, I missed that. Will fix.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in #81

@coryan coryan merged commit 67fc1ff into googleapis:master Dec 7, 2017
@coryan coryan deleted the fix-issue-37-integration-bigtable-emulator-develop branch December 7, 2017 04:21
mbrukman pushed a commit that referenced this pull request Dec 9, 2017
Leftover review comment from PR #74.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cla: yes This human has signed the Contributor License Agreement.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Implement integration test for Apply(Single) against Cloud Bigtable Emulator

3 participants