You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ignite.apache.org by is...@apache.org on 2021/03/30 09:56:31 UTC
[ignite-python-thin-client] branch master updated: IGNITE-13405 Fix
cache configuration serialization/deserialization
This is an automated email from the ASF dual-hosted git repository.
isapego pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/ignite-python-thin-client.git
The following commit(s) were added to refs/heads/master by this push:
new 2fd7fda IGNITE-13405 Fix cache configuration serialization/deserialization
2fd7fda is described below
commit 2fd7fda79d756b760ffa40a3afccb28db7a3b11e
Author: Ivan Dashchinskiy <iv...@gmail.com>
AuthorDate: Tue Mar 30 12:55:33 2021 +0300
IGNITE-13405 Fix cache configuration serialization/deserialization
This closes #25
---
pyignite/datatypes/cache_config.py | 4 +-
pyignite/datatypes/cache_properties.py | 2 +-
pyignite/datatypes/prop_codes.py | 2 -
tests/common/test_cache_config.py | 108 +++++++++++++++++++++++++++------
tests/config/ignite-config.xml.jinja2 | 29 ++++++---
5 files changed, 112 insertions(+), 33 deletions(-)
diff --git a/pyignite/datatypes/cache_config.py b/pyignite/datatypes/cache_config.py
index 67b353d..04ff607 100644
--- a/pyignite/datatypes/cache_config.py
+++ b/pyignite/datatypes/cache_config.py
@@ -120,16 +120,16 @@ CacheKeyConfiguration = StructArray([
cache_config_struct = Struct([
('length', Int),
+ ('cache_atomicity_mode', CacheAtomicityMode),
('backups_number', Int),
('cache_mode', CacheMode),
- ('cache_atomicity_mode', CacheAtomicityMode),
('copy_on_read', Bool),
('data_region_name', String),
('eager_ttl', Bool),
('statistics_enabled', Bool),
('group_name', String),
- ('invalidate', Int),
('default_lock_timeout', Long),
+ ('max_concurrent_async_operations', Int),
('max_query_iterators', Int),
('name', String),
('is_onheap_cache_enabled', Bool),
diff --git a/pyignite/datatypes/cache_properties.py b/pyignite/datatypes/cache_properties.py
index 127b6f3..d924507 100644
--- a/pyignite/datatypes/cache_properties.py
+++ b/pyignite/datatypes/cache_properties.py
@@ -67,7 +67,7 @@ def prop_map(code: int):
PROP_CACHE_KEY_CONFIGURATION: PropCacheKeyConfiguration,
PROP_DEFAULT_LOCK_TIMEOUT: PropDefaultLockTimeout,
PROP_MAX_CONCURRENT_ASYNC_OPERATIONS: PropMaxConcurrentAsyncOperation,
- PROP_PARTITION_LOSS_POLICY: PartitionLossPolicy,
+ PROP_PARTITION_LOSS_POLICY: PropPartitionLossPolicy,
PROP_EAGER_TTL: PropEagerTTL,
PROP_STATISTICS_ENABLED: PropStatisticsEnabled,
}[code]
diff --git a/pyignite/datatypes/prop_codes.py b/pyignite/datatypes/prop_codes.py
index adea281..72ffce1 100644
--- a/pyignite/datatypes/prop_codes.py
+++ b/pyignite/datatypes/prop_codes.py
@@ -47,5 +47,3 @@ PROP_MAX_CONCURRENT_ASYNC_OPERATIONS = 403
PROP_PARTITION_LOSS_POLICY = 404
PROP_EAGER_TTL = 405
PROP_STATISTICS_ENABLED = 406
-
-PROP_INVALIDATE = -1
diff --git a/tests/common/test_cache_config.py b/tests/common/test_cache_config.py
index f4c8067..e68eef5 100644
--- a/tests/common/test_cache_config.py
+++ b/tests/common/test_cache_config.py
@@ -12,24 +12,88 @@
# 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.
+
+from inspect import getmembers
+
+import pyignite
import pytest
-from pyignite.datatypes.prop_codes import PROP_NAME, PROP_CACHE_KEY_CONFIGURATION
+from pyignite.datatypes.cache_config import (
+ CacheMode, CacheAtomicityMode, WriteSynchronizationMode, PartitionLossPolicy, RebalanceMode
+)
+from pyignite.datatypes.prop_codes import (
+ PROP_NAME, PROP_CACHE_KEY_CONFIGURATION, PROP_CACHE_MODE, PROP_CACHE_ATOMICITY_MODE, PROP_BACKUPS_NUMBER,
+ PROP_WRITE_SYNCHRONIZATION_MODE, PROP_COPY_ON_READ, PROP_READ_FROM_BACKUP, PROP_DATA_REGION_NAME,
+ PROP_IS_ONHEAP_CACHE_ENABLED, PROP_GROUP_NAME, PROP_DEFAULT_LOCK_TIMEOUT, PROP_MAX_CONCURRENT_ASYNC_OPERATIONS,
+ PROP_PARTITION_LOSS_POLICY, PROP_EAGER_TTL, PROP_STATISTICS_ENABLED, PROP_REBALANCE_MODE, PROP_REBALANCE_DELAY,
+ PROP_REBALANCE_TIMEOUT, PROP_REBALANCE_BATCH_SIZE, PROP_REBALANCE_BATCHES_PREFETCH_COUNT, PROP_REBALANCE_ORDER,
+ PROP_REBALANCE_THROTTLE, PROP_QUERY_ENTITIES, PROP_QUERY_PARALLELISM, PROP_QUERY_DETAIL_METRIC_SIZE,
+ PROP_SQL_SCHEMA, PROP_SQL_INDEX_INLINE_MAX_SIZE, PROP_SQL_ESCAPE_ALL, PROP_MAX_QUERY_ITERATORS
+)
from pyignite.exceptions import CacheError
cache_name = 'config_cache'
@pytest.fixture
-def cache_config():
+def test_cache_settings():
return {
PROP_NAME: cache_name,
+ PROP_CACHE_MODE: CacheMode.PARTITIONED,
+ PROP_CACHE_ATOMICITY_MODE: CacheAtomicityMode.TRANSACTIONAL,
+ PROP_BACKUPS_NUMBER: 2,
+ PROP_WRITE_SYNCHRONIZATION_MODE: WriteSynchronizationMode.FULL_SYNC,
+ PROP_COPY_ON_READ: True,
+ PROP_READ_FROM_BACKUP: True,
+ PROP_DATA_REGION_NAME: 'SmallDataRegion',
+ PROP_IS_ONHEAP_CACHE_ENABLED: True,
+ PROP_QUERY_ENTITIES: [{
+ 'table_name': cache_name + '_table',
+ 'key_field_name': 'KEY',
+ 'key_type_name': 'java.lang.String',
+ 'value_field_name': 'VAL',
+ 'value_type_name': 'java.lang.String',
+ 'field_name_aliases': [
+ {'alias': 'val', 'field_name': 'VAL'},
+ {'alias': 'key', 'field_name': 'KEY'}
+ ],
+ 'query_fields': [
+ {
+ 'name': 'KEY',
+ 'type_name': 'java.lang.String'
+ },
+ {
+ 'name': 'VAL',
+ 'type_name': 'java.lang.String'
+ }
+ ],
+ 'query_indexes': []
+ }],
+ PROP_QUERY_PARALLELISM: 20,
+ PROP_QUERY_DETAIL_METRIC_SIZE: 10,
+ PROP_SQL_SCHEMA: 'PUBLIC',
+ PROP_SQL_INDEX_INLINE_MAX_SIZE: 1024,
+ PROP_SQL_ESCAPE_ALL: True,
+ PROP_MAX_QUERY_ITERATORS: 200,
+ PROP_REBALANCE_MODE: RebalanceMode.SYNC,
+ PROP_REBALANCE_DELAY: 1000,
+ PROP_REBALANCE_TIMEOUT: 5000,
+ PROP_REBALANCE_BATCH_SIZE: 100,
+ PROP_REBALANCE_BATCHES_PREFETCH_COUNT: 10,
+ PROP_REBALANCE_ORDER: 3,
+ PROP_REBALANCE_THROTTLE: 10,
+ PROP_GROUP_NAME: cache_name + '_group',
PROP_CACHE_KEY_CONFIGURATION: [
{
- 'type_name': 'blah',
+ 'type_name': 'java.lang.String',
'affinity_key_field_name': 'abc1234',
}
],
+ PROP_DEFAULT_LOCK_TIMEOUT: 3000,
+ PROP_MAX_CONCURRENT_ASYNC_OPERATIONS: 100,
+ PROP_PARTITION_LOSS_POLICY: PartitionLossPolicy.READ_WRITE_ALL,
+ PROP_EAGER_TTL: True,
+ PROP_STATISTICS_ENABLED: True
}
@@ -48,15 +112,15 @@ async def async_cache(async_client):
@pytest.fixture
-def cache_with_config(client, cache_config):
- cache = client.get_or_create_cache(cache_config)
+def cache_with_config(client, test_cache_settings):
+ cache = client.get_or_create_cache(test_cache_settings)
yield cache
cache.destroy()
@pytest.fixture
-async def async_cache_with_config(async_client, cache_config):
- cache = await async_client.get_or_create_cache(cache_config)
+async def async_cache_with_config(async_client, test_cache_settings):
+ cache = await async_client.get_or_create_cache(test_cache_settings)
yield cache
await cache.destroy()
@@ -72,44 +136,50 @@ async def test_cache_get_configuration_async(async_client, async_cache):
assert (await async_cache.settings())[PROP_NAME] == cache_name
-def test_get_or_create_with_config_existing(client, cache_with_config, cache_config):
+def test_get_or_create_with_config_existing(client, cache_with_config, test_cache_settings):
assert cache_name in client.get_cache_names()
with pytest.raises(CacheError):
- client.create_cache(cache_config)
+ client.create_cache(test_cache_settings)
- cache = client.get_or_create_cache(cache_config)
+ cache = client.get_or_create_cache(test_cache_settings)
assert cache.settings == cache_with_config.settings
@pytest.mark.asyncio
-async def test_get_or_create_with_config_existing_async(async_client, async_cache_with_config, cache_config):
+async def test_get_or_create_with_config_existing_async(async_client, async_cache_with_config, test_cache_settings):
assert cache_name in (await async_client.get_cache_names())
with pytest.raises(CacheError):
- await async_client.create_cache(cache_config)
+ await async_client.create_cache(test_cache_settings)
- cache = await async_client.get_or_create_cache(cache_config)
+ cache = await async_client.get_or_create_cache(test_cache_settings)
assert (await cache.settings()) == (await async_cache_with_config.settings())
+ALL_PROPS = {name: value for name, value in getmembers(pyignite.datatypes.prop_codes) if name.startswith('PROP')}
+
-def test_get_or_create_with_config_new(client, cache_config):
+def test_get_or_create_with_config_new(client, test_cache_settings):
assert cache_name not in client.get_cache_names()
- cache = client.get_or_create_cache(cache_config)
+ cache = client.get_or_create_cache(test_cache_settings)
try:
assert cache_name in client.get_cache_names()
- assert cache.settings[PROP_NAME] == cache_name
+ real_cache_settings = cache.settings
+ assert real_cache_settings == test_cache_settings
+ assert set(real_cache_settings.keys()) == set(ALL_PROPS.values())
finally:
cache.destroy()
@pytest.mark.asyncio
-async def test_get_or_create_with_config_new_async(async_client, cache_config):
+async def test_get_or_create_with_config_new_async(async_client, test_cache_settings):
assert cache_name not in (await async_client.get_cache_names())
- cache = await async_client.get_or_create_cache(cache_config)
+ cache = await async_client.get_or_create_cache(test_cache_settings)
try:
assert cache_name in (await async_client.get_cache_names())
- assert (await cache.settings())[PROP_NAME] == cache_name
+ real_cache_settings = await cache.settings()
+ assert real_cache_settings == test_cache_settings
+ assert set(real_cache_settings.keys()) == set(ALL_PROPS.values())
finally:
await cache.destroy()
diff --git a/tests/config/ignite-config.xml.jinja2 b/tests/config/ignite-config.xml.jinja2
index 85daf0f..2bf5129 100644
--- a/tests/config/ignite-config.xml.jinja2
+++ b/tests/config/ignite-config.xml.jinja2
@@ -27,20 +27,31 @@
http://www.springframework.org/schema/util/spring-util.xsd">
<bean id="grid.cfg" class="org.apache.ignite.configuration.IgniteConfiguration">
- {% if use_auth %}
- <property name="dataStorageConfiguration">
- <bean class="org.apache.ignite.configuration.DataStorageConfiguration">
- <property name="defaultDataRegionConfiguration">
+ <property name="dataStorageConfiguration">
+ <bean class="org.apache.ignite.configuration.DataStorageConfiguration">
+ <property name="defaultDataRegionConfiguration">
+ <bean class="org.apache.ignite.configuration.DataRegionConfiguration">
+ {% if use_auth %}
+ <property name="persistenceEnabled" value="true"/>
+ {% endif %}
+ </bean>
+ </property>
+ <property name="dataRegionConfigurations">
+ <list>
<bean class="org.apache.ignite.configuration.DataRegionConfiguration">
- <property name="persistenceEnabled" value="true"/>
+ <property name="name" value="SmallDataRegion"/>
+ <property name="maxSize" value="#{20 * 1024 * 1024}"/>
</bean>
- </property>
- </bean>
- </property>
+ </list>
+ </property>
+ </bean>
+ </property>
- <property name="authenticationEnabled" value="true"/>
+ {% if use_auth %}
+ <property name="authenticationEnabled" value="true"/>
{% endif %}
+
{% if use_ssl %}
<property name="connectorConfiguration"><null/></property>
{% endif %}