public function testBuildBinIndex() { $builder = BinIndexQuery::builder($this->namespace, 'foo', 'bar')->withNamespace($this->namespace)->withTermFilter('@gmail.com')->withIndexName('index-mail')->withPaginationSort(true)->withMatch('val'); $command = $builder->build(); $query = $command->getQuery(); $this->assertInstanceOf('Riak\\Client\\Core\\Query\\RiakIndexQuery', $query); $this->assertInstanceOf('Riak\\Client\\Command\\Index\\BinIndexQuery', $command); $this->assertEquals('index-mail_bin', $query->getIndexName()); $this->assertSame($this->namespace, $query->getNamespace()); $this->assertSame('@gmail.com', $query->getTermFilter()); $this->assertTrue($query->getPaginationSort()); $this->assertSame('val', $query->getMatch()); }
public function testContinuationIndexQuery() { $builder = BinIndexQuery::builder()->withNamespace($this->namespace)->withTermFilter('@gmail.com')->withIndexName('emails')->withReturnTerms(true)->withStart('user1')->withMaxResults(2)->withEnd('user4'); $result1 = $this->client->execute($builder->build()); $this->assertInstanceOf('Riak\\Client\\Command\\Index\\Response\\IndexQueryResponse', $result1); $this->assertFalse($result1->hasContinuation()); $values1 = $result1->getEntries(); $continuation1 = $result1->getContinuation(); $this->assertCount(2, $values1); $this->assertNotNull($continuation1); $this->assertTrue($result1->hasContinuation()); $this->assertInstanceOf('Riak\\Client\\Command\\Index\\Response\\IndexEntry', $values1[0]); $this->assertInstanceOf('Riak\\Client\\Command\\Index\\Response\\IndexEntry', $values1[1]); usort($values1, function (IndexEntry $a, IndexEntry $b) { return strcmp($a->getLocation()->getKey(), $b->getLocation()->getKey()); }); $this->assertEquals('user1', $values1[0]->getLocation()->getKey()); $this->assertEquals('user2', $values1[1]->getLocation()->getKey()); $this->assertEquals('*****@*****.**', $values1[0]->getIndexKey()); $this->assertEquals('*****@*****.**', $values1[1]->getIndexKey()); $result2 = $this->client->execute($builder->withContinuation($continuation1)->build()); $this->assertInstanceOf('Riak\\Client\\Command\\Index\\Response\\IndexQueryResponse', $result2); $this->assertFalse($result2->hasContinuation()); $iterator2 = $result2->getIterator(); $values2 = iterator_to_array($iterator2); $continuation2 = $result2->getContinuation(); $this->assertCount(1, $values2); $this->assertNull($continuation2); $this->assertInstanceOf('Riak\\Client\\Command\\Index\\Response\\IndexEntry', $values2[0]); usort($values1, function (IndexEntry $a, IndexEntry $b) { return strcmp($a->getLocation()->getKey(), $b->getLocation()->getKey()); }); $this->assertEquals('user3', $values2[0]->getLocation()->getKey()); $this->assertEquals('*****@*****.**', $values2[0]->getIndexKey()); }