Skip to content

Commit

Permalink
Show settings support
Browse files Browse the repository at this point in the history
  • Loading branch information
djklim87 committed Nov 17, 2023
1 parent 46ed37b commit cced12b
Show file tree
Hide file tree
Showing 2 changed files with 92 additions and 1 deletion.
20 changes: 20 additions & 0 deletions src/Manticore/ManticoreConnector.php
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,26 @@ public function addTableToCluster($tableName, $log = true): bool
return true;
}

public function showSettings($log = false): array
{
$settings = $this->fetcher->fetch("show settings", $log);

if ($this->getConnectionError()) {
return [];
}

$searchdSettings = [];
foreach ($settings as $row) {
if ($row['Setting_name'] === 'searchd.listen'){
$searchdSettings[$row['Setting_name']][] = $row['Value'];
continue;
}
$searchdSettings[$row['Setting_name']] = $row['Value'];
}


return $searchdSettings;
}

public function reloadIndexes()
{
Expand Down
73 changes: 72 additions & 1 deletion tests/ManticoreConnectorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -573,7 +573,6 @@ public function joinClusterReturnFalseOnConnectionError()
}



/**
* @test
* @return void
Expand Down Expand Up @@ -708,6 +707,78 @@ public function optimize()
}


/**
* @test
*
* @return void
*/
public function showSettings()
{
$this->mock->shouldReceive('fetch')
->withArgs(['show settings', false])
->andReturn(
[
['Setting_name' => 'configuration_file', 'Value' => '/etc/manticoresearch/envreader.sh'],
['Setting_name' => 'worker_pid', 'Value' => '1'],
['Setting_name' => 'searchd.query_log_format', 'Value' => 'sphinxql'],
['Setting_name' => 'searchd.listen', 'Value' => '9306:mysql41'],
['Setting_name' => 'searchd.listen', 'Value' => '/var/run/mysqld/mysqld.sock:mysql41'],
['Setting_name' => 'searchd.listen', 'Value' => '9308:http'],
['Setting_name' => 'searchd.listen', 'Value' => '172.17.0.2:9312'],
['Setting_name' => 'searchd.listen', 'Value' => '172.17.0.2:9315-9325:replication'],
['Setting_name' => 'searchd.max_packet_size', 'Value' => '128M'],
['Setting_name' => 'searchd.log', 'Value' => '/var/log/manticore/searchd.log'],
['Setting_name' => 'searchd.pid_file', 'Value' => '/var/run/manticore/searchd.pid'],
['Setting_name' => 'searchd.data_dir', 'Value' => '/var/lib/manticore'],
['Setting_name' => 'searchd.binlog_path', 'Value' => '/var/lib/manticore/binlog'],
['Setting_name' => 'common.plugin_dir', 'Value' => '/usr/local/lib/manticore']
]
);

$this->mock->shouldReceive('getConnectionError')->andReturn(false);

$result = $this->manticoreConnection->showSettings();
$this->assertSame(
$result,
[
'configuration_file' => '/etc/manticoresearch/envreader.sh',
'worker_pid' => '1',
'searchd.query_log_format' => 'sphinxql',
'searchd.listen' => [
'9306:mysql41',
'/var/run/mysqld/mysqld.sock:mysql41',
'9308:http',
'172.17.0.2:9312',
'172.17.0.2:9315-9325:replication'
],
'searchd.max_packet_size' => '128M',
'searchd.log' => '/var/log/manticore/searchd.log',
'searchd.pid_file' => '/var/run/manticore/searchd.pid',
'searchd.data_dir' => '/var/lib/manticore',
'searchd.binlog_path' => '/var/lib/manticore/binlog',
'common.plugin_dir' => '/usr/local/lib/manticore'
]
);
}


/**
* @test
*
* @return void
*/
public function showSettingsConnectionError()
{
$this->mock->shouldReceive('fetch')
->withArgs(['show settings', false])
->andReturnNull();

$this->mock->shouldReceive('getConnectionError')->andReturn(true);

$result = $this->manticoreConnection->showSettings();
$this->assertEmpty($result);
}

/**
* @test
* @return void
Expand Down

0 comments on commit cced12b

Please sign in to comment.