Permalink
Browse files

- started stress testing

  • Loading branch information...
1 parent 0e10535 commit 0812ea6eeffd5b7f66d8b83642fed0f4c5a09d56 Nickolay Platonov committed Aug 9, 2010
View
@@ -54,6 +54,7 @@ COMPONENTS = {
"+Core",
"KiokuJS.Test.Person",
+ "KiokuJS.Test.Vertex",
"KiokuJS.Test.Fixture",
"KiokuJS.Test.Fixture.ObjectGraph",
View
@@ -16,7 +16,8 @@ Class('KiokuJS.Test', {
'ObjectGraph',
'Overwrite',
'Update',
- 'Remove'
+ 'Remove',
+ 'StressLoad.Tree'
]
}
},
@@ -1,3 +1,5 @@
+// XXX a test for KiokuJS.Backend.Feature.Overwrite
+
Class('KiokuJS.Test.Fixture.Overwrite', {
isa : 'KiokuJS.Test.Fixture',
@@ -0,0 +1,203 @@
+Class('KiokuJS.Test.Fixture.StressLoad.Tree', {
+
+ isa : 'KiokuJS.Test.Fixture',
+
+ use : 'KiokuJS.Test.Vertex',
+
+
+ has : {
+ sort : 100
+ },
+
+
+ methods : {
+
+
+ },
+
+
+
+ continued : {
+
+ methods : {
+
+ populate : function (handle, t) {
+ //======================================================================================================================================================================================================================================================
+ t.diag('KiokuJS.Test.Fixture.StressLoad - Sanity')
+
+
+ var ID = 1
+
+ Class('KiokuJS.Test.Fixture.StressLoad.Point', {
+
+ has : {
+ ID : null,
+
+ checkSum : Joose.I.Array,
+
+ ref1 : null,
+ ref2 : null,
+ ref3 : null,
+ ref4 : null,
+ ref5 : null,
+ ref6 : null,
+ ref7 : null,
+ ref8 : null,
+ ref9 : null,
+ ref10 : null
+ },
+
+
+ methods : {
+
+ initialize : function () {
+ this.ID = ID++
+ },
+
+
+ fillRef : function (index, object) {
+ this[ 'ref' + index ] = object
+
+ this.checkSum[ index ] = object.ID
+ }
+ }
+ })
+
+
+ //======================================================================================================================================================================================================================================================
+ t.diag('Graph setup')
+
+ var Homer = this.originalHomer = new KiokuJS.Test.Person({
+ name : 'Homer Simpson'
+ })
+
+ var Marge = new KiokuJS.Test.Person({
+ name : 'Marge Simpson'
+ })
+
+ var Bart = new KiokuJS.Test.Person({
+ name : 'Bart Simpson'
+ })
+
+ var Lisa = new KiokuJS.Test.Person({
+ name : 'Lisa Simpson'
+ })
+
+ t.ok(Homer.self == Homer, 'Self-reference established')
+
+ Homer.spouse(Marge)
+ Marge.spouse(Homer)
+
+ Bart.father = Lisa.father = Homer
+ Bart.mother = Lisa.mother = Marge
+
+ var kids = [ Bart, Lisa ]
+
+ Homer.children = Marge.children = kids
+
+
+ //======================================================================================================================================================================================================================================================
+ t.diag('Populating')
+
+ var scope = handle.newScope()
+
+ scope.store(Homer).andThen(function (homerID) {
+
+ this.homerID = homerID
+
+ //======================================================================================================================================================================================================================================================
+ t.diag('Retrieving live object from the same scope')
+
+ scope.lookUp(homerID).andThen(function (homer2) {
+
+ t.ok(homer2 === Homer, 'Retrieved the Homer object from live objects')
+
+ this.CONTINUE()
+ })
+
+ }, this)
+ },
+
+
+ verify : function (handle, t) {
+
+ var newScope = handle.newScope()
+
+ newScope.lookUp(this.homerID).andThen(function (homer3) {
+
+ //======================================================================================================================================================================================================================================================
+ t.diag('Retrieving from backend')
+
+ t.ok(homer3 !== this.originalHomer, 'Retrieved Homer is another instance this time')
+
+ t.ok(homer3.name == 'Homer Simpson', 'But it has a correct name')
+ t.ok(homer3.self === homer3, 'Self-reference was reflected correctly #1')
+
+
+ var marge3 = homer3.spouse()
+
+ t.ok(marge3.self = marge3, 'Self-reference was reflected correctly #2')
+
+ t.ok(marge3 instanceof KiokuJS.Test.Person, 'Marge2 isa Person')
+ t.ok(marge3.name == 'Marge Simpson', 'Marge has a correct name')
+
+ t.ok(marge3.spouse() === homer3, 'Marge2&Homer2 are spouses')
+
+ t.ok(marge3.children === homer3.children, 'Marge2&Homer2 have correct kids')
+
+
+
+ var kids = marge3.children
+
+ t.ok(kids.length == 2, 'we forgot Maggy..')
+
+ t.ok((kids[0] instanceof KiokuJS.Test.Person) && (kids[1] instanceof KiokuJS.Test.Person), 'Both kids are Persons')
+
+ var bart3 = kids[0]
+ var lisa3 = kids[1]
+
+ t.ok(bart3.name == 'Bart Simpson', 'First kid in array is Bart')
+ t.ok(lisa3.name == 'Lisa Simpson', 'Second kid in array is Lisa')
+
+ t.ok(bart3.father == homer3 && bart3.mother == marge3, 'Bart3 has correct parents')
+ t.ok(lisa3.father == homer3 && lisa3.mother == marge3, 'Lisa3 has correct parents')
+
+
+ //======================================================================================================================================================================================================================================================
+ t.diag('Examining scope')
+
+ t.ok(newScope.objectPinned(homer3), 'Homer is in scope')
+ t.ok(newScope.objectPinned(marge3), 'Marge is in scope')
+
+ t.ok(newScope.objectPinned(marge3.children), 'Kids are in scope')
+
+ t.ok(newScope.objectPinned(bart3), 'Bart is in scope')
+ t.ok(newScope.objectPinned(lisa3), 'Lisa is in scope')
+
+
+ //======================================================================================================================================================================================================================================================
+ t.diag('Retrieving unknown key')
+
+ var thrown = false
+
+ newScope.lookUp('foobar').except(function (e) {
+
+ thrown = true
+
+ t.isaOk(e, KiokuJS.Exception.LookUp, 'Correct exception thrown')
+
+ this.CONTINUE()
+
+ }).andThen(function () {
+
+ t.ok(thrown, 'Exception thrown')
+
+ this.CONTINUE()
+ })
+
+ }, this)
+ }
+ }
+ }
+
+})
@@ -1,3 +1,5 @@
+// XXX this is not a test for KiokuJS.Backend.Feature.Update, just for scope.update & deepUpdate methods
+
Class('KiokuJS.Test.Fixture.Update', {
isa : 'KiokuJS.Test.Fixture',
View
@@ -0,0 +1,79 @@
+Class('KiokuJS.Test.Vertex', {
+
+ has : {
+ ID : null,
+
+ checkSum : Joose.I.Array,
+
+ ref0 : null,
+ ref1 : null,
+ ref2 : null,
+ ref3 : null,
+ ref4 : null,
+ ref5 : null,
+ ref6 : null,
+ ref7 : null,
+ ref8 : null,
+ ref9 : null
+ },
+
+
+ methods : {
+
+ initialize : function () {
+ this.ID = this.my.ID++
+ },
+
+
+ addRef : function (object) {
+ var index = this.checkSum.length
+
+
+ this[ 'ref' + index ] = object
+
+ this.checkSum[ index ] = object.ID
+ },
+
+
+ check : function () {
+ Joose.A.each(this.checkSum, function (ID, index) {
+
+ if (this[ 'ref' + index ].ID != ID) throw "Integrity error"
+
+ }, this)
+ }
+ },
+
+
+ my : {
+
+ has : {
+ ID : 1,
+
+ HOST : null
+ },
+
+
+ createVertex : function (level, maxRefs) {
+
+ var vertex = new this.HOST()
+
+ if (level) {
+
+ var refsNum = 1 + Math.floor(Math.random() * (maxRefs - 1))
+
+ for (var i = 1; i < refsNum; i++) vertex.addRef(this.createVertex(level - 1, maxRefs))
+ }
+
+ return vertex
+ },
+
+
+ createGeneration : function (levels, maxRefs) {
+ return this.createVertex(levels, maxRefs)
+ }
+
+ }
+})
+
+
Oops, something went wrong.

0 comments on commit 0812ea6

Please sign in to comment.