diff --git a/.travis.yml b/.travis.yml index b871cd16..d09baef8 100644 --- a/.travis.yml +++ b/.travis.yml @@ -6,7 +6,7 @@ python: - 3.5 - 3.6 before_install: - - sh scripts/setup_arangodb.sh + - bash scripts/setup_arangodb.sh install: - pip install coverage - pip install pytest diff --git a/arango/collections/base.py b/arango/collections/base.py index d1afb0ce..3b662c10 100644 --- a/arango/collections/base.py +++ b/arango/collections/base.py @@ -224,6 +224,12 @@ def properties(self): :raises arango.exceptions.CollectionPropertiesError: If the collection properties cannot be retrieved. """ + _cluster_parameters = { + 'numberOfShards': 'number_of_shards', + 'shardKeys': 'shard_keys', + 'replicationFactor': 'replication_factor', + } + request = Request( method='get', endpoint='/_api/collection/{}/properties'.format(self._name) @@ -235,7 +241,7 @@ def handler(res): key_options = res.body.get('keyOptions', {}) - return { + properties = { 'id': res.body.get('id'), 'name': res.body.get('name'), 'edge': res.body.get('type') == 3, @@ -251,6 +257,12 @@ def handler(res): 'key_offset': key_options.get('offset') } + for parameter, alt_name in _cluster_parameters.items(): + if parameter in res.body: + properties[alt_name] = res.body.get(parameter) + + return properties + return request, handler @api_method diff --git a/scripts/setup_arangodb.sh b/scripts/setup_arangodb.sh index 556ec37b..068a5b7e 100644 --- a/scripts/setup_arangodb.sh +++ b/scripts/setup_arangodb.sh @@ -22,17 +22,50 @@ ARANGODB_DIR="$DIR/$NAME" ARANGOD="${ARANGODB_DIR}/bin/arangod_x86_64" # create database directory -mkdir ${TMP_DIR} +mkdir -p ${TMP_DIR}/agency +mkdir -p ${TMP_DIR}/primary +mkdir -p ${TMP_DIR}/coordinator + +echo "Starting ArangoDB Coordinator '${ARANGOD}'" -echo "Starting ArangoDB '${ARANGOD}'" ${ARANGOD} \ - --database.directory ${TMP_DIR} \ + --database.directory ${TMP_DIR}/agency \ + --configuration none \ + --server.endpoint tcp://127.0.0.1:8531 \ + --javascript.app-path ${ARANGODB_DIR}/js/apps \ + --javascript.startup-directory ${ARANGODB_DIR}/js \ + --server.jwt-secret=secret_password \ + --database.maximal-journal-size 1048576 \ + --agency.my-address=tcp://127.0.0.1:8531 \ + --agency.endpoint=tcp://127.0.0.1:8531 \ + --agency.activate=true \ + --agency.size=1 \ + --agency.supervision=true & + +${ARANGOD} \ + --database.directory ${TMP_DIR}/primary \ + --configuration none \ + --server.endpoint tcp://127.0.0.1:8530 \ + --javascript.app-path ${ARANGODB_DIR}/js/apps \ + --javascript.startup-directory ${ARANGODB_DIR}/js \ + --server.jwt-secret=secret_password \ + --database.maximal-journal-size 1048576 \ + --cluster.agency-endpoint=tcp://127.0.0.1:8531 \ + --cluster.my-role=PRIMARY \ + --cluster.my-address=tcp://127.0.0.1:8530 & + +${ARANGOD} \ + --database.directory ${TMP_DIR}/coordinator \ --configuration none \ --server.endpoint tcp://127.0.0.1:8529 \ --javascript.app-path ${ARANGODB_DIR}/js/apps \ --javascript.startup-directory ${ARANGODB_DIR}/js \ - --database.maximal-journal-size 1048576 & + --server.jwt-secret=secret_password \ + --database.maximal-journal-size 1048576 \ + --cluster.agency-endpoint=tcp://127.0.0.1:8531 \ + --cluster.my-role=COORDINATOR \ + --cluster.my-address=tcp://127.0.0.1:8529 & sleep 2 @@ -45,7 +78,19 @@ if [ "x$process" == "x" ]; then exit 1 fi -echo "Waiting until ArangoDB is ready on port 8529" -sleep 10 +echo "Waiting until ArangoDB Coordinator is ready on port 8529" +timeout=120 +n=0 +while [[ (-z `curl -k --basic --user "root:" -s "http://127.0.0.1:8529/_api/version" `) && (n -lt timeout) ]] ; do + echo -n "." + sleep 1s + n=$[$n+1] +done + +if [[ n -eq timeout ]]; +then + echo "Could not start ArangoDB. Timeout reached." + exit 1 +fi echo "ArangoDB is up" diff --git a/tests/test_collection.py b/tests/test_collection.py index 4dbc69be..e8b9e88c 100644 --- a/tests/test_collection.py +++ b/tests/test_collection.py @@ -42,6 +42,9 @@ def test_properties(): assert isinstance(properties['compact'], bool) assert isinstance(properties['volatile'], bool) assert isinstance(properties['journal_size'], int) + assert isinstance(properties['replication_factor'], int) + assert isinstance(properties['number_of_shards'], int) + assert isinstance(properties['shard_keys'], list) assert properties['keygen'] in ('autoincrement', 'traditional') assert isinstance(properties['user_keys'], bool) if properties['key_increment'] is not None: