|
| 1 | +import pytest |
| 2 | + |
| 3 | +import weaviate |
| 4 | +from weaviate.collections.classes.config import ( |
| 5 | + Configure, |
| 6 | + DataType, |
| 7 | + Property, |
| 8 | +) |
| 9 | +from weaviate.util import parse_version_string |
| 10 | + |
| 11 | + |
| 12 | +NODE_NAME = "node1" |
| 13 | +NUM_OBJECT = 10 |
| 14 | + |
| 15 | + |
| 16 | +@pytest.fixture(scope="module") |
| 17 | +def client(): |
| 18 | + client = weaviate.connect_to_local() |
| 19 | + client.collections.delete_all() |
| 20 | + yield client |
| 21 | + client.collections.delete_all() |
| 22 | + |
| 23 | + |
| 24 | +def test_rest_nodes_without_data(client: weaviate.WeaviateClient): |
| 25 | + """get nodes status without data""" |
| 26 | + resp = client.cluster.rest_nodes(output="verbose") |
| 27 | + assert len(resp) == 1 |
| 28 | + assert "gitHash" in resp[0] |
| 29 | + assert resp[0]["name"] == NODE_NAME |
| 30 | + assert resp[0]["shards"] is None |
| 31 | + assert resp[0]["stats"]["objectCount"] == 0 |
| 32 | + assert resp[0]["stats"]["shardCount"] == 0 |
| 33 | + assert resp[0]["status"] == "HEALTHY" |
| 34 | + assert "version" in resp[0] |
| 35 | + |
| 36 | + |
| 37 | +def test_rest_nodes_with_data(client: weaviate.WeaviateClient): |
| 38 | + """get nodes status with data""" |
| 39 | + collection_name_1 = "Collection_1" |
| 40 | + uncap_collection_name_1 = "collection_1" |
| 41 | + collection = client.collections.create( |
| 42 | + name=collection_name_1, |
| 43 | + properties=[Property(name="Name", data_type=DataType.TEXT)], |
| 44 | + vectorizer_config=Configure.Vectorizer.none(), |
| 45 | + ) |
| 46 | + collection.data.insert_many([{"Name": f"name {i}"} for i in range(NUM_OBJECT)]) |
| 47 | + |
| 48 | + collection_name_2 = "Collection_2" |
| 49 | + collection = client.collections.create( |
| 50 | + name=collection_name_2, |
| 51 | + properties=[Property(name="Name", data_type=DataType.TEXT)], |
| 52 | + vectorizer_config=Configure.Vectorizer.none(), |
| 53 | + ) |
| 54 | + collection.data.insert_many([{"Name": f"name {i}"} for i in range(NUM_OBJECT * 2)]) |
| 55 | + |
| 56 | + # server behaviour changed by https://github.com/weaviate/weaviate/pull/4203 |
| 57 | + server_is_at_least_124 = parse_version_string( |
| 58 | + client.get_meta()["version"] |
| 59 | + ) > parse_version_string("1.24") |
| 60 | + |
| 61 | + resp = client.cluster.rest_nodes(output="verbose") |
| 62 | + assert len(resp) == 1 |
| 63 | + assert "gitHash" in resp[0] |
| 64 | + assert resp[0]["name"] == NODE_NAME |
| 65 | + assert len(resp[0]["shards"]) == 2 |
| 66 | + assert resp[0]["stats"]["objectCount"] == 0 if server_is_at_least_124 else NUM_OBJECT * 3 |
| 67 | + assert resp[0]["stats"]["shardCount"] == 2 |
| 68 | + assert resp[0]["status"] == "HEALTHY" |
| 69 | + assert "version" in resp[0] |
| 70 | + |
| 71 | + shards = sorted(resp[0]["shards"], key=lambda x: x["class"]) |
| 72 | + assert shards[0]["class"] == collection_name_1 |
| 73 | + assert shards[0]["objectCount"] == 0 if server_is_at_least_124 else NUM_OBJECT |
| 74 | + assert shards[1]["class"] == collection_name_2 |
| 75 | + assert shards[1]["objectCount"] == 0 if server_is_at_least_124 else NUM_OBJECT * 2 |
| 76 | + |
| 77 | + resp = client.cluster.rest_nodes(collection=collection_name_1, output="verbose") |
| 78 | + assert len(resp) == 1 |
| 79 | + assert "gitHash" in resp[0] |
| 80 | + assert resp[0]["name"] == NODE_NAME |
| 81 | + assert len(resp[0]["shards"]) == 1 |
| 82 | + assert resp[0]["stats"]["shardCount"] == 1 |
| 83 | + assert resp[0]["status"] == "HEALTHY" |
| 84 | + assert "version" in resp[0] |
| 85 | + assert resp[0]["stats"]["objectCount"] == 0 if server_is_at_least_124 else NUM_OBJECT |
| 86 | + |
| 87 | + resp = client.cluster.rest_nodes(uncap_collection_name_1, output="verbose") |
| 88 | + assert len(resp) == 1 |
| 89 | + assert "gitHash" in resp[0] |
| 90 | + assert resp[0]["name"] == NODE_NAME |
| 91 | + assert len(resp[0]["shards"]) == 1 |
| 92 | + assert resp[0]["stats"]["shardCount"] == 1 |
| 93 | + assert resp[0]["status"] == "HEALTHY" |
| 94 | + assert "version" in resp[0] |
| 95 | + assert resp[0]["stats"]["objectCount"] == 0 if server_is_at_least_124 else NUM_OBJECT |
0 commit comments