From cbdc5c495c456ed054b95ecf7e05fdbbea92a91e Mon Sep 17 00:00:00 2001 From: Anthony Geay Date: Wed, 22 Jul 2015 14:43:20 +0200 Subject: [PATCH] 2 more tests. --- src/SALOMESDS/SALOMESDS_KeyWaiter.cxx | 16 ++++----- src/SALOMESDS/SALOMESDS_Transaction.cxx | 5 +-- src/SALOMESDS/TestSalomeSDS.py | 45 +++++++++++++++++++++++++ 3 files changed, 55 insertions(+), 11 deletions(-) diff --git a/src/SALOMESDS/SALOMESDS_KeyWaiter.cxx b/src/SALOMESDS/SALOMESDS_KeyWaiter.cxx index 84975a48f..5249be58d 100644 --- a/src/SALOMESDS/SALOMESDS_KeyWaiter.cxx +++ b/src/SALOMESDS/SALOMESDS_KeyWaiter.cxx @@ -57,15 +57,11 @@ KeyWaiter::KeyWaiter(PickelizedPyObjServer *var, const SALOME::ByteVec& keyVal): 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 @@ -108,6 +104,8 @@ SALOME::ByteVec *KeyWaiter::waitFor() */ void KeyWaiter::valueJustCome(PyObject *val) { + if(_ze_value==val) + return ; if(_ze_value) Py_XDECREF(_ze_value); _ze_value=val; diff --git a/src/SALOMESDS/SALOMESDS_Transaction.cxx b/src/SALOMESDS/SALOMESDS_Transaction.cxx index 9f3163b44..ca9bc32ee 100644 --- a/src/SALOMESDS/SALOMESDS_Transaction.cxx +++ b/src/SALOMESDS/SALOMESDS_Transaction.cxx @@ -99,8 +99,9 @@ TransactionDictModify::TransactionDictModify(DataScopeServerTransaction *dsct, c void TransactionDictModify::prepareRollBackInCaseOfFailure() { _zeDataBefore.clear(); - SALOME::ByteVec *zeDataBefore(_varc->fetchSerializedContent()); - PickelizedPyObjServer::FromByteSeqToCpp(*zeDataBefore,_zeDataBefore); + PyObject *zeDictPy(_varc->getPyObj()); + Py_XINCREF(zeDictPy); + _zeDataBefore=_varc->pickelize(zeDictPy); } void TransactionDictModify::rollBack() diff --git a/src/SALOMESDS/TestSalomeSDS.py b/src/SALOMESDS/TestSalomeSDS.py index 788664e29..9a5fd83e0 100644 --- a/src/SALOMESDS/TestSalomeSDS.py +++ b/src/SALOMESDS/TestSalomeSDS.py @@ -150,6 +150,51 @@ class SalomeSDSTest(unittest.TestCase): 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 -- 2.39.2