]> SALOME platform Git repositories - modules/kernel.git/commitdiff
Salome HOME
2 more tests.
authorAnthony Geay <anthony.geay@edf.fr>
Wed, 22 Jul 2015 12:43:20 +0000 (14:43 +0200)
committerAnthony Geay <anthony.geay@edf.fr>
Wed, 22 Jul 2015 12:43:20 +0000 (14:43 +0200)
src/SALOMESDS/SALOMESDS_KeyWaiter.cxx
src/SALOMESDS/SALOMESDS_Transaction.cxx
src/SALOMESDS/TestSalomeSDS.py

index 84975a48f2bfdb5f5b6f07c8daae2dd5655a4b79..5249be58d3c14e244f58fd450eef61d206bd57ad 100644 (file)
@@ -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;
index 9f3163b44e9f3ef9985f949c8e765156591f7a96..ca9bc32ee239973a6f449cbb05667e115dce6d17 100644 (file)
@@ -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()
index 788664e29d98aaa6bb5300fe50695b285e1a53ed..9a5fd83e095a63433490d851f8a4f3205979977d 100644 (file)
@@ -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