Skip to content

Commit

Permalink
Merge pull request #102 from basho/develop
Browse files Browse the repository at this point in the history
Misc improvements
  • Loading branch information
christophermancini committed Aug 21, 2015
2 parents 18e4ec2 + 0be3888 commit af51209
Show file tree
Hide file tree
Showing 10 changed files with 107 additions and 132 deletions.
11 changes: 11 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
* text=auto

*.php text eol=lf
*.yml text eol=lf
*.xml text eol=lf
*.md text eol=lf

*.png binary
*.jpg binary
*.gif binary
*.ico binary
36 changes: 32 additions & 4 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,13 +1,41 @@
language: php

php:
- 5.4
- 5.5
- 5.6
- 7.0
- hhvm
sudo: false # enables docker
install:
- composer install

sudo: required

addons:
hosts:
- riak-test

before_script:
- composer self-update
- composer install --prefer-source
- sudo riak-admin bucket-type create phptest_counters '{"props":{"datatype":"counter"}}'
- sudo riak-admin bucket-type create phptest_maps '{"props":{"datatype":"map"}}'
- sudo riak-admin bucket-type create phptest_sets '{"props":{"datatype":"set"}}'
- sudo riak-admin bucket-type create phptest_search '{"props":{}}'
- sudo riak-admin bucket-type create phptest_leveldb '{"props":{"backend":"leveldb_backend"}}'
- sudo riak-admin bucket-type activate phptest_counters
- sudo riak-admin bucket-type activate phptest_maps
- sudo riak-admin bucket-type activate phptest_sets
- sudo riak-admin bucket-type activate phptest_search
- sudo riak-admin bucket-type activate phptest_leveldb

notifications:
webhooks: http://basho-engbot.herokuapp.com/travis?key=8d594c660ec46f616e37e24fd941c0ea1fc67963
email: [email protected]
script: "php vendor/bin/phpunit --testsuite 'Unit Tests'"

script: "./vendor/bin/phpunit --coverage-text"

services:
- riak

matrix:
allow_failures:
- php: 7.0
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
"psr-4": {"Basho\\Tests\\": "tests/"}
},
"support": {
"issues": "https://github.com/sebastianbergmann/phpunit/issues"
"issues": "https://github.com/basho/riak-php-client/issues"
},
"repositories": [
{
Expand All @@ -62,4 +62,4 @@
"apigen/apigen": "4.1.*",
"basho/tools": "1.0.0"
}
}
}
19 changes: 1 addition & 18 deletions src/Riak.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,13 +67,6 @@ class Riak
'max_connect_attempts' => 3,
];

/**
* Unique id for this client connection
*
* @var string
*/
protected $clientId = '';

/**
* The actively connected Riak Node from the ring
*
Expand All @@ -99,8 +92,6 @@ class Riak
*/
public function __construct(array $nodes, array $config = [], Api $api = NULL)
{
$this->clientId = 'php_' . base_convert(mt_rand(), 10, 36);

// wash any custom keys if any
$this->nodes = array_values($nodes);
$this->setActiveNodeIndex($this->pickNode());
Expand All @@ -114,7 +105,7 @@ public function __construct(array $nodes, array $config = [], Api $api = NULL)
$this->api = $api;
} else {
// default to HTTP bridge class
$this->api = new Http($this->getClientID(), $this->config);
$this->api = new Http($this->config);
}
}

Expand Down Expand Up @@ -165,14 +156,6 @@ public function getConfigValue($key)
return $this->config[$key];
}

/**
* @return string
*/
public function getClientID()
{
return $this->clientId;
}

/**
* @return array
*/
Expand Down
13 changes: 1 addition & 12 deletions src/Riak/Api.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,17 +69,14 @@ abstract class Api
*/
protected $node = null;

protected $clientId = '';

protected $success = null;

protected $error = '';

protected $config = [];

public function __construct($clientId, array $config = [])
public function __construct(array $config = [])
{
$this->clientId = $clientId;
$this->config = $config;
}

Expand All @@ -91,14 +88,6 @@ public function getError()
return $this->error;
}

/**
* @return string
*/
public function getClientId()
{
return $this->clientId;
}

/**
* @return int
*/
Expand Down
70 changes: 28 additions & 42 deletions tests/functional/MapOperationsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,20 @@
*/
class MapOperationsTest extends TestCase
{
/**
* Key to be used for tests
*
* @var string
*/
private static $key = '';

/**
* Array of context generated from working with the same Set
*
* @var array
*/
private static $context = [];

public static function setUpBeforeClass()
{
// make completely random key based on time
Expand Down Expand Up @@ -98,16 +110,7 @@ public function testAddNewWithKey($riak)
// this is wonky, its not 201 because the key may have been generated on another node
$this->assertEquals('204', $response->getStatusCode());
$this->assertEmpty($response->getLocation());
}

/**
* @depends testAddNewWithKey
* @dataProvider getLocalNodeConnection
*
* @param $riak \Basho\Riak
*/
public function testFetchOk($riak)
{
$command = (new Command\Builder\FetchMap($riak))
->buildLocation(static::$key, 'Teams', static::MAP_BUCKET_TYPE)
->build();
Expand All @@ -124,10 +127,13 @@ public function testFetchOk($riak)

$this->assertInstanceOf('Basho\Riak\DataType\Counter', $map->getCounter('teams'));
$this->assertEquals(1, $map->getCounter('teams')->getData());
$this->assertNotEmpty($map->getContext());

static::$context[] = $response->getMap()->getContext();
}

/**
* @depends testFetchOk
* @depends testAddNewWithKey
* @dataProvider getLocalNodeConnection
*
* @param $riak \Basho\Riak
Expand All @@ -153,16 +159,7 @@ public function testAddExisting($riak)

// 204 - No Content
$this->assertEquals('204', $response->getStatusCode());
}

/**
* @depends testAddExisting
* @dataProvider getLocalNodeConnection
*
* @param $riak \Basho\Riak
*/
public function testFetchOk2($riak)
{
$command = (new Command\Builder\FetchMap($riak))
->buildLocation(static::$key, 'Teams', static::MAP_BUCKET_TYPE)
->build();
Expand All @@ -181,43 +178,37 @@ public function testFetchOk2($riak)
$this->assertEquals(3, $map->getCounter('teams')->getData());

$this->assertTrue($map->getFlag('expansion_year'));

static::$context[] = $response->getMap()->getContext();
}

/**
* @depends testFetchOk2
* @depends testAddExisting
* @dataProvider getLocalNodeConnection
*
* @param $riak \Basho\Riak
*
* @expectedException \Basho\Riak\DataType\Exception
*/
public function testRemoveExisting($riak)
{
$updateSetBuilder = (new Command\Builder\UpdateSet($riak))
->remove('Thrashers')
->add('Lightning');

// build a map update command
// build a map update command with stale context
$command = (new Command\Builder\UpdateMap($riak))
->removeFlag('expansion_year')
->updateSet('ATLANTIC_DIVISION', $updateSetBuilder)
->buildLocation(static::$key, 'Teams', static::MAP_BUCKET_TYPE)
->withContext(static::$context[0])
->build();

$response = $command->execute();

// 204 - No Content
$this->assertEquals('204', $response->getStatusCode());
}

/**
* @depends testRemoveExisting
* @dataProvider getLocalNodeConnection
*
* @param $riak \Basho\Riak
*
* @expectedException \Basho\Riak\DataType\Exception
*/
public function testFetchOk3($riak)
{
$command = (new Command\Builder\FetchMap($riak))
->buildLocation(static::$key, 'Teams', static::MAP_BUCKET_TYPE)
->build();
Expand All @@ -236,10 +227,12 @@ public function testFetchOk3($riak)
$this->assertEquals(3, $map->getCounter('teams')->getData());

$this->assertTrue($map->getFlag('expansion_year'));

static::$context[] = $response->getMap()->getContext();
}

/**
* @depends testFetchOk3
* @depends testRemoveExisting
* @dataProvider getLocalNodeConnection
*
* @param $riak \Basho\Riak
Expand All @@ -260,16 +253,7 @@ public function testAddMapExisting($riak)

// 204 - No Content
$this->assertEquals('204', $response->getStatusCode());
}

/**
* @depends testAddMapExisting
* @dataProvider getLocalNodeConnection
*
* @param $riak \Basho\Riak
*/
public function testFetchOk4($riak)
{
$command = (new Command\Builder\FetchMap($riak))
->buildLocation(static::$key, 'Teams', static::MAP_BUCKET_TYPE)
->build();
Expand All @@ -283,5 +267,7 @@ public function testFetchOk4($riak)
$this->assertInstanceOf('Basho\Riak\DataType\Map', $map->getMap('preferences'));
$this->assertEquals('Email Alerts', $map->getMap('preferences')->getRegister('label'));
$this->assertFalse($map->getMap('preferences')->getFlag('notifications'));

static::$context[] = $response->getMap()->getContext();
}
}
4 changes: 2 additions & 2 deletions tests/functional/ObjectOperationsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -176,8 +176,8 @@ public function testFetchDeleted($riak)

$this->assertEquals('404', $response->getStatusCode());

// deleted key's still leave behind a tombstone with their causal context, aka vclock
$this->assertNotEmpty($response->getVclock());
// deleted keys leave behind a tombstone with their causal context, aka vclock unless delete_immediate = 1
//$this->assertNotEmpty($response->getVclock());
}

/**
Expand Down
2 changes: 1 addition & 1 deletion tests/functional/SecurityFeaturesTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ public function testPasswordAuth()
(new Riak\Node\Builder())
->atHost(static::TEST_NODE_HOST)
->onPort(static::TEST_NODE_SECURE_PORT)
->usingPasswordAuthentication('passuser', 'Test1234')
->usingPasswordAuthentication('riakpass', 'Test1234')
->withCertificateAuthorityFile(getcwd() . '/vendor/basho/tools/test-ca/certs/cacert.pem')
->build()
];
Expand Down
Loading

0 comments on commit af51209

Please sign in to comment.