git ssb

0+

wanderer🌟 / js-primea-hypervisor



Commit 59e5c5ee7cd9ec4372da75fa9427c4f06b0a6806

created creationService

Signed-off-by: wanderer <mjbecze@gmail.com>
wanderer committed on 8/23/2017, 11:54:14 PM
Parent: 3b4b2beeb7a486206a69ebd40d66cf3440380002

Files changed

creationService.jschanged
package.jsonchanged
tests/index.jschanged
creationService.jsView
@@ -65,8 +65,5 @@
6565 // get a hash from a POJO
6666 _getHashFromObj (obj) {
6767 return this.hypervisor.graph.flush(obj).then(obj => obj['/'])
6868 }
69-
70- // NOPe
71- startup () {}
7269 }
package.jsonView
@@ -2,17 +2,17 @@
22 "name": "primea-hypervisor",
33 "version": "0.1.0",
44 "description": "this is a JS implemention of the primea hypervisor",
55 "scripts": {
6- "coverage": "node --harmony ./node_modules/istanbul/lib/cli.js cover ./tests/index.js",
6+ "coverage": "node ./node_modules/istanbul/lib/cli.js cover ./tests/index.js",
77 "coveralls": "npm run coverage && coveralls <coverage/lcov.info",
88 "lint": "standard",
99 "build:docs": "npm run build:docs:hypervisor && npm run build:docs:kernel && npm run build:docs:scheduler && npm run build:docs:portManager",
1010 "build:docs:hypervisor": "documentation build ./index.js --github --shallow --sort-order source -f md > ./docs/hypervisor.md",
1111 "build:docs:kernel": "documentation build ./kernel.js --github --shallow --sort-order source -f md > ./docs/kernel.md",
1212 "build:docs:portManager": "documentation build ./portManager.js --github --shallow --sort-order source -f md > ./docs/portManager.md",
1313 "build:docs:scheduler": "documentation build ./scheduler.js --github --shallow --sort-order source -f md > ./docs/scheduler.md",
14- "test": "node --harmony ./tests/index.js"
14+ "test": "node ./tests/index.js"
1515 },
1616 "repository": {
1717 "type": "git",
1818 "url": "git+https://github.com/primea/js-primea-hypervisor.git"
tests/index.jsView
@@ -9,15 +9,15 @@
99 start: false
1010 })
1111
1212 class BaseContainer extends AbstractContainer {
13- onCreation (message) {
13+ onCreation(message) {
1414 const port = message.ports[0]
1515 if (port) {
1616 return this.kernel.ports.bind('root', port)
1717 }
1818 }
19- static get typeId () {
19+ static get typeId() {
2020 return 9
2121 }
2222 }
2323
@@ -29,9 +29,9 @@
2929 '/': 'zdpuAqbcQhgu2T2MBgHbYu1MtHXyZzNsCaQjTPTR6NN9s5hbk'
3030 }
3131
3232 class testVMContainer extends BaseContainer {
33- onMessage (m) {
33+ onMessage(m) {
3434 t.true(m === message, 'should recive a message')
3535 }
3636 }
3737
@@ -76,9 +76,9 @@
7676 '/': 'zdpuAop4nt8pqzg7duciSYbZmWfDaBiz87RCtGCbb35ewUrbW'
7777 }
7878
7979 class testVMContainer extends BaseContainer {
80- onCreation () {}
80+ onCreation() {}
8181 }
8282
8383 try {
8484 const hypervisor = new Hypervisor(node.dag)
@@ -117,9 +117,9 @@
117117 }
118118 let hasResolved = false
119119
120120 class testVMContainer2 extends BaseContainer {
121- onMessage (m) {
121+ onMessage(m) {
122122 t.true(m === message, 'should recive a message')
123123 return new Promise((resolve, reject) => {
124124 setTimeout(() => {
125125 this.kernel.incrementTicks(1)
@@ -128,15 +128,15 @@
128128 }, 200)
129129 })
130130 }
131131
132- static get typeId () {
132+ static get typeId() {
133133 return 99
134134 }
135135 }
136136
137137 class testVMContainer extends BaseContainer {
138- async onMessage (m) {
138+ async onMessage(m) {
139139 const [portRef1, portRef2] = this.kernel.ports.createChannel()
140140 await this.kernel.createInstance(this.kernel.createMessage({
141141 data: {
142142 type: testVMContainer2.typeId
@@ -179,9 +179,9 @@
179179 t.deepEquals(stateRoot, expectedState, 'expected state')
180180
181181 // test reviving the state
182182 class testVMContainer3 extends BaseContainer {
183- onMessage (m) {
183+ onMessage(m) {
184184 const port = this.kernel.ports.get('child')
185185 this.kernel.send(port, m)
186186 this.kernel.incrementTicks(1)
187187 }
@@ -195,9 +195,9 @@
195195
196196 tape('traps', async t => {
197197 t.plan(1)
198198 class Root extends BaseContainer {
199- async onMessage (m) {
199+ async onMessage(m) {
200200 const [portRef1, portRef2] = this.kernel.ports.createChannel()
201201 const [portRef3, portRef4] = this.kernel.ports.createChannel()
202202 const [portRef5, portRef6] = this.kernel.ports.createChannel()
203203
@@ -256,9 +256,9 @@
256256 t.plan(2)
257257 let runs = 0
258258
259259 class Root extends BaseContainer {
260- async onMessage (m) {
260+ async onMessage(m) {
261261 if (!runs) {
262262 runs++
263263 const [portRef1, portRef2] = this.kernel.ports.createChannel()
264264 const [portRef3, portRef4] = this.kernel.ports.createChannel()
@@ -294,27 +294,27 @@
294294 runs++
295295 // t.equals(m.data, 'third', 'should recived the second message')
296296 }
297297 }
298- static get typeId () {
298+ static get typeId() {
299299 return 299
300300 }
301301 }
302302
303303 class First extends BaseContainer {
304- onMessage (m) {
304+ onMessage(m) {
305305 this.kernel.incrementTicks(2)
306306 return this.kernel.send(m.fromPort, this.kernel.createMessage({
307307 data: 'second'
308308 }))
309309 }
310- static get typeId () {
310+ static get typeId() {
311311 return 29
312312 }
313313 }
314314
315315 class Waiter extends BaseContainer {
316- onMessage (m) {
316+ onMessage(m) {
317317 return new Promise((resolve, reject) => {
318318 setTimeout(() => {
319319 this.kernel.send(m.fromPort, this.kernel.createMessage({
320320 data: 'first'
@@ -358,10 +358,10 @@
358358 t.plan(3)
359359 let runs = 0
360360
361361 class Root extends BaseContainer {
362- onIdle () {}
363- async onMessage (m) {
362+ onIdle() {}
363+ async onMessage(m) {
364364 if (!runs) {
365365 runs++
366366 const [portRef1, portRef2] = this.kernel.ports.createChannel()
367367 const [portRef3, portRef4] = this.kernel.ports.createChannel()
@@ -398,39 +398,39 @@
398398 runs++
399399 t.equals(m.data, 'third', 'should recived the third message')
400400 }
401401 }
402- static get typeId () {
402+ static get typeId() {
403403 return 299
404404 }
405405 }
406406
407407 class First extends BaseContainer {
408- onMessage (m) {
408+ onMessage(m) {
409409 this.kernel.incrementTicks(2)
410410 return this.kernel.send(m.fromPort, this.kernel.createMessage({
411411 data: 'second'
412412 }))
413413 }
414- static get typeId () {
414+ static get typeId() {
415415 return 29
416416 }
417417 }
418418
419419 class Second extends BaseContainer {
420- onMessage (m) {
420+ onMessage(m) {
421421 this.kernel.incrementTicks(3)
422422 return this.kernel.send(m.fromPort, this.kernel.createMessage({
423423 data: 'third'
424424 }))
425425 }
426- static get typeId () {
426+ static get typeId() {
427427 return 2
428428 }
429429 }
430430
431431 class Waiter extends BaseContainer {
432- onCreation (m) {
432+ onCreation(m) {
433433 return new Promise((resolve, reject) => {
434434 setTimeout(() => {
435435 this.kernel.send(m.ports[0], this.kernel.createMessage({
436436 data: 'first'
@@ -492,9 +492,9 @@
492492 let runs = 0
493493 let instance
494494
495495 class Root extends BaseContainer {
496- async onMessage (m) {
496+ async onMessage(m) {
497497 let one = this.kernel.ports.get('one')
498498 if (!one) {
499499 const [portRef1, portRef2] = this.kernel.ports.createChannel()
500500 const message1 = this.kernel.createMessage({
@@ -511,15 +511,15 @@
511511 this.kernel.send(one, this.kernel.createMessage())
512512 ])
513513 }
514514 }
515- static get typeId () {
515+ static get typeId() {
516516 return 299
517517 }
518518 }
519519
520520 class First extends BaseContainer {
521- onMessage (m) {
521+ onMessage(m) {
522522 ++runs
523523 if (runs === 2) {
524524 t.equals(instance, this, 'should have same instances')
525525 } else {
@@ -613,9 +613,9 @@
613613 const expectedSr = {
614614 '/': 'zdpuAxKfu5nMTfpz6uHPqXdHZFQDZdRUer8zcQ6nvC4pTQsop'
615615 }
616616 class Root extends BaseContainer {
617- async onMessage (m) {
617+ async onMessage(m) {
618618 const [portRef1, portRef2] = this.kernel.ports.createChannel()
619619 const message1 = this.kernel.createMessage({
620620 data: {
621621 type: First.typeId
@@ -630,13 +630,13 @@
630630 }
631631 }
632632
633633 class First extends BaseContainer {
634- onMessage (m) {
634+ onMessage(m) {
635635 this.kernel.incrementTicks(2)
636636 return this.kernel.ports.delete('root')
637637 }
638- static get typeId () {
638+ static get typeId() {
639639 return 299
640640 }
641641 }
642642
@@ -674,9 +674,9 @@
674674 '/': 'zdpuAxKfu5nMTfpz6uHPqXdHZFQDZdRUer8zcQ6nvC4pTQsop'
675675 }
676676
677677 class Root extends BaseContainer {
678- onMessage (m) {
678+ onMessage(m) {
679679 return this.kernel.createInstance(new Message({
680680 data: {
681681 type: Root.typeId
682682 }
@@ -713,9 +713,9 @@
713713 const expectedSr = {
714714 '/': 'zdpuAxKfu5nMTfpz6uHPqXdHZFQDZdRUer8zcQ6nvC4pTQsop'
715715 }
716716 class Root extends BaseContainer {
717- onMessage (m) {
717+ onMessage(m) {
718718 const [, portRef2] = this.kernel.ports.createChannel()
719719 return this.kernel.createInstance(this.kernel.createMessage({
720720 data: {
721721 type: Sub.typeId
@@ -725,9 +725,9 @@
725725 }
726726 }
727727
728728 class Sub extends BaseContainer {
729- async onInitailize (message) {
729+ async onInitailize(message) {
730730 await this.kernel.ports.bind('root', message.ports[0])
731731 const [portRef1, portRef2] = this.kernel.ports.createChannel()
732732 await this.kernel.ports.bind('child', portRef1)
733733 await this.kernel.createInstance(this.kernel.createMessage({
@@ -736,9 +736,9 @@
736736 },
737737 ports: [portRef2]
738738 }))
739739 }
740- static get typeId () {
740+ static get typeId() {
741741 return 299
742742 }
743743 }
744744
@@ -776,9 +776,9 @@
776776 const expectedSr = {
777777 '/': 'zdpuAr4A3i1t6B7BkLT9C7DoxwvFnNg74gEzyqhpFj7nqVBy6'
778778 }
779779 class Root extends BaseContainer {
780- async onMessage (m) {
780+ async onMessage(m) {
781781 if (m.ports.length) {
782782 const port = this.kernel.ports.get('test1')
783783 await this.kernel.send(port, m)
784784 return this.kernel.ports.unbind('test1')
@@ -807,9 +807,9 @@
807807 }
808808 }
809809
810810 class Sub extends BaseContainer {
811- async onMessage (message) {
811+ async onMessage(message) {
812812 if (message.data === 'getChannel') {
813813 const ports = this.kernel.ports.createChannel()
814814 await this.kernel.send(message.fromPort, this.kernel.createMessage({
815815 data: 'bindPort',
@@ -819,9 +819,9 @@
819819 } else if (message.data === 'bindPort') {
820820 return this.kernel.ports.bind('channel', message.ports[0])
821821 }
822822 }
823- static get typeId () {
823+ static get typeId() {
824824 return 299
825825 }
826826 }
827827
@@ -851,14 +851,14 @@
851851
852852 t.end()
853853 })
854854
855- tape.only('should remove multiple subgraphs', async t => {
855+ tape('should remove multiple subgraphs', async t => {
856856 const expectedSr = {
857857 '/': 'zdpuAzYGmZeZsi5Zer7LXCTm1AsmqpUMJAXZnEeFW2UVDZj2P'
858858 }
859859 class Root extends BaseContainer {
860- onMessage (m) {
860+ onMessage(m) {
861861 if (m.ports.length) {
862862 const port = this.kernel.ports.get('test1')
863863 return Promise.all([
864864 this.kernel.send(port, m),
@@ -891,9 +891,9 @@
891891 }
892892 }
893893
894894 class Sub extends BaseContainer {
895- async onMessage (message) {
895+ async onMessage(message) {
896896 if (message.data === 'getChannel') {
897897 const ports = this.kernel.ports.createChannel()
898898 await this.kernel.send(message.fromPort, this.kernel.createMessage({
899899 data: 'bindPort',
@@ -903,9 +903,9 @@
903903 } else if (message.data === 'bindPort') {
904904 return this.kernel.ports.bind('channel', message.ports[0])
905905 }
906906 }
907- static get typeId () {
907+ static get typeId() {
908908 return 299
909909 }
910910 }
911911
@@ -947,9 +947,9 @@
947947 let runs = 0
948948 const returnValue = 'this is a test'
949949
950950 class testVMContainer extends BaseContainer {
951- onMessage (m) {
951+ onMessage(m) {
952952 runs++
953953 if (runs === 1) {
954954 return returnValue
955955 } else {
@@ -991,10 +991,10 @@
991991
992992 tape('start up', async t => {
993993 t.plan(1)
994994 class testVMContainer extends BaseContainer {
995- onMessage () {}
996- onStartup () {
995+ onMessage() {}
996+ onStartup() {
997997 t.true(true, 'should start up')
998998 }
999999 }
10001000
@@ -1011,9 +1011,9 @@
10111011 tape('large code size', async t => {
10121012 t.plan(1)
10131013 const content = Buffer.from(new ArrayBuffer(1000000))
10141014 class testVMContainer extends BaseContainer {
1015- onMessage () {}
1015+ onMessage() {}
10161016 }
10171017
10181018 const hypervisor = new Hypervisor(node.dag)
10191019 hypervisor.registerContainer(testVMContainer)
@@ -1026,9 +1026,9 @@
10261026 const instance = await hypervisor.getInstance(hypervisor.ROOT_ID)
10271027 t.equals(content.length, instance.code.length)
10281028 })
10291029
1030- tape.skip('creation service messaging', async t => {
1030+ tape('creation service messaging', async t => {
10311031 t.plan(1)
10321032 class TestVMContainer extends BaseContainer {
10331033 async onCreation (m) {
10341034 const creationPort = m.ports[0]
@@ -1070,9 +1070,13 @@
10701070 },
10711071 ports: [port]
10721072 }))
10731073
1074- await hypervisor.createStateRoot()
1075- await hypervisor.graph.tree(hypervisor.state, Infinity, true)
1076- console.log(JSON.stringify(hypervisor.state, null, 2))
1074+ const stateRoot = await hypervisor.createStateRoot()
1075+ // await hypervisor.graph.tree(hypervisor.state, Infinity, true)
1076+ console.log(stateRoot)
1077+ const expectedSR = {
1078+ '/': 'zdpuAonuhk7ZhdghJh4saaUCskY5mXZ6M9BcV9iAhCanAQx9i'
1079+ }
1080+ t.deepEquals(stateRoot, expectedSR)
10771081 })
10781082 })

Built with git-ssb-web