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
1519import 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+ )
1833from pygridgain .exceptions import CacheError
1934
2035cache_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 ()
0 commit comments