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 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()); }
/** * {@inheritdoc} */ public function fromDomain(DomainObjectReference $reference) { $riakObject = new RiakObject(); $location = $reference->getLocation(); $domainObject = $reference->getDomainObject(); $riakObjectValue = $this->fromDomainObject($domainObject); $riakObject->setValue($riakObjectValue); $this->domainHydrator->setRiakObjectValues($riakObject, $domainObject, $location); return $riakObject; }
public function testToDomain() { $riakObject = new RiakObject(); $domainObject = new SimpleObject('[1,2,3]'); $namespace = new RiakNamespace('type', 'bucket'); $location = new RiakLocation($namespace, 'riak-key'); $reference = new RiakObjectReference($riakObject, $location, SimpleObject::CLASS_NAME); $riakObject->setValue('{"value":[1,2,3]}'); $this->instance->expects($this->once())->method('toDomainObject')->with($this->equalTo('{"value":[1,2,3]}'), $this->equalTo(SimpleObject::CLASS_NAME))->willReturn($domainObject); $this->hydrator->expects($this->once())->method('setDomainObjectValues')->with($this->equalTo($domainObject), $this->equalTo($riakObject), $this->equalTo($location)); $this->assertSame($domainObject, $this->instance->toDomain($reference)); }
/** * @param \Riak\Client\Core\Message\Kv\Content $content * @param \Riak\Client\Core\Query\VClock $vClock * * @return \Riak\Client\Core\Query\RiakObject */ private function convertToRiakObject(Content $content, VClock $vClock) { $object = new RiakObject(); $object->setVClock($vClock); $object->setVtag($content->vtag); $object->setValue($content->value); $object->setContentType($content->contentType); $object->setIsDeleted((bool) $content->deleted); $object->setLastModified($content->lastModified); if ($content->indexes) { $object->setIndexes($this->createRiakIndexList($content->indexes)); } if ($content->metas) { $object->setUserMeta(new RiakUsermeta($content->metas)); } if ($content->links) { $object->setLinks($this->createRiakLinkList($content->links)); } return $object; }
public function testListKeys() { $key = uniqid(); $object = new RiakObject(); $namespace = new RiakNamespace('default', 'bucket'); $location = new RiakLocation($namespace, $key); $object->setValue('[1,1,1]'); $object->setContentType('application/json'); $this->client->execute(StoreValue::builder($location, $object)->withPw(RiakOption::ALL)->withW(RiakOption::ALL)->withReturnBody(true)->build()); $command = ListKeys::builder($namespace)->withNamespace($namespace)->build(); $result = $this->client->execute($command); $iterator = $result->getIterator(); $locations = []; $this->assertInternalType('array', $locations); $this->assertInstanceOf('Iterator', $iterator); $this->assertInstanceOf('Riak\\Client\\Command\\Kv\\Response\\ListKeysResponse', $result); foreach ($result->getLocations() as $location) { $locations[$location->getKey()] = $location; } $this->assertArrayHasKey($key, $locations); $this->assertInstanceOf('Riak\\Client\\Core\\Query\\RiakLocation', $locations[$key]); $this->assertEquals($namespace, $locations[$key]->getNamespace()); $this->assertEquals($key, $locations[$key]->getKey()); }