Exemplo n.º 1
0
 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());
 }
Exemplo n.º 2
0
 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());
 }
Exemplo n.º 3
0
 public function testStore()
 {
     $riakObject = new RiakObject();
     $putResponse = new PutResponse();
     $command = StoreValue::builder()->withLocation($this->location)->withValue($riakObject)->withReturnBody(true)->withDw(1)->withPw(2)->withW(3)->build();
     $riakObject->setContentType('application/json');
     $riakObject->setValue('2,2,2]');
     $c1 = new Content();
     $c2 = new Content();
     $putResponse->vClock = 'vclock-hash';
     $putResponse->contentList = [$c1, $c2];
     $c1->lastModified = 'Sat, 01 Jan 2015 01:01:01 GMT';
     $c1->contentType = 'application/json';
     $c1->value = '[1,1,1]';
     $c2->lastModified = 'Sat, 02 Jan 2015 02:02:02 GMT';
     $c2->contentType = 'application/json';
     $c2->value = '[2,2,2]';
     $this->adapter->expects($this->once())->method('send')->will($this->returnValue($putResponse));
     $result = $this->client->execute($command);
     $this->assertInstanceOf('Riak\\Client\\Command\\Kv\\Response\\StoreValueResponse', $result);
     $this->assertInstanceOf('Riak\\Client\\Core\\Query\\VClock', $result->getVectorClock());
     $this->assertTrue($result->hasValues());
     $this->assertCount(2, $result->getValues());
     $this->assertEquals(2, $result->getNumberOfValues());
     $this->assertEquals('vclock-hash', $result->getVectorClock()->getValue());
     $values = $result->getValues();
     $this->assertInstanceOf('Riak\\Client\\Core\\Query\\RiakObject', $values[0]);
     $this->assertInstanceOf('Riak\\Client\\Core\\Query\\RiakObject', $values[1]);
     $this->assertEquals('Sat, 01 Jan 2015 01:01:01 GMT', $values[0]->getLastModified());
     $this->assertEquals('Sat, 02 Jan 2015 02:02:02 GMT', $values[1]->getLastModified());
     $this->assertEquals('application/json', $values[0]->getContentType());
     $this->assertEquals('application/json', $values[1]->getContentType());
     $this->assertEquals('[1,1,1]', $values[0]->getValue());
     $this->assertEquals('[2,2,2]', $values[1]->getValue());
 }
 private function storeObject($key, $data)
 {
     $json = json_encode($data);
     $object = new RiakObject($json, 'application/json');
     $location = new RiakLocation($this->namespace, $key);
     $this->client->execute(StoreValue::builder($location, $object)->withPw(1)->withW(2)->build());
     $this->locations[] = $location;
 }
Exemplo n.º 5
0
 private function storeObject($key, $info, array $groups, array $emails)
 {
     $json = json_encode($info);
     $object = new RiakObject($json, 'application/json');
     $location = new RiakLocation($this->namespace, $key);
     $command = StoreValue::builder($location, $object)->withPw(1)->withW(2)->build();
     $object->addIndex(new RiakIndexInt('groups', $groups));
     $object->addIndex(new RiakIndexBin('emails', $emails));
     $this->client->execute($command);
     $this->locations[] = $location;
 }
Exemplo n.º 6
0
 private function storeObject($key, $data, array $tags, array $links)
 {
     $json = json_encode($data);
     $object = new RiakObject($json, 'application/json');
     $location = new RiakLocation($this->namespace, $key);
     $command = StoreValue::builder($location, $object)->withPw(1)->withW(2)->build();
     $object->addIndex(new RiakIndexBin('tags', $tags));
     $object->addIndex(new RiakIndexInt('links', $links));
     $this->client->execute($command);
     $this->locations[] = $location;
 }
Exemplo n.º 7
0
 protected function storeObject($key, RiakObject $object)
 {
     if ($this->isStored($key)) {
         return;
     }
     if ($this->isIndexed($key)) {
         return;
     }
     $location = new RiakLocation($this->namespace, $key);
     $command = StoreValue::builder($location, $object)->withPw(1)->withW(2)->build();
     $this->client->execute($command);
     $this->insureIsIndexed($key);
 }
 public function testStoreUsingConverter()
 {
     $domainObject = new DomainObject([1, 2, 3]);
     $response = new PutResponse();
     $command = StoreValue::builder()->withLocation($this->location)->withValue($domainObject)->build();
     $respContent = new Content();
     $response->vClock = 'vclock-hash';
     $response->contentList = [$respContent];
     $respContent->contentType = 'application/json';
     $respContent->lastModified = 1420246861;
     $respContent->value = '1,2,3';
     $callback = function ($subject) {
         $this->assertInstanceOf('Riak\\Client\\Core\\Message\\Kv\\PutRequest', $subject);
         $this->assertInstanceOf('Riak\\Client\\Core\\Message\\Kv\\Content', $subject->content);
         $this->assertEquals('plain/text', $subject->content->contentType);
         $this->assertEquals('1,2,3', $subject->content->value);
         return true;
     };
     $this->transport->expects($this->once())->method('send')->with($this->callback($callback))->will($this->returnValue($response));
     $this->assertInstanceOf('Riak\\Client\\Command\\Kv\\Response\\StoreValueResponse', $this->client->execute($command));
 }
Exemplo n.º 9
0
 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());
 }