Example #1
0
 setTimeout(function(){
     monitor.running=false
     zk.a_create("/test/1","data", 0,function (rc,error,path){
         monitor.running=true
         monitor.refresh()
     })
 },100)
 zk.a_exists(offsetPath, false, function(rc, error, stat) {
   if (rc != 0) {
     if (error == 'no node') {
       log.debug('initializeConsumerOffsets/initializePartitions/noOffsets');
       zk.a_create(offsetPath, '0', null, function(rc, error) {
         if (rc != 0) {
           partitionCb(error);
         } else {
           result.push({ broker: partitions.broker, partition: partition.index, offset: '0' });
           partitionCb();
         }
       });
     } else {
       log.debug('initializeConsumerOffsets/initializePartitions/unknownError');
       partitionCb(error);
     }
   } else {
     log.debug('initializeConsumerOffsets/initializePartitions/setOffsets');
     zk.a_set(offsetPath, 0, stat.version, function(rc, error) {
       if (rc != 0) {
         partitionCb(error);
       } else {
         result.push({ broker: partitions.broker, partition: partition.index, offset: '0' });
         partitionCb();
       }
     });
   }
 });
Example #3
0
		function(callback) {
			var node = OPTS.znode;
			return zk.a_create(node, null, 0, function(rc, msg) {
				if (rc != 0)
					return callback(new Error(msg));

				return callback(null, node);
			});
		}
Example #4
0
zk.connect(function(err) {
    if (err) throw err;
    console.log("zk session established, id=%s", zk.client_id);
    zk.a_create("/clustertest/server", "some value", ZooKeeper.ZOO_SEQUENCE | ZooKeeper.ZOO_PERSISTENT, function(rc, error, path) {
        if (rc != 0) {
            console.log("zk node create result: %d, error: '%s', path=%s", rc, error, path);
        } else {
            console.log("created zk node %s", path);
            process.nextTick(function() {
                //zk.close ();
            });
        }
    });
});
 zk.a_exists(offsetPath, false, function(rc, error, stat) {
   if (rc != 0) {
     if (error == 'no node') {
       return zk.a_create(offsetPath, offset, null, function(rc, error) {
         return offsetCallback((rc != 0) ? error : null);
       });
     } else {
       return offsetCallback('Error retriving offset: ' + error);
     }
   } else {
     zk.a_set(offsetPath, offset.offset, stat.version, function(rc, error) {
       return offsetCallback((rc != 0) ? error : null);
     });
   }
 });
Example #6
0
  it("should notify on each child remove",function(done){
      var callable = {}
      var monitor
      callable.nodeRemoved = function(obj){
          should.exist(obj)
          obj.path.should.equal("/test")
          obj.node.should.equal("1")
          monitor.shutdown()
          done()
      }
      callable.nodeDataChange = function(obj){}
      callable.nodeAdded = function(initialNodes){
          zk.a_delete_("/test/1",-1,function(rc, error){})
      }
      zk.a_create("/test/1","data", 0,function (rc,error,path){
         monitor = new ZKMonitor(zk,callable) 
         monitor.pathMonitor("/test")
      })
 })
Example #7
0
function execute(callback) {
        var path = '/test/zkleak_memoryusage';
        zk.a_create(path, 'hoge', 0, function(rc, err , createdPath) {
                if (rc != 0) return callback(err);
                logger.info('create success ' +createdPath);
                zk.a_exists(createdPath, true, function(rc, err, stat) {
                        if (rc != 0) return callback(err);
                        logger.info('a_exists success');
                        zk.a_delete_(createdPath, 0, function(rc, err) {
                                if (rc != 0) return callback(err);
                                logger.info('delete success');
                        });
                });
              zk.aw_exists ( createdPath,function(type, state, path){
                      logger.info('aw_exists watcher called');
                      return callback(null, path);
              }
              , function(rc, err, path) {
                      if (rc != 0) return callback(err);
              });
        });
}
Example #8
0
 it("should notify on each child add",function(done){
     var callable = {}
     var called = false
     callable.nodeRemoved = function(obj){}
     callable.nodeDataChange = function(obj){}
     callable.nodeAdded = function(obj){
         should.exist(obj)
         obj.path.should.equal("/test")
         obj.node.should.equal("1")
         obj.data.should.equal("data")
         if(!called){
             called = true
             done()
              
          }
     }
     var monitor = new ZKMonitor(zk,callable) 
     monitor.pathMonitor("/test")
         zk.a_create("/test/1","data", 0,function (rc,error,path){
     })
     
 })
Example #9
0
 beforeEach(function(done){
     zk.a_create("/test","", 0,function (rc, error, path){
          zk.a_get_children("/test",false,function(rc,error,children){
              var count = 0;
              var finish = 0
              if(children)
                  finish = children.length
              if(finish==0){
                  done()
                  return;
              }
     
              for(var i in children){
                  zk.a_delete_("/test/"+children[i],-1,function(rc,error,path){
                      count++;
                      if(count>=finish){
                          done()
                      }
                  })
              }
          })
      })
  })
Example #10
0
 setTimeout(function(){
     monitor.actualPath["/test"].push("1")
     zk.a_create("/test/1","data", 0,function (rc,error,path){
         monitor.refresh()
     })
 },100)