aggregator.once('harvest', function (encoded) { expect(encoded, '1st harvest').an('array'); aggregator.add(createTransaction('/testTwo', 8000)); aggregator.once('harvest', function (encoded) { expect(encoded, '2nd harvest').an('array'); aggregator.add(createTransaction('/testThr', 8000)); aggregator.once('harvest', function (encoded) { expect(encoded, '3rd harvest').an('array'); aggregator.add(createTransaction('/testFor', 8000)); aggregator.once('harvest', function (encoded) { expect(encoded, '4th harvest').an('array'); aggregator.add(createTransaction('/testF5v', 8000)); aggregator.once('harvest', function (encoded) { expect(encoded, '5th harvest').an('array'); // n = 5, so this sixth transaction is gonna lose aggregator.add(createTransaction('/testSix', 9000)); aggregator.once('harvest', function (encoded) { should.not.exist(encoded, '6th harvest'); expect(aggregator.requestTimes['WebTransaction/Uri/testOne'], "1 of top 5").equal(8000); expect(aggregator.requestTimes['WebTransaction/Uri/testTwo'], "2 of top 5").equal(8000); expect(aggregator.requestTimes['WebTransaction/Uri/testThr'], "3 of top 5").equal(8000); expect(aggregator.requestTimes['WebTransaction/Uri/testFor'], "4 of top 5").equal(8000); expect(aggregator.requestTimes['WebTransaction/Uri/testF5v'], "5 of top 5").equal(8000); should.not.exist(aggregator.requestTimes['WebTransaction/Uri/testSix'], "6 of top 5 -- OOPS"); return done(); }); aggregator.harvest(); }); aggregator.harvest(); }); aggregator.harvest(); }); aggregator.harvest(); }); aggregator.harvest(); });
.then(function(persistedTags){ model.tags = persistedTags; //Transfer tag array into id string. TODO: move to utils var tagIdArray = []; for (var i in model.tags) { tagIdArray.push('%' + model.tags[i].id + '%'); } if (tagIdArray.length > 0) { model.tags = tagIdArray.join(','); } if (!id) { bo.add(model).then( function (success) { res.statusCode = 200; res.json(success); }, function (failure) { res.statusCode = 400; res.json({ code: 'ERR_DB_CREATE_EMPLOYEE_FAILURE', reason: '生成新员工信息时数据库出错' }); } ); } else { bo.update(model).then( function (success) { res.statusCode = 200; res.json(success); }, function (failure) { res.statusCode = 400; res.json({ code: 'ERR_DB_SAVE_EMPLOYEE_FAILURE', reason: '更新员工信息时数据库出错' }); } ); } });
aggregator.harvest(function () { // n = 5, so this sixth transaction is gonna lose aggregator.reset(fifth.getTrace()); var sixth = createTransaction('/testSix', 8000); aggregator.add(sixth); aggregator.harvest(function (error, encoded) { should.not.exist(error); should.not.exist(encoded, '6th harvest'); var times = aggregator.requestTimes; expect(times['WebTransaction/Uri/testOne'], "1 of top 5").equal(8000); expect(times['WebTransaction/Uri/testTwo'], "2 of top 5").equal(8000); expect(times['WebTransaction/Uri/testThr'], "3 of top 5").equal(8000); expect(times['WebTransaction/Uri/testFor'], "4 of top 5").equal(8000); expect(times['WebTransaction/Uri/testF5v'], "5 of top 5").equal(8000); should.not.exist(times['WebTransaction/Uri/testSix'], "6 of top 5 -- OOPS"); done(); }); });
async function mainTask() { try { // Path is not specified if (process.argv[2] === undefined) { console.log('missing argument.'); return; } await ipfs.daemonStart(); const _stdout = await ipfs.add(process.argv[2]); // Create hash list for (let _line of _stdout.split('\n')) { let _hash = _line.split(' ')[1]; if (_hash) { hashes.push(_hash); await recordHash(_line); } } await checkUpload(); } catch(e) { console.log(e); } }
async.forEach(characters, function (character, _callback) { // name is required if (!character.hasOwnProperty('name')) { _callback(); return; } var filler = require(__appbase + 'controllers/filler/characters'); character = filler.matchToModel(character); // add house to db Characters.add(character, function (success, data) { if (success != 1) { console.log('Problem:' + data); } else { console.log('SUCCESS: ' + data.name); } _callback(); }); },
before(function () { agent = helper.loadMockedAgent(); agent.config.capture_params = true; var transaction = new Transaction(agent) , trace = new Trace(transaction) , segment = new TraceSegment(trace, 'UnitTest') , url = '/test' , params; // Express uses positional parameters sometimes params = ['first', 'another']; params.test3 = '50'; webChild = segment.add(url); transaction.setName(url, 200); webChild.markAsWeb(url, params); trace.setDurationInMillis(1, 0); webChild.setDurationInMillis(1, 0); });
demoInfo.createView = function(){ var view = new DemoTemplateView(demoInfo); var rows = []; rows[0] = new RowColumnView({views:[null, 'Real', 'Min', 'Max']}); rows[1] = new RowColumnView({views:['Day 1', 10, 7, 30]}); rows[2] = new RowColumnView({views:['Day 2', '-', '!', 60]}); rows[3] = new RowColumnView({views:['Day 3', 41, '-', 90.5]}); var table = Ti.UI.createTableView({ right:0, left:0, height:200, backgroundColor:'#fff', data:rows }); view.add(table); return view; };
app.get("/tracker", function (req, res) { var type = null; var jsonPayload = _.chain(req.query) .mapValues(function (value) { try { return JSON.parse(value); } catch (e) { return value; }; }).mapKeys(function (value, key) { if (key === "action_name") { type = type_pageView; } else if (key === "link") { type = type_link; } else if (key === "search") { type = type_search; } if (_.startsWith(key, '_')) { //Cloudant doesn't authorize key starting with _ return key.replace(/^_/, ''); } return key; }).value(); if (type) { jsonPayload.type = type; } //Capture the IP address var ip = req.headers['x-client-ip'] || req.headers['x-forwarded-for'] || req.connection.remoteAddress; if (ip) { jsonPayload.ip = ip; } q.add(jsonPayload, function (err, data) { io.emit("output", jsonPayload) res.status(200).end(); }); res.status(200).end(); });
pubFunc.call(pubRecord.collection, item.args, function(dataArray){ if (typeof pubRecord.clients[item.socketId] == 'undefined') { //没有socketId的记录意味着没有subscribe过这个publish return; }; var snapshot = pubRecord.clients[item.socketId].snapshot; if(JSON.stringify(dataArray) === JSON.stringify(snapshot)){ //如果这条增量没有导致实质的数据改变,就不推送了 stop = true; }; if (!stop) { var diffData = findDiff(dataArray, snapshot, PublishContainer[item.pubname]["modelName"]); var dataVersion = snapshotMgr.add(item.pubname, dataArray); netMessage.sendMessage({ pubname : item.pubname, data : !PublishContainer[item.pubname].plainStruct ? diffData :dataArray, //这里其实就是struct,不过传输的是没有删除过clientid,和id的版本 flag : 'live_data', version : dataVersion }, 'data_write_from_server_delta', item.socketId, function(err){ fw.log('send data_write_from_server_delta fail ' + err , item.pubname , item.socketId); },function(){ fw.dev('send data_write_from_server_delta ok...' , item.pubname , item.socketId); } ); pubRecord.clients[item.socketId].snapshot = dataArray; }; }, client);
VNLS.ns('watch.utils').removeRecursive(tmp_dir,function(err,es){ fs.mkdirSync(tmp_dir, "0755"); watch.add(tmp_dir).onChange(function(file,previous,current,action){ // Should have 4 params expect(file).toEqual(fp1); // These are the possible actions // we trigger them down the road within the promise if(action === 'new'){ detect_new = true; } if(action === 'change'){ detect_change = true; } if(action === 'delete'){ detect_delete = true; } // where 'previous' and 'current' // are stats // http://nodejs.org/api/fs.html#fs_class_fs_stats }); p.done(); });
aggregator.harvest(function (error, encoded, trace) { verifier(encoded, true); aggregator.reset(trace); aggregator.add(createTransaction('/testOne', 415)); aggregator.harvest(function (error, encoded, trace) { verifier(encoded, true); aggregator.reset(trace); aggregator.add(createTransaction('/testTwo', 510)); aggregator.harvest(function (error, encoded, trace) { verifier(encoded, true); aggregator.reset(trace); aggregator.add(createTransaction('/testOne', 502)); aggregator.harvest(function (error, encoded) { verifier(encoded, false); done(); }); }); }); });
aggregator.once('harvest', function (encoded) { verifier(encoded, true); aggregator.add(createTransaction('/testOne', 415)); aggregator.once('harvest', function (encoded) { verifier(encoded, true); aggregator.add(createTransaction('/testTwo', 510)); aggregator.once('harvest', function (encoded) { verifier(encoded, true); aggregator.add(createTransaction('/testOne', 502)); aggregator.once('harvest', function (encoded) { verifier(encoded, false); return done(); }); aggregator.harvest(); }); aggregator.harvest(); }); aggregator.harvest(); });
demoInfo.createView = function(){ var view = new DemoTemplateView(demoInfo); //FlipImage does not animate right in vertical layout, so we need an additional view with absolute layout var contentView = Ti.UI.createView({left:0, right:0, height:200}); var badgeImg1 = new BadgeImage({ image: 'http://developer.appcelerator.com/assets/img/badge_titan.png', height: 100, left:20, width: 100, bottom:0 }); var badgeImg2 = new BadgeImage({ image: 'http://developer.appcelerator.com/assets/img/badge_titan.png', height: 100, width: 100, bottom:0 }); var badgeImg3 = new BadgeImage({ image: 'http://developer.appcelerator.com/assets/img/badge_titan.png', height: 100, width: 100, right:20, bottom:0 }); contentView.add(badgeImg1); contentView.add(badgeImg2); contentView.add(badgeImg3); view.add(contentView); return view; };
it('should call remove Travellers by passed in id', function(){ var travellers = new travellers_collection(); var id = _.uniqueId("traveller__"); travellers.add([ { name: "Test Person", _id: id }, { name: "Another Test Person", _id: 2 } ]) expect(travellers.models.length).to.equal(2); expect(travellers.models[0].id === id); travellers.removeTraveller(id); expect(travellers.models.length).to.equal(1); expect(travellers.models[0].id === 2); expect(travellers.models[1]).to.be.undefined; });
it('should not remove a traveller if no id matches', function(){ var travellers = new travellers_collection(); var id = _.uniqueId("traveller__"); travellers.add([ { name: "Test Person", _id: id }, { name: "Another Test Person", _id: 2 } ]) expect(travellers.models.length).to.equal(2); expect(travellers.models[0].id === id); travellers.removeTraveller(12345); expect(travellers.models.length).to.equal(2); expect(travellers.models[0].id === id); expect(travellers.models[1].id === 2); });
router.use = function( filename ){ if( filename === 'konter' ) return setupKonterRoutes(); try{ var mod = require(filename); logger.warn('not implemented to init an external module'); } catch(e){ // if error is different from module not fond, throw it if( e.code !== 'MODULE_NOT_FOUND' ) throw e; var orig = filename; if( !fs.existsSync( filename ) ) filename = path.join( process.cwd(), config.appsDir, filename ); if( fs.existsSync( path.join(filename,'index.js') ) ){ require( filename )( app, socket ); logger.info( 'route', path.basename(filename.replace(path.extname(filename),'')), 'initialized.'); } var viewsPath = path.join( process.cwd(), config.appsDir, orig, 'views' ); if( fs.existsSync( viewsPath ) ) views.add( viewsPath ); var culturesPath = path.join( process.cwd(), config.appsDir, orig, 'cultures' ); if( fs.existsSync( culturesPath ) ){ fs.readdirSync( culturesPath ).forEach( function( culture ){ Globalize.addCulture( culture.replace('.js',''), require( path.join( culturesPath, culture ) ) ); }); } } }
it('emits events as soon as and only if they can be sent in correct order', function () { spyOn(eventQueue, 'emit'); // add messages that may not be processed yet... eventQueue.add(randomEvent(5)); eventQueue.add(randomEvent(2)); eventQueue.add(randomEvent(3)); expect(eventQueue.emit).not.toHaveBeenCalled(); // add one message to trigger processing... eventQueue.add(randomEvent(1)); expect(eventQueue.emit).toHaveBeenCalled(); expect(eventQueue.emit.calls[0].args[1]).toBe(randomEvent[1]); expect(eventQueue.emit.calls[1].args[1]).toBe(randomEvent[2]); expect(eventQueue.emit.calls[2].args[1]).toBe(randomEvent[3]); expect(eventQueue.emit.mostRecentCall.args[1]).toBe(randomEvent[3]); // event 5 may not have been processed yet. it waits for 4: eventQueue.add(randomEvent(4)); expect(eventQueue.emit.calls[3].args[1]).toBe(randomEvent[4]); expect(eventQueue.emit.calls[4].args[1]).toBe(randomEvent[5]); // just to be sure eventQueue is still sane, do another one // (assertion creep has begun. if i do another five, please shoot me) eventQueue.add(randomEvent(6)); expect(eventQueue.emit.calls[5].args[1]).toBe(randomEvent[6]); expect(eventQueue.emit.mostRecentCall.args[1]).toBe(randomEvent[6]); });
function patch(fs) { //obj_patch.add(fs, 'fs', 'openSync', wrapper.callWrapper); //obj_patch.add(fs, 'fs', 'readSync', wrapper.callWrapper); //obj_patch.add(fs, 'fs', 'writeSync', wrapper.callWrapper); //obj_patch.add(fs, 'fs', 'readFileSync', wrapper.callWrapper); //obj_patch.add(fs, 'fs', 'writeFileSync', wrapper.callWrapper); //obj_patch.add(fs, 'fs', 'appendFileSync', wrapper.callWrapper); obj_patch.add(fs, 'fs', 'renameSync', wrapper.callWrapper); obj_patch.add(fs, 'fs', 'mkdirSync', wrapper.callWrapper); obj_patch.add(fs, 'fs', 'readdirSync', wrapper.callWrapper); //obj_patch.add(fs, 'fs', 'open', wrapper.callWithCallbackWrapper); //obj_patch.add(fs, 'fs', 'read', wrapper.callWithCallbackWrapper); //obj_patch.add(fs, 'fs', 'write', wrapper.callWithCallbackWrapper); //obj_patch.add(fs, 'fs', 'readFile', wrapper.callWithCallbackWrapper); //obj_patch.add(fs, 'fs', 'writeFile', wrapper.callWithCallbackWrapper); //obj_patch.add(fs, 'fs', 'appendFile', wrapper.callWithCallbackWrapper); obj_patch.add(fs, 'fs', 'rename', wrapper.callWithCallbackWrapper); obj_patch.add(fs, 'fs', 'mkdir', wrapper.callWithCallbackWrapper); obj_patch.add(fs, 'fs', 'readdir', wrapper.callWithCallbackWrapper); }
it("inserts node if it is not already inserted", function () { var encapsulatedObject = {}, graph = new Graph(); assert.strictEqual(graph.add(encapsulatedObject).vertex.value, encapsulatedObject); });
* http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ var assert = require('assert'); var dir = process.cwd() + "/run_pass/require1/"; // Load a JS file. var x = require(dir + "require_add"); assert.equal(x.add(1,4), 5); // Load a package. var pkg1 = require(dir + "test_pkg"); assert.equal(pkg1.add(22, 44), 66); assert.equal(pkg1.multi(22, 44), 968); assert.equal(pkg1.add2(22, 44), 66); var pkg2 = require(dir + "test_index"); assert.equal(pkg2.add(22, 44), 66); assert.equal(pkg2.multi(22, 44), 968); assert.equal(pkg2.add2(22, 44), 66); // Load invalid modules. assert.throws(function() { var test3 = require('run_pass/require1/babel-template');
_.each(resolvedExample, (value, key) => { // Remove fields common to the top-level of all nodes. We add these // elsewhere so don't need to infer their type. if (value === INVALID_VALUE || (isRoot && EXCLUDE_KEYS[key])) return // Several checks to see if a field is pointing to custom type // before we try automatic inference. const nextSelector = selector ? `${selector}.${key}` : key const fieldSelector = `${rootTypeName}.${nextSelector}` let fieldName = key let inferredField // First check for manual field => type mappings in the site's // gatsby-config.js if (mapping && _.includes(Object.keys(mapping), fieldSelector)) { inferredField = inferFromMapping(value, mapping, fieldSelector, types) // Second if the field has a suffix of ___node. We use then the value // (a node id) to find the node and use that node's type as the field } else if (key.includes(`___NODE`)) { ;[fieldName] = key.split(`___`) inferredField = inferFromFieldName(value, nextSelector, types) lazyFields.add(typeName, fieldName) } // Replace unsupported values const sanitizedFieldName = createKey(fieldName) // If a pluging has already provided a type for this, don't infer it. if (ignoreFields && ignoreFields.includes(sanitizedFieldName)) { return } // Finally our automatic inference of field value type. if (!inferredField) { inferredField = inferGraphQLType({ nodes, types, exampleValue: value, selector: nextSelector, }) } if (!inferredField) return // If sanitized field name is different from original field name // add resolve passthrough to reach value using original field name if (sanitizedFieldName !== fieldName) { const { resolve: fieldResolve, ...inferredFieldWithoutResolve } = inferredField // Using copy if field as we sometimes have predefined frozen // field definitions and we can't mutate them. inferredField = inferredFieldWithoutResolve if (fieldResolve) { // If field has resolver, call it with adjusted resolveInfo // that points to original field name inferredField.resolve = (source, args, context, resolveInfo) => fieldResolve(source, args, context, { ...resolveInfo, fieldName: fieldName, }) } else { inferredField.resolve = source => source[fieldName] } } inferredFields[sanitizedFieldName] = inferredField })
before(function() { moderate.add({ mem: "Task 2", ex: 7000 }); });
var nodes = args.forEach(function(arg) { groupBy.add(arg.toNode()); });
var nodes = args.forEach(function(arg) { orderBy.add(arg.toNode()); });
dropColumn: function(column) { var dropClause = new DropColumn(); dropClause.add(column.toNode()); this.nodes[0].add(dropClause); return this; },
addColumn: function(column) { var addClause = new AddColumn(); addClause.add(column.toNode()); this.nodes[0].add(addClause); return this; },
Object.keys(o).forEach(function(key) { var val = o[key]; update.add(self.table[key].value(val && val.toNode ? val.toNode() : new ParameterNode(val))); });
var addCity = function(city, callb) { Cities.add(city, function (success, data) { console.log((success != 1) ? 'Problem:' + data : 'SUCCESS: ' + data.name); callb(true); }); };
onComplete = function(dataArray){ var deltaFlag = false; pubRecord.clients[socketId] = pubRecord.clients[socketId] || {snapshot : []}; pubRecord.clients[socketId].snapshot = dataArray; var snapshot = pubRecord.clients[socketId].snapshot; //通过 clientVersion 判断是first subscribe还是redo subscribe //如果有clientVersion && server端有记录,则增量传输 if(clientVersion && snapshotMgr.get(pubname, clientVersion)){ var diffData = findDiff(dataArray, snapshotMgr[pubname].get(pubname, clientVersion), PublishContainer[pubname]["modelName"]); if(!diffData.length){ return false; //没有diff, 不用下发 } deltaFlag = true; //有diff,增量下发 } var dataVersion = snapshotMgr.add(pubname ,dataArray); //如果是分页请求,且为该页第一次请求,保存其左右边界 if (pubRecord.isByPage && typeof pubRecord.leftBound == 'undefined' && typeof pubRecord.rightBound == 'undefined' && dataArray.length) { //如果是byPage,则传递到server的第一个参数一定是pageOptions,读取其中的page和uniqueField var _pageOptions = args[0], uniqueField = _pageOptions['uniqueField']; var leftBound, rightBound; //要求数据集应该是基于uniqueField排序的 leftBound = dataArray[0][uniqueField]; rightBound = dataArray[dataArray.length - 1][uniqueField]; if (_pageOptions.page == 1) { //如果是第一页则左边界为无约束 leftBound = -1; }; _pageOptions.bounds = {left : leftBound, right : rightBound}; }; //start to write_data to client var params = { pubname: pubname, modelName : modelName, uk:uk, data : dataArray, flag : deltaFlag ? 'live_data' : 'full_ship', version : dataVersion }; var cmd = deltaFlag ? 'data_write_from_server_delta' : 'data_write_from_server'; netMessage.sendMessage(params, cmd, socketId, function(err){ fw.log('send data_write_from_server fail ' + err , socketId); }, function(){ //fw.dev('send data_write_from_server ok ' , deltaFlag ? diffData : dataArray); } ); };
assert.throws(function () { graph.add(1); });