Beispiel #1
0
 /**
  * @return bool
  */
 public function purge()
 {
     $update = $this->client->createUpdate();
     $update->addDeleteQuery($this->deleteQuery);
     $update->addCommit();
     $result = $this->client->update($update);
     return 0 == $result->getStatus();
 }
 public function testConstructorAndGetters()
 {
     $client = new Client();
     $endpoint = $client->getEndpoint();
     $httpException = new HttpException('test exception');
     $event = new EndpointFailure($endpoint, $httpException);
     $this->assertEquals($endpoint, $event->getEndpoint());
     $this->assertEquals($httpException, $event->getException());
 }
 /**
  * @depends testConstructorAndGetters
  *
  * @param PreCreateResult $event
  */
 public function testSetAndGetQuery($event)
 {
     $client = new Client();
     $query = $client->createSelect();
     $query->setQuery('test123');
     $response = new Response('', array('HTTP 1.0 200 OK'));
     $result = new Result($client, $query, $response);
     $event->setResult($result);
     $this->assertEquals($result, $event->getResult());
 }
Beispiel #4
0
 public function testConstructorAndGetters()
 {
     $client = new Client();
     $query = $client->createSelect();
     $query->setQuery('test123');
     $response = new Response('', array('HTTP 1.0 200 OK'));
     $result = new Result($client, $query, $response);
     $event = new PostExecute($query, $result);
     $this->assertEquals($query, $event->getQuery());
     $this->assertEquals($result, $event->getResult());
 }
 public function testConstructorAndGetters()
 {
     $client = new Client();
     $request = new Request();
     $request->addParam('testparam', 'test value');
     $endpoint = $client->getEndpoint();
     $event = new PreExecuteRequest($request, $endpoint);
     $this->assertEquals($request, $event->getRequest());
     $this->assertEquals($endpoint, $event->getEndpoint());
     return $event;
 }
 public function testConstructorAndGetters()
 {
     $client = new Client();
     $request = new Request();
     $request->addParam('testparam', 'test value');
     $endpoint = $client->getEndpoint();
     $response = new Response('', array('HTTP 1.0 200 OK'));
     $event = new PostExecuteRequest($request, $endpoint, $response);
     $this->assertEquals($request, $event->getRequest());
     $this->assertEquals($endpoint, $event->getEndpoint());
     $this->assertEquals($response, $event->getResponse());
 }
 public function testAddAndGetQueries()
 {
     $client = new Client();
     $client->clearEndpoints();
     $client->createEndpoint('local1');
     $endpoint2 = $client->createEndpoint('local2');
     $this->plugin->initPlugin($client, array());
     $query1 = $client->createSelect()->setQuery('test1');
     $query2 = $client->createSelect()->setQuery('test2');
     $this->plugin->addQuery(1, $query1);
     $this->plugin->addQuery(2, $query2, $endpoint2);
     $this->assertEquals(array(1 => array('query' => $query1, 'endpoint' => 'local1'), 2 => array('query' => $query2, 'endpoint' => 'local2')), $this->plugin->getQueries());
 }
Beispiel #8
0
 /**
  * @param array <string> $files
  *
  * @return array
  */
 public function load(array $files)
 {
     $update = $this->client->createUpdate();
     /** @var $loader \Nelmio\Alice\Loader\Base */
     $loader = $this->getLoader('yaml');
     $loader->setProviders($this->providers);
     foreach ($files as $file) {
         $update->addDocuments($loader->load($file));
     }
     $update->addCommit();
     if (null !== $update) {
         $this->client->execute($update);
     }
 }
 public function testPluginIntegration()
 {
     $client = new Client();
     $client->registerPlugin('testplugin', $this->plugin);
     $input = array('key' => 'xid', 'type' => 'param', 'name' => 'xid', 'value' => 123);
     $this->plugin->addCustomization($input);
     $originalRequest = new Request();
     $expectedRequest = new Request();
     $expectedRequest->addParam('xid', 123);
     // this should be the effect of the customization
     $observer = $this->getMock('Solarium\\Core\\Client\\Adapter\\Http', array('execute'));
     $observer->expects($this->once())->method('execute')->with($this->equalTo($expectedRequest))->will($this->returnValue(new Response('', array('HTTP 1.0 200 OK'))));
     $client->setAdapter($observer);
     $client->executeRequest($originalRequest);
 }
 /**
  * @param Query $query
  * @param callable $transform
  * @param null $readEndpoint
  * @param null $writeEndpoint
  */
 public function updateNoBuffer(Query $query, callable $transform, $readEndpoint = null, $writeEndpoint = null, $commit = true)
 {
     $update = $this->solarium->createUpdate();
     $documents = $this->solarium->execute($query, $readEndpoint);
     foreach ($documents as $document) {
         $update->addDocument($transform($document));
     }
     if (count($documents) > 0 && $commit === true) {
         $update->addCommit();
     }
     $this->solarium->execute($update, $writeEndpoint);
 }
 public function testCreateQueryPostPlugin()
 {
     $type = Client::QUERY_SELECT;
     $options = array('optionA' => 1, 'optionB' => 2);
     $query = $this->client->createQuery($type, $options);
     $expectedEvent = new PostCreateQueryEvent($type, $options, $query);
     $expectedEvent->setDispatcher($this->client->getEventDispatcher());
     $expectedEvent->setName(Events::POST_CREATE_QUERY);
     $observer = $this->getMock('Solarium\\Core\\Plugin\\Plugin', array('postCreateQuery'));
     $observer->expects($this->once())->method('postCreateQuery')->with($this->equalTo($expectedEvent));
     $this->client->getEventDispatcher()->addListener(Events::POST_CREATE_QUERY, array($observer, 'postCreateQuery'));
     $this->client->createQuery($type, $options);
 }
 public function testFailoverMaxRetries()
 {
     $this->plugin = new TestLoadbalancer();
     // special loadbalancer that returns endpoints in fixed order
     $adapter = new TestAdapterForFailover();
     $adapter->setFailCount(10);
     $this->client->setAdapter($adapter);
     // set special mock that fails for all endpoints
     $this->plugin->initPlugin($this->client, array());
     $request = new Request();
     $endpoints = array('server1' => 1, 'server2' => 1);
     $this->plugin->setEndpoints($endpoints);
     $this->plugin->setFailoverEnabled(true);
     $query = new SelectQuery();
     $event = new PreCreateRequestEvent($query);
     $this->plugin->preCreateRequest($event);
     $this->setExpectedException('Solarium\\Exception\\RuntimeException', 'Maximum number of loadbalancer retries reached');
     $event = new PreExecuteRequestEvent($request, new Endpoint());
     $this->plugin->preExecuteRequest($event);
 }
 public function testPluginIntegration()
 {
     $client = new Client();
     $client->registerPlugin('testplugin', $this->plugin);
     $this->plugin->setMaxQueryStringLength(1);
     // this forces POST for even the smallest queries
     $query = $client->createSelect();
     $request = $client->createRequest($query);
     // default method is GET, the plugin should have changed this to POST
     $this->assertEquals(Request::METHOD_POST, $request->getMethod());
 }
 public function setUp()
 {
     $this->plugin = new PrefetchIterator();
     $this->client = new Client();
     $this->query = $this->client->createSelect();
 }