--[[----------------------------------------------------------------------------

LrDocStoreTypeMigratorVerificationTest.lua

--------------------------------------------------------------------------------

Copyright 2020 Adobe
All Rights Reserved.

NOTICE: All information contained herein is, and remains
the property of Adobe and its suppliers, if any. The intellectual
and technical concepts contained herein are proprietary to Adobe
and its suppliers and are protected by all applicable intellectual
property laws, including trade secret and copyright laws
Dissemination of this information or reproduction of this material
is strictly forbidden unless prior written permission is obtained
from Adobe.

------------------------------------------------------------------------------]]


	-- LrDocStoreMigrator
local WFCatalogTestUtils = require 'WFCatalogTestUtils'

	-- WF.core.self_test
local WFRxTestCase = require 'WFRxTestCase'

	-- WF.core.os
local KSPathUtils = require 'KSPathUtils'
local WFFileUtils = require 'WFFileUtils'

	-- WF.sqlite.doc_store
local WFRxDocStore = require 'WFRxDocStore'

--============================================================================--

local LrDocStoreTypeMigratorVerificationTest = {}

--------------------------------------------------------------------------------

function LrDocStoreTypeMigratorVerificationTest.rxTestBackFillTypeAndSubtypeLuaArchiveStyleCatalog_testPerformance( rxTest )

	rxTest:setTimeLimit( 1600 )
	
	local docStore
	local docStoreFolderPath = KSPathUtils.getStandardFilePath( "home" ) 
	local catalogPath = WFCatalogTestUtils.getCachedCatalogPath("shrunkenCatalogs/luaArchiveStyle")
	local docStorePath = KSPathUtils.child( docStoreFolderPath, "rxTestBackFillTypeAndSubtypeLuaArchiveStyleCatalog-Managed Catalog.mcat" )
	docStorePath = WFFileUtils.ensureFileNameIsUnique( docStorePath )
	
	if not WFFileUtils.exists(docStoreFolderPath) then
		WFFileUtils.mkdir( docStoreFolderPath )
	end
	
	-- Check if catalogs are cached, if they're not cached download them from Artifactory
	rxTest:waitFor( WFCatalogTestUtils.getCatalogsFromArtifactory("shrunkenCatalogs/luaArchiveStyle"))


	-- Copy catalog. This removes the need to redownload it after it has been changed.

	WFFileUtils.copy( catalogPath, docStorePath ) 
	
	-- cleanup after the test
	rxTest:finally( function()
		if docStore then
			docStore.close()
			docStore = nil
		end
		
		if docStorePath then
			WFFileUtils.delete( docStorePath )
			WFFileUtils.delete( docStorePath .. '-shm' )
			WFFileUtils.delete( docStorePath .. '-wal' )
		end
		
	end)
	
	-- Set up docstore
	docStore = WFRxDocStore( docStorePath )

	-- Check the doctore's integrity
	local checkIntegrity = docStore:isCorrupt()
	local obs = rxTest:observe( checkIntegrity )
	obs:expectData('false')	
	
	-- Check docstore content
	local numOfDocsOfTypeAndSubtype = docStore:DEBUG_getNumberOfDocsByTypeAndSubtype()
	obs = rxTest:observe( numOfDocsOfTypeAndSubtype )
	obs:expectData(
	{
		{
			"album",
			"adhoc",
			1,
		},
		{
			"album",
			"cluster",
			1,
		},
		{
			"album",
			"collection",
			1,
		},
		{
			"album",
			"collection_set",
			1,
		},
		{
			"album",
			"project",
			1,
		},
		{
			"album",
			"topic",
			1,
		},
		{
			"album_asset",
			[3] = 1,
		},
		{
			"asset",
			"camera_profile",
			1,
		},
		{
			"asset",
			"image",
			1,
		},
		{
			"asset",
			"person",
			1,
		},
		{
			"asset",
			"preset",
			1,
		},
		{
			"asset",
			"profile",
			1,
		},
		{
			"asset",
			"stack",
			1,
		},
		{
			"asset",
			"task",
			1,
		},
		{
			"asset",
			"video",
			1,
		},
		{
			"catalog",
			"lightroom",
			1,
		},
		{
			"comment",
			"user",
			1,
		},
		{
			"favorite",
			"user",
			1,
		},
		{
			"feedbackuser",
			[3] = 1,
		},
		{
			"gen-album",
			[3] = 1,
		},
		{
			"space",
			"adhoc",
			1,
		},
		{
			"space",
			"gallery",
			1,
		},
		{
			"space",
			"shared",
			1,
		},
		{
			"space_album",
			[3] = 1,
		},
		{
			"stack_asset",
			[3] = 1,
		},
	})
	rxTest:expectOnlyCompleted( docStore:halt() )
					
end

--------------------------------------------------------------------------------
function LrDocStoreTypeMigratorVerificationTest.rxTestBackFillTypeAndSubtypeMessagePackedStyleCatalog_testPerformance( rxTest )

	rxTest:setTimeLimit( 1600 )
	
	local docStore
	local docStoreFolderPath = KSPathUtils.getStandardFilePath( "home" ) 
	local catalogPath = WFCatalogTestUtils.getCachedCatalogPath("shrunkenCatalogs/messagePackedStyle")
	local docStorePath = KSPathUtils.child( docStoreFolderPath, "rxTestBackFillTypeAndSubtypeMessagePackedStyleCatalog-Managed Catalog.mcat" )
	docStorePath = WFFileUtils.ensureFileNameIsUnique( docStorePath )
	
	if not WFFileUtils.exists(docStoreFolderPath) then
		WFFileUtils.mkdir( docStoreFolderPath )
	end
	
	-- Check if catalogs are cached, if they're not cached download them from Artifactory
	rxTest:waitFor( WFCatalogTestUtils.getCatalogsFromArtifactory("shrunkenCatalogs/messagePackedStyle"))


	-- Copy catalog. This removes the need to redownload it after it has been changed.

	WFFileUtils.copy( catalogPath, docStorePath ) 
	
	-- cleanup after the test
	rxTest:finally( function()
		if docStore then
			docStore.close()
			docStore = nil
		end
		
		if docStorePath then
			WFFileUtils.delete( docStorePath )
			WFFileUtils.delete( docStorePath .. '-shm' )
			WFFileUtils.delete( docStorePath .. '-wal' )
		end
	end)
	
	-- Set up docstore
	docStore = WFRxDocStore( docStorePath )

		-- Check the doctore's integrity
	local checkIntegrity = docStore:isCorrupt()
	local obs = rxTest:observe( checkIntegrity )
	obs:expectData('false')	
	
	-- Check docstore content
	local numOfDocsOfTypeAndSubtype = docStore:DEBUG_getNumberOfDocsByTypeAndSubtype()
	obs = rxTest:observe( numOfDocsOfTypeAndSubtype )
	obs:expectData(
	{
		{
			[3] = 1,
		},
		{
			"album",
			"cluster",
			1,
		},
		{
			"album",
			"collection",
			1,
		},
		{
			"album",
			"collection_set",
			1,
		},
		{
			"album",
			"project",
			1,
		},
		{
			"album_asset",
			[3] = 1,
		},
		{
			"asset",
			"image",
			1,
		},
		{
			"asset",
			"person",
			1,
		},
		{
			"asset",
			"video",
			1,
		},
		{
			"gen-album",
			[3] = 1,
		},
		{
			"space",
			"shared",
			1,
		},
		{
			"space_album",
			[3] = 1,
		},
	})
	rxTest:expectOnlyCompleted( docStore:halt() )
					
end

--------------------------------------------------------------------------------
function LrDocStoreTypeMigratorVerificationTest.rxTestBackFillTypeAndSubtypeMixedStyleCatalog_testPerformance( rxTest )

	rxTest:setTimeLimit( 1600 )
	
	local docStore
	local docStoreFolderPath = KSPathUtils.getStandardFilePath( "home" ) 
	local catalogPath = WFCatalogTestUtils.getCachedCatalogPath("shrunkenCatalogs/mixedStyle")
	local docStorePath = KSPathUtils.child( docStoreFolderPath, "rxTestBackFillTypeAndSubtypeMixedStyleCatalog-Managed Catalog.mcat" )
	docStorePath = WFFileUtils.ensureFileNameIsUnique( docStorePath )
	
	if not WFFileUtils.exists(docStoreFolderPath) then
		WFFileUtils.mkdir( docStoreFolderPath )
	end
	
	-- Check if catalogs are cached, if they're not cached download them from Artifactory
	rxTest:waitFor( WFCatalogTestUtils.getCatalogsFromArtifactory("shrunkenCatalogs/mixedStyle"))


	-- Copy catalog. This removes the need to redownload it after it has been changed.

	WFFileUtils.copy( catalogPath, docStorePath ) 
	
	-- cleanup after the test
	rxTest:finally( function()
		if docStore then
			docStore.close()
			docStore = nil
		end
		
		if docStorePath then
			WFFileUtils.delete( docStorePath )
			WFFileUtils.delete( docStorePath .. '-shm' )
			WFFileUtils.delete( docStorePath .. '-wal' )
		end
	end)
	
	-- Set up docstore
	docStore = WFRxDocStore( docStorePath )

		-- Check the doctore's integrity
	local checkIntegrity = docStore:isCorrupt()
	local obs = rxTest:observe( checkIntegrity )
	obs:expectData('false')	
	
	-- Check docstore content
	local numOfDocsOfTypeAndSubtype = docStore:DEBUG_getNumberOfDocsByTypeAndSubtype()
	obs = rxTest:observe( numOfDocsOfTypeAndSubtype )
	obs:expectData({
		{
			"album",
			"collection",
			1,
		},
		{
			"album",
			"collection_set",
			1,
		},
		{
			"album",
			"project",
			1,
		},
		{
			"album_asset",
			[3] = 1,
		},
		{
			"asset",
			"camera_profile",
			1,
		},
		{
			"asset",
			"deleted_image",
			1,
		},
		{
			"asset",
			"image",
			1,
		},
		{
			"asset",
			"layout_segment",
			1,
		},
		{
			"asset",
			"person",
			1,
		},
		{
			"asset",
			"preset",
			1,
		},
		{
			"asset",
			"stack",
			1,
		},
		{
			"asset",
			"task",
			1,
		},
		{
			"asset",
			"video",
			1,
		},
		{
			"catalog",
			"lightroom",
			1,
		},
		{
			"comment",
			"user",
			1,
		},
		{
			"error",
			"InputValidationError",
			1,
		},
		{
			"error",
			"NotHeadRevisionPreconditionError",
			1,
		},
		{
			"error",
			"RevisionExistsError",
			1,
		},
		{
			"favorite",
			"user",
			1,
		},
		{
			"feedbackuser",
			[3] = 1,
		},
		{
			"space",
			"adhoc",
			1,
		},
		{
			"space",
			"gallery",
			1,
		},
		{
			"space",
			"shared",
			1,
		},
		{
			"space_album",
			[3] = 1,
		},
		{
			"space_user",
			[3] = 1,
		},
		{
			"spaceinvite",
			"request",
			1,
		},
		{
			"spaceinvite",
			"single_use",
			1,
		},
		{
			"stack_asset",
			[3] = 1,
		},
	})	
	rxTest:expectOnlyCompleted( docStore:halt() )

end

--------------------------------------------------------------------------------
function LrDocStoreTypeMigratorVerificationTest.rxTestBackFillTypeAndSubtypeJreurCatalog_testPerformance( rxTest )

	rxTest:setTimeLimit( 1700 )
	
	local docStore
	local docStoreFolderPath = KSPathUtils.getStandardFilePath( "home" ) 
	local catalogPath = WFCatalogTestUtils.getCachedCatalogPath("Jreur")
	local docStorePath = KSPathUtils.child( docStoreFolderPath, "rxTestBackFillTypeAndSubtypeJreurCatalog-Managed Catalog.mcat" )
	docStorePath = WFFileUtils.ensureFileNameIsUnique( docStorePath )
	
	if not WFFileUtils.exists(docStoreFolderPath) then
		WFFileUtils.mkdir( docStoreFolderPath )
	end
	
	-- Check if catalogs are cached, if they're not cached download them from Artifactory
	rxTest:waitFor( WFCatalogTestUtils.getCatalogsFromArtifactory("Jreur"))


	-- Copy catalog. This removes the need to redownload it after it has been changed.

	WFFileUtils.copy( catalogPath, docStorePath ) 
	
	-- cleanup after the test
	rxTest:finally( function()
		if docStore then
			docStore.close()
			docStore = nil
		end
		
		if docStorePath then
			WFFileUtils.delete( docStorePath )
			WFFileUtils.delete( docStorePath .. '-shm' )
			WFFileUtils.delete( docStorePath .. '-wal' )
		end
	end)
	
	-- Set up docstore
	docStore = WFRxDocStore( docStorePath )

		-- Check the doctore's integrity
	local checkIntegrity = docStore:isCorrupt()
	local obs = rxTest:observe( checkIntegrity )
	obs:expectData('false')	
	
	-- Check docstore content
	local numOfDocsOfTypeAndSubtype = docStore:DEBUG_getNumberOfDocsByTypeAndSubtype()
	obs = rxTest:observe( numOfDocsOfTypeAndSubtype )
	obs:expectData({
		{
			[3] = 9,
		},
		{
			"album",
			"collection",
			256,
		},
		{
			"album",
			"collection_set",
			18,
		},
		{
			"album_asset",
			[3] = 236617,
		},
		{
			"asset",
			"deleted_image",
			18,
		},
		{
			"asset",
			"deleted_video",
			2,
		},
		{
			"asset",
			"image",
			170343,
		},
		{
			"asset",
			"layout_segment",
			669,
		},
		{
			"asset",
			"person",
			23013,
		},
		{
			"asset",
			"preset",
			1,
		},
		{
			"asset",
			"stack",
			62,
		},
		{
			"asset",
			"task",
			2,
		},
		{
			"asset",
			"video",
			1867,
		},
		{
			"catalog",
			"lightroom",
			1,
		},
		{
			"comment",
			"user",
			32,
		},
		{
			"error",
			"NotHeadRevisionPreconditionError",
			162,
		},
		{
			"error",
			"RevisionExistsError",
			17146,
		},
		{
			"favorite",
			"user",
			304,
		},
		{
			"feedbackuser",
			[3] = 121,
		},
		{
			"space",
			"adhoc",
			4,
		},
		{
			"space",
			"shared",
			76,
		},
		{
			"space_album",
			[3] = 81,
		},
		{
			"space_user",
			[3] = 102,
		},
		{
			"spaceinvite",
			"request",
			3,
		},
		{
			"spaceinvite",
			"single_use",
			18,
		},
		{
			"stack_asset",
			[3] = 220,
		},
		{
			"version",
			"edit",
			11070,
		},
		{
			"watermark",
			"text",
			1,
		},
	})	
	rxTest:expectOnlyCompleted( docStore:halt() )

end
--------------------------------------------------------------------------------
function LrDocStoreTypeMigratorVerificationTest.rxTestBackFillTypeAndSubtypeBsutherlCatalog_testPerformance( rxTest )

	rxTest:setTimeLimit( 1700 )
	
	local docStore
	local docStoreFolderPath = KSPathUtils.getStandardFilePath( "home" ) 
	local catalogPath = WFCatalogTestUtils.getCachedCatalogPath("bsutherl")
	local docStorePath = KSPathUtils.child( docStoreFolderPath, "rxTestBackFillTypeAndSubtypeBsutherlCatalog-Managed Catalog.mcat" )
	docStorePath = WFFileUtils.ensureFileNameIsUnique( docStorePath )
	
	if not WFFileUtils.exists(docStoreFolderPath) then
		WFFileUtils.mkdir( docStoreFolderPath )
	end
	
	-- Check if catalogs are cached, if they're not cached download them from Artifactory
	rxTest:waitFor( WFCatalogTestUtils.getCatalogsFromArtifactory("bsutherl"))


	-- Copy catalog. This removes the need to redownload it after it has been changed.

	WFFileUtils.copy( catalogPath, docStorePath ) 
	
	-- cleanup after the test
	rxTest:finally( function()
		if docStore then
			docStore.close()
			docStore = nil
		end
		
		if docStorePath then
			WFFileUtils.delete( docStorePath )
			WFFileUtils.delete( docStorePath .. '-shm' )
			WFFileUtils.delete( docStorePath .. '-wal' )
		end
	end)
	
	-- Set up docstore
	docStore = WFRxDocStore( docStorePath )

		-- Check the doctore's integrity
	local checkIntegrity = docStore:isCorrupt()
	local obs = rxTest:observe( checkIntegrity )
	obs:expectData('false')	
	
	-- Check docstore content
	local numOfDocsOfTypeAndSubtype = docStore:DEBUG_getNumberOfDocsByTypeAndSubtype()
	obs = rxTest:observe( numOfDocsOfTypeAndSubtype )
	obs:expectData({
	{
			"album",
			"collection",
			146,
		},
		{
			"album",
			"collection_set",
			11,
		},
		{
			"album",
			"topic",
			2,
		},
		{
			"album_asset",
			[3] = 10363,
		},
		{
			"asset",
			"camera_profile",
			1302,
		},
		{
			"asset",
			"deleted_image",
			20,
		},
		{
			"asset",
			"image",
			12047,
		},
		{
			"asset",
			"layout_segment",
			40,
		},
		{
			"asset",
			"person",
			1816,
		},
		{
			"asset",
			"preset",
			12,
		},
		{
			"asset",
			"stack",
			45,
		},
		{
			"asset",
			"task",
			2,
		},
		{
			"asset",
			"video",
			126,
		},
		{
			"catalog",
			"lightroom",
			1,
		},
		{
			"comment",
			"user",
			68,
		},
		{
			"error",
			"NotHeadRevisionPreconditionError",
			1,
		},
		{
			"error",
			"RevisionExistsError",
			73,
		},
		{
			"favorite",
			"user",
			905,
		},
		{
			"feedbackuser",
			[3] = 590,
		},
		{
			"space",
			"adhoc",
			4,
		},
		{
			"space",
			"shared",
			90,
		},
		{
			"space_album",
			[3] = 94,
		},
		{
			"space_user",
			[3] = 529,
		},
		{
			"spaceinvite",
			"request",
			5,
		},
		{
			"spaceinvite",
			"single_use",
			29,
		},
		{
			"stack_asset",
			[3] = 160,
		},
		{
			"version",
			"edit",
			206,
		},
		{
			"version",
			"version",
			1,
		},
		{
			"watermark",
			"text",
			4,
		},
	})	
	rxTest:expectOnlyCompleted( docStore:halt() )

end
--------------------------------------------------------------------------------
function LrDocStoreTypeMigratorVerificationTest.rxTestBackFillTypeAndSubtypeCmarbleCatalog_testPerformance( rxTest )

	rxTest:setTimeLimit( 1700 )
	
	local docStore
	local docStoreFolderPath = KSPathUtils.getStandardFilePath( "home" ) 
	local catalogPath = WFCatalogTestUtils.getCachedCatalogPath("cmarble")
	local docStorePath = KSPathUtils.child( docStoreFolderPath, "rxTestBackFillTypeAndSubtypeCmarbleCatalog-Managed Catalog.mcat" )
	docStorePath = WFFileUtils.ensureFileNameIsUnique( docStorePath )
	
	if not WFFileUtils.exists(docStoreFolderPath) then
		WFFileUtils.mkdir( docStoreFolderPath )
	end
	
	-- Check if catalogs are cached, if they're not cached download them from Artifactory
	rxTest:waitFor( WFCatalogTestUtils.getCatalogsFromArtifactory("cmarble"))


	-- Copy catalog. This removes the need to redownload it after it has been changed.

	WFFileUtils.copy( catalogPath, docStorePath ) 
	
	-- cleanup after the test
	rxTest:finally( function()
		if docStore then
			docStore.close()
			docStore = nil
		end
		
		if docStorePath then
			WFFileUtils.delete( docStorePath )
			WFFileUtils.delete( docStorePath .. '-shm' )
			WFFileUtils.delete( docStorePath .. '-wal' )
		end
	end)
	
	-- Set up docstore
	docStore = WFRxDocStore( docStorePath )

		-- Check the doctore's integrity
	local checkIntegrity = docStore:isCorrupt()
	local obs = rxTest:observe( checkIntegrity )
	obs:expectData('false')	
	
	-- Check docstore content
	local numOfDocsOfTypeAndSubtype = docStore:DEBUG_getNumberOfDocsByTypeAndSubtype()
	obs = rxTest:observe( numOfDocsOfTypeAndSubtype )
	obs:expectData({
		{
			"album",
			"collection",
			922,
		},
		{
			"album",
			"collection_set",
			70,
		},
		{
			"album",
			"project",
			26,
		},
		{
			"album_asset",
			[3] = 201934,
		},
		{
			"asset",
			"camera_profile",
			935,
		},
		{
			"asset",
			"deleted_image",
			46,
		},
		{
			"asset",
			"image",
			73545,
		},
		{
			"asset",
			"layout_segment",
			204,
		},
		{
			"asset",
			"person",
			4093,
		},
		{
			"asset",
			"preset",
			575,
		},
		{
			"asset",
			"stack",
			228,
		},
		{
			"asset",
			"task",
			2,
		},
		{
			"asset",
			"video",
			1550,
		},
		{
			"catalog",
			"lightroom",
			1,
		},
		{
			"comment",
			"user",
			81,
		},
		{
			"error",
			"InputValidationError",
			1,
		},
		{
			"error",
			"NotHeadRevisionPreconditionError",
			1,
		},
		{
			"error",
			"RevisionExistsError",
			792,
		},
		{
			"favorite",
			"user",
			872,
		},
		{
			"feedbackuser",
			[3] = 409,
		},
		{
			"space",
			"adhoc",
			6,
		},
		{
			"space",
			"gallery",
			1,
		},
		{
			"space",
			"shared",
			93,
		},
		{
			"space_album",
			[3] = 118,
		},
		{
			"space_user",
			[3] = 335,
		},
		{
			"spaceinvite",
			"request",
			4,
		},
		{
			"spaceinvite",
			"single_use",
			21,
		},
		{
			"stack_asset",
			[3] = 1227,
		},
	})	
	rxTest:expectOnlyCompleted( docStore:halt() )

end
--------------------------------------------------------------------------------
function LrDocStoreTypeMigratorVerificationTest.rxTestBackFillTypeAndSubtypeKcastroCatalog_testPerformance( rxTest )

	rxTest:setTimeLimit( 1700 )
	
	local docStore
	local docStoreFolderPath = KSPathUtils.getStandardFilePath( "home" ) 
	local catalogPath = WFCatalogTestUtils.getCachedCatalogPath("kcastro")
	local docStorePath = KSPathUtils.child( docStoreFolderPath, "rxTestBackFillTypeAndSubtypeKcastroCatalog-Managed Catalog.mcat" )
	docStorePath = WFFileUtils.ensureFileNameIsUnique( docStorePath )
	
	if not WFFileUtils.exists(docStoreFolderPath) then
		WFFileUtils.mkdir( docStoreFolderPath )
	end
	
	-- Check if catalogs are cached, if they're not cached download them from Artifactory
	rxTest:waitFor( WFCatalogTestUtils.getCatalogsFromArtifactory("kcastro"))


	-- Copy catalog. This removes the need to redownload it after it has been changed.

	WFFileUtils.copy( catalogPath, docStorePath ) 
	
	-- cleanup after the test
	rxTest:finally( function()
		if docStore then
			docStore.close()
			docStore = nil
		end
		
		if docStorePath then
			WFFileUtils.delete( docStorePath )
			WFFileUtils.delete( docStorePath .. '-shm' )
			WFFileUtils.delete( docStorePath .. '-wal' )
		end
	end)
	
	-- Set up docstore
	docStore = WFRxDocStore( docStorePath )

		-- Check the doctore's integrity
	local checkIntegrity = docStore:isCorrupt()
	local obs = rxTest:observe( checkIntegrity )
	obs:expectData('false')	
	
	-- Check docstore content
	local numOfDocsOfTypeAndSubtype = docStore:DEBUG_getNumberOfDocsByTypeAndSubtype()
	obs = rxTest:observe( numOfDocsOfTypeAndSubtype )
	obs:expectData({
		{
			[3] = 13,
		},
		{
			"album",
			"cluster",
			1,
		},
		{
			"album",
			"collection",
			1120,
		},
		{
			"album",
			"collection_set",
			179,
		},
		{
			"album",
			"project",
			1,
		},
		{
			"album",
			"topic",
			1098,
		},
		{
			"album_asset",
			[3] = 178817,
		},
		{
			"asset",
			"camera_profile",
			9090,
		},
		{
			"asset",
			"deleted_image",
			5,
		},
		{
			"asset",
			"image",
			157013,
		},
		{
			"asset",
			"layout_segment",
			13,
		},
		{
			"asset",
			"person",
			14582,
		},
		{
			"asset",
			"preset",
			2491,
		},
		{
			"asset",
			"profile",
			37,
		},
		{
			"asset",
			"stack",
			95,
		},
		{
			"asset",
			"task",
			2,
		},
		{
			"asset",
			"video",
			34,
		},
		{
			"catalog",
			"lightroom",
			1,
		},
		{
			"comment",
			"user",
			14,
		},
		{
			"error",
			"NotHeadRevisionPreconditionError",
			540,
		},
		{
			"error",
			"RevisionExistsError",
			2912,
		},
		{
			"favorite",
			"user",
			230,
		},
		{
			"feedbackuser",
			[3] = 124,
		},
		{
			"space",
			"gallery",
			1,
		},
		{
			"space",
			"review",
			1,
		},
		{
			"space",
			"shared",
			28,
		},
		{
			"space_album",
			[3] = 29,
		},
		{
			"space_user",
			[3] = 104,
		},
		{
			"spaceinvite",
			"request",
			1,
		},
		{
			"spaceinvite",
			"single_use",
			1,
		},
		{
			"stack_asset",
			[3] = 321,
		},
		{
			"version",
			"edit",
			4481,
		},
		{
			"watermark",
			"text",
			1,
		},
	})	
	rxTest:expectOnlyCompleted( docStore:halt() )

end
--------------------------------------------------------------------------------
function LrDocStoreTypeMigratorVerificationTest.rxTestBackFillTypeAndSubtypeRcoencasCatalog_testPerformance( rxTest )

	rxTest:setTimeLimit( 1700 )
	
	local docStore
	local docStoreFolderPath = KSPathUtils.getStandardFilePath( "home" ) 
	local catalogPath = WFCatalogTestUtils.getCachedCatalogPath("rcoencas")
	local docStorePath = KSPathUtils.child( docStoreFolderPath, "rxTestBackFillTypeAndSubtypeRcoencasCatalog-Managed Catalog.mcat" )
	docStorePath = WFFileUtils.ensureFileNameIsUnique( docStorePath )
	
	if not WFFileUtils.exists(docStoreFolderPath) then
		WFFileUtils.mkdir( docStoreFolderPath )
	end
	
	-- Check if catalogs are cached, if they're not cached download them from Artifactory
	rxTest:waitFor( WFCatalogTestUtils.getCatalogsFromArtifactory("rcoencas"))


	-- Copy catalog. This removes the need to redownload it after it has been changed.

	WFFileUtils.copy( catalogPath, docStorePath ) 
	
	-- cleanup after the test
	rxTest:finally( function()
		if docStore then
			docStore.close()
			docStore = nil
		end
		
		if docStorePath then
			WFFileUtils.delete( docStorePath )
			WFFileUtils.delete( docStorePath .. '-shm' )
			WFFileUtils.delete( docStorePath .. '-wal' )
		end
	end)
	
	-- Set up docstore
	docStore = WFRxDocStore( docStorePath )

		-- Check the doctore's integrity
	local checkIntegrity = docStore:isCorrupt()
	local obs = rxTest:observe( checkIntegrity )
	obs:expectData('false')	
	
	-- Check docstore content
	local numOfDocsOfTypeAndSubtype = docStore:DEBUG_getNumberOfDocsByTypeAndSubtype()
	obs = rxTest:observe( numOfDocsOfTypeAndSubtype )
	obs:expectData({
		{
			"album",
			"cluster",
			1,
		},
		{
			"album",
			"collection",
			597,
		},
		{
			"album",
			"collection_set",
			17,
		},
		{
			"album",
			"project",
			35,
		},
		{
			"album",
			"topic",
			1722,
		},
		{
			"album_asset",
			[3] = 92769,
		},
		{
			"asset",
			"camera_profile",
			1904,
		},
		{
			"asset",
			"deleted_image",
			1,
		},
		{
			"asset",
			"image",
			49881,
		},
		{
			"asset",
			"layout_segment",
			221,
		},
		{
			"asset",
			"person",
			5731,
		},
		{
			"asset",
			"preset",
			2656,
		},
		{
			"asset",
			"profile",
			17,
		},
		{
			"asset",
			"stack",
			14,
		},
		{
			"asset",
			"task",
			5,
		},
		{
			"asset",
			"video",
			1445,
		},
		{
			"catalog",
			"lightroom",
			1,
		},
		{
			"comment",
			"user",
			529,
		},
		{
			"error",
			"RevisionExistsError",
			22,
		},
		{
			"favorite",
			"user",
			1138,
		},
		{
			"feedbackuser",
			[3] = 964,
		},
		{
			"space",
			"adhoc",
			90,
		},
		{
			"space",
			"gallery",
			1,
		},
		{
			"space",
			"review",
			22,
		},
		{
			"space",
			"shared",
			490,
		},
		{
			"space_album",
			[3] = 626,
		},
		{
			"space_user",
			[3] = 903,
		},
		{
			"spaceinvite",
			"request",
			128,
		},
		{
			"spaceinvite",
			"single_use",
			90,
		},
		{
			"stack_asset",
			[3] = 56,
		},
		{
			"version",
			"edit",
			34,
		},
		{
			"watermark",
			"text",
			1,
		},
	})	
	rxTest:expectOnlyCompleted( docStore:halt() )

end
--------------------------------------------------------------------------------
function LrDocStoreTypeMigratorVerificationTest.rxTestBackFillTypeAndSubtypeHaliuMac2_4_1Catalog_testPerformance( rxTest )

	rxTest:setTimeLimit( 1700 )
	
	local docStore
	local docStoreFolderPath = KSPathUtils.getStandardFilePath( "home" ) 
	local catalogPath = WFCatalogTestUtils.getCachedCatalogPath("haliu/2.4.1mac")
	local docStorePath = KSPathUtils.child( docStoreFolderPath, "rxTestBackFillTypeAndSubtypeHaliuMac2_4_1Catalog-Managed Catalog.mcat" )
	docStorePath = WFFileUtils.ensureFileNameIsUnique( docStorePath )
	
	if not WFFileUtils.exists(docStoreFolderPath) then
		WFFileUtils.mkdir( docStoreFolderPath )
	end
	
	-- Check if catalogs are cached, if they're not cached download them from Artifactory
	rxTest:waitFor( WFCatalogTestUtils.getCatalogsFromArtifactory("haliu/2.4.1mac"))


	-- Copy catalog. This removes the need to redownload it after it has been changed.

	WFFileUtils.copy( catalogPath, docStorePath ) 
	
	-- cleanup after the test
	rxTest:finally( function()
		if docStore then
			docStore.close()
			docStore = nil
		end
		
		if docStorePath then
			WFFileUtils.delete( docStorePath )
			WFFileUtils.delete( docStorePath .. '-shm' )
			WFFileUtils.delete( docStorePath .. '-wal' )
		end
	end)
	
	-- Set up docstore
	docStore = WFRxDocStore( docStorePath )

		-- Check the doctore's integrity
	local checkIntegrity = docStore:isCorrupt()
	local obs = rxTest:observe( checkIntegrity )
	obs:expectData('false')	
	
	-- Check docstore content
	local numOfDocsOfTypeAndSubtype = docStore:DEBUG_getNumberOfDocsByTypeAndSubtype()
	obs = rxTest:observe( numOfDocsOfTypeAndSubtype )
	obs:expectData({
		{
			"album",
			"collection",
			203,
		},
		{
			"album",
			"collection_set",
			25,
		},
		{
			"album",
			"project",
			3,
		},
		{
			"album",
			"topic",
			2,
		},
		{
			"album_asset",
			[3] = 207476,
		},
		{
			"asset",
			"deleted_image",
			1,
		},
		{
			"asset",
			"image",
			194607,
		},
		{
			"asset",
			"layout_segment",
			144,
		},
		{
			"asset",
			"person",
			21482,
		},
		{
			"asset",
			"preset",
			36,
		},
		{
			"asset",
			"profile",
			77,
		},
		{
			"asset",
			"stack",
			454,
		},
		{
			"asset",
			"task",
			3,
		},
		{
			"asset",
			"video",
			2195,
		},
		{
			"catalog",
			"lightroom",
			1,
		},
		{
			"comment",
			"user",
			76,
		},
		{
			"favorite",
			"user",
			476,
		},
		{
			"feedbackuser",
			[3] = 51,
		},
		{
			"space",
			"adhoc",
			15,
		},
		{
			"space",
			"gallery",
			1,
		},
		{
			"space",
			"shared",
			126,
		},
		{
			"space_album",
			[3] = 163,
		},
		{
			"space_user",
			[3] = 3,
		},
		{
			"spaceinvite",
			"single_use",
			7,
		},
		{
			"stack_asset",
			[3] = 1973,
		},
		{
			"version",
			"edit",
			22,
		},
	})	
	rxTest:expectOnlyCompleted( docStore:halt() )

end
--------------------------------------------------------------------------------
function LrDocStoreTypeMigratorVerificationTest.rxTestBackFillTypeAndSubtypeHaliuMac4_3Catalog_testPerformance( rxTest )

	rxTest:setTimeLimit( 1700 )
	
	local docStore
	local docStoreFolderPath = KSPathUtils.getStandardFilePath( "home" ) 
	local catalogPath = WFCatalogTestUtils.getCachedCatalogPath("haliu/4_mac")
	local docStorePath = KSPathUtils.child( docStoreFolderPath, "rxTestBackFillTypeAndSubtypeHaliuMac4_3Catalog-Managed Catalog.mcat" )
	docStorePath = WFFileUtils.ensureFileNameIsUnique( docStorePath )
	
	if not WFFileUtils.exists(docStoreFolderPath) then
		WFFileUtils.mkdir( docStoreFolderPath )
	end
	
	-- Check if catalogs are cached, if they're not cached download them from Artifactory
	rxTest:waitFor( WFCatalogTestUtils.getCatalogsFromArtifactory("haliu/4_mac"))


	-- Copy catalog. This removes the need to redownload it after it has been changed.

	WFFileUtils.copy( catalogPath, docStorePath ) 
	
	-- cleanup after the test
	rxTest:finally( function()
		if docStore then
			docStore.close()
			docStore = nil
		end
		
		if docStorePath then
			WFFileUtils.delete( docStorePath )
			WFFileUtils.delete( docStorePath .. '-shm' )
			WFFileUtils.delete( docStorePath .. '-wal' )
		end
	end)
	
	-- Set up docstore
	docStore = WFRxDocStore( docStorePath )

		-- Check the doctore's integrity
	local checkIntegrity = docStore:isCorrupt()
	local obs = rxTest:observe( checkIntegrity )
	obs:expectData('false')	
	
	-- Check docstore content
	local numOfDocsOfTypeAndSubtype = docStore:DEBUG_getNumberOfDocsByTypeAndSubtype()
	obs = rxTest:observe( numOfDocsOfTypeAndSubtype )
	obs:expectData({
		{
			"album",
			"collection",
			134,
		},
		{
			"album",
			"collection_set",
			1,
		},
		{
			"album",
			"project",
			3,
		},
		{
			"album_asset",
			[3] = 10491,
		},
		{
			"asset",
			"camera_profile",
			1,
		},
		{
			"asset",
			"image",
			17444,
		},
		{
			"asset",
			"person",
			1403,
		},
		{
			"asset",
			"preset",
			3,
		},
		{
			"asset",
			"stack",
			81,
		},
		{
			"asset",
			"video",
			131,
		},
		{
			"catalog",
			"lightroom",
			1,
		},
		{
			"comment",
			"user",
			512,
		},
		{
			"favorite",
			"user",
			353,
		},
		{
			"feedbackuser",
			[3] = 468,
		},
		{
			"space",
			"shared",
			132,
		},
		{
			"space_album",
			[3] = 129,
		},
		{
			"space_user",
			[3] = 452,
		},
		{
			"spaceinvite",
			"request",
			3,
		},
		{
			"spaceinvite",
			"single_use",
			65,
		},
		{
			"stack_asset",
			[3] = 635,
		},
		{
			"version",
			"edit",
			1602,
		},
		{
			"watermark",
			"text",
			1,
		},
	})	
	rxTest:expectOnlyCompleted( docStore:halt() )

end
--------------------------------------------------------------------------------
function LrDocStoreTypeMigratorVerificationTest.rxTestBackFillTypeAndSubtypeHaliuLrA6_2Catalog_testPerformance( rxTest )

	rxTest:setTimeLimit( 1700 )
	
	local docStore
	local docStoreFolderPath = KSPathUtils.getStandardFilePath( "home" ) 
	local catalogPath = WFCatalogTestUtils.getCachedCatalogPath("haliu/6.2LrA")
	local docStorePath = KSPathUtils.child( docStoreFolderPath, "rxTestBackFillTypeAndSubtypeHaliuLrA6_2Catalog-Managed Catalog.mcat" )
	docStorePath = WFFileUtils.ensureFileNameIsUnique( docStorePath )
	
	if not WFFileUtils.exists(docStoreFolderPath) then
		WFFileUtils.mkdir( docStoreFolderPath )
	end
	
	-- Check if catalogs are cached, if they're not cached download them from Artifactory
	rxTest:waitFor( WFCatalogTestUtils.getCatalogsFromArtifactory("haliu/6.2LrA"))


	-- Copy catalog. This removes the need to redownload it after it has been changed.

	WFFileUtils.copy( catalogPath, docStorePath ) 
	
	-- cleanup after the test
	rxTest:finally( function()
		if docStore then
			docStore.close()
			docStore = nil
		end
		
		if docStorePath then
			WFFileUtils.delete( docStorePath )
			WFFileUtils.delete( docStorePath .. '-shm' )
			WFFileUtils.delete( docStorePath .. '-wal' )
		end
	end)
	
	-- Set up docstore
	docStore = WFRxDocStore( docStorePath )

		-- Check the doctore's integrity
	local checkIntegrity = docStore:isCorrupt()
	local obs = rxTest:observe( checkIntegrity )
	obs:expectData('false')	
	
	-- Check docstore content
	local numOfDocsOfTypeAndSubtype = docStore:DEBUG_getNumberOfDocsByTypeAndSubtype()
	obs = rxTest:observe( numOfDocsOfTypeAndSubtype )
	obs:expectData({
		{
			"album",
			"collection",
			306,
		},
		{
			"album",
			"collection_set",
			26,
		},
		{
			"album",
			"project",
			3,
		},
		{
			"album",
			"topic",
			2,
		},
		{
			"album_asset",
			[3] = 211438,
		},
		{
			"asset",
			"deleted_image",
			33,
		},
		{
			"asset",
			"image",
			205123,
		},
		{
			"asset",
			"layout_segment",
			144,
		},
		{
			"asset",
			"person",
			22112,
		},
		{
			"asset",
			"preset",
			36,
		},
		{
			"asset",
			"profile",
			77,
		},
		{
			"asset",
			"stack",
			903,
		},
		{
			"asset",
			"task",
			3,
		},
		{
			"asset",
			"video",
			2278,
		},
		{
			"catalog",
			"lightroom",
			1,
		},
		{
			"comment",
			"user",
			442,
		},
		{
			"favorite",
			"user",
			2635,
		},
		{
			"feedbackuser",
			[3] = 1118,
		},
		{
			"space",
			"adhoc",
			15,
		},
		{
			"space",
			"gallery",
			1,
		},
		{
			"space",
			"shared",
			196,
		},
		{
			"space_album",
			[3] = 233,
		},
		{
			"space_user",
			[3] = 885,
		},
		{
			"spaceinvite",
			"single_use",
			5,
		},
		{
			"stack_asset",
			[3] = 3770,
		},
		{
			"version",
			"edit",
			2859,
		},
		{
			"watermark",
			"text",
			1,
		},
	})	
	rxTest:expectOnlyCompleted( docStore:halt() )

end
--------------------------------------------------------------------------------

return WFRxTestCase.wrapSuite( LrDocStoreTypeMigratorVerificationTest )