-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
CLIENTAPI-27: Refactor unit tests to use less VoltDB servers
Split tests in ClientTest up into ClientTest, ClientOfflineTest, and ClientSecurityTest based on how each needs to interact with a VoltDB server (if at all). ClientTest and ClientSecurityTest each start just a single VoltDB server. Leaving StatusListenerTest alone for now because the minimal speed gains don't justify the optimization. Those tests are better off left independent. Overall, the running time of the unit tests went from 44 seconds to 24 seconds on my desktop.
- Loading branch information
Ed Mazur
committed
Aug 24, 2010
1 parent
5e10026
commit dcc8c04
Showing
8 changed files
with
250 additions
and
165 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,118 @@ | ||
<?php | ||
|
||
/* This file is part of VoltDB. | ||
* Copyright (C) 2008-2010 VoltDB L.L.C. | ||
* | ||
* Permission is hereby granted, free of charge, to any person obtaining | ||
* a copy of this software and associated documentation files (the | ||
* "Software"), to deal in the Software without restriction, including | ||
* without limitation the rights to use, copy, modify, merge, publish, | ||
* distribute, sublicense, and/or sell copies of the Software, and to | ||
* permit persons to whom the Software is furnished to do so, subject to | ||
* the following conditions: | ||
* | ||
* The above copyright notice and this permission notice shall be | ||
* included in all copies or substantial portions of the Software. | ||
* | ||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, | ||
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF | ||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. | ||
* IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR | ||
* OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, | ||
* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR | ||
* OTHER DEALINGS IN THE SOFTWARE. | ||
*/ | ||
|
||
/** | ||
* Tests that all Client methods behave correctly and throw proper exceptions when no VoltDB server is running. | ||
*/ | ||
class ClientOfflineTest extends PHPUnit_Framework_TestCase { | ||
|
||
/** | ||
* Client::create(), Client::createConnection() | ||
*/ | ||
|
||
public function testCreateConnectionNoServerRunning() { | ||
$client = Client::create(); | ||
parent::setExpectedException('ConnectException'); | ||
$client->createConnection('localhost'); | ||
} | ||
|
||
/** | ||
* Client::createFromPool() | ||
*/ | ||
|
||
public function testCreateFromPoolNoServerRunning() { | ||
parent::setExpectedException('ConnectException'); | ||
Client::createFromPool('localhost'); | ||
} | ||
|
||
/** | ||
* Client::invoke() | ||
*/ | ||
|
||
public function testInvokeNoConnection() { | ||
$client = Client::create(); | ||
parent::setExpectedException('NoConnectionsException'); | ||
$client->invoke($this->getSelect()); | ||
} | ||
|
||
/** | ||
* Client::invokeAsync() | ||
*/ | ||
|
||
public function testInvokeAsyncNoConnection() { | ||
$client = Client::create(); | ||
parent::setExpectedException('NoConnectionsException'); | ||
$client->invokeAsync($this->getSelect(), new ClientOfflineTestCallback()); | ||
} | ||
|
||
/** | ||
* Client::runOnce() | ||
*/ | ||
|
||
public function testRunOnceNoConnections() { | ||
$client = Client::create(); | ||
parent::setExpectedException('NoConnectionsException'); | ||
$client->runOnce(); | ||
} | ||
|
||
/** | ||
* Client::run() | ||
*/ | ||
|
||
public function testRunNoConnections() { | ||
$client = Client::create(); | ||
parent::setExpectedException('NoConnectionsException'); | ||
$client->run(); | ||
} | ||
|
||
/** | ||
* Client::drain() | ||
*/ | ||
|
||
public function testDrainNoConnections() { | ||
$client = Client::create(); | ||
parent::setExpectedException('NoConnectionsException'); | ||
$client->drain(); | ||
} | ||
|
||
/** | ||
* Test helper | ||
*/ | ||
|
||
private function getSelect() { | ||
$parameters = new Parameters(); | ||
$parameters->push(new Parameter(voltdb::WIRE_TYPE_STRING)); | ||
$selectProcedure = new Procedure('Select', $parameters); | ||
$selectProcedure->params()->addString('Spanish'); | ||
return $selectProcedure; | ||
} | ||
|
||
} | ||
|
||
class ClientOfflineTestCallback extends ProcedureCallback { | ||
|
||
public function callback($response) {} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
<?php | ||
|
||
/* This file is part of VoltDB. | ||
* Copyright (C) 2008-2010 VoltDB L.L.C. | ||
* | ||
* Permission is hereby granted, free of charge, to any person obtaining | ||
* a copy of this software and associated documentation files (the | ||
* "Software"), to deal in the Software without restriction, including | ||
* without limitation the rights to use, copy, modify, merge, publish, | ||
* distribute, sublicense, and/or sell copies of the Software, and to | ||
* permit persons to whom the Software is furnished to do so, subject to | ||
* the following conditions: | ||
* | ||
* The above copyright notice and this permission notice shall be | ||
* included in all copies or substantial portions of the Software. | ||
* | ||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, | ||
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF | ||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. | ||
* IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR | ||
* OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, | ||
* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR | ||
* OTHER DEALINGS IN THE SOFTWARE. | ||
*/ | ||
|
||
/** | ||
* Tests that Client methods involving security behave correctly. | ||
*/ | ||
class ClientSecurityTest extends PHPUnit_Framework_TestCase { | ||
|
||
private static $server; | ||
|
||
public static function setUpBeforeClass() { | ||
self::$server = new SecuritySuite(); | ||
self::$server->start(); | ||
} | ||
|
||
public static function tearDownAfterClass() { | ||
self::$server->stop(); | ||
} | ||
|
||
public function testCreateConnectionSecurity() { | ||
$client = Client::create(); | ||
|
||
// don't specify credentials | ||
try { | ||
$client->createConnection('localhost'); | ||
parent::assertTrue(false, 'Shouldn\'t have been able to authenticate.'); | ||
} catch (ConnectException $e) {} | ||
|
||
// specify incorrect credentials | ||
try { | ||
$client->createConnection('localhost', 'user-1', 'password-x'); | ||
parent::assertTrue(false, 'Shouldn\'t have been able to authenticate.'); | ||
} catch (ConnectException $e) {} | ||
|
||
// specify correct credentials | ||
try { | ||
$client->createConnection('localhost', 'user-1', 'password-1'); | ||
} catch (ConnectException $e) { | ||
parent::assertTrue(false, 'Should have been able to authenticate.'); | ||
} | ||
} | ||
|
||
public function testCreateFromPoolSecurity() { | ||
// don't specify credentials | ||
try { | ||
Client::createFromPool('localhost'); | ||
parent::assertTrue(false, 'Shouldn\'t have been able to authenticate.'); | ||
} catch (ConnectException $e) {} | ||
|
||
// specify incorrect credentials | ||
try { | ||
Client::createFromPool('localhost', 'user-1', 'password-x'); | ||
parent::assertTrue(false, 'Shouldn\'t have been able to authenticate.'); | ||
} catch (ConnectException $e) {} | ||
|
||
// specify correct credentials | ||
try { | ||
Client::createFromPool('localhost', 'user-1', 'password-1'); | ||
} catch (ConnectException $e) { | ||
parent::assertTrue(false, 'Should have been able to authenticate.'); | ||
} | ||
} | ||
|
||
} |
Oops, something went wrong.