/** * @param \Kbrw\RiakBundle\Model\Cluster\Cluster $cluster * @param \Kbrw\RiakBundle\Model\Bucket\Bucket $bucket * @param \Kbrw\RiakBundle\Model\Search\Query $query * @return array<string,string> */ public function getConfig($cluster, $bucket, $query) { $config = $query->getConfig(); $config["protocol"] = $cluster->getProtocol(); $config["domain"] = $cluster->getDomain(); $config["port"] = $cluster->getPort(); $config["bucket"] = $bucket->getName(); return $config; }
public function setup() { parent::setup(); // create bucket $this->bucket = new Bucket("foo"); $this->bucket->getProps()->setNVal(5); // insert bucket into a cluster $riakKVServiceClient = new MockedRiakKVServiceClient($this->getContainer()); $riakBucketServiceClient = new MockedRiakBucketServiceClient($this->getContainer()); $guzzleClientProviderTest = new SimpleGuzzleClientProviderTest(); $guzzleClientProvider = $guzzleClientProviderTest->getGuzzleClientProvider(); $eventDispatcher = $this->getService("event_dispatcher"); $this->cluster = new Cluster("backend", "http", "localhost", "1234", "frontend", 50, array(), $guzzleClientProvider, $eventDispatcher, $riakBucketServiceClient, $riakKVServiceClient); $this->cluster->addBucket($this->bucket); }
/** * @param \Kbrw\RiakBundle\Model\Cluster\Cluster $cluster * @param \Kbrw\RiakBundle\Model\Bucket\Bucket $bucket * @return array<string,string> */ public function getConfig($cluster, $bucket, $r = null, $w = null, $dw = null) { $config = array(); $config["protocol"] = $cluster->getProtocol(); $config["domain"] = $cluster->getDomain(); $config["port"] = $cluster->getPort(); $config["bucket"] = $bucket->getName(); $config["r"] = $r; $config["w"] = $w; $config["dw"] = $dw; return $config; }
<?php use Kbrw\RiakBundle\Model\Bucket\Bucket; $object = new Bucket("retailer"); $object->getProps()->setR("quorum"); $object->getProps()->setW("quorum"); $object->getProps()->setDw("quorum"); $object->getProps()->setRw("quorum");
/** * @test */ public function splitFetchRequestsWhenMaxParallelCallsIsReached() { $riakKVServiceClient = $this->getMockBuilder("Kbrw\\RiakBundle\\Service\\WebserviceClient\\Riak\\RiakKVServiceClient")->setMethods(array("doFetch"))->getMock(); $riakKVServiceClient->contentTypeNormalizer = $this->getService("kbrw.content.type.normalizer"); $riakKVServiceClient->serializer = $this->getService("jms_serializer"); $riakKVServiceClient->logger = $this->getService("logger"); $riakKVServiceClient->expects($this->exactly(3))->method("doFetch")->will($this->returnValue(new Datas())); $bucket = new Bucket(); $bucket->setFormat("json"); $cluster = new Cluster(); $cluster->setMaxParallelCalls(2); // the 5 put requests will be done using THREE curl_multi requests $riakKVServiceClient->fetch($cluster, $bucket, array("foo1", "foo2", "foo3", "foo4", "foo5")); }
/** * @param string $key * @param mixed $data * @param \Kbrw\RiakBundle\Model\Bucket\Bucket $bucket */ protected function insertData($key, $data) { $serializedContent = $this->getService("jms_serializer")->serialize($data, $this->bucket->getFormat()); $this->bucket->riakBucketServiceClient->content[$key] = $serializedContent; $this->bucket->riakKVServiceClient->content[$key] = $serializedContent; }
/** * @param \Kbrw\RiakBundle\Model\Cluster\Cluster $cluster * @param \Kbrw\RiakBundle\Model\Bucket\Bucket $bucket * @return boolean */ public function save($cluster, $bucket) { $request = $this->getClient($cluster->getGuzzleClientProviderService(), $this->getConfig($cluster, $bucket->getName(), null))->put(); try { $extra = array("method" => "PUT"); $ts = microtime(true); $request->setBody($this->serializer->serialize($bucket, "json")); $extra["serialization_time"] = microtime(true); -$ts; $request->setHeader("Content-Type", "application/json"); $response = $request->send(); $this->logResponse($response, $extra); return $response->getStatusCode() == "204"; } catch (CurlException $e) { $this->logger->err("Riak is unavailable" . $e->getMessage()); throw new RiakUnavailableException(); } catch (\Exception $e) { $this->logger->err("Error while setting properties on bucket '" . $bucket->getName() . "'. Full message is : " . $e->getMessage()); } return false; }
/** * @param string | \Kbrw\RiakBundle\Model\Bucket\Bucket $bucket * @param boolean $buildFromCluster * @return \Kbrw\RiakBundle\Model\Bucket\Bucket */ public function addBucket(&$bucket, $buildFromCluster = false) { if ($buildFromCluster) { $bucketName = $bucket instanceof \Kbrw\RiakBundle\Model\Bucket\Bucket ? $bucket->getName() : $bucket; $bucket = $this->bucketProperties($bucketName); } if (!$bucket instanceof \Kbrw\RiakBundle\Model\Bucket\Bucket) { $bucket = new Bucket($bucket); } $bucket->setRiakBucketServiceClient($this->riakBucketServiceClient); $bucket->setRiakKVServiceClient($this->riakKVServiceClient); $bucket->setRiakSearchServiceClient($this->riakSearchServiceClient); $bucket->setCluster($this); if (isset($this->eventDispatcher)) { $event = new GenericEvent("riak.bucket.add"); $event->setArgument("bucket", $bucket); $this->eventDispatcher->dispatch("riak.bucket.add", $event); } $this->buckets[$bucket->getName()] = $bucket; return $bucket; }