コード例 #1
0
 public function testFetchUsingConflicResolver()
 {
     $getResponse = new GetResponse();
     $command = FetchValue::builder()->withLocation($this->location)->build();
     $c1 = new Content();
     $c2 = new Content();
     $getResponse->vClock = 'vclock-hash';
     $getResponse->contentList = [$c1, $c2];
     $c1->contentType = 'application/json';
     $c1->lastModified = 1420246861;
     $c1->value = '{"value":"line 1"}';
     $c2->contentType = 'application/json';
     $c2->lastModified = 1420250522;
     $c2->value = '{"value":"line 2"}';
     $this->adapter->expects($this->once())->method('send')->will($this->returnValue($getResponse));
     $result = $this->client->execute($command);
     $this->assertInstanceOf('Riak\\Client\\Command\\Kv\\Response\\FetchValueResponse', $result);
     $this->assertInstanceOf('Riak\\Client\\Core\\Query\\VClock', $result->getVectorClock());
     $this->assertTrue($result->hasValues());
     $this->assertFalse($result->getNotFound());
     $this->assertCount(2, $result->getValues());
     $this->assertEquals(2, $result->getNumberOfValues());
     $this->assertEquals('vclock-hash', $result->getVectorClock()->getValue());
     $values = $result->getValues();
     $domain = $result->getValue(SimpleObject::CLASS_NAME);
     $this->assertInstanceOf(SimpleObject::CLASS_NAME, $domain);
     $this->assertNotSame($domain, $values[0]);
     $this->assertNotSame($domain, $values[1]);
     $this->assertEquals("line 1" . PHP_EOL . "line 2", $domain->getValue());
 }
コード例 #2
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());
 }
コード例 #3
0
 protected function isStored($key)
 {
     $location = new RiakLocation($this->namespace, $key);
     $command = FetchValue::builder($location)->withNotFoundOk(true)->build();
     $response = $this->client->execute($command);
     return $response->getNotFound() == false;
 }
コード例 #4
0
 public function testFetch()
 {
     $getResponse = new GetResponse();
     $command = FetchValue::builder()->withLocation($this->location)->withBasicQuorum(true)->withNotFoundOk(true)->withPr(2)->withR(2)->build();
     $c1 = new Content();
     $c2 = new Content();
     $getResponse->vClock = 'vclock-hash';
     $getResponse->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($getResponse));
     $result = $this->client->execute($command);
     $this->assertInstanceOf('Riak\\Client\\Command\\Kv\\Response\\FetchValueResponse', $result);
     $this->assertInstanceOf('Riak\\Client\\Core\\Query\\VClock', $result->getVectorClock());
     $this->assertTrue($result->hasValues());
     $this->assertFalse($result->getNotFound());
     $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());
 }
コード例 #5
0
ファイル: RiakLinkTest.php プロジェクト: php-riak/riak-client
 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());
 }
コード例 #6
0
 public function testFetchUsingConverter()
 {
     $getResponse = new GetResponse();
     $command = FetchValue::builder()->withLocation($this->location)->build();
     $content = new Content();
     $getResponse->vClock = 'vclock-hash';
     $getResponse->contentList = [$content];
     $content->contentType = 'application/json';
     $content->lastModified = 1420246861;
     $content->value = '1,2,3';
     $this->transport->expects($this->once())->method('send')->will($this->returnValue($getResponse));
     $result = $this->client->execute($command);
     $this->assertInstanceOf('Riak\\Client\\Command\\Kv\\Response\\FetchValueResponse', $result);
     $this->assertInstanceOf('Riak\\Client\\Core\\Query\\VClock', $result->getVectorClock());
     $this->assertTrue($result->hasValues());
     $this->assertFalse($result->getNotFound());
     $this->assertCount(1, $result->getValues());
     $this->assertEquals(1, $result->getNumberOfValues());
     $this->assertEquals('vclock-hash', $result->getVectorClock()->getValue());
     $domain = $result->getValue(DomainObject::CLASS_NAME);
     $this->assertInstanceOf(DomainObject::CLASS_NAME, $domain);
     $this->assertEquals([1, 2, 3], $domain->getValues());
 }
コード例 #7
0
 public function testDomainObjectStoreAndFetchValueWithSiblings()
 {
     $key = uniqid();
     $object1 = new SimpleObject('[1,1,1]');
     $object2 = new SimpleObject('[2,2,2]');
     $location = new RiakLocation(new RiakNamespace('default', 'bucket'), $key);
     $store1 = StoreValue::builder($location, $object1)->withPw(1)->withW(1)->build();
     $store2 = StoreValue::builder($location, $object2)->withW(1)->build();
     $fetch = FetchValue::builder($location)->withNotFoundOk(true)->withR(1)->build();
     $delete = DeleteValue::builder($location)->build();
     $resultFetch1 = $this->client->execute($fetch);
     $resultStore1 = $this->client->execute($store1);
     $resultStore2 = $this->client->execute($store2);
     $resultFetch2 = $this->client->execute($fetch);
     $resultDelete = $this->client->execute($delete);
     $resultFetch3 = $this->client->execute($fetch);
     $this->assertTrue($resultFetch1->getNotFound());
     $this->assertFalse($resultFetch2->getNotFound());
     $this->assertTrue($resultFetch3->getNotFound());
     $this->assertInstanceOf('Riak\\Client\\Command\\Kv\\Response\\StoreValueResponse', $resultStore1);
     $this->assertInstanceOf('Riak\\Client\\Command\\Kv\\Response\\StoreValueResponse', $resultStore2);
     $this->assertInstanceOf('Riak\\Client\\Command\\Kv\\Response\\FetchValueResponse', $resultFetch2);
     $this->assertInstanceOf('Riak\\Client\\Command\\Kv\\Response\\FetchValueResponse', $resultFetch3);
     $this->assertInstanceOf('Riak\\Client\\Command\\Kv\\Response\\DeleteValueResponse', $resultDelete);
     $values = $resultFetch2->getValues(SimpleObject::CLASS_NAME);
     $this->assertCount(2, $values);
     $this->assertInstanceOf(SimpleObject::CLASS_NAME, $values[0]);
     $this->assertInstanceOf(SimpleObject::CLASS_NAME, $values[1]);
     $this->assertEquals($key, $values[0]->getRiakKey());
     $this->assertEquals($key, $values[1]->getRiakKey());
     $this->assertEquals('default', $values[0]->getRiakBucketType());
     $this->assertEquals('default', $values[1]->getRiakBucketType());
     $this->assertEquals('bucket', $values[0]->getRiakBucketName());
     $this->assertEquals('bucket', $values[1]->getRiakBucketName());
     $this->assertEquals('[1,1,1]', $values[0]->getValue());
     $this->assertEquals('[2,2,2]', $values[1]->getValue());
 }