basho / riak-nodejs-client

The Riak client for Node.js.
Apache License 2.0
72 stars 28 forks source link

Cannot ping local node [JIRA: CLIENTS-863] #158

Closed jlai403 closed 8 years ago

jlai403 commented 8 years ago

I'm following the Getting Started with NodeJS docs but can't seem to ping my local node. I have other similar tests in the same project using another librarie, riak-dc, and have no problem pinging/ storing data.

I'm not sure what I'm missing in my setup.

suite('RiakJsTests', function() {

    setup(function(done) {
        client = new Riak.Client(['127.0.0.1:8098'], function (err, c) {
            assert.isNull(err);
            assert.isOk(c);
            done();
        });
    });

    test('#ping()', function(done) {
        console.log(client);
        client.ping(function (err, pong) {
            assert.isNull(err);
            assert.isTrue(pong);
            done();
        });
    });
});
lukebakken commented 8 years ago

Hello,

I need to improve that document. Take a look at this code example:

var Riak = require('basho-riak-client');
var nodes = [
    'riak-test:10017',
    'riak-test:10027',
    'riak-test:10037',
    'riak-test:10047'
];
var client = new Riak.Client(nodes, function (err, c) {
    // NB: at this point the client is fully initialized, and
    // 'client' and 'c' are the same object
});

Note that the Riak.Client constructor takes a callback argument that is called when the object is ready to execute commands. In your code (and as the rest of the code examples aren't clear about), you have a good chance of trying to execute .ping() before the Riak.Client object is actually ready to use. You probably are getting or logging a "no Riak nodes available" error.

If you move the .ping() call inside of the constructor callback, or use some other synchronization mechanism, your issue will be resolved.

I intend to improve the developer experience with this, see issue #129 and subscribe to it if you'd like to follow progress.

lukebakken commented 8 years ago

@jlai403 - also see #146

Thanks for using Riak and the Node.js client :smile:

jlai403 commented 8 years ago

I've tried putting the ping in the callback but I'm still not getting a ping response back. I get the log when I'm in the Riak.Client callback, but not for the ping callback. My test just times out.

test('#ping()', function(done) {
        var client = new Riak.Client(['127.0.0.1:8098'], function (err, c) {
            assert.isNull(err);
            assert.isOk(c);
            console.log('Riak.Client');
            c.ping(function (err, pong) {
                console.log('ping');
                assert.isNull(err);
                assert.isTrue(pong);
                done();
            });
        });
    });
lukebakken commented 8 years ago

@jlai403 - 8098 is the HTTP port, you need to use 8087, which is the standard TCP port.

lukebakken commented 8 years ago

See #156 to follow progress on that particular item.

jlai403 commented 8 years ago

awesome, thanks for the quick response @lukebakken

lukebakken commented 8 years ago

Great! Everything resolved then?

jlai403 commented 8 years ago

Yup, all is good now thanks!

Basho-JIRA commented 7 years ago

Fixed, or closed via GitHub issues.

[posted via JIRA by Alexander Moore]