Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions pyignite/datatypes/cache_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,16 +120,16 @@ class CacheAtomicityMode(Int):

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),
Expand Down
2 changes: 1 addition & 1 deletion pyignite/datatypes/cache_properties.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
2 changes: 0 additions & 2 deletions pyignite/datatypes/prop_codes.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,5 +47,3 @@
PROP_PARTITION_LOSS_POLICY = 404
PROP_EAGER_TTL = 405
PROP_STATISTICS_ENABLED = 406

PROP_INVALIDATE = -1
108 changes: 89 additions & 19 deletions tests/common/test_cache_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
}


Expand All @@ -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()

Expand All @@ -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()
29 changes: 20 additions & 9 deletions tests/config/ignite-config.xml.jinja2
Original file line number Diff line number Diff line change
Expand Up @@ -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 %}
Expand Down