def test_create_Segment(self): try: segment = None with self.index.new_txn() as txn: segmentId = self.index.new_segment(txn) segment = Segment(txn, self.index, segmentId) self.failUnless(segmentId == 1) finally: if segment: segment.close() try: segment = None with self.index.new_txn() as txn: segmentId = self.index.new_segment(txn) segment = Segment(txn, self.index, segmentId) self.failUnless(segmentId == 2) finally: if segment: segment.close() try: segment = None with self.index.new_txn() as txn: segmentId = self.index.new_segment(txn) segment = Segment(txn, self.index, segmentId) self.failUnless(segmentId == 3) finally: if segment: segment.close() self.failUnless(sorted(self.index.iter_segments(None)) == [1,2,3])
def test_read_write_term(self): try: segment = None with self.index.new_txn() as txn: self.index.add_segment(txn, u'store.1', None) segment = Segment(self.env, txn, u'store.1') key = [u'fieldname', u'fieldtype', u'foo'] # test writing an event, then retreiving it with self.index.new_txn() as txn: segment.set_term(txn, key, True) self.failUnless(segment.get_term(None, key) == True) # test modifying the same event, then retrieving it with self.index.new_txn() as txn: segment.set_event(txn, key, False) self.failUnless(segment.get_event(None, key) == False) finally: if segment: segment.close()
def test_read_write_posting(self): try: key = [u'fieldname', u'fieldtype', u'foo', 1, 1] segment = None with self.index.new_txn() as txn: self.index.add_segment(txn, u'store.1', None) segment = Segment(self.env, txn, u'store.1') # test writing an event, then retreiving it with self.index.new_txn() as txn: segment.set_posting(txn, key, True) self.failUnless(segment.get_posting(None, key) == True) # test verifying the existence of the event self.failUnless(segment.contains_posting(None, key) == True) # test modifying the same event, then retrieving it with self.index.new_txn() as txn: segment.set_posting(txn, key, False) self.failUnless(segment.get_posting(None, key) == False) finally: if segment: segment.close()
def test_read_write_meta(self): try: segment = None with self.index.new_txn() as txn: self.index.add_segment(txn, u'store.1', None) segment = Segment(self.env, txn, u'store.1') segment.set_meta(txn, u'foo', True) self.failUnless(segment.get_meta(None, u'foo') == True) finally: if segment: segment.close()
def test_read_write_field(self): try: key = [u'fieldname', u'fieldtype'] segment = None with self.index.new_txn() as txn: self.index.add_segment(txn, u'store.1', None) segment = Segment(self.env, txn, u'store.1') with self.index.new_txn() as txn: segment.set_field(txn, key, True) self.failUnless(segment.get_field(None, key) == True) finally: if segment: segment.close()
def test_create_Segment(self): try: segment = None with self.index.new_txn() as txn: self.index.add_segment(txn, u'store.1', None) segment = Segment(self.env, txn, u'store.1') finally: if segment: segment.close() try: segment = None with self.index.new_txn() as txn: self.index.add_segment(txn, u'store.2', None) segment = Segment(self.env, txn, u'store.2') finally: if segment: segment.close() try: segment = None with self.index.new_txn() as txn: self.index.add_segment(txn, u'store.3', None) segment = Segment(self.env, txn, u'store.3') finally: if segment: segment.close() segments = [name for name,_ in self.index.iter_segments(None)] self.failUnless(segments == [u'store.1', u'store.2', u'store.3'])
def test_iter_postings_reverse(self): try: prefix = [u'fieldname', u'fieldtype', u'foo'] segment = None with self.index.new_txn() as txn: self.index.add_segment(txn, u'store.1', None) segment = Segment(self.env, txn, u'store.1') segment.set_posting(txn, prefix + [1,1], True) segment.set_posting(txn, prefix + [1,2], True) segment.set_posting(txn, prefix + [1,3], True) segment.set_posting(txn, prefix + [1,4], True) segment.set_posting(txn, prefix + [1,5], True) # test iterating all postings in reverse order with self.index.new_txn() as txn: postings = list(segment.iter_postings(txn, None, None, True)) self.failUnless(postings == [ (prefix + [1,5], True), (prefix + [1,4], True), (prefix + [1,3], True), (prefix + [1,2], True), (prefix + [1,1], True), ]) # test iterating a subset of postings in reverse order with self.index.new_txn() as txn: postings = list(segment.iter_postings(txn, prefix + [1,2], prefix + [1,4], True)) self.failUnless(postings == [ (prefix + [1,4], True), (prefix + [1,3], True), (prefix + [1,2], True), ]) # test iterating from a specified key in reverse order with self.index.new_txn() as txn: postings = list(segment.iter_postings(txn, prefix + [1,3], None, True)) self.failUnless(postings == [ (prefix + [1,5], True), (prefix + [1,4], True), (prefix + [1,3], True), ]) # test iterating until a specified key in reverse order with self.index.new_txn() as txn: postings = list(segment.iter_postings(txn, None, prefix + [1,3], True)) self.failUnless(postings == [ (prefix + [1,3], True), (prefix + [1,2], True), (prefix + [1,1], True), ]) finally: if segment: segment.close()
def test_create_Segment(self): try: segment = None with self.index.new_txn() as txn: self.index.add_segment(txn, u'store.1', None) segment = Segment(self.env, txn, u'store.1') finally: if segment: segment.close() try: segment = None with self.index.new_txn() as txn: self.index.add_segment(txn, u'store.2', None) segment = Segment(self.env, txn, u'store.2') finally: if segment: segment.close() try: segment = None with self.index.new_txn() as txn: self.index.add_segment(txn, u'store.3', None) segment = Segment(self.env, txn, u'store.3') finally: if segment: segment.close() segments = [name for name, _ in self.index.iter_segments(None)] self.failUnless(segments == [u'store.1', u'store.2', u'store.3'])
def test_iter_postings_reverse(self): try: prefix = [u'fieldname', u'fieldtype', u'foo'] segment = None with self.index.new_txn() as txn: self.index.add_segment(txn, u'store.1', None) segment = Segment(self.env, txn, u'store.1') segment.set_posting(txn, prefix + [1, 1], True) segment.set_posting(txn, prefix + [1, 2], True) segment.set_posting(txn, prefix + [1, 3], True) segment.set_posting(txn, prefix + [1, 4], True) segment.set_posting(txn, prefix + [1, 5], True) # test iterating all postings in reverse order with self.index.new_txn() as txn: postings = list(segment.iter_postings(txn, None, None, True)) self.failUnless(postings == [ (prefix + [1, 5], True), (prefix + [1, 4], True), (prefix + [1, 3], True), (prefix + [1, 2], True), (prefix + [1, 1], True), ]) # test iterating a subset of postings in reverse order with self.index.new_txn() as txn: postings = list( segment.iter_postings(txn, prefix + [1, 2], prefix + [1, 4], True)) self.failUnless(postings == [ (prefix + [1, 4], True), (prefix + [1, 3], True), (prefix + [1, 2], True), ]) # test iterating from a specified key in reverse order with self.index.new_txn() as txn: postings = list( segment.iter_postings(txn, prefix + [1, 3], None, True)) self.failUnless(postings == [ (prefix + [1, 5], True), (prefix + [1, 4], True), (prefix + [1, 3], True), ]) # test iterating until a specified key in reverse order with self.index.new_txn() as txn: postings = list( segment.iter_postings(txn, None, prefix + [1, 3], True)) self.failUnless(postings == [ (prefix + [1, 3], True), (prefix + [1, 2], True), (prefix + [1, 1], True), ]) finally: if segment: segment.close()
def test_delete_Segment(self): with self.index.new_txn() as txn: self.index.add_segment(txn, u'store.1', None) segment = Segment(self.env, txn, u'store.1') with self.index.new_txn() as txn: self.index.delete_segment(txn, u'store.1')