From 328d8bef380ed023d6c7401f0335a391ba11d0a3 Mon Sep 17 00:00:00 2001 From: Joohwan Oh Date: Mon, 10 Apr 2017 20:42:26 -0700 Subject: [PATCH] Add parameter replication_factor to method Database.create_collection --- .travis.yml | 1 + README.rst | 4 ++-- arango/database.py | 20 +++++++++++++++++++- arango/version.py | 2 +- docs/index.rst | 2 +- scripts/setup_arangodb.sh | 2 +- tests/test_cursor.py | 16 ++++++++-------- tests/test_database.py | 1 + 8 files changed, 34 insertions(+), 14 deletions(-) diff --git a/.travis.yml b/.travis.yml index e717f21d..b871cd16 100644 --- a/.travis.yml +++ b/.travis.yml @@ -4,6 +4,7 @@ python: - 2.7 - 3.4 - 3.5 + - 3.6 before_install: - sh scripts/setup_arangodb.sh install: diff --git a/README.rst b/README.rst index 50e98c2e..9e90c047 100644 --- a/README.rst +++ b/README.rst @@ -14,7 +14,7 @@ :target: https://badge.fury.io/py/python-arango :alt: Package Version -.. image:: https://img.shields.io/badge/python-2.7%2C%203.4%2C%203.5-blue.svg +.. image:: https://img.shields.io/badge/python-2.7%2C%203.4%2C%203.5%2C%203.6-blue.svg :target: https://github.com/joowani/python-arango :alt: Python Versions @@ -45,7 +45,7 @@ Features Compatibility ============= -- Python versions 2.7.x, 3.4.x and 3.5.x are supported +- Python versions 2.7.x, 3.4.x, 3.5.x and 3.6.x are supported - Latest version of python-arango (3.x) supports ArangoDB 3.x only - Older versions of python-arango support ArangoDB 1.x ~ 2.x only diff --git a/arango/database.py b/arango/database.py index b7bd5db2..1d1c4fa7 100644 --- a/arango/database.py +++ b/arango/database.py @@ -237,7 +237,8 @@ def create_collection(self, key_generator="traditional", shard_fields=None, shard_count=None, - index_bucket_count=None): + index_bucket_count=None, + replication_factor=None): """Create a new collection. .. note:: @@ -280,6 +281,21 @@ def create_collection(self, parallel (e.g. 64 might be a sensible value for a collection with 100,000,000 documents. :type index_bucket_count: int + :param replication_factor: the number of copies of each shard on + different servers in a cluster, whose allowed values are: + + .. code-block:: none + + 1: only one copy is kept (no synchronous replication). + + k: k-1 replicas are kept and any two copies are replicated + across different DBServers synchronously, meaning every + write to the master is copied to all slaves before the + operation is reported successful. + + Default: ``1``. + + :type replication_factor: int :returns: the new collection object :rtype: arango.collections.Collection :raises arango.exceptions.CollectionCreateError: if the collection @@ -308,6 +324,8 @@ def create_collection(self, data['shardKeys'] = shard_fields if index_bucket_count is not None: data['indexBuckets'] = index_bucket_count + if replication_factor is not None: + data['replicationFactor'] = replication_factor res = self._conn.post('/_api/collection', data=data) if res.status_code not in HTTP_OK: diff --git a/arango/version.py b/arango/version.py index 8ee9c90b..c6e72944 100644 --- a/arango/version.py +++ b/arango/version.py @@ -1 +1 @@ -VERSION = '3.5.0' +VERSION = '3.6.0' diff --git a/docs/index.rst b/docs/index.rst index a57fe109..e90d5609 100644 --- a/docs/index.rst +++ b/docs/index.rst @@ -21,7 +21,7 @@ Features Compatibility ============= -- Python versions 2.7.x, 3.4.x and 3.5.x are supported +- Python versions 2.7.x, 3.4.x, 3.5.x and 3.6.x are supported - Latest version of python-arango (3.x) supports ArangoDB 3.x only - Older versions of python-arango support ArangoDB 1.x ~ 2.x only diff --git a/scripts/setup_arangodb.sh b/scripts/setup_arangodb.sh index 612bb1c8..f4485aa4 100644 --- a/scripts/setup_arangodb.sh +++ b/scripts/setup_arangodb.sh @@ -3,7 +3,7 @@ DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" cd $DIR -VERSION=3.1.10 +VERSION=3.1.17 NAME=ArangoDB-$VERSION if [ ! -d "$DIR/$NAME" ]; then diff --git a/tests/test_cursor.py b/tests/test_cursor.py index 054b14c3..d9b2ce79 100644 --- a/tests/test_cursor.py +++ b/tests/test_cursor.py @@ -56,7 +56,7 @@ def test_read_cursor_init(): assert cursor.warnings() == [] assert cursor.count() == 4 assert clean_keys(cursor.batch()) == [doc1, doc2] - assert isinstance(cursor.statistics()['execution_time'], float) + assert isinstance(cursor.statistics()['execution_time'], (int, float)) @pytest.mark.order2 @@ -73,7 +73,7 @@ def test_read_cursor_first(): assert cursor.warnings() == [] assert cursor.count() == 4 assert clean_keys(cursor.batch()) == [doc2] - assert isinstance(cursor.statistics()['execution_time'], float) + assert isinstance(cursor.statistics()['execution_time'], (int, float)) @pytest.mark.order3 @@ -90,7 +90,7 @@ def test_read_cursor_second(): assert cursor.warnings() == [] assert cursor.count() == 4 assert clean_keys(cursor.batch()) == [] - assert isinstance(cursor.statistics()['execution_time'], float) + assert isinstance(cursor.statistics()['execution_time'], (int, float)) @pytest.mark.order4 @@ -107,7 +107,7 @@ def test_read_cursor_third(): assert cursor.warnings() == [] assert cursor.count() == 4 assert clean_keys(cursor.batch()) == [doc3] - assert isinstance(cursor.statistics()['execution_time'], float) + assert isinstance(cursor.statistics()['execution_time'], (int, float)) @pytest.mark.order5 @@ -124,7 +124,7 @@ def test_read_cursor_finish(): assert cursor.warnings() == [] assert cursor.count() == 4 assert clean_keys(cursor.batch()) == [] - assert isinstance(cursor.statistics()['execution_time'], float) + assert isinstance(cursor.statistics()['execution_time'], (int, float)) with pytest.raises(StopIteration): cursor.next() assert cursor.close(ignore_missing=True) is False @@ -185,7 +185,7 @@ def test_write_cursor_init(): assert cursor.warnings() == [] assert cursor.count() == 2 assert clean_keys(cursor.batch()) == [doc1] - assert isinstance(cursor.statistics()['execution_time'], float) + assert isinstance(cursor.statistics()['execution_time'], (int, float)) @pytest.mark.order8 @@ -202,7 +202,7 @@ def test_write_cursor_first(): assert cursor.warnings() == [] assert cursor.count() == 2 assert clean_keys(cursor.batch()) == [] - assert isinstance(cursor.statistics()['execution_time'], float) + assert isinstance(cursor.statistics()['execution_time'], (int, float)) @pytest.mark.order9 @@ -219,7 +219,7 @@ def test_write_cursor_second(): assert cursor.warnings() == [] assert cursor.count() == 2 assert clean_keys(cursor.batch()) == [] - assert isinstance(cursor.statistics()['execution_time'], float) + assert isinstance(cursor.statistics()['execution_time'], (int, float)) with pytest.raises(StopIteration): cursor.next() assert cursor.close(ignore_missing=True) is False diff --git a/tests/test_database.py b/tests/test_database.py index 546c1396..02ecafe0 100644 --- a/tests/test_database.py +++ b/tests/test_database.py @@ -89,6 +89,7 @@ def test_create_collection(): shard_count=2, shard_fields=["test_attr"], index_bucket_count=10, + replication_factor=1 ) properties = col.properties() assert 'id' in properties