|
16 | 16 | #
|
17 | 17 |
|
18 | 18 | import uuid
|
19 |
| -import pytest |
20 | 19 |
|
21 | 20 | from google.cloud import aiplatform
|
22 | 21 |
|
|
52 | 51 | _TEST_INDEX_ENDPOINT_DISPLAY_NAME = "endpoint_name"
|
53 | 52 | _TEST_INDEX_ENDPOINT_DESCRIPTION = "my endpoint"
|
54 | 53 |
|
55 |
| -_TEST_INDEX_ENDPOINT_VPC_NETWORK = "projects/{}/global/networks/{}".format( |
56 |
| - e2e_base._PROJECT_NUMBER, e2e_base._VPC_NETWORK_NAME |
57 |
| -) |
58 |
| - |
59 | 54 | # DEPLOYED INDEX
|
60 | 55 | _TEST_DEPLOYED_INDEX_ID = f"deployed_index_id_{uuid.uuid4()}"
|
61 | 56 | _TEST_DEPLOYED_INDEX_DISPLAY_NAME = f"deployed_index_display_name_{uuid.uuid4()}"
|
|
167 | 162 | ]
|
168 | 163 |
|
169 | 164 |
|
170 |
| -@pytest.mark.skip(reason="TestMatchingEngine not available") |
171 | 165 | class TestMatchingEngine(e2e_base.TestEndToEnd):
|
172 | 166 |
|
173 | 167 | _temp_prefix = "temp_vertex_sdk_e2e_matching_engine_test"
|
@@ -226,9 +220,84 @@ def test_create_get_list_matching_engine_index(self, shared_state):
|
226 | 220 |
|
227 | 221 | assert updated_index.name == get_index.name
|
228 | 222 |
|
| 223 | + # Create endpoint and check that it is listed |
| 224 | + my_index_endpoint = aiplatform.MatchingEngineIndexEndpoint.create( |
| 225 | + display_name=_TEST_INDEX_ENDPOINT_DISPLAY_NAME, |
| 226 | + description=_TEST_INDEX_ENDPOINT_DESCRIPTION, |
| 227 | + network=e2e_base._VPC_NETWORK_URI, |
| 228 | + labels=_TEST_LABELS, |
| 229 | + ) |
| 230 | + assert my_index_endpoint.resource_name in [ |
| 231 | + index_endpoint.resource_name |
| 232 | + for index_endpoint in aiplatform.MatchingEngineIndexEndpoint.list() |
| 233 | + ] |
| 234 | + |
| 235 | + assert my_index_endpoint.labels == _TEST_LABELS |
| 236 | + assert my_index_endpoint.display_name == _TEST_INDEX_ENDPOINT_DISPLAY_NAME |
| 237 | + assert my_index_endpoint.description == _TEST_INDEX_ENDPOINT_DESCRIPTION |
| 238 | + |
| 239 | + shared_state["resources"].append(my_index_endpoint) |
| 240 | + |
| 241 | + # Deploy endpoint |
| 242 | + my_index_endpoint = my_index_endpoint.deploy_index( |
| 243 | + index=index, |
| 244 | + deployed_index_id=_TEST_DEPLOYED_INDEX_ID, |
| 245 | + display_name=_TEST_DEPLOYED_INDEX_DISPLAY_NAME, |
| 246 | + ) |
| 247 | + |
| 248 | + # Update endpoint |
| 249 | + updated_index_endpoint = my_index_endpoint.update( |
| 250 | + display_name=_TEST_DISPLAY_NAME_UPDATE, |
| 251 | + description=_TEST_DESCRIPTION_UPDATE, |
| 252 | + labels=_TEST_LABELS_UPDATE, |
| 253 | + ) |
| 254 | + |
| 255 | + assert updated_index_endpoint.labels == _TEST_LABELS_UPDATE |
| 256 | + assert updated_index_endpoint.display_name == _TEST_DISPLAY_NAME_UPDATE |
| 257 | + assert updated_index_endpoint.description == _TEST_DESCRIPTION_UPDATE |
| 258 | + |
| 259 | + # Mutate deployed index |
| 260 | + my_index_endpoint.mutate_deployed_index( |
| 261 | + deployed_index_id=_TEST_DEPLOYED_INDEX_ID, |
| 262 | + min_replica_count=_TEST_MIN_REPLICA_COUNT_UPDATED, |
| 263 | + max_replica_count=_TEST_MAX_REPLICA_COUNT_UPDATED, |
| 264 | + ) |
| 265 | + |
| 266 | + deployed_index = my_index_endpoint.deployed_indexes[0] |
| 267 | + |
| 268 | + assert deployed_index.id == _TEST_DEPLOYED_INDEX_ID |
| 269 | + assert deployed_index.index == index.resource_name |
| 270 | + assert ( |
| 271 | + deployed_index.automatic_resources.min_replica_count |
| 272 | + == _TEST_MIN_REPLICA_COUNT_UPDATED |
| 273 | + ) |
| 274 | + assert ( |
| 275 | + deployed_index.automatic_resources.max_replica_count |
| 276 | + == _TEST_MAX_REPLICA_COUNT_UPDATED |
| 277 | + ) |
| 278 | + |
| 279 | + # TODO: Test `my_index_endpoint.match` request. This requires running this test in a VPC. |
| 280 | + # results = my_index_endpoint.match( |
| 281 | + # deployed_index_id=_TEST_DEPLOYED_INDEX_ID, queries=[_TEST_MATCH_QUERY] |
| 282 | + # ) |
| 283 | + |
| 284 | + # assert results[0][0].id == 870 |
| 285 | + |
| 286 | + # Undeploy index |
| 287 | + my_index_endpoint = my_index_endpoint.undeploy_index( |
| 288 | + deployed_index_id=deployed_index.id |
| 289 | + ) |
| 290 | + |
229 | 291 | # Delete index and check that it is no longer listed
|
230 | 292 | index.delete()
|
231 | 293 | list_indexes = aiplatform.MatchingEngineIndex.list()
|
232 | 294 | assert get_index.resource_name not in [
|
233 | 295 | index.resource_name for index in list_indexes
|
234 | 296 | ]
|
| 297 | + |
| 298 | + # Delete index endpoint and check that it is no longer listed |
| 299 | + my_index_endpoint.delete() |
| 300 | + assert my_index_endpoint.resource_name not in [ |
| 301 | + index_endpoint.resource_name |
| 302 | + for index_endpoint in aiplatform.MatchingEngineIndexEndpoint.list() |
| 303 | + ] |
0 commit comments