Пример #1
0
 def test_noBatchService(self):
     """
     A L{Store} with no database directory cannot be adapted to
     L{iaxiom.IBatchService}.
     """
     st = store.Store()
     self.assertRaises(TypeError, iaxiom.IBatchService, st)
     self.assertIdentical(iaxiom.IBatchService(st, None), None)
Пример #2
0
 def testBatchService(self):
     """
     Make sure SubStores can be adapted to L{iaxiom.IBatchService}.
     """
     dbdir = filepath.FilePath(self.mktemp())
     s = store.Store(dbdir)
     ss = substore.SubStore.createNew(s, 'substore')
     bs = iaxiom.IBatchService(ss)
     self.failUnless(iaxiom.IBatchService.providedBy(bs))
Пример #3
0
 def test_subStoreNoBatchService(self):
     """
     A user L{Store} attached to a site L{Store} with no database directory
     cannot be adapted to L{iaxiom.IBatchService}.
     """
     st = store.Store(filesdir=self.mktemp())
     ss = substore.SubStore.createNew(st, ['substore']).open()
     self.assertRaises(TypeError, iaxiom.IBatchService, ss)
     self.assertIdentical(iaxiom.IBatchService(ss, None), None)
Пример #4
0
 def testCalling(self):
     """
     Test invoking a method on an item in the batch process.
     """
     dbdir = filepath.FilePath(self.mktemp())
     s = store.Store(dbdir)
     ss = substore.SubStore.createNew(s, 'substore')
     service.IService(s).startService()
     d = iaxiom.IBatchService(ss).call(BatchCallTestItem(store=ss.open()).callIt)
     def called(ign):
         self.failUnless(ss.open().findUnique(BatchCallTestItem).called, "Was not called")
         return service.IService(s).stopService()
     return d.addCallback(called)
Пример #5
0
    def test_itemAddedWithoutBatchService(self):
        """
        If the store has no batch service, C{itemAdded} doesn't start the batch
        process and also doesn't raise an exception.
        """
        # An in-memory store can't have a batch service.
        st = store.Store()
        svc = service.IService(st)
        svc.startService()
        self.addCleanup(svc.stopService)

        procType = batch.processor(TestWorkUnit)
        proc = procType(store=st)
        listener = WorkListener(store=st)
        proc.addReliableListener(listener, style=iaxiom.REMOTE)

        proc.itemAdded()

        # And still there should be no batch service at all.
        self.assertIdentical(iaxiom.IBatchService(st, None), None)
Пример #6
0
    def test_itemAddedBeforeStarted(self):
        """
        If C{itemAdded} is called before the batch service is started, the batch
        process is not started.
        """
        st = store.Store(self.mktemp())

        procType = batch.processor(TestWorkUnit)
        proc = procType(store=st)
        listener = WorkListener(store=st)
        proc.addReliableListener(listener, style=iaxiom.REMOTE)

        proc.itemAdded()

        # When the service later starts, the batch service needn't start its
        # process.  Not that this would be bad.  Feel free to reverse this
        # behavior if you really want.
        svc = service.IService(st)
        svc.startService()
        self.addCleanup(svc.stopService)

        batchService = iaxiom.IBatchService(st)
        self.assertEqual(batchService.batchController.mode, 'stopped')
Пример #7
0
 def reclassify(self):
     return iaxiom.IBatchService(self.filter.store).call(
         self.filter.reclassify)
Пример #8
0
 def retrain(self):
     return iaxiom.IBatchService(self.filter.store).call(
         self.filter.retrain)
Пример #9
0
 def __init__(self, substore):
     self.storepath = substore.dbdir
     self.service = iaxiom.IBatchService(substore.parent)
Пример #10
0
    def search(self,
               aString,
               keywords=None,
               count=None,
               offset=0,
               sortAscending=True,
               retry=3):
        ident = "%s/%d" % (self.store, self.storeID)
        b = iaxiom.IBatchService(self.store)
        if VERBOSE:
            log.msg("%s issuing suspend" % (ident, ))
        d = b.suspend(self.storeID)

        def reallySearch(ign):
            if VERBOSE:
                log.msg("%s getting reader index" % (ident, ))
            idx = self.openReadIndex()

            if VERBOSE:
                log.msg("%s searching for %s" %
                        (ident, aString.encode('utf-8')))
            results = idx.search(aString, keywords, sortAscending)
            if VERBOSE:
                log.msg("%s found %d results" % (ident, len(results)))

            if count is None:
                end = None
            else:
                end = offset + count

            results = results[offset:end]

            if VERBOSE:
                log.msg("%s sliced from %s to %s, leaving %d results" %
                        (ident, offset, end, len(results)))
            return results

        d.addCallback(reallySearch)

        def resumeIndexing(results):
            if VERBOSE:
                log.msg("%s issuing resume" % (ident, ))
            b.resume(self.storeID).addErrback(log.err)
            return results

        d.addBoth(resumeIndexing)

        def searchFailed(err):
            log.msg("Search failed somehow:")
            log.err(err)
            if retry:
                log.msg("Re-issuing search")
                return self.search(aString,
                                   keywords,
                                   count,
                                   offset,
                                   retry=retry - 1)
            else:
                log.msg("Wow, lots of failures searching.  Giving up and "
                        "returning (probably wrong!) no results to user.")
                return []

        d.addErrback(searchFailed)
        return d