public function testObjectWithLinks() { $object = new RiakObject(); $object->setValue('{"name": "fabio"}'); $object->setContentType('application/json'); $object->addLink(new RiakLink(null, null, null)); $object->addLink(new RiakLink(null, null, null)); $object->getLinks()->get(0)->setBucket('bucket'); $object->getLinks()->get(0)->setKey('first'); $object->getLinks()->get(0)->setTag('foo'); $object->getLinks()->get(1)->setBucket('bucket'); $object->getLinks()->get(1)->setKey('second'); $object->getLinks()->get(1)->setTag('bar'); $store = StoreValue::builder($this->location, $object)->withPw(1)->withW(1)->build(); $fetch = FetchValue::builder($this->location)->withR(1)->build(); $this->client->execute($store); $result = $this->client->execute($fetch); $riakObject = $result->getValue(); $riakLinks = $riakObject->getLinks(); $this->assertFalse($result->getNotFound()); $this->assertInstanceOf('Riak\\Client\\Command\\Kv\\Response\\FetchValueResponse', $result); $this->assertInstanceOf('Riak\\Client\\Core\\Query\\Link\\RiakLinkList', $riakLinks); $this->assertInstanceOf('Riak\\Client\\Core\\Query\\RiakObject', $riakObject); $this->assertEquals('{"name": "fabio"}', $riakObject->getValue()); $this->assertCount(2, $riakLinks); $this->assertInstanceOf('Riak\\Client\\Core\\Query\\Link\\RiakLink', $riakLinks[0]); $this->assertInstanceOf('Riak\\Client\\Core\\Query\\Link\\RiakLink', $riakLinks[1]); $this->assertEquals('bucket', $riakLinks[0]->getBucket()); $this->assertEquals('bucket', $riakLinks[1]->getBucket()); $this->assertEquals('first', $riakLinks[0]->getKey()); $this->assertEquals('second', $riakLinks[1]->getKey()); $this->assertEquals('foo', $riakLinks[0]->getTag()); $this->assertEquals('bar', $riakLinks[1]->getTag()); $this->client->execute(DeleteValue::builder($this->location)->build()); }
protected function tearDown() { if ($this->client) { $this->client->execute(DeleteValue::builder($this->location)->build()); } parent::tearDown(); }
public function testDelete() { $deleteResponse = new DeleteResponse(); $command = DeleteValue::builder()->withLocation($this->location)->withVClock($this->vClock)->withPr(1)->withPw(1)->withRw(2)->withDw(2)->withW(3)->withR(3)->build(); $this->adapter->expects($this->once())->method('send')->will($this->returnValue($deleteResponse)); $result = $this->client->execute($command); $this->assertInstanceOf('Riak\\Client\\Command\\Kv\\Response\\DeleteValueResponse', $result); }
public function testSiblingsWithIndexes() { $key = uniqid(); $object1 = new RiakObject(); $object2 = new RiakObject(); $location = new RiakLocation(new RiakNamespace('default', 'bucket'), $key); $object1->addIndex(new RiakIndexBin('group', ['guest'])); $object1->setContentType('application/json'); $object1->setValue('{"name": "fabio"}'); $object2->addIndex(new RiakIndexBin('group', ['admin'])); $object2->setContentType('application/json'); $object2->setValue('{"name": "fabio"}'); $this->client->execute(StoreValue::builder($location, $object1)->withW(3)->build()); $this->client->execute(StoreValue::builder($location, $object2)->withW(3)->build()); $result = $this->client->execute(FetchValue::builder($location)->withNotFoundOk(true)->withR(1)->build()); $this->assertInstanceOf('Riak\\Client\\Command\\Kv\\Response\\FetchValueResponse', $result); $this->assertCount(2, $result->getValues()); $riakObject1 = $result->getValues()->offsetGet(0); $riakObject2 = $result->getValues()->offsetGet(1); $riakIndexes1 = $riakObject1->getIndexes(); $riakIndexes2 = $riakObject2->getIndexes(); $this->assertInstanceOf('Riak\\Client\\Core\\Query\\Index\\RiakIndexList', $riakIndexes1); $this->assertInstanceOf('Riak\\Client\\Core\\Query\\Index\\RiakIndexList', $riakIndexes2); $this->assertCount(1, $riakIndexes1); $this->assertTrue(isset($riakIndexes1['group'])); $this->assertTrue(isset($riakIndexes2['group'])); $this->assertInstanceOf('Riak\\Client\\Core\\Query\\Index\\RiakIndexBin', $riakIndexes1['group']); $this->assertInstanceOf('Riak\\Client\\Core\\Query\\Index\\RiakIndexBin', $riakIndexes2['group']); $this->assertEquals('group', $riakIndexes1['group']->getName()); $this->assertEquals('group', $riakIndexes2['group']->getName()); $this->assertEquals(['guest'], $riakIndexes1['group']->getValues()); $this->assertEquals(['admin'], $riakIndexes2['group']->getValues()); $this->client->execute(DeleteValue::builder($location)->build()); }
public function testGeneratedKey() { $object = new RiakObject(); $location = new RiakLocation(new RiakNamespace('default', 'bucket'), null); $object->setValue('[1,1,1]'); $object->setContentType('application/json'); $store = StoreValue::builder($location, $object)->withReturnBody(true)->withPw(1)->withW(1)->build(); $result = $this->client->execute($store); $riakObject = $result->getValue(); $this->assertInstanceOf('Riak\\Client\\Command\\Kv\\Response\\StoreValueResponse', $result); $this->assertInstanceOf('Riak\\Client\\Core\\Query\\RiakObject', $riakObject); $this->assertEquals('[1,1,1]', $riakObject->getValue()); $this->assertNotNull($result->getGeneratedKey()); $location->setKey($result->getGeneratedKey()); $this->client->execute(DeleteValue::builder($location)->build()); }