Skip to content

Commit e80a129

Browse files
isapegoivandasch
andauthored
GG-32959 [IGNITE-13405] Fix cache configuration serialization/deserialization (#35)
(cherry picked from commit 2fd7fda) Co-authored-by: Ivan Dashchinskiy <ivandasch@gmail.com>
1 parent 3f5d779 commit e80a129

5 files changed

Lines changed: 112 additions & 33 deletions

File tree

pygridgain/datatypes/cache_config.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -120,16 +120,16 @@ class CacheAtomicityMode(Int):
120120

121121
cache_config_struct = Struct([
122122
('length', Int),
123+
('cache_atomicity_mode', CacheAtomicityMode),
123124
('backups_number', Int),
124125
('cache_mode', CacheMode),
125-
('cache_atomicity_mode', CacheAtomicityMode),
126126
('copy_on_read', Bool),
127127
('data_region_name', String),
128128
('eager_ttl', Bool),
129129
('statistics_enabled', Bool),
130130
('group_name', String),
131-
('invalidate', Int),
132131
('default_lock_timeout', Long),
132+
('max_concurrent_async_operations', Int),
133133
('max_query_iterators', Int),
134134
('name', String),
135135
('is_onheap_cache_enabled', Bool),

pygridgain/datatypes/cache_properties.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ def prop_map(code: int):
6767
PROP_CACHE_KEY_CONFIGURATION: PropCacheKeyConfiguration,
6868
PROP_DEFAULT_LOCK_TIMEOUT: PropDefaultLockTimeout,
6969
PROP_MAX_CONCURRENT_ASYNC_OPERATIONS: PropMaxConcurrentAsyncOperation,
70-
PROP_PARTITION_LOSS_POLICY: PartitionLossPolicy,
70+
PROP_PARTITION_LOSS_POLICY: PropPartitionLossPolicy,
7171
PROP_EAGER_TTL: PropEagerTTL,
7272
PROP_STATISTICS_ENABLED: PropStatisticsEnabled,
7373
}[code]

pygridgain/datatypes/prop_codes.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,5 +47,3 @@
4747
PROP_PARTITION_LOSS_POLICY = 404
4848
PROP_EAGER_TTL = 405
4949
PROP_STATISTICS_ENABLED = 406
50-
51-
PROP_INVALIDATE = -1

tests/common/test_cache_config.py

Lines changed: 89 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -12,24 +12,88 @@
1212
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1313
# See the License for the specific language governing permissions and
1414
# limitations under the License.
15+
16+
from inspect import getmembers
17+
18+
import pygridgain
1519
import pytest
1620

17-
from pygridgain.datatypes.prop_codes import PROP_NAME, PROP_CACHE_KEY_CONFIGURATION
21+
from pygridgain.datatypes.cache_config import (
22+
CacheMode, CacheAtomicityMode, WriteSynchronizationMode, PartitionLossPolicy, RebalanceMode
23+
)
24+
from pygridgain.datatypes.prop_codes import (
25+
PROP_NAME, PROP_CACHE_KEY_CONFIGURATION, PROP_CACHE_MODE, PROP_CACHE_ATOMICITY_MODE, PROP_BACKUPS_NUMBER,
26+
PROP_WRITE_SYNCHRONIZATION_MODE, PROP_COPY_ON_READ, PROP_READ_FROM_BACKUP, PROP_DATA_REGION_NAME,
27+
PROP_IS_ONHEAP_CACHE_ENABLED, PROP_GROUP_NAME, PROP_DEFAULT_LOCK_TIMEOUT, PROP_MAX_CONCURRENT_ASYNC_OPERATIONS,
28+
PROP_PARTITION_LOSS_POLICY, PROP_EAGER_TTL, PROP_STATISTICS_ENABLED, PROP_REBALANCE_MODE, PROP_REBALANCE_DELAY,
29+
PROP_REBALANCE_TIMEOUT, PROP_REBALANCE_BATCH_SIZE, PROP_REBALANCE_BATCHES_PREFETCH_COUNT, PROP_REBALANCE_ORDER,
30+
PROP_REBALANCE_THROTTLE, PROP_QUERY_ENTITIES, PROP_QUERY_PARALLELISM, PROP_QUERY_DETAIL_METRIC_SIZE,
31+
PROP_SQL_SCHEMA, PROP_SQL_INDEX_INLINE_MAX_SIZE, PROP_SQL_ESCAPE_ALL, PROP_MAX_QUERY_ITERATORS
32+
)
1833
from pygridgain.exceptions import CacheError
1934

2035
cache_name = 'config_cache'
2136

2237

2338
@pytest.fixture
24-
def cache_config():
39+
def test_cache_settings():
2540
return {
2641
PROP_NAME: cache_name,
42+
PROP_CACHE_MODE: CacheMode.PARTITIONED,
43+
PROP_CACHE_ATOMICITY_MODE: CacheAtomicityMode.TRANSACTIONAL,
44+
PROP_BACKUPS_NUMBER: 2,
45+
PROP_WRITE_SYNCHRONIZATION_MODE: WriteSynchronizationMode.FULL_SYNC,
46+
PROP_COPY_ON_READ: True,
47+
PROP_READ_FROM_BACKUP: True,
48+
PROP_DATA_REGION_NAME: 'SmallDataRegion',
49+
PROP_IS_ONHEAP_CACHE_ENABLED: True,
50+
PROP_QUERY_ENTITIES: [{
51+
'table_name': cache_name + '_table',
52+
'key_field_name': 'KEY',
53+
'key_type_name': 'java.lang.String',
54+
'value_field_name': 'VAL',
55+
'value_type_name': 'java.lang.String',
56+
'field_name_aliases': [
57+
{'alias': 'val', 'field_name': 'VAL'},
58+
{'alias': 'key', 'field_name': 'KEY'}
59+
],
60+
'query_fields': [
61+
{
62+
'name': 'KEY',
63+
'type_name': 'java.lang.String'
64+
},
65+
{
66+
'name': 'VAL',
67+
'type_name': 'java.lang.String'
68+
}
69+
],
70+
'query_indexes': []
71+
}],
72+
PROP_QUERY_PARALLELISM: 20,
73+
PROP_QUERY_DETAIL_METRIC_SIZE: 10,
74+
PROP_SQL_SCHEMA: 'PUBLIC',
75+
PROP_SQL_INDEX_INLINE_MAX_SIZE: 1024,
76+
PROP_SQL_ESCAPE_ALL: True,
77+
PROP_MAX_QUERY_ITERATORS: 200,
78+
PROP_REBALANCE_MODE: RebalanceMode.SYNC,
79+
PROP_REBALANCE_DELAY: 1000,
80+
PROP_REBALANCE_TIMEOUT: 5000,
81+
PROP_REBALANCE_BATCH_SIZE: 100,
82+
PROP_REBALANCE_BATCHES_PREFETCH_COUNT: 10,
83+
PROP_REBALANCE_ORDER: 3,
84+
PROP_REBALANCE_THROTTLE: 10,
85+
PROP_GROUP_NAME: cache_name + '_group',
2786
PROP_CACHE_KEY_CONFIGURATION: [
2887
{
29-
'type_name': 'blah',
88+
'type_name': 'java.lang.String',
3089
'affinity_key_field_name': 'abc1234',
3190
}
3291
],
92+
PROP_DEFAULT_LOCK_TIMEOUT: 3000,
93+
PROP_MAX_CONCURRENT_ASYNC_OPERATIONS: 100,
94+
PROP_PARTITION_LOSS_POLICY: PartitionLossPolicy.READ_WRITE_ALL,
95+
PROP_EAGER_TTL: True,
96+
PROP_STATISTICS_ENABLED: True
3397
}
3498

3599

@@ -48,15 +112,15 @@ async def async_cache(async_client):
48112

49113

50114
@pytest.fixture
51-
def cache_with_config(client, cache_config):
52-
cache = client.get_or_create_cache(cache_config)
115+
def cache_with_config(client, test_cache_settings):
116+
cache = client.get_or_create_cache(test_cache_settings)
53117
yield cache
54118
cache.destroy()
55119

56120

57121
@pytest.fixture
58-
async def async_cache_with_config(async_client, cache_config):
59-
cache = await async_client.get_or_create_cache(cache_config)
122+
async def async_cache_with_config(async_client, test_cache_settings):
123+
cache = await async_client.get_or_create_cache(test_cache_settings)
60124
yield cache
61125
await cache.destroy()
62126

@@ -72,44 +136,50 @@ async def test_cache_get_configuration_async(async_client, async_cache):
72136
assert (await async_cache.settings())[PROP_NAME] == cache_name
73137

74138

75-
def test_get_or_create_with_config_existing(client, cache_with_config, cache_config):
139+
def test_get_or_create_with_config_existing(client, cache_with_config, test_cache_settings):
76140
assert cache_name in client.get_cache_names()
77141

78142
with pytest.raises(CacheError):
79-
client.create_cache(cache_config)
143+
client.create_cache(test_cache_settings)
80144

81-
cache = client.get_or_create_cache(cache_config)
145+
cache = client.get_or_create_cache(test_cache_settings)
82146
assert cache.settings == cache_with_config.settings
83147

84148

85149
@pytest.mark.asyncio
86-
async def test_get_or_create_with_config_existing_async(async_client, async_cache_with_config, cache_config):
150+
async def test_get_or_create_with_config_existing_async(async_client, async_cache_with_config, test_cache_settings):
87151
assert cache_name in (await async_client.get_cache_names())
88152

89153
with pytest.raises(CacheError):
90-
await async_client.create_cache(cache_config)
154+
await async_client.create_cache(test_cache_settings)
91155

92-
cache = await async_client.get_or_create_cache(cache_config)
156+
cache = await async_client.get_or_create_cache(test_cache_settings)
93157
assert (await cache.settings()) == (await async_cache_with_config.settings())
94158

159+
ALL_PROPS = {name: value for name, value in getmembers(pygridgain.datatypes.prop_codes) if name.startswith('PROP')}
160+
95161

96-
def test_get_or_create_with_config_new(client, cache_config):
162+
def test_get_or_create_with_config_new(client, test_cache_settings):
97163
assert cache_name not in client.get_cache_names()
98-
cache = client.get_or_create_cache(cache_config)
164+
cache = client.get_or_create_cache(test_cache_settings)
99165
try:
100166
assert cache_name in client.get_cache_names()
101-
assert cache.settings[PROP_NAME] == cache_name
167+
real_cache_settings = cache.settings
168+
assert real_cache_settings == test_cache_settings
169+
assert set(real_cache_settings.keys()) == set(ALL_PROPS.values())
102170
finally:
103171
cache.destroy()
104172

105173

106174
@pytest.mark.asyncio
107-
async def test_get_or_create_with_config_new_async(async_client, cache_config):
175+
async def test_get_or_create_with_config_new_async(async_client, test_cache_settings):
108176
assert cache_name not in (await async_client.get_cache_names())
109177

110-
cache = await async_client.get_or_create_cache(cache_config)
178+
cache = await async_client.get_or_create_cache(test_cache_settings)
111179
try:
112180
assert cache_name in (await async_client.get_cache_names())
113-
assert (await cache.settings())[PROP_NAME] == cache_name
181+
real_cache_settings = await cache.settings()
182+
assert real_cache_settings == test_cache_settings
183+
assert set(real_cache_settings.keys()) == set(ALL_PROPS.values())
114184
finally:
115185
await cache.destroy()

tests/config/ignite-config.xml.jinja2

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -26,20 +26,31 @@
2626
http://www.springframework.org/schema/util/spring-util.xsd">
2727

2828
<bean id="grid.cfg" class="org.apache.ignite.configuration.IgniteConfiguration">
29-
{% if use_auth %}
30-
<property name="dataStorageConfiguration">
31-
<bean class="org.apache.ignite.configuration.DataStorageConfiguration">
32-
<property name="defaultDataRegionConfiguration">
29+
<property name="dataStorageConfiguration">
30+
<bean class="org.apache.ignite.configuration.DataStorageConfiguration">
31+
<property name="defaultDataRegionConfiguration">
32+
<bean class="org.apache.ignite.configuration.DataRegionConfiguration">
33+
{% if use_auth %}
34+
<property name="persistenceEnabled" value="true"/>
35+
{% endif %}
36+
</bean>
37+
</property>
38+
<property name="dataRegionConfigurations">
39+
<list>
3340
<bean class="org.apache.ignite.configuration.DataRegionConfiguration">
34-
<property name="persistenceEnabled" value="true"/>
41+
<property name="name" value="SmallDataRegion"/>
42+
<property name="maxSize" value="#{20 * 1024 * 1024}"/>
3543
</bean>
36-
</property>
37-
</bean>
38-
</property>
44+
</list>
45+
</property>
46+
</bean>
47+
</property>
3948

40-
<property name="authenticationEnabled" value="true"/>
49+
{% if use_auth %}
50+
<property name="authenticationEnabled" value="true"/>
4151
{% endif %}
4252

53+
4354
{% if use_ssl %}
4455
<property name="connectorConfiguration"><null/></property>
4556
{% endif %}

0 commit comments

Comments
 (0)