Skip to content

Commit

Permalink
Merge pull request #36 from Smolevich/35-add-replication
Browse files Browse the repository at this point in the history
Add new method for ns service
  • Loading branch information
Smolevich authored Feb 18, 2024
2 parents dc21bc7 + 4ab413c commit 0a13e07
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 0 deletions.
19 changes: 19 additions & 0 deletions src/Reindexer/Services/Namespaces.php
Original file line number Diff line number Diff line change
Expand Up @@ -219,4 +219,23 @@ public function getMetaDataKey(string $name, string $key): Response
$this->defaultHeaders
);
}

public function schema(string $name, array $config): Response
{
$uri = new Uri(
sprintf(
'/api/%s/db/%s/namespaces/%s/schema',
$this->version,
$this->getDatabase(),
$name
)
);

return $this->client->request(
'PUT',
(string)$uri,
json_encode($config),
$this->defaultHeaders
);
}
}
41 changes: 41 additions & 0 deletions tests/Feature/Reindexer/ServiceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use Reindexer\Client\Api;
use Reindexer\Entities\Index;
use Reindexer\Enum\IndexType;
use Reindexer\Response;
use Reindexer\Services\Database;
use Reindexer\Services\Index as ReindexerIndex;
use Reindexer\Services\Item;
Expand Down Expand Up @@ -172,4 +173,44 @@ public function testSetHeaders()
);
$this->assertCount(2, $response->getRequestHeaders());
}

public function testSchema()
{
$config = [
'type' => 'namespaces',
'namespaces' => [
'wal_size' => 5000000
]
];
$response = $this->nsService->schema($this->namespaceName, $config);
$this->assertSame(
[
'success' => true,
'response_code' => 200,
'description' => ''
],
$response->getDecodedResponseBody(true)
);
}

public function testSetReplication()
{
$config = [
'type' => 'namespaces',
'replication' => [
'role' => 'master',
'cluster_id' => 2,
'server_id' => 0
]
];
$this->itemService->setNamespace(urlencode('#config'));
$response = $this->itemService->update($config);
$this->assertSame(
[
'updated' => 1,
'success' => true,
],
$response->getDecodedResponseBody(true)
);
}
}

0 comments on commit 0a13e07

Please sign in to comment.