Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Driver for reflector load testing #475

Open
wants to merge 3 commits into
base: development
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions support/client/lib/vwf.js
Expand Up @@ -391,6 +391,7 @@
active: false
},
{ library: "vwf/view/lesson", active: false},
{ library: "vwf/view/load-test", active: false},
{ library: "vwf/view/threejs",
disabledBy: ["vwf/model/glge", "vwf/view/glge"],
active: false
Expand Down Expand Up @@ -453,6 +454,7 @@
{ library: "vwf/view/document", active: true },
{ library: "vwf/view/editor", active: false },
{ library: "vwf/view/lesson", active: false},
{ library: "vwf/view/load-test", active: false},
{ library: "vwf/view/google-earth", active: false },
{ library: "vwf/view/cesium", active: false },
{ library: "vwf/view/blockly", active: false },
Expand Down
187 changes: 187 additions & 0 deletions support/client/lib/vwf/view/load-test.js
@@ -0,0 +1,187 @@
"use strict";

// Copyright 2015 United States Government, as represented by the Secretary of Defense, Under
// Secretary of Defense (Personnel & Readiness).
//
// Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
// in compliance with the License. You may obtain a copy of the License at
//
// 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.

/// @module vwf/view/document
/// @requires vwf/view

define( [ "module", "vwf/view" ], function( module, view ) {

return view.load( module, {

initialize: function() {

this.state.enabled = false;
this.state.duration = 10;

this.state.size = 1;
this.state.interval = 1;
this.state.clients = {};

this.state.startTime = 0;
this.state.lastTime = 0;
this.state.intervalID = undefined;
this.state.payload = "*";

this.state.results = [];
this.state.others = 0;
this.state.pending = 0;

},

createdNode: function( nodeID, childID, childExtendsID, childImplementsIDs, childSource, childType, childIndex, childName, callback /* ready */ ) {

if ( this.kernel.uri( nodeID ) === "http://vwf.example.com/clients.vwf" ) {
this.state.clients[ childID ] = true;
}

},

deletedNode: function( nodeID ) {

if ( this.state.clients[ nodeID ] ) {
delete this.state.clients[ nodeID ];
}

},

createdProperty: function( nodeID, propertyName, propertyValue ) {

return this.initializedProperty( nodeID, propertyName, propertyValue );

},

initializedProperty: function( nodeID, propertyName, propertyValue ) {

if ( propertyName !== "ping" || propertyValue !== null ) {
return this.satProperty( nodeID, propertyName, propertyValue );
}

},

satProperty: function( nodeID, propertyName, propertyValue ) {

if ( nodeID === this.kernel.application() ) {

switch( propertyName ) {
case "enabled": enabled.call( this, propertyValue ); break;
case "duration": duration.call( this, propertyValue ); break;
case "size": size.call( this, propertyValue ); break;
case "interval": interval.call( this, propertyValue ); break;
}

}

},

calledMethod: function( nodeID, methodName, methodParameters, methodValue ) {

if ( nodeID === this.kernel.application() && methodName == "ping" ) {
pong.call( this, methodParameters[ 0 ] );
}

},

} );

function ping() {

var time = +new Date;

if ( time - this.state.startTime < this.state.duration * 1000 ) {
while( this.state.lastTime < time ) {
this.state.lastTime += this.state.interval * 1000;
this.kernel.callMethod( this.kernel.application(), "ping", [ time, this.state.payload ] );
this.state.pending++;
}
} else {
enabled.call( this, false );
console.log( "Results", this.state );
}

}

function pong( pingTime ) {

if ( enabled.call( this ) ) {
if ( this.kernel.client() === this.kernel.moniker() ) {
this.state.results.push( { ping: pingTime, pong: +new Date } );
this.state.pending--;
} else {
this.state.others++;
}
}

}

function enabled( value ) {

var self = this;

if ( value !== undefined ) {

value = !! value;

if ( value !== this.state.enabled ) {

if ( value ) {
this.state.startTime = this.state.lastTime = +new Date;
this.state.intervalID = setInterval( function() { ping.call( self ) }, interval.call( self ) * 1000 );
} else if ( this.state.intervalID ) {
clearInterval( this.state.intervalID );
this.state.intervalID = undefined;
}

this.state.enabled = value;

}

}

return this.state.enabled;
}

function duration( value ) {

if ( value !== undefined ) {
value = +value || 10;
this.state.duration = value;
}

return this.state.duration;
}

function size( value ) {

if ( value !== undefined ) {
value = +value || 1;
this.state.size = value;
this.state.payload = "";
for ( var i = 0; i < value; i++ ) { this.state.payload += "*" }
}

return this.state.size;
}

function interval( value ) {

if ( value !== undefined ) {
value = +value || 1;
this.state.interval = value;
}

return this.state.interval;
}

} );