Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Run "env YRMCDS_SERVER=localhost make test" to run these tests. You need to run yrmcds server at localhost, of course.
- Loading branch information
Showing
15 changed files
with
513 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
--TEST-- | ||
Check for \yrmcds\Client construction. | ||
--SKIPIF-- | ||
<?php | ||
require('skipif.inc'); | ||
--FILE-- | ||
<?php | ||
require('test.inc'); | ||
get_client(); | ||
echo 'ok'; | ||
--EXPECT-- | ||
ok |
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,12 @@ | ||
--TEST-- | ||
Check for \yrmcds\Client construction (persistent connection). | ||
--SKIPIF-- | ||
<?php | ||
require('skipif.inc'); | ||
--FILE-- | ||
<?php | ||
require('test.inc'); | ||
get_client('hoge'); | ||
echo 'ok'; | ||
--EXPECT-- | ||
ok |
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,18 @@ | ||
--TEST-- | ||
Check for \yrmcds\Client with NOOP. | ||
--SKIPIF-- | ||
<?php | ||
require('skipif.inc'); | ||
--FILE-- | ||
<?php | ||
require('test.inc'); | ||
$c = get_client(); | ||
$serial = $c->noop(); | ||
if( !is_int($serial) ) die('Non integer return value'); | ||
$r = $c->recv(); | ||
if( $r->serial !== $serial ) die('serial mismatch'); | ||
if( $r->command !== \yrmcds\CMD_NOOP ) die('command mismatch'); | ||
if( $r->status !== \yrmcds\STATUS_OK ) die('status is not ok'); | ||
echo 'ok'; | ||
--EXPECT-- | ||
ok |
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,39 @@ | ||
--TEST-- | ||
Check for \yrmcds\Client with SET and GET. | ||
--SKIPIF-- | ||
<?php | ||
require('skipif.inc'); | ||
--FILE-- | ||
<?php | ||
require('test.inc'); | ||
$c = get_client(); | ||
$key = gen_key(); | ||
$serial = $c->set($key, 'abc', 11); | ||
$r = $c->recv(); | ||
if( $r->serial !== $serial ) die('serial mismatch'); | ||
if( $r->command !== \yrmcds\CMD_SET ) die('command mismatch'); | ||
if( $r->status !== \yrmcds\STATUS_OK ) die('status is not ok'); | ||
echo "set ok\n"; | ||
|
||
$serial = $c->get($key); | ||
$r = $c->recv(); | ||
if( $r->serial !== $serial ) die('serial mismatch'); | ||
if( $r->command !== \yrmcds\CMD_GET ) die('command mismatch'); | ||
if( $r->status !== \yrmcds\STATUS_OK ) die('status is not ok'); | ||
if( $r->data !== 'abc' ) die('data mismatch'); | ||
if( $r->flags != 11 ) die('flags mismatch'); | ||
echo "get ok\n"; | ||
|
||
$serial = $c->getk($key); | ||
$r = $c->recv(); | ||
if( $r->serial !== $serial ) die('serial mismatch'); | ||
if( $r->command !== \yrmcds\CMD_GETK ) die('command mismatch'); | ||
if( $r->status !== \yrmcds\STATUS_OK ) die('status is not ok'); | ||
if( $r->key !== $key ) die('key mismatch'); | ||
if( $r->data !== 'abc' ) die('data mismatch'); | ||
if( $r->flags != 11 ) die('flags mismatch'); | ||
echo 'getk ok'; | ||
--EXPECT-- | ||
set ok | ||
get ok | ||
getk ok |
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,29 @@ | ||
--TEST-- | ||
Check for \yrmcds\Client for auto prefixing. | ||
--SKIPIF-- | ||
<?php | ||
require('skipif.inc'); | ||
--FILE-- | ||
<?php | ||
require('test.inc'); | ||
$prefix = 'prefix-'; | ||
$c = get_client(NULL, $prefix); | ||
$key = gen_key(); | ||
$serial = $c->set($key, 'abc'); | ||
$r = $c->recv(); | ||
if( $r->serial !== $serial ) die('serial mismatch'); | ||
if( $r->command !== \yrmcds\CMD_SET ) die('command mismatch'); | ||
if( $r->status !== \yrmcds\STATUS_OK ) die('status is not ok'); | ||
echo "set ok\n"; | ||
|
||
$serial = $c->getk($key); | ||
$r = $c->recv(); | ||
if( $r->serial !== $serial ) die('serial mismatch'); | ||
if( $r->command !== \yrmcds\CMD_GETK ) die('command mismatch'); | ||
if( $r->status !== \yrmcds\STATUS_OK ) die('status is not ok'); | ||
if( $r->key !== $prefix.$key ) die('key mismatch'); | ||
if( $r->data !== 'abc' ) die('data mismatch'); | ||
echo 'get ok'; | ||
--EXPECT-- | ||
set ok | ||
get ok |
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,51 @@ | ||
--TEST-- | ||
Check for \yrmcds\Client for add and replace. | ||
--SKIPIF-- | ||
<?php | ||
require('skipif.inc'); | ||
--FILE-- | ||
<?php | ||
require('test.inc'); | ||
$c = get_client(); | ||
$key = gen_key(); | ||
$serial = $c->replace($key, 'abc'); | ||
$r = $c->recv(); | ||
if( $r->serial !== $serial ) die('serial mismatch'); | ||
if( $r->command !== \yrmcds\CMD_REPLACE ) die('command mismatch'); | ||
if( $r->status !== \yrmcds\STATUS_NOTFOUND ) die('status is not ok'); | ||
echo "failed to replace (expected)\n"; | ||
|
||
$serial = $c->add($key, 'abc'); | ||
$r = $c->recv(); | ||
if( $r->serial !== $serial ) die('serial mismatch'); | ||
if( $r->command !== \yrmcds\CMD_ADD ) die('command mismatch'); | ||
if( $r->status !== \yrmcds\STATUS_OK ) die('status is not ok'); | ||
echo "add ok\n"; | ||
|
||
$serial = $c->add($key, 'abc'); | ||
$r = $c->recv(); | ||
if( $r->serial !== $serial ) die('serial mismatch'); | ||
if( $r->command !== \yrmcds\CMD_ADD ) die('command mismatch'); | ||
if( $r->status !== \yrmcds\STATUS_EXISTS ) die('status is not ok'); | ||
echo "failed to add (expected)\n"; | ||
|
||
$serial = $c->replace($key, 'def'); | ||
$r = $c->recv(); | ||
if( $r->serial !== $serial ) die('serial mismatch'); | ||
if( $r->command !== \yrmcds\CMD_REPLACE ) die('command mismatch'); | ||
if( $r->status !== \yrmcds\STATUS_OK ) die('status is not ok'); | ||
echo "replace ok\n"; | ||
|
||
$serial = $c->get($key); | ||
$r = $c->recv(); | ||
if( $r->serial !== $serial ) die('serial mismatch'); | ||
if( $r->command !== \yrmcds\CMD_GET ) die('command mismatch'); | ||
if( $r->status !== \yrmcds\STATUS_OK ) die('status is not ok'); | ||
if( $r->data !== 'def' ) die('data mismatch'); | ||
echo 'get ok'; | ||
--EXPECT-- | ||
failed to replace (expected) | ||
add ok | ||
failed to add (expected) | ||
replace ok | ||
get ok |
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,43 @@ | ||
--TEST-- | ||
Check for \yrmcds\Client for append and prepend. | ||
--SKIPIF-- | ||
<?php | ||
require('skipif.inc'); | ||
--FILE-- | ||
<?php | ||
require('test.inc'); | ||
$c = get_client(); | ||
$key = gen_key(); | ||
$serial = $c->set($key, 'abc'); | ||
$r = $c->recv(); | ||
if( $r->serial !== $serial ) die('serial mismatch'); | ||
if( $r->command !== \yrmcds\CMD_SET ) die('command mismatch'); | ||
if( $r->status !== \yrmcds\STATUS_OK ) die('status is not ok'); | ||
echo "set ok\n"; | ||
|
||
$serial = $c->append($key, 'xyz'); | ||
$r = $c->recv(); | ||
if( $r->serial !== $serial ) die('serial mismatch'); | ||
if( $r->command !== \yrmcds\CMD_APPEND ) die('command mismatch'); | ||
if( $r->status !== \yrmcds\STATUS_OK ) die('status is not ok'); | ||
echo "append ok\n"; | ||
|
||
$serial = $c->prepend($key, '012'); | ||
$r = $c->recv(); | ||
if( $r->serial !== $serial ) die('serial mismatch'); | ||
if( $r->command !== \yrmcds\CMD_PREPEND ) die('command mismatch'); | ||
if( $r->status !== \yrmcds\STATUS_OK ) die('status is not ok'); | ||
echo "prepend ok\n"; | ||
|
||
$serial = $c->get($key); | ||
$r = $c->recv(); | ||
if( $r->serial !== $serial ) die('serial mismatch'); | ||
if( $r->command !== \yrmcds\CMD_GET ) die('command mismatch'); | ||
if( $r->status !== \yrmcds\STATUS_OK ) die('status is not ok'); | ||
if( $r->data !== '012abcxyz' ) die('data mismatch'); | ||
echo 'get ok'; | ||
--EXPECT-- | ||
set ok | ||
append ok | ||
prepend ok | ||
get ok |
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,55 @@ | ||
--TEST-- | ||
Check for \yrmcds\Client for expiration. | ||
--SKIPIF-- | ||
<?php | ||
require('skipif.inc'); | ||
--FILE-- | ||
<?php | ||
require('test.inc'); | ||
$c = get_client(); | ||
$key = gen_key(); | ||
$serial = $c->set($key, 'abc', 0, 1); | ||
$r = $c->recv(); | ||
if( $r->serial !== $serial ) die('serial mismatch'); | ||
if( $r->command !== \yrmcds\CMD_SET ) die('command mismatch'); | ||
if( $r->status !== \yrmcds\STATUS_OK ) die('status is not ok'); | ||
echo "set ok\n"; | ||
|
||
sleep(2); | ||
|
||
$serial = $c->get($key); | ||
$r = $c->recv(); | ||
if( $r->serial !== $serial ) die('serial mismatch'); | ||
if( $r->command !== \yrmcds\CMD_GET ) die('command mismatch'); | ||
if( $r->status !== \yrmcds\STATUS_NOTFOUND ) die('status is not ok'); | ||
echo "get failed (expected)\n"; | ||
|
||
$key = gen_key(); | ||
$serial = $c->set($key, 'abc', 0, 2); | ||
$r = $c->recv(); | ||
if( $r->serial !== $serial ) die('serial mismatch'); | ||
if( $r->command !== \yrmcds\CMD_SET ) die('command mismatch'); | ||
if( $r->status !== \yrmcds\STATUS_OK ) die('status is not ok'); | ||
echo "set ok\n"; | ||
|
||
$serial = $c->touch($key, 0); | ||
$r = $c->recv(); | ||
if( $r->serial !== $serial ) die('serial mismatch'); | ||
if( $r->command !== \yrmcds\CMD_TOUCH ) die('command mismatch'); | ||
if( $r->status !== \yrmcds\STATUS_OK ) die('status is not ok'); | ||
echo "touch ok\n"; | ||
|
||
sleep(3); | ||
|
||
$serial = $c->get($key); | ||
$r = $c->recv(); | ||
if( $r->serial !== $serial ) die('serial mismatch'); | ||
if( $r->command !== \yrmcds\CMD_GET ) die('command mismatch'); | ||
if( $r->status !== \yrmcds\STATUS_OK ) die('status is not ok'); | ||
echo 'get ok'; | ||
--EXPECT-- | ||
set ok | ||
get failed (expected) | ||
set ok | ||
touch ok | ||
get ok |
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,54 @@ | ||
--TEST-- | ||
Check for \yrmcds\Client for compare-and-swap. | ||
--SKIPIF-- | ||
<?php | ||
require('skipif.inc'); | ||
--FILE-- | ||
<?php | ||
require('test.inc'); | ||
$c = get_client(); | ||
$key = gen_key(); | ||
$serial = $c->set($key, 'abc', 3); | ||
$r = $c->recv(); | ||
if( $r->serial !== $serial ) die('serial mismatch'); | ||
if( $r->command !== \yrmcds\CMD_SET ) die('command mismatch'); | ||
if( $r->status !== \yrmcds\STATUS_OK ) die('status is not ok'); | ||
echo "set ok\n"; | ||
|
||
$serial = $c->get($key); | ||
$r = $c->recv(); | ||
if( $r->serial !== $serial ) die('serial mismatch'); | ||
if( $r->command !== \yrmcds\CMD_GET ) die('command mismatch'); | ||
if( $r->status !== \yrmcds\STATUS_OK ) die('status is not ok'); | ||
$cas = $r->cas_unique; | ||
if( $cas === 0 ) die('invalid CAS value'); | ||
echo "get ok\n"; | ||
|
||
$serial = $c->set($key, 'xyz', 16, 0, $cas); | ||
$r = $c->recv(); | ||
if( $r->serial !== $serial ) die('serial mismatch'); | ||
if( $r->command !== \yrmcds\CMD_SET ) die('command mismatch'); | ||
if( $r->status !== \yrmcds\STATUS_OK ) die('status is not ok'); | ||
echo "set ok\n"; | ||
|
||
$serial = $c->set($key, '012', 0, 0, $cas); // old CAS value | ||
$r = $c->recv(); | ||
if( $r->serial !== $serial ) die('serial mismatch'); | ||
if( $r->command !== \yrmcds\CMD_SET ) die('command mismatch'); | ||
if( $r->status === \yrmcds\STATUS_OK ) die('status must not be ok'); | ||
echo "set failed (expected)\n"; | ||
|
||
$serial = $c->get($key); | ||
$r = $c->recv(); | ||
if( $r->serial !== $serial ) die('serial mismatch'); | ||
if( $r->command !== \yrmcds\CMD_GET ) die('command mismatch'); | ||
if( $r->status !== \yrmcds\STATUS_OK ) die('status is not ok'); | ||
if( $r->flags !== 16 ) die('flags mismatch'); | ||
if( $r->data !== 'xyz' ) die('data mismatch'); | ||
echo 'get ok'; | ||
--EXPECT-- | ||
set ok | ||
get ok | ||
set ok | ||
set failed (expected) | ||
get ok |
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,44 @@ | ||
--TEST-- | ||
Check for \yrmcds\Client for incr. | ||
--SKIPIF-- | ||
<?php | ||
require('skipif.inc'); | ||
--FILE-- | ||
<?php | ||
require('test.inc'); | ||
$c = get_client(); | ||
$key = gen_key(); | ||
|
||
$serial = $c->incr($key, 2); | ||
$r = $c->recv(); | ||
if( $r->serial !== $serial ) die('serial mismatch'); | ||
if( $r->command !== \yrmcds\CMD_INCREMENT ) die('command mismatch'); | ||
if( $r->status !== \yrmcds\STATUS_NOTFOUND ) die('status is not ok'); | ||
echo "incr failed (expected)\n"; | ||
|
||
$serial = $c->incr2($key, 10, 100); | ||
$r = $c->recv(); | ||
if( $r->serial !== $serial ) die('serial mismatch'); | ||
if( $r->command !== \yrmcds\CMD_INCREMENT ) die('command mismatch'); | ||
if( $r->status !== \yrmcds\STATUS_OK ) die('status is not ok'); | ||
echo "incr2 ok\n"; | ||
|
||
$serial = $c->incr($key, 2); | ||
$r = $c->recv(); | ||
if( $r->serial !== $serial ) die('serial mismatch'); | ||
if( $r->command !== \yrmcds\CMD_INCREMENT ) die('command mismatch'); | ||
if( $r->status !== \yrmcds\STATUS_OK ) die('status is not ok'); | ||
echo "incr ok\n"; | ||
|
||
$serial = $c->get($key); | ||
$r = $c->recv(); | ||
if( $r->serial !== $serial ) die('serial mismatch'); | ||
if( $r->command !== \yrmcds\CMD_GET ) die('command mismatch'); | ||
if( $r->status !== \yrmcds\STATUS_OK ) die('status is not ok'); | ||
if( ((int)$r->data) !== 102 ) die('data mismatch'); | ||
echo "get ok\n"; | ||
--EXPECT-- | ||
incr failed (expected) | ||
incr2 ok | ||
incr ok | ||
get ok |
Oops, something went wrong.