Ejemplo n.º 1
0
    def test_purge_expired( self ):

        processor = Mock()
        cache = _K8sCache( processor, 'foo' )

        current_time = time.time()
        obj1 = self.DummyObject( current_time - 10 )
        obj2 = self.DummyObject( current_time + 15 )
        obj3 = self.DummyObject( current_time - 20 )

        objects = {
            'default': {
                'obj1': obj1,
                'obj2': obj2,
                'obj3': obj3
            }
        }

        # we should probably look at using actual values returned from k8s here
        # and loading them via 'cache.update'
        cache._objects = objects

        cache.purge_unused(current_time)

        objects = cache._objects.get('default', {})
        self.assertEquals( 1, len( objects ) )
        self.assertTrue( 'obj2' in objects )
        self.assertTrue( objects['obj2'] is obj2 )
Ejemplo n.º 2
0
    def __init__(self):

        self.__processor = FakeProcessor()
        self.__pod_cache = _K8sCache(self.__processor, "Pod")
        self.wait_timeout = 5
        self.k8s = FakeK8s(wait_timeout=self.wait_timeout)
        self.__clock = FakeClock()
Ejemplo n.º 3
0
    def test_purge_expired(self):

        processor = Mock()
        cache = _K8sCache(processor, "foo")

        current_time = time.time()
        obj1 = self.DummyObject(current_time - 10)
        obj2 = self.DummyObject(current_time + 15)
        obj3 = self.DummyObject(current_time - 20)

        objects = {"default": {"obj1": obj1, "obj2": obj2, "obj3": obj3}}

        # we should probably look at using actual values returned from k8s here
        # and loading them via 'cache.update'
        cache._objects = objects

        cache.purge_unused(current_time)

        objects = cache._objects.get("default", {})
        self.assertEquals(1, len(objects))
        self.assertTrue("obj2" in objects)
        self.assertTrue(objects["obj2"] is obj2)
Ejemplo n.º 4
0
 def setUp(self):
     super(Test_K8sCache, self).setUp()
     self.k8s = FakeK8s()
     self.clock = FakeClock()
     self.processor = FakeProcessor()
     self.cache = _K8sCache(self.processor, "foo")
Ejemplo n.º 5
0
 def setUp(self):
     self.k8s = FakeK8s()
     self.clock = FakeClock()
     self.processor = FakeProcessor()
     self.cache = _K8sCache( self.processor, 'foo' )