Skip to content

Commit

Permalink
integration tests for shards
Browse files Browse the repository at this point in the history
  • Loading branch information
hkulekci committed Jun 26, 2024
1 parent ae5456f commit c5998d1
Show file tree
Hide file tree
Showing 2 changed files with 68 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/Endpoints/Collections.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
}
}
62 changes: 62 additions & 0 deletions tests/Integration/Endpoints/Collections/ShardsTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
<?php
/**
* @since Jun 2024
* @author Haydar KULEKCI <[email protected]>
*/

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();
}
}

0 comments on commit c5998d1

Please sign in to comment.