Exemplo n.º 1
0
def insert(db, key, rev, value):
    info = DocumentInfo(key)
    info.revSequence = rev
    # cas, exp, flags
    info.revMeta = str(struct.pack(REV_META_PACK, 1, 2, 3))
    info.deleted = False
    return db.save(info, value)
Exemplo n.º 2
0
def insert(db, key, rev, value):
    info = DocumentInfo(key)
    info.revSequence = rev
    # cas, exp, flags
    info.revMeta = str(struct.pack(REV_META_PACK, 1, 2, 3))
    info.deleted = False
    return db.save(info, value)
Exemplo n.º 3
0
def insert_multi(db, keys, values):
    """Inserts multiple keys / values."""

    ids = []
    for k in keys:
        info = DocumentInfo(k)
        info.revSequence = 1
        # cas, exp, flags
        info.revMeta = str(struct.pack(REV_META_PACK, 1, 2, 3))
        info.deleted = False
        ids.append(info)
    return db.saveMultiple(ids, values)
Exemplo n.º 4
0
def insert_multi(db, keys, values):
    """Inserts multiple keys / values."""

    ids = []
    for k in keys:
        info = DocumentInfo(k)
        info.revSequence = 1
        # cas, exp, flags
        info.revMeta = str(struct.pack(REV_META_PACK, 1, 2, 3))
        info.deleted = False
        ids.append(info)
    return db.saveMultiple(ids, values)
Exemplo n.º 5
0
    def testMetadata(self):
        info = DocumentInfo("meta")
        info.revSequence = 23
        info.revMeta = "fancy metadata here"
        info.contentType = DocumentInfo.INVALID_JSON
        self.store[info] = "the regular non-meta data"

        gotInfo = self.store.getInfo("meta")
        self.assertEquals(gotInfo.id, "meta")
        self.assertEquals(gotInfo.revSequence, info.revSequence)
        self.assertEquals(gotInfo.revMeta, info.revMeta)
        self.assertEquals(gotInfo.contentType, info.contentType)
        self.assertFalse(gotInfo.compressed)
Exemplo n.º 6
0
    def testMetadata(self):
        info = DocumentInfo("meta")
        info.revSequence = 23
        info.revMeta = "fancy metadata here"
        info.contentType = DocumentInfo.INVALID_JSON
        self.store[info] = "the regular non-meta data"

        gotInfo = self.store.getInfo("meta")
        self.assertEquals(gotInfo.id, "meta")
        self.assertEquals(gotInfo.revSequence, info.revSequence)
        self.assertEquals(gotInfo.revMeta, info.revMeta)
        self.assertEquals(gotInfo.contentType, info.contentType)
        self.assertFalse(gotInfo.compressed)
Exemplo n.º 7
0
    def testBinaryMeta(self):
        # Make sure binary data, as produced by Python's struct module, works in revMeta.
        packed = struct.pack(">QII", 0, 1, 2)
        d = DocumentInfo("bin")
        d.revMeta = packed
        self.store[d] = "value"

        doc_info = self.store.getInfo("bin")
        self.assertEqual(doc_info.revMeta, packed)
        i1, i2, i3 = struct.unpack(">QII", doc_info.revMeta)
        self.assertEqual(i1, 0)
        self.assertEqual(i2, 1)
        self.assertEqual(i3, 2)
Exemplo n.º 8
0
    def testMetadataSave(self):
        info = DocumentInfo("meta")
        info.revSequence = 23
        info.revMeta = "fancy metadata here"
        info.contentType = DocumentInfo.INVALID_JSON
        self.store[info] = "the regular non-meta data"

        self.store.commit()
        self.store.close()
        self.store = CouchStore("/tmp/test.couch", 'r')

        gotInfo = self.store.getInfo("meta")
        self.assertEquals(gotInfo.id, "meta")
        self.assertEquals(gotInfo.revSequence, info.revSequence)
        self.assertEquals(gotInfo.revMeta, info.revMeta)
        self.assertEquals(gotInfo.contentType, info.contentType)
        self.assertFalse(gotInfo.compressed)
Exemplo n.º 9
0
 def testMultipleMeta(self):
     k = []
     v = []
     for i in range(1000):
         d = DocumentInfo(str(i))
         d.revMeta = "hello-%s" % i
         k.append(d)
         v.append("world-%s" % i)
     self.store.saveMultiple(k, v)
     self.store.commit()
     self.store.close()
     self.store = CouchStore("/tmp/test.couch", 'r')
     for doc_info in self.store.changesSince(0):
         i = int(doc_info.id)
         self.assertEqual(doc_info.revMeta, "hello-%s" % i)
         doc_contents = doc_info.getContents()
         self.assertEqual(doc_contents, "world-%s" % i)
Exemplo n.º 10
0
    def testMetadataSave(self):
        info = DocumentInfo("meta")
        info.revSequence = 23
        info.revMeta = "fancy metadata here"
        info.contentType = DocumentInfo.INVALID_JSON
        self.store[info] = "the regular non-meta data"

        self.store.commit()
        self.store.close()
        self.store = CouchStore("/tmp/test.couch", 'r')

        gotInfo = self.store.getInfo("meta")
        self.assertEquals(gotInfo.id, "meta")
        self.assertEquals(gotInfo.revSequence, info.revSequence)
        self.assertEquals(gotInfo.revMeta, info.revMeta)
        self.assertEquals(gotInfo.contentType, info.contentType)
        self.assertFalse(gotInfo.compressed)
Exemplo n.º 11
0
 def testMultipleMeta(self):
     k = []
     v = []
     for i in range(1000):
         d = DocumentInfo(str(i))
         d.revMeta = "hello-%s" % i
         k.append(d)
         v.append("world-%s" % i)
     self.store.saveMultiple(k, v)
     self.store.commit()
     self.store.close()
     self.store = CouchStore("/tmp/test.couch", 'r')
     for doc_info in self.store.changesSince(0):
         i = int(doc_info.id)
         self.assertEqual(doc_info.revMeta, "hello-%s" % i)
         doc_contents = doc_info.getContents()
         self.assertEqual(doc_contents, "world-%s" % i)
Exemplo n.º 12
0
 def testMultipleMetaStruct(self):
     k = []
     v = []
     for i in range(1000):
         d = DocumentInfo(str(i))
         d.revMeta = struct.pack(">QII", i * 3, i * 2, i)
         k.append(d)
         v.append("world-%s" % i)
     self.store.saveMultiple(k, v)
     self.store.commit()
     self.store.close()
     self.store = CouchStore("/tmp/test.couch", 'r')
     for doc_info in self.store.changesSince(0):
         i = int(doc_info.id)
         i3, i2, i1 = struct.unpack(">QII", doc_info.revMeta)
         self.assertEqual(i3, i * 3)
         self.assertEqual(i2, i * 2)
         self.assertEqual(i1, i * 1)
         doc_contents = doc_info.getContents()
         self.assertEqual(doc_contents, "world-%s" % doc_info.id)
Exemplo n.º 13
0
 def testMultipleMetaStruct(self):
     k = []
     v = []
     for i in range(1000):
         d = DocumentInfo(str(i))
         d.revMeta = struct.pack(">QII", i * 3, i * 2, i)
         k.append(d)
         v.append("world-%s" % i)
     self.store.saveMultiple(k, v)
     self.store.commit()
     self.store.close()
     self.store = CouchStore("/tmp/test.couch", 'r')
     for doc_info in self.store.changesSince(0):
         i = int(doc_info.id)
         i3, i2, i1 = struct.unpack(">QII", doc_info.revMeta)
         self.assertEqual(i3, i * 3)
         self.assertEqual(i2, i * 2)
         self.assertEqual(i1, i * 1)
         doc_contents = doc_info.getContents()
         self.assertEqual(doc_contents, "world-%s" % doc_info.id)