Skip to content

Commit

Permalink
* Change exceptionCode after merge pr
Browse files Browse the repository at this point in the history
* Fix Docker for tests
* Some type fix
* Fix types: max_execution_time & setConnectTimeOut
  • Loading branch information
isublimity committed Dec 20, 2022
1 parent 7e7e83d commit f9cfee2
Show file tree
Hide file tree
Showing 7 changed files with 31 additions and 17 deletions.
2 changes: 1 addition & 1 deletion src/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ public function setTimeout(int $timeout)
/**
* @return float
*/
public function getTimeout(): float
public function getTimeout(): int
{
return $this->settings()->getTimeOut();
}
Expand Down
21 changes: 12 additions & 9 deletions src/Settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -93,11 +93,11 @@ public function database($db)
}

/**
* @return float
* @return int
*/
public function getTimeOut(): float
public function getTimeOut(): int
{
return $this->get('max_execution_time');
return intval($this->get('max_execution_time'));
}

/**
Expand Down Expand Up @@ -172,10 +172,13 @@ public function makeSessionId()
}

/**
* @param float $time
*
* max_execution_time - is integer in Seconds clickhouse source
*
* @param int $time
* @return $this
*/
public function max_execution_time(float $time)
public function max_execution_time(int $time)
{
$this->set('max_execution_time',$time);
return $this;
Expand All @@ -193,7 +196,7 @@ public function getSettings()
* @param array $settings_array
* @return $this
*/
public function apply($settings_array)
public function apply(array $settings_array)
{
foreach ($settings_array as $key => $value) {
$this->set($key, $value);
Expand All @@ -205,15 +208,15 @@ public function apply($settings_array)
/**
* @param int|bool $flag
*/
public function setReadOnlyUser($flag)
public function setReadOnlyUser(mixed $flag):void
{
$this->_ReadOnlyUser = $flag;
}

/**
* @return bool
*/
public function isReadOnlyUser()
public function isReadOnlyUser():bool
{
return $this->_ReadOnlyUser;
}
Expand All @@ -222,7 +225,7 @@ public function isReadOnlyUser()
* @param string $name
* @return mixed|null
*/
public function getSetting($name)
public function getSetting(string $name)
{
if (!isset($this->settings[$name])) {
return null;
Expand Down
2 changes: 1 addition & 1 deletion src/Transport/Http.php
Original file line number Diff line number Diff line change
Expand Up @@ -423,7 +423,7 @@ public function setConnectTimeOut(float $connectTimeOut)
/**
* get ConnectTimeOut in seconds
*
* @return int
* @return float
*/
public function getConnectTimeOut(): float
{
Expand Down
4 changes: 2 additions & 2 deletions tests/ClientTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -780,7 +780,7 @@ public function testExceptionWrite()
public function testExceptionInsert()
{
$this->expectException(QueryException::class);
$this->expectExceptionCode(404);
$this->expectExceptionCode(60); // Table default.ZZZZZ doesn't exist

$this->client->insert('bla_bla', [
['HASH1', [11, 22, 33]],
Expand All @@ -799,7 +799,7 @@ public function testExceptionInsertNoData() : void
public function testExceptionSelect()
{
$this->expectException(QueryException::class);
$this->expectExceptionCode(404);
$this->expectExceptionCode(60); // Table not exists

$this->client->select("SELECT * FROM XXXXX_SSS")->rows();
}
Expand Down
11 changes: 8 additions & 3 deletions tests/FormatQueryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,22 +56,27 @@ public function testCreateTableTEMPORARYNoSession()

public function testClientTimeoutSettings()
{
// https://github.com/smi2/phpClickHouse/issues/168
// Only setConnectTimeOut & getConnectTimeOut can be float
// max_execution_time - is integer in clickhouse source - Seconds
$this->client->database('default');

$timeout = 0.55;
$timeout = 0.55; // un support, "clickhouse source - Seconds"
$this->client->setTimeout($timeout); // 1500 ms
$this->client->select('SELECT 123,123 as ping ')->rows();
$this->assertSame(intval($timeout), $this->client->getTimeout());
$this->assertSame(intval($timeout), intval($this->client->getTimeout()));

$timeout = 10.0;
$this->client->setTimeout($timeout); // 10 seconds
$this->client->select('SELECT 123,123 as ping ')->rows();
$this->assertSame(intval($timeout), $this->client->getTimeout());


// getConnectTimeOut is curl, can be float
$timeout = 5.14;
$this->client->setConnectTimeOut($timeout); // 5 seconds
$this->client->select('SELECT 123,123 as ping ')->rows();
$this->assertSame(5, $this->client->getConnectTimeOut());
$this->assertSame(5.14, $this->client->getConnectTimeOut());
}


Expand Down
Empty file.
8 changes: 7 additions & 1 deletion tests/docker-compose.yaml
Original file line number Diff line number Diff line change
@@ -1,12 +1,18 @@
version: '3'
services:

clickhouse-server:
image: clickhouse/clickhouse-server
image: clickhouse/clickhouse-server:21.9
hostname: clickhouse
container_name: clickhouse
ports:
- 9000:9000
- 8123:8123
sysctls:
net.core.somaxconn: 1024
net.ipv4.tcp_syncookies: 0
volumes:
- "./docker-clickhouse:/var/lib/clickhouse"
ulimits:
nofile:
soft: 262144
Expand Down

0 comments on commit f9cfee2

Please sign in to comment.