-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
227 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
from chromadb.api.client import AdminClient, Client | ||
|
||
|
||
def test_database_tenant_collections(client: Client) -> None: | ||
# Create a new database in the default tenant | ||
admin_client = AdminClient.from_system(client._system) | ||
admin_client.create_database("test_db") | ||
|
||
# Create collections in this new database | ||
client.set_database("test_db") | ||
client.create_collection("collection", metadata={"database": "test_db"}) | ||
|
||
# Create collections in the default database | ||
client.set_database("default") | ||
client.create_collection("collection", metadata={"database": "default"}) | ||
|
||
# List collections in the default database | ||
collections = client.list_collections() | ||
assert len(collections) == 1 | ||
assert collections[0].name == "collection" | ||
assert collections[0].metadata == {"database": "default"} | ||
|
||
# List collections in the new database | ||
client.set_database("test_db") | ||
collections = client.list_collections() | ||
assert len(collections) == 1 | ||
assert collections[0].metadata == {"database": "test_db"} | ||
|
||
# Update the metadata in both databases to different values | ||
client.set_database("default") | ||
client.list_collections()[0].modify(metadata={"database": "default2"}) | ||
|
||
client.set_database("test_db") | ||
client.list_collections()[0].modify(metadata={"database": "test_db2"}) | ||
|
||
# Validate that the metadata was updated | ||
client.set_database("default") | ||
collections = client.list_collections() | ||
assert len(collections) == 1 | ||
assert collections[0].metadata == {"database": "default2"} | ||
|
||
client.set_database("test_db") | ||
collections = client.list_collections() | ||
assert len(collections) == 1 | ||
assert collections[0].metadata == {"database": "test_db2"} | ||
|
||
# Delete the collections and make sure databases are isolated | ||
client.set_database("default") | ||
client.delete_collection("collection") | ||
|
||
collections = client.list_collections() | ||
assert len(collections) == 0 | ||
|
||
client.set_database("test_db") | ||
collections = client.list_collections() | ||
assert len(collections) == 1 | ||
|
||
client.delete_collection("collection") | ||
collections = client.list_collections() | ||
assert len(collections) == 0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
from concurrent.futures import ThreadPoolExecutor | ||
from chromadb.api.client import AdminClient, Client | ||
|
||
|
||
def test_multiple_clients_concurrently(client: Client) -> None: | ||
"""Tests running multiple clients, each against their own database, concurrently.""" | ||
admin_client = AdminClient.from_system(client._system) | ||
admin_client.create_database("test_db") | ||
|
||
CLIENT_COUNT = 100 | ||
COLLECTION_COUNT = 500 | ||
|
||
# Each database will create the same collections by name, with differing metadata | ||
databases = [f"db{i}" for i in range(CLIENT_COUNT)] | ||
for database in databases: | ||
admin_client.create_database(database) | ||
|
||
collections = [f"collection{i}" for i in range(COLLECTION_COUNT)] | ||
|
||
# Create N clients, each on a seperate thread, each with their own database | ||
def run_target(n: int) -> None: | ||
thread_client = Client( | ||
tenant="default", database=databases[n], settings=client._system.settings | ||
) | ||
for collection in collections: | ||
thread_client.create_collection( | ||
collection, metadata={"database": databases[n]} | ||
) | ||
|
||
with ThreadPoolExecutor(max_workers=CLIENT_COUNT) as executor: | ||
executor.map(run_target, range(CLIENT_COUNT)) | ||
|
||
# Create a final client, which will be used to verify the collections were created | ||
client = Client(settings=client._system.settings) | ||
|
||
# Verify that the collections were created | ||
for database in databases: | ||
client.set_database(database) | ||
seen_collections = client.list_collections() | ||
assert len(seen_collections) == COLLECTION_COUNT | ||
for collection in seen_collections: | ||
assert collection.name in collections | ||
assert collection.metadata == {"database": database} |
Oops, something went wrong.