generates random activity
Last updated 4 years ago by smc-tenacious .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install happn-random-activity-generator 
SYNC missed versions from official npm registry.

random activity generator

takes a happn client at construction time, and performs random activities against the clients happn server. highly configurable - allows for the percentage of gets, sets, removes and ons to be configured. For ons, gets and removes some initial data needs to be created - this is also configurable


npm install happn-random-activity-generator --save-dev


var RandomActivity = require('happn-random-activity-generator');

//the options are the second parameter - the amounts are the default amounts
generator = new RandomActivity(happnClientInstance, {
	interval:20,//in milliseconds, the interval between each new random call
	percentageGets:[0,20],//range out of 100 of gets that are randomly chosen
	percentageSets:[20,80],//range out of 100 of sets that are randomly chosen
	percentageRemoves:[80,90],//range out of 100 of removes that are randomly chosen
	percentageOns:[90,100],//range out of 100 of ons that are randomly chosen
	initialDataRemoveCount:40,//initial data generated for remove calls
	initialDataOnCount:20,//initial data generated for on calls
	initialDataGetCount:50,//initial data generated for get calls
	randomDataSize:3,//the random data object has a bigData property, this setting creates a string of length (32 * 3)
	onTimeout:100//when the verify operation runs, this is the timeout reached when testing ons

start, stop and verify:

when you start the random activity, the timespan it takes to generate the initial data is stored - this is so that when you stop the activity, the system waits for that timespan to actually stop - this allows for accuracy that is not affected by the initialization procedure

var happn = require('happn')
var service = happn.service;
var happn_client = happn.client;

service.create(function(e, instance){
	if (e) return callback(e);
	serviceInstance = instance;

	happn_client.create(function(e, cli){

		if (e) return callback(e);
		clientInstance = cli;

		//instantiate the generator here:
		var RandomActivity = require('happn-random-activity-generator');
		generator = new RandomActivity(clientInstance);

		//start random activity - we use a key "test" to store the generated log data
		//this is so we can run multiple parallel tests if necessary
		generator.generateActivityStart("test", function(e){

			//wait a while, then stop


				//end the generation run
				generator.generateActivityEnd("test", function(aggregatedLog){

					//verify the database state matches the logs
					generator.verify(function(e, log){

					"test");//verify the "test" group


			}, 2000);



you can create 2 generators, have one do a run, then pass it to another generator (perhaps connected to a different db) - its logs is parsed and exactly the same activity is replicated

the following is an example from the test

generator.generateActivityStart("test", function(){
		generator.generateActivityEnd("test", function(aggregatedLog){

			var RandomActivity = require('happn-random-activity-generator');
			generator2 = new RandomActivity(clientInstance);
			generator2.replay(generator, "test", function(e, replayLog){

				if (e) return callback(e);





	}, 2000);

daemon mode

this is for testing activity over a long period (days/weeks/months), running in this mode does not store a replay log, and only stores aggregated data related to the run

following example from the test

generator.generateActivityStart("test", function(){
		generator.generateActivityEnd("test", function(aggregatedLog){
	}, 2000);
}, "daemon");//NB here is where you set the mode to "daemon"

Current Tags

  • 0.2.1                                ...           latest (4 years ago)

3 Versions

  • 0.2.1                                ...           4 years ago
  • 0.2.0                                ...           4 years ago
  • 0.0.1                                ...           4 years ago
Maintainers (1)
Today 0
This Week 0
This Month 0
Last Day 0
Last Week 0
Last Month 2
Dependencies (2)
Dev Dependencies (12)
Dependents (2)

Copyright 2014 - 2016 © taobao.org |