public function testNoReplyReconnectImmediately() { \r\js('while(true) {}', 2.0)->run($this->conn, array('noreply' => true)); $t = time(true); $this->conn->reconnect(false); $this->assertLessThan(0.5, time(true) - $t); }
public function run() { $this->requireDataset('Control'); $this->requireDataset('Heroes'); $this->checkQueryResult(r\rDo(array(1, 2, 3), function ($x, $y, $z) { return $x->mul($y->add($z)); }), 5.0); $this->checkQueryResult(r\branch(r\expr(true), r\expr('true'), r\expr('false')), 'true'); $this->checkQueryResult(r\branch(r\expr(false), r\expr('true'), r\expr('false')), 'false'); $this->checkQueryResult(r\expr(array(1, 2, 3))->rForeach(function ($x) { return r\db('Control')->table('t1')->insert(array('x' => $x)); })->attr('inserted'), 3.0); $this->checkQueryResult(r\db('Control')->table('t1')->map(r\row('x')), array(1, 2, 3)); $errorCaught = false; try { r\error('ERRRRRR')->run($this->conn); } catch (r\RqlUserError $e) { $errorCaught = true; } if (!$errorCaught) { echo "rrror() did not throw an error.\n"; } // Js is also tested separately in JsTest $this->checkQueryResult(r\js("'str1' + 'str2'"), 'str1str2'); $this->checkQueryResult(r\expr('5.0')->coerceTo('number'), 5.0); $this->checkQueryResult(r\expr(5.0)->coerceTo('string'), '5'); $this->checkQueryResult(r\expr(5.0)->typeOf(), 'NUMBER'); $this->checkQueryResult(r\expr('foo')->typeOf(), 'STRING'); $this->checkQueryResult(r\expr(null)->typeOf(), 'NULL'); $this->checkQueryResult(r\expr(array(1, 2, 3))->typeOf(), 'ARRAY'); $this->checkQueryResult(r\expr(array('x' => 1))->typeOf(), 'OBJECT'); $this->checkQueryResult(r\db('Heroes')->table('marvel')->info(), array('type' => "TABLE", 'primary_key' => 'superhero', 'name' => 'marvel', 'indexes' => array(), 'db' => array('type' => 'DB', 'name' => 'Heroes'))); $this->datasets['Control']->reset(); }
public function run() { $this->requireDataset('Heroes'); $this->checkQueryResult(r\db('Heroes')->table('marvel')->get('Wolverine')->replace(array('superhero' => 'Wolverine', 'age' => 30)), array('unchanged' => 0, 'skipped' => 0, 'replaced' => 1, 'inserted' => 0, 'errors' => 0, 'deleted' => 0)); $this->checkQueryResult(r\db('Heroes')->table('marvel')->get('Wolverine')->replace(array('superhero' => 'Wolverine', 'age' => r\js('35')), true), array('unchanged' => 0, 'skipped' => 0, 'replaced' => 1, 'inserted' => 0, 'errors' => 0, 'deleted' => 0)); $this->datasets['Heroes']->reset(); }
public function run() { $this->requireDataset('Heroes'); $this->checkQueryResult(r\db('Heroes')->table('marvel')->get('Wolverine')->update(array('age' => 30)), array('unchanged' => 0, 'skipped' => 0, 'replaced' => 1, 'inserted' => 0, 'errors' => 0, 'deleted' => 0)); $this->checkQueryResult(r\db('Heroes')->table('marvel')->update(function ($r) { return $r->merge(array('age' => 5)); }), array('unchanged' => 0, 'skipped' => 0, 'replaced' => 3, 'inserted' => 0, 'errors' => 0, 'deleted' => 0)); $this->checkQueryResult(r\db('Heroes')->table('marvel')->update(array('age' => r\row('age')->add(1))), array('unchanged' => 0, 'skipped' => 0, 'replaced' => 3, 'inserted' => 0, 'errors' => 0, 'deleted' => 0)); $this->checkQueryResult(r\db('Heroes')->table('marvel')->update(array('age' => r\row('age')->add(r\js('1'))), array('durability' => 'soft', 'non_atomic' => true)), array('unchanged' => 0, 'skipped' => 0, 'replaced' => 3, 'inserted' => 0, 'errors' => 0, 'deleted' => 0)); $this->datasets['Heroes']->reset(); }
public function run() { $this->checkQueryResult(r\js("'str1' + 'str2'"), "str1str2"); $t = microtime(true); try { r\js('while(true) {}', 1.3)->run($this->conn); } catch (r\RqlUserError $e) { } if (microtime(true) - $t > 2.0 || microtime(true) - $t < 1.3) { echo "Js timeout doesn't seem to work\n"; } }
public function run() { $this->requireDataset('Control'); $this->requireDataset('Heroes'); $this->checkQueryResult(r\rDo(array(1, 2, 3), function ($x, $y, $z) { return $x->mul($y->add($z)); }), 5.0); $this->checkQueryResult(r\branch(r\expr(true), r\expr('true'), r\expr('false')), 'true'); $this->checkQueryResult(r\branch(r\expr(false), r\expr('true'), r\expr('false')), 'false'); $this->checkQueryResult(r\expr(array(1, 2, 3))->rForeach(function ($x) { return r\db('Control')->table('t1')->insert(array('x' => $x)); })->getField('inserted'), 3.0); $this->checkQueryResult(r\db('Control')->table('t1')->map(r\row('x')), array(1, 2, 3)); $errorCaught = false; try { r\error('ERRRRRR')->run($this->conn); } catch (r\RqlServerError $e) { $errorCaught = true; } if (!$errorCaught) { echo "rrror() did not throw an error.\n"; } // Js is also tested separately in JsTest $this->checkQueryResult(r\js("'str1' + 'str2'"), 'str1str2'); $this->checkQueryResult(r\expr('5.0')->coerceTo('number'), 5.0); $this->checkQueryResult(r\expr(5.0)->coerceTo('string'), '5'); $this->checkQueryResult(r\expr(5.0)->typeOf(), 'NUMBER'); $this->checkQueryResult(r\expr('foo')->typeOf(), 'STRING'); $this->checkQueryResult(r\expr(null)->typeOf(), 'NULL'); $this->checkQueryResult(r\expr(array(1, 2, 3))->typeOf(), 'ARRAY'); $this->checkQueryResult(r\expr(array('x' => 1))->typeOf(), 'OBJECT'); $this->checkQueryResult(r\db('Heroes')->table('marvel')->info()->pluck(array('type', 'name')), array('type' => "TABLE", 'name' => 'marvel')); $this->checkQueryResult(r\expr(array('a' => 4))->getField('a')->rDefault(5), 4.0); $this->checkQueryResult(r\expr(array('a' => 4))->getField('b')->rDefault(5), 5.0); $this->checkQueryResult(r\expr(array('a' => 4))->getField('b')->rDefault(function ($e) { return r\expr(5); }), 5.0); $this->checkQueryResult(r\range()->limit(3), array(0, 1, 2)); $this->checkQueryResult(r\range(3), array(0, 1, 2)); $this->checkQueryResult(r\range(1, 3), array(1, 2)); $this->checkQueryResult(r\expr("123")->toJsonString(), "\"123\""); $this->datasets['Control']->reset(); }
public function testJsTimeout() { $this->setExpectedException('\\r\\Exceptions\\RqlServerError', 'Runtime error: JavaScript query `while(true) {}` timed out after 1.300 seconds'); \r\js('while(true) {}', 1.3)->run($this->conn); }
public function testReplaceNonAtomic() { $res = $this->db()->table('marvel')->get('Wolverine')->replace(array('superhero' => 'Wolverine', 'age' => \r\js('35')))->run($this->conn, array('non_atomic' => true)); $this->assertObStatus(array('replaced' => 1), $res); }
public function testUpdateRowAdd() { $this->db()->table('marvel')->update(array('age' => 30))->run($this->conn, $this->opts); $res = $this->db()->table('marvel')->update(array('age' => \r\row('age')->add(\r\js('1'))))->run($this->conn, array('durability' => 'soft', 'non_atomic' => true)); $this->assertObStatus(array('replaced' => 3), $res); }
public function run() { $this->checkQueryResult(r\expr(true), true); // Pre-test $this->conn->reconnect(); $this->checkQueryResult(r\expr(true), true); // Reconnect validation $this->conn->setTimeout(1); $triggeredDriverError = false; try { r\js('while(true) {}', 2.0)->run($this->conn); } catch (r\RqlServerError $e) { } catch (r\RqlDriverError $e) { $triggeredDriverError = true; $this->conn->reconnect(); } if (!$triggeredDriverError) { echo "Connection did not time out as it should have.\n"; } $this->conn->setTimeout(60); $triggeredDriverError = false; try { r\js('while(true) {}', 2.0)->run($this->conn); } catch (r\RqlServerError $e) { } catch (r\RqlDriverError $e) { $triggeredDriverError = true; $this->conn->reconnect(); } if ($triggeredDriverError) { echo "Connection did time out when it should not have.\n"; } r\js('while(true) {}', 2.0)->run($this->conn, array("noreply" => true)); $t = time(true); $this->conn->noreplyWait(); if (time(true) - $t < 1.5) { echo "noreplyWait did not wait.\n"; } r\js('while(true) {}', 2.0)->run($this->conn, array("noreply" => true)); $t = time(true); $this->conn->close(); if (time(true) - $t < 1.5) { echo "close did not wait.\n"; } $this->conn->reconnect(); r\js('while(true) {}', 2.0)->run($this->conn, array("noreply" => true)); $t = time(true); $this->conn->reconnect(); if (time(true) - $t < 1.5) { echo "reconnect did not wait.\n"; } r\js('while(true) {}', 2.0)->run($this->conn, array("noreply" => true)); $t = time(true); $this->conn->close(false); if (time(true) - $t > 0.5) { echo "close did wait when it shouldn't.\n"; } $this->conn->reconnect(); r\js('while(true) {}', 2.0)->run($this->conn, array("noreply" => true)); $t = time(true); $this->conn->reconnect(false); if (time(true) - $t > 0.5) { echo "reconnect did wait when it shouldn't.\n"; } }