2019-02-12

Setting up Cassandra database service on TravisCI


At this time of writing TravisCI says that if you want to run a Cassandra service you have to add a cassandra service according to https://docs.travis-ci.com/user/database-setup/#cassandra:
services:
  - cassandra
but if you try to initialize cassandra you might find out that cassandra is not yet ready or running depending on timing.

The solution is:
And now cassandra is ready to be used in your tests (for example https://github.com/davidemoro/pytest-play-docker/blob/master/tests/test_cassandra.yml . In this case I'm using using plain yml files thanks to pytest-play)
sudo: required
services:
- cassandra
before_script:
- bash travis/setup_cassandra.sh
script:
- ... run test
view raw .travis.yml hosted with ❤ by GitHub
#!/bin/bash
function cassandra_ready() {
count=0
while ! cqlsh -e "describe cluster;" 2>&1 ; do
echo "waiting for cassandra"
if [ $count -gt 30 ]
then
exit
fi
(( count += 1 ))
sleep 1
done
echo "cassandra is ready"
}
cassandra_ready
cqlsh -e "create keyspace dev with replication = {'class': 'SimpleStrategy', 'replication_factor': 1}; USE dev; create table play(code int primary key, title varchar); insert into play (code, title) values (1, 'hello!');"
---
- provider: play_cassandra
type: execute
connection:
contact_points:
- 127.0.0.1
port: 9042
auth_provider:
username: cassandra
password: cassandra
keyspace: dev
query: SELECT title from play WHERE code = 1;
variable: title
variable_expression: results[0].title
assertion: "'$title' == 'hello!'"

No comments:

Post a Comment

Note: only a member of this blog may post a comment.