GC.isDoomed() and GC.isDestroyed() functions were added

io.murano.system.GC.isDoomed() static method was added. It can be used
within the .destroy method to test if other object is also going to be
destroyed.

io.murano.system.GC.isDestroyed() static method was added. It checks if
the object is destroyed and thus no methods can be invoked on it.

Targets-blueprint: dependency-driven-resource-deallocation
Change-Id: I9ca51f342be27e88e149f217b41145becdfbe232
This commit is contained in:
Stan Lagun 2016-09-07 00:47:58 -07:00
parent 0aea40e215
commit dc050d41cb
5 changed files with 72 additions and 7 deletions

View File

@ -114,6 +114,7 @@ class ObjectStore(object):
]
with helpers.with_object_store(self):
if sentenced_objects:
self._pending_destruction.update(sentenced_objects)
for __ in self._destroy_garbage(sentenced_objects):
pass
@ -149,6 +150,9 @@ class ObjectStore(object):
count += 1
return count
def is_doomed(self, obj):
return obj.destroyed or obj in self._pending_destruction
def _destroy_garbage(self, sentenced_objects):
dd_graph = {}

View File

@ -74,3 +74,13 @@ class GarbageCollector(object):
@staticmethod
def collect():
helpers.get_executor().object_store.cleanup()
@staticmethod
@specs.parameter('object_', dsl.MuranoObjectParameter(decorate=False))
def is_doomed(object_):
return helpers.get_object_store().is_doomed(object_)
@staticmethod
@specs.parameter('object_', dsl.MuranoObjectParameter(decorate=False))
def is_destroyed(object_):
return object_.destroyed

View File

@ -1,11 +1,11 @@
Namespaces:
sys: io.murano.system
std: io.murano
Name: TestGCNode
Extends: Node
Methods:
.init:
Body:
- $.find(Node)
foo:
Body:
- trace(foo)
@ -22,8 +22,18 @@ Methods:
- trace($.value)
---
Namespaces:
sys: io.murano.system
Name: TestGCNode2
Extends: TestGCNode
Methods:
.destroy:
Body:
- trace(list($.nodes.select(sys:GC.isDoomed($))))
- $owner: $.find(std:Object)
- trace(sys:GC.isDoomed($owner))
---
Name: TestGC
@ -77,3 +87,29 @@ Methods:
- $obj.foo()
- $this.destroyed: $obj
testIsDoomed:
Body:
- $model:
:TestGCNode2:
value: A
nodes:
- :TestGCNode2:
value: B
- new($model, $this)
- sys:GC.collect()
testIsDestroyed:
Body:
- $val: new(Node, value => X)
- sys:GC.subscribeDestruction($val, $this, _handler3)
- $val: null
- sys:GC.collect()
- trace(sys:GC.isDestroyed($this.destroyed))
_handler3:
Arguments:
- obj:
Contract: $.class(Node).notNull()
Body:
- trace(sys:GC.isDestroyed($obj))
- $this.destroyed: $obj

View File

@ -13,7 +13,6 @@
# under the License.
from murano.dsl import exceptions
from murano.engine.system import garbage_collector
from murano.tests.unit.dsl.foundation import object_model as om
from murano.tests.unit.dsl.foundation import test_case
@ -64,3 +63,11 @@ class TestGC(test_case.DslTestCase):
exceptions.ObjectDestroyedError,
self.runner.testCallOnDestroyedObject)
self.assertEqual(['foo', 'X'], self.traces)
def test_is_doomed(self):
self.runner.testIsDoomed()
self.assertEqual([[], True, 'B', [True], False, 'A'], self.traces)
def test_is_destroyed(self):
self.runner.testIsDestroyed()
self.assertEqual([False, True], self.traces)

View File

@ -0,0 +1,8 @@
---
features:
- io.murano.system.GC.isDoomed() static method was added. It can be used
within the ``.destroy`` method to test if other object is also going to be
destroyed.
- io.murano.system.GC.isDestroyed() static method was added. It checks if
the object is destroyed and thus no methods can be invoked on it.