generated from coulomb/repo-seed
73 lines
2.4 KiB
Python
73 lines
2.4 KiB
Python
from __future__ import annotations
|
|
|
|
import os
|
|
from time import perf_counter
|
|
|
|
import pytest
|
|
|
|
from kontextual_engine import Classification, ServiceRuntime, Sensitivity
|
|
from kontextual_engine.adapters.memory import InMemoryAssetRegistryRepository
|
|
|
|
|
|
pytestmark = [pytest.mark.cmis, pytest.mark.capacity]
|
|
|
|
|
|
@pytest.mark.skipif(
|
|
os.getenv("KONTEXTUAL_RUN_CAPACITY") != "1",
|
|
reason="Set KONTEXTUAL_RUN_CAPACITY=1 to run CMIS read-side capacity probes.",
|
|
)
|
|
def test_cmis_read_side_query_and_relationship_capacity_probe() -> None:
|
|
runtime = ServiceRuntime(repository=InMemoryAssetRegistryRepository())
|
|
context = runtime.operation_context(actor_id="cmis-capacity", correlation_id="corr-cmis-capacity")
|
|
asset_count = 400
|
|
relationship_count = 250
|
|
|
|
for index in range(asset_count):
|
|
runtime.asset_service().create_asset(
|
|
f"Capacity Asset {index:04d}",
|
|
Classification(
|
|
asset_type="document",
|
|
sensitivity=Sensitivity.PUBLIC if index % 5 == 0 else Sensitivity.INTERNAL,
|
|
owner=f"capacity-owner-{index % 7}",
|
|
topics=("capacity", f"group-{index % 11}"),
|
|
),
|
|
context,
|
|
asset_id=f"asset-capacity-{index:04d}",
|
|
)
|
|
|
|
for index in range(relationship_count):
|
|
runtime.create_relationship(
|
|
{
|
|
"source_asset_id": f"asset-capacity-{index:04d}",
|
|
"target_id": f"asset-capacity-{asset_count - 1:04d}",
|
|
"predicate": "capacity-related-to",
|
|
"target_kind": "asset",
|
|
"confidence": 0.9,
|
|
},
|
|
context,
|
|
)
|
|
|
|
query_started = perf_counter()
|
|
query = runtime.cmis_query(
|
|
"readonly-browser",
|
|
"SELECT * FROM cmis:document WHERE kontextual:topics IN ('capacity') ORDER BY cmis:name DESC",
|
|
context,
|
|
max_items=25,
|
|
)
|
|
query_seconds = perf_counter() - query_started
|
|
|
|
relationships_started = perf_counter()
|
|
relationships = runtime.cmis_relationships(
|
|
"readonly-browser",
|
|
context,
|
|
object_id=f"cmis:asset:asset-capacity-{asset_count - 1:04d}",
|
|
relationship_direction="target",
|
|
)
|
|
relationships_seconds = perf_counter() - relationships_started
|
|
|
|
assert query["total_num_items"] == asset_count
|
|
assert query["num_items"] == 25
|
|
assert relationships["count"] == relationship_count
|
|
assert query_seconds < 5.0
|
|
assert relationships_seconds < 3.0
|