[Erp5-report] r36171 seb - in /erp5/trunk/products/ERP5: Document/ tests/

nobody at svn.erp5.org nobody at svn.erp5.org
Wed Jun 9 17:58:03 CEST 2010


Author: seb
Date: Wed Jun  9 17:58:03 2010
New Revision: 36171

URL: http://svn.erp5.org?rev=36171&view=rev
Log:
allow to rebuild portal_ids from values stored on ZODB

Modified:
    erp5/trunk/products/ERP5/Document/SQLNonContinuousIncreasingIdGenerator.py
    erp5/trunk/products/ERP5/tests/testIdTool.py

Modified: erp5/trunk/products/ERP5/Document/SQLNonContinuousIncreasingIdGenerator.py
URL: http://svn.erp5.org/erp5/trunk/products/ERP5/Document/SQLNonContinuousIncreasingIdGenerator.py?rev=36171&r1=36170&r2=36171&view=diff
==============================================================================
--- erp5/trunk/products/ERP5/Document/SQLNonContinuousIncreasingIdGenerator.py [utf8] (original)
+++ erp5/trunk/products/ERP5/Document/SQLNonContinuousIncreasingIdGenerator.py [utf8] Wed Jun  9 17:58:03 2010
@@ -209,3 +209,26 @@ class SQLNonContinuousIncreasingIdGenera
         'idTool_zDropTable and/or idTool_zCreateTable could not be found.'
     drop_method()
     create_method()
+
+  security.declareProtected(Permissions.AccessContentsInformation,
+      'rebuildSqlTable')
+  def rebuildSqlTable(self):
+    """
+      After a mysql crash, it could be needed to restore values stored in
+      zodb into mysql
+
+      TODO : take into account the case where the value is stored every X
+             generation 
+    """
+    portal = self.getPortalObject()
+    getattr(portal, 'IdTool_zDropTable')()
+    getattr(self, 'SQLNonContinuousIncreasingIdGenerator_zCreateTable')()
+
+  security.declareProtected(Permissions.AccessContentsInformation,
+      'rebuildSqlTable')
+  def getPersistentIdDict(self):
+    """
+      Return all data stored in zodb
+    """
+    return dict([(x[0],x[1].value) for x in
+       getattr(self, 'last_max_id_dict', {}).iteritems()])

Modified: erp5/trunk/products/ERP5/tests/testIdTool.py
URL: http://svn.erp5.org/erp5/trunk/products/ERP5/tests/testIdTool.py?rev=36171&r1=36170&r2=36171&view=diff
==============================================================================
--- erp5/trunk/products/ERP5/tests/testIdTool.py [utf8] (original)
+++ erp5/trunk/products/ERP5/tests/testIdTool.py [utf8] Wed Jun  9 17:58:03 2010
@@ -32,6 +32,7 @@ import unittest
 import transaction
 
 from Products.ERP5Type.tests.ERP5TypeTestCase import ERP5TypeTestCase
+from _mysql_exceptions import ProgrammingError
 
 class TestIdTool(ERP5TypeTestCase):
 
@@ -259,6 +260,25 @@ class TestIdTool(ERP5TypeTestCase):
                                         id_generator='test_application_sql',
                                         id_group='a04', id_count=3))
 
+  def test_05_RebuildTableForDefaultSQLNonContinuousIncreasingIdGenerator(self):
+    """
+      It should be possible to reconstruct the portal_ids table thanks to
+      data stored in ZODB
+    """
+    portal = self.getPortalObject()
+    generator = self.id_tool._getLatestGeneratorValue(
+       'mysql_non_continuous_increasing')
+    self.assertTrue(generator is not None)
+    generator.generateNewId(id_group='foo_bar', default=4)
+    self.assertEquals(generator.last_max_id_dict['foo_bar'].value, 4)
+    portal.IdTool_zDropTable()
+    sql_connection = self.getSQLConnection()
+    query = 'select last_id from portal_ids where id_group="foo_bar"'
+    self.assertRaises(ProgrammingError, sql_connection.manage_test, query)
+    generator.rebuildSqlTable()
+    result =  sql_connection.manage_test(query)
+    self.assertEqual(result[0].last_id, 4)
+
 def test_suite():
   suite = unittest.TestSuite()
   suite.addTest(unittest.makeSuite(TestIdTool))




More information about the Erp5-report mailing list