diff --git a/src/Endpoints/Collections.php b/src/Endpoints/Collections.php index 8e9d887..4e5f69c 100644 --- a/src/Endpoints/Collections.php +++ b/src/Endpoints/Collections.php @@ -13,6 +13,7 @@ use Qdrant\Endpoints\Collections\Cluster; use Qdrant\Endpoints\Collections\Index; use Qdrant\Endpoints\Collections\Points; +use Qdrant\Endpoints\Collections\Shards; use Qdrant\Endpoints\Collections\Snapshots; use Qdrant\Exception\InvalidArgumentException; use Qdrant\Models\Request\CreateCollection; @@ -134,4 +135,9 @@ public function cluster(): Cluster { return (new Cluster($this->client))->setCollectionName($this->collectionName); } + + public function shards(): Shards + { + return (new Shards($this->client))->setCollectionName($this->collectionName); + } } diff --git a/tests/Integration/Endpoints/Collections/ShardsTest.php b/tests/Integration/Endpoints/Collections/ShardsTest.php new file mode 100644 index 0000000..465b67b --- /dev/null +++ b/tests/Integration/Endpoints/Collections/ShardsTest.php @@ -0,0 +1,62 @@ + + */ + +namespace Integration\Endpoints\Collections; + +use Qdrant\Endpoints\Collections; +use Qdrant\Exception\InvalidArgumentException; +use Qdrant\Models\Request\CollectionConfig\CreateShardKey; +use Qdrant\Models\Request\CollectionConfig\DeleteShardKey; +use Qdrant\Models\Request\CreateIndex; +use Qdrant\Tests\Integration\AbstractIntegration; + +class ShardsTest extends AbstractIntegration +{ + /** + * @throws InvalidArgumentException + */ + public function testCollectionCreateShards(): void + { + //TODO: We need to find a way to enable distributed mode in tests? + $this->expectException(InvalidArgumentException::class); + $this->expectExceptionMessage('Bad request: Distributed mode disabled'); + + $collection = new Collections($this->client); + $this->createCollections('sample-collection'); + $collection->setCollectionName('sample-collection'); + + $shards = $collection->shards(); + $this->assertEquals('sample-collection', $shards->getCollectionName()); + + $shards->create(new CreateShardKey(1)); + } + + /** + * @throws InvalidArgumentException + */ + public function testCollectionDeleteShards(): void + { + //TODO: We need to find a way to enable distributed mode in tests? + $this->expectException(InvalidArgumentException::class); + $this->expectExceptionMessage('Bad request: Distributed mode disabled'); + + $collection = new Collections($this->client); + $this->createCollections('sample-collection'); + $collection->setCollectionName('sample-collection'); + + $shards = $collection->shards(); + $this->assertEquals('sample-collection', $shards->getCollectionName()); + + $shards->delete(new DeleteShardKey(1)); + } + + protected function tearDown(): void + { + parent::tearDown(); + + $this->getCollections('sample-collection')->delete(); + } +} \ No newline at end of file