1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115
|
<?php
namespace Basho\Tests;
use Basho\Riak\Command;
/**
* Class BucketOperationsTest
*
* Functional tests related to bucket operations
*
* @author Christopher Mancini <cmancini at basho d0t com>
* @author Luke Bakken <lbakken@basho.com>
*/
class BucketOperationsTest extends TestCase
{
private static $hll_present = false;
public static function setUpBeforeClass()
{
parent::setUpBeforeClass();
try {
$command = (new Command\Builder\FetchBucketProperties(static::$riak))
->buildBucket('test', static::HLL_BUCKET_TYPE)
->build();
$response = $command->execute();
if ($response->isSuccess() && $response->getCode() == 200) {
static::$hll_present = true;
}
} catch (\Exception $ex) {
static::$hll_present = false;
}
}
public function testStore()
{
$command = (new Command\Builder\SetBucketProperties(static::$riak))
->buildBucket('test')
->set('allow_mult', false)
->build();
$response = $command->execute();
$this->assertEquals('204', $response->getCode(), $response->getMessage());
}
public function testFetch()
{
$command = (new Command\Builder\FetchBucketProperties(static::$riak))
->buildBucket('test')
->build();
$response = $command->execute();
$this->assertEquals('200', $response->getCode());
$bucket = $response->getBucket();
$this->assertNotEmpty($bucket->getProperties());
$this->assertFalse($bucket->getProperty('allow_mult'));
}
public function testStore2()
{
$command = (new Command\Builder\SetBucketProperties(static::$riak))
->buildBucket('test')
->set('allow_mult', true)
->build();
$response = $command->execute();
$this->assertEquals('204', $response->getCode(), $response->getMessage());
}
public function testFetch2()
{
$command = (new Command\Builder\FetchBucketProperties(static::$riak))
->buildBucket('test')
->build();
$response = $command->execute();
$this->assertEquals('200', $response->getCode());
$bucket = $response->getBucket();
$this->assertNotEmpty($bucket->getProperties());
$this->assertTrue($bucket->getProperty('allow_mult'));
}
public function testFetchAndStoreHllPrecision()
{
if (static::$hll_present) {
$command = (new Command\Builder\FetchBucketProperties(static::$riak))
->buildBucket('test' . md5(rand(0, 99) . time()), static::HLL_BUCKET_TYPE)
->build();
$bucket = $command->execute()->getBucket();
$this->assertNotEmpty($bucket->getProperties());
$this->assertEquals(14, $bucket->getProperty('hll_precision'));
$command = (new Command\Builder\SetBucketProperties(static::$riak))
->buildBucket('test', static::HLL_BUCKET_TYPE)
->set('hll_precision', 12)
->build();
$response = $command->execute();
$this->assertEquals('204', $response->getCode(), $response->getMessage());
} else {
throw new \PHPUnit_Framework_SkippedTestError("hlls bucket type is not enabled and activated, skipping");
}
}
}
|