def test_deleteItem(self): objectType = "CacheTestObj1" undertestCacheObjectStore = undertest.ObjectStore_Caching( ConfigDict, self.getObjectStoreExternalFns(), detailLogging=False, type='testMEM', factoryFn=undertest.createObjectStoreInstance) internalMainObjectStore = undertestCacheObjectStore.mainStore internalCacheObjectStore = undertestCacheObjectStore.cachingStore genericTests.addSampleRows(undertestCacheObjectStore, 500, bbString='BB', offset=0, objectType=objectType) objectKey = "1231" def dbfn(connectionContext): return connectionContext.removeJSONObject( objectType=objectType, objectKey=objectKey, objectVersion=1, ignoreMissingObject=False) newObjectVersion = undertestCacheObjectStore.executeInsideTransaction( dbfn)
def test_cacheWontGrowAboveMaxSizeWhenAddingdifferentKEys(self): objectType = "CacheTestObj1" undertestCacheObjectStore = undertest.ObjectStore_Caching( ConfigDict, self.getObjectStoreExternalFns(), detailLogging=False, type='testMEM', factoryFn=undertest.createObjectStoreInstance) internalMainObjectStore = undertestCacheObjectStore.mainStore internalCacheObjectStore = undertestCacheObjectStore.cachingStore genericTests.addSampleRows(undertestCacheObjectStore, 500, bbString='BB', offset=0, objectType=objectType) objectKey = "1231" def dbfn(con): return con.getAllRowsForObjectType(objectType=objectType, filterFN=None, outputFN=None, whereClauseText="") cacheRows = internalCacheObjectStore.executeInsideConnectionContext( dbfn) mainRows = internalMainObjectStore.executeInsideConnectionContext(dbfn) self.assertEquals(len(cacheRows), 100) self.assertEquals(len(mainRows), 500)
def test_canLookupObjectInMainStoreNotAddedViaCache(self): objectType = "CacheTestObj1" undertestCacheObjectStore = undertest.ObjectStore_Caching( ConfigDict, self.getObjectStoreExternalFns(), detailLogging=False, type='testMEM', factoryFn=undertest.createObjectStoreInstance) internalMainObjectStore = undertestCacheObjectStore.mainStore genericTests.addSampleRows(internalMainObjectStore, 5, bbString='BB', offset=0, objectType=objectType) objectKey = "1231" def dbfn(storeConnection): #Get sample row from cacheStore and make sure it is correct return storeConnection.getObjectJSON(objectType=objectType, objectKey=objectKey) (objectDict, ObjectVersion, creationDate, lastUpdateDate, objectKey ) = undertestCacheObjectStore.executeInsideConnectionContext(dbfn) expected = copy.deepcopy(genericTests.JSONString) expected["AA"] = 1 self.assertEqual(objectDict, expected)
def dbfn(storeConnection): addSampleRows(storeConnection, 5, 'yyYYyyy') addSampleRows(storeConnection, 5, 'xxxxxxx', 5) def outputFN(item): return item[0] paginatedParamValues = { 'offset': 0, 'pagesize': 10, 'query': 'dfgdbdfgfgfvfdgfd', 'sort': None } res = storeConnection.getPaginatedResult( "Test1", paginatedParamValues, outputFN) expectedRes = [] assertCorrectPaginationResult(testClass, res, 0, 10, 0) self.assertJSONStringsEqualWithIgnoredKeys(res['result'], expectedRes, [], msg='Wrong result')
def setupTwoMemoryStoresReadyForAMigration(self, extfns): migratingStore = undertest.ObjectStore_Migrating( copy.deepcopy(ConfigDict), extfns, detailLogging=False, type='testMIG', factoryFn=undertest.createObjectStoreInstance) genericTests.addSampleRows(migratingStore.fromStore, 5, bbString='BB', offset=0, objectType="MigrationTestObj1") genericTests.addSampleRows(migratingStore.fromStore, 3, bbString='BB', offset=0, objectType="MigrationTestObj2") genericTests.addSampleRows(migratingStore.fromStore, 10, bbString='BB', offset=0, objectType="MigrationTestObj3") #Assert all the data is in from store but not in to store self.assertObjectStoreHasRightNumberOfObjects( migratingStore.fromStore, copy.deepcopy(migratingStoresStartingAmounts)) self.assertObjectStoreHasRightNumberOfObjects(migratingStore.toStore, {}) #When querying migrating store the data must be self.assertObjectStoreHasRightNumberOfObjects( migratingStore, copy.deepcopy(migratingStoresStartingAmounts)) return migratingStore
def test_secondLookupComesFromCache(self): objectType = "CacheTestObj1" undertestCacheObjectStore = undertest.ObjectStore_Caching( ConfigDict, self.getObjectStoreExternalFns(), detailLogging=False, type='testMEM', factoryFn=undertest.createObjectStoreInstance) internalMainObjectStore = undertestCacheObjectStore.mainStore internalCacheObjectStore = undertestCacheObjectStore.cachingStore #Add data to the main store internalMainObjectStore = undertestCacheObjectStore.mainStore genericTests.addSampleRows(internalMainObjectStore, 5, bbString='BB', offset=0, objectType=objectType) objectKey = "1231" #Lookup object from undertest objectKey = "1231" def dbfn(storeConnection): return storeConnection.getObjectJSON(objectType=objectType, objectKey=objectKey) (objectDict, ObjectVersion, creationDate, lastUpdateDate, objectKey ) = undertestCacheObjectStore.executeInsideConnectionContext(dbfn) expected = copy.deepcopy(genericTests.JSONString) expected["AA"] = 1 self.assertEqual(objectDict, expected) #Check it is in cache objectKey = "1231" def dbfn(storeConnection): # Get sample row from cacheStore and make sure it is correct return storeConnection.getObjectJSON(objectType=objectType, objectKey=objectKey) (objectDict, ObjectVersion, creationDate, lastUpdateDate, objectKey ) = internalCacheObjectStore.executeInsideConnectionContext(dbfn) expected = copy.deepcopy(genericTests.JSONString) expected["AA"] = 1 self.assertEqual(objectDict["d"], expected) #change the cache only def changeInCacheFn(connectionContext): obj, _, _, _, _ = connectionContext.getObjectJSON( objectType=objectType, objectKey=objectKey) obj["d"]["BB"] = "BBCacheChange" return connectionContext.saveJSONObject(objectKey, objectType, obj, None) savedVer = internalCacheObjectStore.executeInsideTransaction( changeInCacheFn) #lookup again make sure we get the change def dbfn(storeConnection): return storeConnection.getObjectJSON(objectType=objectType, objectKey=objectKey) (objectDict, ObjectVersion, creationDate, lastUpdateDate, objectKey ) = undertestCacheObjectStore.executeInsideConnectionContext(dbfn) expected = copy.deepcopy(genericTests.JSONString) expected["AA"] = 1 expected["BB"] = "BBCacheChange" self.assertEqual(objectDict, expected)