experimenting with 'reserved uids'

This commit is contained in:
Kevin Jahns
2014-08-07 21:52:50 +02:00
parent efc4e502cf
commit 9e1d9e568f
77 changed files with 509 additions and 1482 deletions

View File

@@ -1,159 +0,0 @@
(function() {
var Connector_uninitialized, Yatta, chai, expect, should, sinon, sinonChai, _;
chai = require('chai');
expect = chai.expect;
should = chai.should();
sinon = require('sinon');
sinonChai = require('sinon-chai');
_ = require("underscore");
chai.use(sinonChai);
Yatta = require("../lib/Frameworks/JsonYatta.coffee");
Connector_uninitialized = require("../lib/Connectors/TestConnector.coffee");
/*
describe "JsonYatta", ->
beforeEach (done)->
@last_user = 10
@users = []
@Connector = Connector_uninitialized @users
for i in [0..(@last_user+1)]
@users.push(new Yatta i, @Connector)
done()
it "can handle many engines, many operations, concurrently (random)", ->
number_of_test_cases_multiplier = 1
repeat_this = 100 * number_of_test_cases_multiplier
doSomething_amount = 200 * number_of_test_cases_multiplier
number_of_engines = 12 + number_of_test_cases_multiplier - 1
@time = 0
@ops = 0
users = []
generateInsertOp = (user_num)->
chars = "1234567890"
pos = _.random 0, (users[user_num].val('name').length-1)
length = 1 #_.random 0, 10
nextchar = chars[(_.random 0, (chars.length-1))]
text = ""
_(length).times ()-> text += nextchar
users[user_num].val('name').insertText pos, text
null
generateReplaceOp = (user_num)->
chars = "abcdefghijklmnopqrstuvwxyz"
length = _.random 0, 10
nextchar = chars[(_.random 0, (chars.length-1))]
text = ""
_(length).times ()-> text += nextchar
users[user_num].val('name').replaceText text
generateDeleteOp = (user_num)->
if users[user_num].val('name').val().length > 0
pos = _.random 0, (users[user_num].val('name').val().length-1)
length = 1 # _.random 0, ot.val('name').length - pos
ops1 = users[user_num].val('name').deleteText pos, length
undefined
generateRandomOp = (user_num)->
op_gen = [generateDeleteOp, generateInsertOp, generateReplaceOp]
i = _.random (op_gen.length - 1)
op = op_gen[i](user_num)
applyRandomOp = (user_num)->
user = users[user_num]
user.getConnector().flushOneRandom()
doSomething = do ()->
()->
user_num = _.random (number_of_engines-1)
choices = [applyRandomOp, generateRandomOp]
*if (users[user_num].buffer[user_num].length < maximum_ops_per_engine)
* choices = choices.concat generateRandomOp
choice = _.random (choices.length-1)
choices[choice](user_num)
console.log ""
for times in [1..repeat_this]
*console.log "repeated_this x #{times} times"
users = []
Connector = Connector_uninitialized users
users.push(new Yatta 0, Connector)
users[0].val('name',"initial")
for i in [1...number_of_engines]
users.push(new Yatta i, Connector)
found_error = false
*try
time_now = (new Date).getTime()
for i in [1..doSomething_amount]
doSomething()
for user,user_number in users
user.getConnector().flushAll()
@time += (new Date()).getTime() - time_now
number_of_created_operations = 0
for i in [0...(users.length)]
number_of_created_operations += users[i].getConnector().getOpsInExecutionOrder().length
@ops += number_of_created_operations*users.length
ops_per_msek = Math.floor(@ops/@time)
console.log "#{times}/#{repeat_this}: Every collaborator (#{users.length}) applied #{number_of_created_operations} ops in a different order." + " Over all we consumed #{@ops} operations in #{@time/1000} seconds (#{ops_per_msek} ops/msek)."
console.log users[0].val('name').val()
for i in [0...(users.length-1)]
if ((users[i].val('name').val() isnt users[i+1].val('name').val()) )# and (number_of_created_operations <= 6 or true)) or found_error
printOpsInExecutionOrder = (otnumber, otherotnumber)->
ops = users[otnumber].getConnector().getOpsInExecutionOrder()
for s in ops
console.log JSON.stringify s
console.log ""
s = "ops = ["
for o,j in ops
if j isnt 0
s += ", "
s += "op#{j}"
s += "]"
console.log s
console.log "@users[@last_user].ot.applyOps ops"
console.log "expect(@users[@last_user].ot.val('name')).to.equal(\"#{users[otherotnumber].val('name')}\")"
ops
console.log ""
console.log "Found an OT Puzzle!"
console.log "OT states:"
for u,j in users
console.log "OT#{j}: "+u.val('name')
console.log "\nOT execution order (#{i},#{i+1}):"
printOpsInExecutionOrder i, i+1
console.log ""
ops = printOpsInExecutionOrder i+1, i
console.log ""
*/
}).call(this);

View File

@@ -1,163 +0,0 @@
(function() {
var Connector_uninitialized, Yatta, chai, expect, should, sinon, sinonChai, _;
chai = require('chai');
expect = chai.expect;
should = chai.should();
sinon = require('sinon');
sinonChai = require('sinon-chai');
_ = require("underscore");
chai.use(sinonChai);
Yatta = require("../lib/Frameworks/TextYatta.coffee");
Connector_uninitialized = require("../lib/Connectors/TestConnector.coffee");
/*
describe "TextYatta", ->
beforeEach (done)->
@last_user = 10
@users = []
@Connector = Connector_uninitialized @users
for i in [0..(@last_user+1)]
@users.push(new Yatta i, @Connector)
done()
it "handles inserts correctly", ->
it "can handle many engines, many operations, concurrently (random)", ->
number_of_test_cases_multiplier = 1
repeat_this = 1 * number_of_test_cases_multiplier
doSomething_amount = 500 * number_of_test_cases_multiplier
number_of_engines = 12 + number_of_test_cases_multiplier - 1
*maximum_ops_per_engine = 20 * number_of_test_cases_multiplier
@time = 0
@ops = 0
users = []
generateInsertOp = (user_num)->
chars = "1234567890"
pos = _.random 0, (users[user_num].val().length-1)
length = 1 #_.random 0, 10
nextchar = chars[(_.random 0, (chars.length-1))]
text = ""
_(length).times ()-> text += nextchar
users[user_num].insertText pos, text
null
generateReplaceOp = (user_num)->
chars = "abcdefghijklmnopqrstuvwxyz"
length = _.random 0, 10
nextchar = chars[(_.random 0, (chars.length-1))]
text = ""
_(length).times ()-> text += nextchar
users[user_num].replaceText text
generateDeleteOp = (user_num)->
if users[user_num].val().length > 0
pos = _.random 0, (users[user_num].val().length-1)
length = 1 # _.random 0, ot.val().length - pos
ops1 = users[user_num].deleteText pos, length
undefined
generateRandomOp = (user_num)->
op_gen = [generateDeleteOp, generateInsertOp, generateReplaceOp]
i = _.random (op_gen.length - 1)
op = op_gen[i](user_num)
applyRandomOp = (user_num)->
user = users[user_num]
user.getConnector().flushOneRandom()
doSomething = do ()->
()->
user_num = _.random (number_of_engines-1)
choices = [applyRandomOp, generateRandomOp]
*if (users[user_num].buffer[user_num].length < maximum_ops_per_engine)
* choices = choices.concat generateRandomOp
choice = _.random (choices.length-1)
choices[choice](user_num)
console.log ""
for times in [1..repeat_this]
*console.log "repeated_this x #{times} times"
users = []
Connector = Connector_uninitialized users
for i in [0..number_of_engines]
users.push(new Yatta i, Connector)
found_error = false
*try
time_now = (new Date).getTime()
for i in [1..doSomething_amount]
doSomething()
for user,user_number in users
user.getConnector().flushAll()
@time += (new Date()).getTime() - time_now
number_of_created_operations = 0
for i in [0...(users.length)]
number_of_created_operations += users[i].getConnector().getOpsInExecutionOrder().length
@ops += number_of_created_operations*users.length
ops_per_msek = Math.floor(@ops/@time)
console.log "#{times}/#{repeat_this}: Every collaborator (#{users.length}) applied #{number_of_created_operations} ops in a different order." + " Over all we consumed #{@ops} operations in #{@time/1000} seconds (#{ops_per_msek} ops/msek)."
console.log users[0].val()
found_inconsistency = false
for i in [0...(users.length-1)]
if ((users[i].val() isnt users[i+1].val()) )# and (number_of_created_operations <= 6 or true)) or found_error
found_inconsistency =true
printOpsInExecutionOrder = (otnumber, otherotnumber)->
ops = users[otnumber].getConnector().getOpsInExecutionOrder()
for s,j in ops
console.log "op#{j} = #{JSON.stringify s}"
console.log ""
s = "ops = ["
for o,j in ops
if j isnt 0
s += ", "
s += "op#{j}"
s += "]"
console.log s
console.log "@users[@last_user].ot.applyOps ops"
console.log "expect(@users[@last_user].val()).to.equal(\"#{users[otherotnumber].val()}\")"
ops
console.log ""
console.log "Found an OT Puzzle!"
console.log "OT states:"
for u,j in users
console.log "OT#{j}: "+u.val()
console.log "\nOT execution order (#{i},#{i+1}):"
printOpsInExecutionOrder i, i+1
console.log ""
ops = printOpsInExecutionOrder i+1, i
console.log ""
if found_inconsistency
throw new Error "dtrn"
* expect(users[i].ot.val()).to.equal(users[i+1].ot.val())
*/
}).call(this);

View File

@@ -34,6 +34,7 @@
this.time = 0;
this.ops = 0;
this.time_now = 0;
this.debug = false;
this.reinitialize();
}
@@ -123,7 +124,7 @@
};
Test.prototype.compareAll = function(test_number) {
var i, j, number_of_created_operations, ops, ops_per_msek, printOpsInExecutionOrder, u, _i, _j, _k, _len, _ref, _ref1, _results;
var i, j, number_of_created_operations, ops, ops_per_msek, printOpsInExecutionOrder, u, _i, _j, _k, _len, _ref, _ref1, _ref2, _results;
this.flushAll();
this.time += (new Date()).getTime() - this.time_now;
number_of_created_operations = 0;
@@ -135,45 +136,53 @@
if (test_number != null) {
console.log(("" + test_number + "/" + this.repeat_this + ": Every collaborator (" + this.users.length + ") applied " + number_of_created_operations + " ops in a different order.") + (" Over all we consumed " + this.ops + " operations in " + (this.time / 1000) + " seconds (" + ops_per_msek + " ops/msek)."));
}
console.log(this.users.length);
_results = [];
for (i = _j = 0, _ref1 = this.users.length - 1; 0 <= _ref1 ? _j < _ref1 : _j > _ref1; i = 0 <= _ref1 ? ++_j : --_j) {
if (this.users[i].val('name').val() !== this.users[i + 1].val('name').val()) {
printOpsInExecutionOrder = function(otnumber, otherotnumber) {
var j, o, ops, s, _k, _l, _len, _len1;
ops = this.users[otnumber].getConnector().getOpsInExecutionOrder();
for (_k = 0, _len = ops.length; _k < _len; _k++) {
s = ops[_k];
console.log(JSON.stringify(s));
}
console.log("");
s = "ops = [";
for (j = _l = 0, _len1 = ops.length; _l < _len1; j = ++_l) {
o = ops[j];
if (j !== 0) {
s += ", ";
}
s += "op" + j;
}
s += "]";
console.log(s);
console.log("@users[@last_user].ot.applyOps ops");
console.log("expect(@users[@last_user].ot.val('name')).to.equal(\"" + (users[otherotnumber].val('name')) + "\")");
return ops;
};
console.log("");
console.log("Found an OT Puzzle!");
console.log("OT states:");
for (j = _k = 0, _len = users.length; _k < _len; j = ++_k) {
u = users[j];
console.log(("OT" + j + ": ") + u.val('name'));
}
console.log("\nOT execution order (" + i + "," + (i + 1) + "):");
printOpsInExecutionOrder(i, i + 1);
console.log("");
ops = printOpsInExecutionOrder(i + 1, i);
_results.push(console.log(""));
if (!this.debug) {
_results.push(expect(this.users[i].val('name').val()).to.equal(this.users[i + 1].val('name').val()));
} else {
_results.push(void 0);
if (this.users[i].val('name').val() !== this.users[i + 1].val('name').val()) {
printOpsInExecutionOrder = (function(_this) {
return function(otnumber, otherotnumber) {
var j, o, ops, s, _k, _l, _len, _len1;
ops = _this.users[otnumber].getConnector().getOpsInExecutionOrder();
for (_k = 0, _len = ops.length; _k < _len; _k++) {
s = ops[_k];
console.log(JSON.stringify(s));
}
console.log("");
s = "ops = [";
for (j = _l = 0, _len1 = ops.length; _l < _len1; j = ++_l) {
o = ops[j];
if (j !== 0) {
s += ", ";
}
s += "op" + j;
}
s += "]";
console.log(s);
console.log("@users[@last_user].ot.applyOps ops");
console.log("expect(@users[@last_user].ot.val('name')).to.equal(\"" + (_this.users[otherotnumber].val('name')) + "\")");
return ops;
};
})(this);
console.log("");
console.log("Found an OT Puzzle!");
console.log("OT states:");
_ref2 = this.users;
for (j = _k = 0, _len = _ref2.length; _k < _len; j = ++_k) {
u = _ref2[j];
console.log(("OT" + j + ": ") + u.val('name'));
}
console.log("\nOT execution order (" + i + "," + (i + 1) + "):");
printOpsInExecutionOrder(i, i + 1);
console.log("");
ops = printOpsInExecutionOrder(i + 1, i);
_results.push(console.log(""));
} else {
_results.push(void 0);
}
}
}
return _results;