<html>
<head>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.5/jquery.min.js"></script>
<script>
$(document).ready(function()
{
var count = 1;
var loop = 0;
var userRead = 0;
var mainRead =0;
var commentRead = 0;
var totalReps = 0;
var currentKey ="";
var d = new Date();
var t_hour = d.getHours();
var t_min = d.getMinutes();
var t_sec = d.getSeconds();
var sTime = d.getTime();
var eTime = 0;
$('#res').hide();
$('#hs').click(function() {
$('#res').toggle('slow');
});
$('#time').html("Start " + t_hour + ":" + t_min + ":" + t_sec + " - ");
doLoop();
function doLoop()
{
loop++;
if(userRead == 0)
{
doUserRead();
}
else if(mainRead == 0)
{
doMainRead();
}
else
{
if(commentRead < 50)
{
doCommentRead();
commentRead++;
}
else if(commentRead == 50)
{
userRead = 0;
mainRead =0;
commentRead = 0;
if(totalReps ==0)
{
currentKey = getRandString(8, 25);
$('#cKey').html("created " + currentKey);
cfTwoInsert(currentKey);
totalReps++;
}
else if(totalReps == 1)
{
$('#cKey').html("<b>deleted</b> " + currentKey);
var q = document.location.href + "testKeyspace/testCF2/"+currentKey+"////QUORUM";
doDELETE(q);
totalReps++;
}
else if(totalReps == 2)
{
var d = new Date();
var t_hour = d.getHours();
var t_min = d.getMinutes();
var t_sec = d.getSeconds();
eTime = d.getTime();
$('#time').append("Stop " + t_hour + ":" + t_min + ":" + t_sec + "<br /> ");
$('#time').append(sTime + " " + eTime);
}
}
}
$("#count").html(loop);
}
function doUserRead()
{
var keyNum = Math.floor(Math.random()*1999);
keyNum ++;
var key = "testKey" + keyNum;
var q = document.location.href + "testKeyspace/testCF3/"+key+"////QUORUM.plain";
userRead = 1;
doGET(q);
}
function doMainRead()
{
var keyNum = Math.floor(Math.random()*1498);
keyNum ++;
var key = "testKey" + keyNum;
var q = document.location.href + "testKeyspace/testCF1/"+key+"////QUORUM.plain";
mainRead = 1;
doGET(q);
}
function doCommentRead()
{
var keyNum = Math.floor(Math.random()*2999);
keyNum ++;
var key = "testKey" + keyNum;
var q = document.location.href + "testKeyspace/testCF2/"+key+"////QUORUM.plain";
doGET(q);
}
function getRandString(maxLen, minLen)
{
var rndString ="";
var len = Math.random()*((maxLen-minLen));
len = Math.floor(minLen+len);
var generator;
for(var i = 0; i < len; i++)
{
generator = Math.random()*(25);
generator = Math.floor(65+generator);
rndString = rndString + String.fromCharCode(generator);
}
return rndString;
}
function getRandDate()
{
var day = (Math.floor(Math.random()*((28)))) + 1;
var month = (Math.floor(Math.random()*((11)))) + 1;
return day + "/" + month + "/2010";
}
function cfOneInsert(rowKey)
{
var title = getRandString(20, 45);
var text = getRandString(40, 60);
var score = (Math.floor(Math.random()*((1000)))) + 1; /*1 - 1001 */
var date = getRandDate();
/*var rowKey = "testKey" + count;*/
var q = document.location.href + "testKeyspace/testCF1/"+rowKey+"////QUORUM";
var POSTData = encodeURIComponent("title") + "=" + encodeURIComponent(title);
POSTData = POSTData + "&" + encodeURIComponent("text") + "=" + encodeURIComponent(text);
POSTData = POSTData + "&" + encodeURIComponent("score") + "=" + encodeURIComponent(score);
POSTData = POSTData + "&" + encodeURIComponent("date") + "=" + encodeURIComponent(date);
$("#result").append(q + " " + POSTData + "\n\n");
doPOST(q, POSTData);
count++;
}
function cfTwoInsert(rowKey)
{
var comment = getRandString(30, 45);
var username = getRandString(6, 15);
var date = getRandDate();
/*var rowKey = "testKey" + count;*/
var q = document.location.href + "testKeyspace/testCF2/"+rowKey+"////QUORUM";
var POSTData = encodeURIComponent("comment") + "=" + encodeURIComponent(comment);
POSTData = POSTData + "&" + encodeURIComponent("username") + "=" + encodeURIComponent(username);
POSTData = POSTData + "&" + encodeURIComponent("date") + "=" + encodeURIComponent(date);
$("#result").prepend(q + " " + POSTData + "\n\n");
doPOST(q, POSTData);
count++;
}
function cfThreeInsert(rowKey)
{
var username = getRandString(30, 45);
var password = getRandString(6, 15);
var firstName = getRandString(6, 25);
var lastName = getRandString(6, 25);
var email = getRandString(6, 15) + "@" + getRandString(5, 9) +".com";
/*var rowKey = "testKey" + count;*/
var q = document.location.href + "testKeyspace/testCF3/"+rowKey+"////QUORUM";
var POSTData = encodeURIComponent("username") + "=" + encodeURIComponent(username);
POSTData = POSTData + "&" + encodeURIComponent("firstName") + "=" + encodeURIComponent(firstName);
POSTData = POSTData + "&" + encodeURIComponent("lastName") + "=" + encodeURIComponent(lastName);
POSTData = POSTData + "&" + encodeURIComponent("email") + "=" + encodeURIComponent(email);
$("#result").prepend(POSTData + "\n\n");
doPOST(q, POSTData);
count++;
}
function doPOST(q, data)
{
$.ajax({
url: q,
type: "POST",
data: data,
dataType: "html",
statusCode:
{
404:function() { $("#error").html("404 - Not Found");},
400:function() { $("#error").html("400 - Bad Request"); },
413:function() { $("#error").html("413 - 413 Request Entity Too Large"); },
415:function() { $("#error").html("415 - Unsupported media type"); },
500:function() { $("#error").html("500 - Internal Server Error"); }
},
success: function(data)
{
$('#result').prepend("POST :\n" + data + "\n");
doLoop();
}
});
}
function doGET(q)
{
$.ajax({
url: q,
type: "GET",
dataType: "html",
statusCode: {
404:function() { $("#error").html("404 - Not Found" + q);},
400:function() { $("#error").html("400 - Bad Request"+ q); },
413:function() { $("#error").html("413 - 413 Request Entity Too Large"+ q); },
415:function() { $("#error").html("415 - Unsupported media type"+ q); },
500:function() { $("#error").html("500 - Internal Server Error"+ q); }
},
success: function(data)
{
$('#result').prepend("GET :\n" + data + "\n");
doLoop();
}
});
}
function doDELETE(q)
{
$.ajax({
url: q,
type: "DELETE",
dataType: "html",
statusCode: {
404:function() { $("#error").html("404 - Not Found" + q);},
400:function() { $("#error").html("400 - Bad Request"+ q); },
413:function() { $("#error").html("413 - 413 Request Entity Too Large"+ q); },
415:function() { $("#error").html("415 - Unsupported media type"+ q); },
500:function() { $("#error").html("500 - Internal Server Error"+ q); }
},
success: function(data)
{
$('#result').prepend("DELETE :\n" + data + "\n");
doLoop();
}
});
}
});
</script>
</head>
<body>
<h1>Thanks for running my test</h1>
<p>It doesnt look like much, but there is lots going on in the background. If you want to know what your computer is doing for the test, read <a href="">This</a></p>
<p>This page will 'refresh' every ~60 seconds</p>
<input type="button" id="hs" value="show/hide console"/>
<div id ="res">
<textarea id="result" style="Width:1000px; height: 350px; border:none; padding: 10px;" > </textarea>
<br />
<br />
<div id="time"> </div>
<div id="error" style="font-weight:bold;"> </div>
<div id="cKey"> </div>
</div>
<br />
<p>Requests done: </p>
<h3 id="count"></h3>
</body>
</html>