|
10 | 10 | import pytest_asyncio
|
11 | 11 |
|
12 | 12 | import tests
|
13 |
| -from coherence import Filters, MapEntry, NamedCache, Session |
| 13 | +from coherence import Aggregators, Filters, MapEntry, NamedCache, Session |
14 | 14 | from coherence.event import MapLifecycleEvent
|
15 |
| -from coherence.extractor import ChainedExtractor, UniversalExtractor |
| 15 | +from coherence.extractor import ChainedExtractor, Extractors, UniversalExtractor |
16 | 16 | from coherence.processor import ExtractorProcessor
|
17 | 17 | from tests.address import Address
|
18 | 18 | from tests.person import Person
|
@@ -562,3 +562,44 @@ def callback(n: str) -> None:
|
562 | 562 | assert not cache.active
|
563 | 563 | finally:
|
564 | 564 | await session.close()
|
| 565 | + |
| 566 | + |
| 567 | +# noinspection PyShadowingNames,DuplicatedCode,PyUnresolvedReferences |
| 568 | +@pytest.mark.asyncio |
| 569 | +async def test_add_remove_index(setup_and_teardown_person_cache: NamedCache[str, Person]) -> None: |
| 570 | + cache: NamedCache[str, Person] = setup_and_teardown_person_cache |
| 571 | + |
| 572 | + await cache.add_index(Extractors.extract("age")) |
| 573 | + result = await cache.aggregate(Aggregators.record(), None, Filters.greater("age", 25)) |
| 574 | + # print(result) |
| 575 | + # {'@class': 'util.SimpleQueryRecord', 'results': [{'@class': 'util.SimpleQueryRecord.PartialResult', |
| 576 | + # 'partitionSet': {'@class': 'net.partition.PartitionSet', 'bits': [2147483647], 'markedCount': -1, |
| 577 | + # 'partitionCount': 31, 'tailMask': 2147483647}, 'steps': [{'@class': 'util.SimpleQueryRecord.PartialResult.Step', |
| 578 | + # 'efficiency': 5, 'filter': 'GreaterFilter(.age, 25)', |
| 579 | + # 'indexLookupRecords': [{'@class': 'util.SimpleQueryRecord.PartialResult.IndexLookupRecord', |
| 580 | + # 'bytes': 6839, 'distinctValues': 5, 'extractor': '.age', 'index': 'Partitioned: Footprint=6.67KB, Size=5', |
| 581 | + # 'indexDesc': 'Partitioned: ', 'ordered': False}], 'keySetSizePost': 0, 'keySetSizePre': 7, 'millis': 0, |
| 582 | + # 'subSteps': []}]}], 'type': {'@class': 'aggregator.QueryRecorder.RecordType', 'enum': 'EXPLAIN'}} |
| 583 | + |
| 584 | + idx_rec = result["results"][0].get("steps")[0].get("indexLookupRecords")[0] |
| 585 | + # print(idx_rec) |
| 586 | + # {'@class': 'util.SimpleQueryRecord.PartialResult.IndexLookupRecord', 'bytes': 6839, 'distinctValues': 5, |
| 587 | + # 'extractor': '.age', 'index': 'Partitioned: Footprint=6.67KB, Size=5', 'indexDesc': 'Partitioned: ', |
| 588 | + # 'ordered': False} |
| 589 | + assert "index" in idx_rec |
| 590 | + |
| 591 | + await cache.remove_index(Extractors.extract("age")) |
| 592 | + result2 = await cache.aggregate(Aggregators.record(), None, Filters.greater("age", 25)) |
| 593 | + print(result2) |
| 594 | + # {'@class': 'util.SimpleQueryRecord', 'results': [{'@class': 'util.SimpleQueryRecord.PartialResult', |
| 595 | + # 'partitionSet': {'@class': 'net.partition.PartitionSet', 'bits': [2147483647], 'markedCount': -1, |
| 596 | + # 'partitionCount': 31, 'tailMask': 2147483647}, 'steps': [{'@class': 'util.SimpleQueryRecord.PartialResult.Step', |
| 597 | + # 'efficiency': 7000, 'filter': 'GreaterFilter(.age, 25)', |
| 598 | + # 'indexLookupRecords': [{'@class': 'util.SimpleQueryRecord.PartialResult.IndexLookupRecord', 'bytes': -1, |
| 599 | + # 'distinctValues': -1, 'extractor': '.age', 'ordered': False}], 'keySetSizePost': 0, 'keySetSizePre': 7, |
| 600 | + # 'millis': 0, 'subSteps': []}]}], 'type': {'@class': 'aggregator.QueryRecorder.RecordType', 'enum': 'EXPLAIN'}} |
| 601 | + idx_rec = result2["results"][0].get("steps")[0].get("indexLookupRecords")[0] |
| 602 | + # print(idx_rec) |
| 603 | + # {'@class': 'util.SimpleQueryRecord.PartialResult.IndexLookupRecord', 'bytes': -1, 'distinctValues': -1, |
| 604 | + # 'extractor': '.age', 'ordered': False} |
| 605 | + assert "index" not in idx_rec |
0 commit comments