Example #1
0
    async def test_lrudict(self):
        lru = s_cache.LruDict(3)
        del lru['foo']
        lru['foo'] = 42
        self.eq(lru['foo'], 42)
        self.len(1, lru)
        self.eq(list(lru), ['foo'])
        del lru['foo']
        self.none(lru.get('foo', None))
        self.none(lru.get('newp', None))
        lru['foo2'] = 'yar'
        lru['foo3'] = 100
        lru['foo4'] = 'yop'
        self.notin('foo', lru)

        # Validate this is a LRU and not least-recently-added
        self.eq(lru['foo3'], 100)
        lru['foo5'] = 1
        lru['foo6'] = True
        self.isin('foo3', lru)

        self.eq(list(lru.items()),
                (('foo3', 100), ('foo5', 1), ('foo6', True)))
        self.eq(list(lru.keys()), ('foo3', 'foo5', 'foo6'))
        self.eq(list(lru.values()), (100, 1, True))

        # Make sure that disabled dict still work
        lru = s_cache.LruDict(0)
        lru['nope'] = 42
        self.none(lru.get('nope', None))
Example #2
0
 def disablingBuidCache(self):
     '''
     Disable and invalidate the layer buid cache for migration
     '''
     self.buidcache = s_cache.LruDict(0)
     yield
     self.buidcache = s_cache.LruDict(BUID_CACHE_SIZE)
Example #3
0
    async def __anit__(self, core, node):

        await s_base.Base.__anit__(self)

        self.core = core
        self.node = node
        self.iden = node.name()
        self.buidcache = s_cache.LruDict(BUID_CACHE_SIZE)

        # splice windows...
        self.windows = []

        self.info = await node.dict()
        self.info.setdefault('owner', 'root')

        self.owner = self.info.get('owner')

        self.conf = await (await node.open(('config', ))).dict()

        for name, info in self.confdefs:

            dval = info.get('defval', s_common.novalu)
            if dval is s_common.novalu:
                continue

            self.conf.setdefault(name, dval)

        self.dirn = s_common.gendir(core.dirn, 'layers', self.iden)

        self._lift_funcs = {
            'indx': self._liftByIndx,
            'prop:re': self._liftByPropRe,
            'univ:re': self._liftByUnivRe,
            'form:re': self._liftByFormRe,
            'prop:ival': self._liftByPropIval,
            'univ:ival': self._liftByUnivIval,
            'form:ival': self._liftByFormIval,
            'tag:prop': self._liftByTagProp,
        }

        self._stor_funcs = {
            'prop:set': self._storPropSet,
            'prop:del': self._storPropDel,
            'buid:set': self._storBuidSet,
            'tag:prop:set': self._storTagPropSet,
            'tag:prop:del': self._storTagPropDel,
        }

        self.fresh = False
        self.canrev = True
        self.spliced = asyncio.Event(loop=self.loop)
        self.onfini(self.spliced.set)

        self.onfini(self._onLayrFini)
Example #4
0
    async def __anit__(self, core, node):

        await s_layer.Layer.__anit__(self, core, node)

        # a remote layer may never be revd
        self.proxy = None
        self.canrev = False

        # Disable buid caching
        self.buidcache = s_cache.LruDict(size=0)

        self.ready = asyncio.Event()
        await self._fireTeleTask()
        self.onfini(self._onRemoteLayerFini)