Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Add: test for search behaviour.

The current implementation does not return the num_found value from
riak. This commit adds an explict test for the search api output from the client.

Also cleanup Vagrantfile and provisioning to support search testing.
(search needs to enabled on the search_test bucket).
  • Loading branch information...
commit 414ccb2c9a04fa135058ef0aa58f9c517113364f 1 parent cdb6a78
@nisaacson nisaacson authored
View
18 Vagrantfile
@@ -9,14 +9,6 @@ Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
# options are documented and commented below. For a complete reference,
# please see the online documentation at vagrantup.com.
- # Every Vagrant virtual environment requires a box to build off of.
- config.vm.box = "precise64_virtualbox"
-
- # The url from where the 'config.vm.box' box will be fetched if it
- # doesn't already exist on the user's system.
- config.vm.box_url = "http://files.vagrantup.com/precise64.box"
- config.vm.provision "shell", path: "test/provision_vagrant.sh"
-
# Create a forwarded port mapping which allows access to a specific port
# within the machine from a port on the host machine. In the example below,
# accessing "localhost:8080" will access port 80 on the guest machine.
@@ -29,9 +21,17 @@ Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
args: "-p 3333:22 -p 8087:8087 -p 8098:8098"
end
+ config.vm.provision "shell", path: "test/provision_vagrant.sh"
+
# override box and box_url when using the "--provider vmware_fusion" flag
- config.vm.provider "vmware_fusion" do |v, override|
+ config.vm.provider :vmware_fusion do |v, override|
override.vm.box = "precise64_fusion"
override.vm.box_url = "http://files.vagrantup.com/precise64_vmware.box"
end
+
+ # override box and box_url when using the "--provider virtualbox" flag
+ config.vm.provider :virtualbox do |v, override|
+ override.vm.box = "precise64_virtualbox"
+ override.vm.box_url = "http://files.vagrantup.com/precise64.box"
+ end
end
View
13 test/client-test.js
@@ -381,6 +381,7 @@ describe('Client test', function () {
});
it('mapred', function (done) {
+ this.slow('.5s');
var mapOpts = {
map: {
source: 'function (v) { return [[v.bucket, v.key]]; }',
@@ -469,18 +470,6 @@ describe('Client test', function () {
}
});
-
- it('search', function (done) {
- client.search({
- index: 'test',
- q: 'test:data'
- }, function (err, reply) {
- expect(err).to.not.exist;
- expect(reply).to.exist;
- done();
- });
- });
-
it('counters', function (done) {
var currentValue = 3;
var bucket = 'test';
View
38 test/provision_vagrant.sh
@@ -9,14 +9,7 @@ function install_from_apt {
return
fi
echo " $TOOL not installed, begin installation from apt"
- sudo apt-get install -qqy curl
- command -v $TOOL > /dev/null
- if [[ $? -eq 0 ]]; then
- echo " $TOOL installed correctly"
- return
- fi
- echo "$TOOL failed to install correctly"
- exit 1
+ sudo apt-get install -qqy $TOOL
}
function install_node {
@@ -28,7 +21,7 @@ function install_node {
fi
echo " nodejs not installed, begin installation from ppa now"
sudo apt-get update
- sudo apt-get install -y -qq python-software-properties python g++ make
+ sudo apt-get install -y -qq python-software-properties
sudo add-apt-repository -y ppa:chris-lea/node.js
sudo apt-get update -y
sudo apt-get install -qqy nodejs
@@ -41,5 +34,32 @@ function install_node {
exit 1
}
+function install_httpie {
+ echo "-----> Install python"
+ command -v http > /dev/null
+ if [[ $? -eq 0 ]]; then
+ echo " httpie already installed"
+ return
+ fi
+ echo "-----> Install pip"
+ sudo apt-get install -qqy python-pip python-dev build-essential
+ sudo pip install --upgrade pip
+ echo "-----> Install httpie"
+ sudo pip install --upgrade httpie
+}
+
+function enable_indexing_on_riak_buckets {
+ echo "-----> Enable search on riak buckets"
+ echo " sleep for 3 seconds to give riak time to start"
+ sleep "3s"
+ BUCKET="search_test"
+ URL="http://localhost:8098/riak/$BUCKET"
+ DATA='{"props":{"precommit":[{"mod":"riak_search_kv_hook","fun":"precommit"}]}}'
+ curl --silent -X PUT -H 'Content-Type: application/json' -d "$DATA" $URL
+ echo " enabled search on bucket: $BUCKET"
+}
+
install_from_apt "curl"
install_node
+enable_indexing_on_riak_buckets
+
View
78 test/search-test.js
@@ -0,0 +1,78 @@
+
+var _ = require('lodash-node');
+var chai = require('chai');
+chai.Assertion.includeStack = true; // defaults to false
+
+var expect = chai.expect;
+var inspect = require('eyespect').inspector();
+var q = require('q');
+var sinon = require('sinon');
+
+var riakpbc = require('../index');
+var client = riakpbc.createClient({ host: 'localhost', port: 8087 });
+
+var numRows = 10;
+var bucket = 'search_test';
+describe('search', function searchSuite() {
+ this.slow('1s');
+ before(function beforeBlock(done) {
+ var promise = connectClient();
+ promise.then(setupFixtures).nodeify(done);
+ });
+
+ after(function afterBlock(done) {
+ this.timeout('10s');
+ return done();
+ });
+
+ it('should return search results', function (done) {
+ var opts = {
+ q: 'bar:value_*',
+ index: bucket,
+ rows: 1,
+ start: 0
+ };
+ client.search(opts, cb);
+
+ function cb(err, reply) {
+ expect(err).to.not.exist;
+ expect(reply, 'should get search reply').to.exist;
+ expect(reply).to.have.ownProperty('docs');
+ expect(reply).to.have.ownProperty('max_score');
+ expect(reply.docs).to.be.an('array');
+ expect(reply.docs.length).to.equal(opts.rows);
+ expect(reply, 'num_found field missing in reply').to.have.ownProperty('num_found');
+ expect(reply.num_found).to.be.above(opts.rows);
+ done();
+ }
+ });
+});
+
+function connectClient() {
+ var promise = q.ninvoke(client, 'connect');
+ return promise;
+}
+
+function setupFixtures() {
+ var promises = _.range(0, numRows).map(createRow);
+ return q.all(promises);
+}
+
+function createRow(id) {
+ var key = [id, 'key'].join('_');
+ var value = {
+ bar: 'value_' + id
+ };
+ var content = {
+ value: JSON.stringify(value),
+ content_type: 'application/json'
+ };
+ var saveOpts = {
+ bucket: bucket,
+ content: content,
+ key: key
+ };
+
+ var promise = q.ninvoke(client, 'put', saveOpts);
+ return promise;
+}
Please sign in to comment.
Something went wrong with that request. Please try again.