throw Exception("KeyWaiter constructor : unexpected return of dict.__contains__ !");
if(retPy==Py_True)
{
- selfMeth=PyObject_GetAttrString(_var->getPyObj(),"__getitem__");
- args=PyTuple_New(1);
- PyTuple_SetItem(args,0,_ze_key); Py_XINCREF(_ze_key); // _ze_key is stolen by PyTuple_SetItem
- retPy=PyObject_CallObject(selfMeth,args);
- if(!retPy)
- throw Exception("KeyWaiter constructor : dict.__contains__ says true but fails to return value !");
- _ze_value=retPy;
- Py_XDECREF(args);
- Py_XDECREF(selfMeth);
+ PyObject *retPy2(PyDict_GetItem(_var->getPyObj(),_ze_key));
+ if(retPy2==NULL)
+ throw Exception("KeyWaiter constructor : dict.getitem fails !");
+ Py_XINCREF(retPy2);
+ _ze_value=retPy2;
go();//notify that value already arrives -> unlock
}
else
*/
void KeyWaiter::valueJustCome(PyObject *val)
{
+ if(_ze_value==val)
+ return ;
if(_ze_value)
Py_XDECREF(_ze_value);
_ze_value=val;
wk=dss.waitForKeyInVar(varName,obj2Str("cd"))
self.assertEqual(str2Obj(wk.waitFor()),[7,8,9,10])
+ def testTransaction3(self):
+ scopeName="Scope1"
+ varName="a"
+ dsm=salome.naming_service.Resolve("/DataServerManager")
+ dsm.cleanScopesInNS()
+ if scopeName in dsm.listScopes():
+ dsm.removeDataScope(scopeName)
+ dss,isCreated=dsm.giveADataScopeTransactionCalled(scopeName)
+ self.assertTrue(isCreated)
+ #
+ t0=dss.createRdExtVarTransac(varName,obj2Str({"ab":[4,5,6]}))
+ dss.atomicApply([t0])
+ #
+ t1=dss.addKeyValueInVarErrorIfAlreadyExisting(varName,obj2Str("cd"),obj2Str([7,8,9,10]))
+ dss.atomicApply([t1])
+ #
+ self.assertEqual(str2Obj(dss.fetchSerializedContent(varName)),{'ab':[4,5,6],'cd':[7,8,9,10]})
+ #
+ t2=dss.removeKeyInVarErrorIfNotAlreadyExisting(varName,obj2Str("ab"))
+ dss.atomicApply([t2])
+ self.assertEqual(str2Obj(dss.fetchSerializedContent(varName)),{'cd':[7,8,9,10]})
+
+ def testTransaction4(self):
+ scopeName="Scope1"
+ varName="a"
+ dsm=salome.naming_service.Resolve("/DataServerManager")
+ dsm.cleanScopesInNS()
+ if scopeName in dsm.listScopes():
+ dsm.removeDataScope(scopeName)
+ dss,isCreated=dsm.giveADataScopeTransactionCalled(scopeName)
+ self.assertTrue(isCreated)
+ #
+ t0=dss.createRdExtVarTransac(varName,obj2Str({"ab":[4,5,6]}))
+ dss.atomicApply([t0])
+ #
+ t1=dss.addKeyValueInVarHard(varName,obj2Str("cd"),obj2Str([7,8,9,10]))
+ dss.atomicApply([t1])
+ #
+ self.assertEqual(str2Obj(dss.fetchSerializedContent(varName)),{'ab':[4,5,6],'cd':[7,8,9,10]})
+ wk,t2=dss.waitForKeyInVarAndKillIt(varName,obj2Str("cd"))
+ self.assertEqual(str2Obj(dss.fetchSerializedContent(varName)),{'ab':[4,5,6],'cd':[7,8,9,10]})
+ self.assertEqual(str2Obj(wk.waitFor()),[7,8,9,10])
+ dss.atomicApply([t2])
+ self.assertEqual(str2Obj(dss.fetchSerializedContent(varName)),{'ab':[4,5,6]})
+
def setUp(self):
salome.salome_init()
pass