Esempio n. 1
0
File: sets.js Progetto: Raynos/crdt
exports['test - filters'] = function (t) {
  var doc = new crdt.Doc()
  console.log("# Filters")

  var set = doc.createSet(function (state) {
    return state.type === 'thing' && state.what <= 5
  })
  var set2 = doc.createSet(function (state) {
    return state.type === 'other' && state.what > 8
  })

  log(set)
  log(set2)

  console.log(set.toJSON())
  console.log(set2.toJSON())

  doc.add({id: 'a', type: 'thing', what: 3})
  doc.add({id: 'b', type: 'thing', what: 5})
  doc.add({id: 'a', type: 'other', what: 7})
  doc.add({id: 'c', type: 'thing', what: 9})

  a.deepEqual(set.toJSON(), [
    { id: 'b', type: 'thing', what: 5 }
  ])

  a.deepEqual(set2.toJSON(), [])

  console.log("passed")
  t.end()
}
Esempio n. 2
0
File: sets.js Progetto: Raynos/crdt
exports['test - post'] = function (t) {

  var doc = new crdt.Doc()

  doc.add({id: 'a', type: 'thing', what: 3})
  doc.add({id: 'b', type: 'thing', what: 5})
  doc.add({id: 'a', type: 'other', what: 7})
  doc.add({id: 'c', type: 'thing', what: 9})

  var set = doc.createSet('type', 'thing')
  var set2 = doc.createSet('type', 'other')

  log(set)
  log(set2)

  console.log(set.toJSON())
  console.log(set2.toJSON())

  a.deepEqual(set.toJSON(), [
    {id: 'b', type: 'thing', what: 5},
    {id: 'c', type: 'thing', what: 9},
  ])

  a.deepEqual(set2.toJSON(), [
    {id: 'a', type: 'other', what: 7}
  ])

  console.log('passed')
  t.end()
}
Esempio n. 3
0
    next(function () {
  
      console.log(cs.queue, bs2.queue, bs.queue, as.queue)

      assert.deepEqual(b.toJSON(), c.toJSON())

      // the crdt will emit 'flush'.

      assert.deepEqual(b.toJSON(), a.toJSON())
      assert.deepEqual(b.toJSON(), c.toJSON())

    t.end()
    })
Esempio n. 4
0
    next(function () { 

      a.deepEqual(hoc.toJSON(), doc.toJSON())

      doc.set('abc', {hello: 7})
      next(function () {

        a.deepEqual(hoc.toJSON(), doc.toJSON())

        console.log('DOC', doc.toJSON())
        console.log('HOC', hoc.toJSON())

        var moc = new crdt.Doc()

        var hs2 = crdt.createStream(hoc)
        var ms = crdt.createStream(moc)

        console.log('DHIST', doc.history())
        console.log('HHIST', hoc.history())

        hs2.pipe(ms).pipe(hs2)

        next(function () {
          a.deepEqual(moc.toJSON(), doc.toJSON())
          console.log('PASSED')
          t.end()
        })
      })
    })
Esempio n. 5
0
 process.on('exit', function () { 
   it(doc.history()).has(hoc.history())
   it(hoc.history()).has(doc.history())
   a.deepEqual(doc.toJSON(), hoc.toJSON())
   it(consistent).ok()
   t.end()
 })
Esempio n. 6
0
  next(function () {

    //what if there where random updates, then was flushed
    //then more changes then flush..

    assert.deepEqual(b.toJSON(), a.toJSON())
    t.end()
  })
Esempio n. 7
0
File: sets.js Progetto: Raynos/crdt
  process.nextTick(function () {
    a.deepEqual(states, [
      { id: 'b', type: 'thing', what: 5 },
      { id: 'c', type: 'thing', what: 9 }
    ])

    t.end()
  })
Esempio n. 8
0
      reader.on('end', function () {
        assert.equal(a.id, b.id)
        assert.deepEqual(a.toJSON(), b.toJSON())
        console.log(b.toJSON())

        assert.ok(b.sync)
        assert.ok(sync)
        t.end()
      })
Esempio n. 9
0
  next(function () {

    //use regular deep equal because tap
    //fails on key ordering.
    //which is probably going to be different
    //because messages may not be in order

    assert.deepEqual(b.toJSON(), a.toJSON())

    t.end()

  })
Esempio n. 10
0
File: sets.js Progetto: Raynos/crdt
exports['test'] = function (t) {

  var doc = new crdt.Doc()
  var set = doc.createSet('type', 'thing')
  var set2 = doc.createSet('type', 'other')

  function log(set) {

    set.on('add', function (row) {
      console.log('add', set.value,'->', row.state)
    })
    set.on('remove', function (row) {
      console.log('rm', set.value,'->', row.state)
    })

  }

  log(set)
  log(set2)

  doc.add({id: 'a', type: 'thing', what: 3})
  doc.add({id: 'b', type: 'thing', what: 5})
  doc.add({id: 'a', type: 'other', what: 7})
  doc.add({id: 'c', type: 'thing', what: 9})

  console.log(set.toJSON())
  console.log(set2.toJSON())

  a.deepEqual(set.toJSON(), [
    {id: 'b', type: 'thing', what: 5},
    {id: 'c', type: 'thing', what: 9},
  ])

  a.deepEqual(set2.toJSON(), [
    {id: 'a', type: 'other', what: 7}
  ])

  console.log('passed')
  t.end()
}
Esempio n. 11
0
  next(function () {
    console.log('flushed!')
    // THIS IS A PROBLEM.
    // since updates are cleared when flush it called
    // it won't work if they are written by more than one stream!
    // need to send updates to both streams.
    // so... emit them rather than return them...

    // IDEA. maybe emit changes when they first occur
    // then continue to change them until it's flushed.
    // (which clears the changes)

    // AHA! the CRDT decides when to flush changes.
    // not the stream.

    // the crdt will emit 'flush'.

    assert.deepEqual(b.toJSON(), a.toJSON())

    assert.deepEqual(b.toJSON(), c.toJSON())

    t.end()

  })
Esempio n. 12
0
  next(function () {

    var hThing = hoc.get('thing')
  assertNormal(doc, 'doc')
  assertNormal(doc, 'hoc')


    a.deepEqual(hThing.toJSON(), thing.toJSON())

    var thing2 = hoc.get('thing2').set({random: Math.random()})
    var hThing2 = doc.get('thing2')

    console.log('HOC', hoc.toJSON())
    console.log('DOC', doc.toJSON())

    console.log(hThing2)

    a.throws(function () {
      a.deepEqual(hThing2.toJSON(), thing2.toJSON())
    })

    
    t.end()
  })
Esempio n. 13
0
  read(fs, function (err, arr) {
		a.deepEqual(arr, expected)
    test.done()
  })
Esempio n. 14
0
var XModel = require('..')
var a = require('assertions')

var x = new XModel()

x
  .set('key', 'value')
  .set('key2', 'value2')
  .set('array', [])

var ary = x.at('array')
ary.splice(0, 0, 'hello')

a.deepEqual(x.toJSON(), {
  key: 'value',
  key2: 'value2',
  array: ['hello']
})

//XXX MORE TESTS !!!
Esempio n. 15
0
 a.throws(function () {
   a.deepEqual(hThing2.toJSON(), thing2.toJSON())
 })
Esempio n. 16
0
 next(function () {
   a.deepEqual(moc.toJSON(), doc.toJSON())
   console.log('PASSED')
   t.end()
 })
Esempio n. 17
0
 read(t, function (err, actual) {
   if(err) test.error(err) //fail
   a.deepEqual(actual, expected)
   test.done()
 })
Esempio n. 18
0
var a = require('assertions')
var XModel = require('..')
var SET = 'set', DEL = 'del', SPL = 'splice'
var x = new XModel()

x.patch([
  [SET, ['root'], [1, 2, 3]]
])

a.deepEqual(x.root,
  [1, 2, 3])

x.patch([
  [SPL, ['root'], [[0, 1, 'ONE']]]
])

a.deepEqual(x.root,
  ['ONE', 2, 3])

/*
  could create changes on the fly,
  but it will actually be quite tricky
  when forexample an old change overrides a previous one
  so just use diff for now
*/

//okay what about references?

function asRef(id) {
  return '#*=' + id
}
Esempio n. 19
0
 function () {
   a.deepEqual(doc.history(), hoc.history())
   a.deepEqual(doc.toJSON(), hoc.toJSON())
   consistent = true
   t.end()
 }