persistentstorage/sql/TEST/t_sqlcompact4.cpp
changeset 29 cce6680bbf1c
parent 17 55f2396f6d25
child 55 44f437012c90
equal deleted inserted replaced
28:7a522c0700d3 29:cce6680bbf1c
  1017 	TEST(err >= 0);
  1017 	TEST(err >= 0);
  1018 	TheDb.Close();
  1018 	TheDb.Close();
  1019 	(void)RSqlDatabase::Delete(KDbName);
  1019 	(void)RSqlDatabase::Delete(KDbName);
  1020 	}
  1020 	}
  1021 
  1021 
       
  1022 /**
       
  1023 @SYMTestCaseID			PDS-SQL-CT-4209
       
  1024 @SYMTestCaseDesc		Corrupted database background compaction test.
       
  1025 						The test creates a database, inserts records, then deletes part of the records.
       
  1026 						The free pages count should be big enough to kick off the background compaction.
       
  1027 						But the database is closed immediatelly and then the db file is corrupted in a such
       
  1028 						way that during the "database open" operation the corruption is not detected.
       
  1029 						But the corruption is detected during the background compaction. The SQL server
       
  1030 						should detect during the compaction that the databas eis corrupted and should
       
  1031 						stop compacting the database (and draining the battery). Unfortunatelly, this 
       
  1032 						cannot be tested automatically, so a breakpoint should be set at the User::After()
       
  1033 						call, and then the SQL server side should be debugged in order to berify that the
       
  1034 						background compaction is really stopped for that database.  
       
  1035 @SYMTestPriority		High
       
  1036 @SYMTestActions			Corrupted database background compaction test.
       
  1037 @SYMTestExpectedResults Test must not fail
       
  1038 @SYMDEF					ou1cimx1#406830
       
  1039 */
       
  1040 void CorruptedDbBckgCompactionTest()
       
  1041 	{
       
  1042 	//Step 1: Create a database with some records
       
  1043 	const TInt KOperationCount = 100;
       
  1044 	(void)RSqlDatabase::Delete(KDbName);
       
  1045 	TInt err = TheDb.Create(KDbName);
       
  1046 	TEST2(err, KErrNone);
       
  1047 	err = TheDb.Exec(_L("BEGIN"));
       
  1048 	TEST(err >= 0);
       
  1049 	err = TheDb.Exec(_L("CREATE TABLE A(I INTEGER, T TEXT)"));
       
  1050 	TEST2(err, 1);
       
  1051 	TheText.SetLength(KTextLen);
       
  1052 	TheText.Fill(TChar('A'));
       
  1053 	for(TInt i=0;i<=KOperationCount;++i)	
       
  1054 		{
       
  1055 		TheSqlTexLen.Format(_L("INSERT INTO A VALUES(%d, '%S')"), i + 1, &TheText);
       
  1056 		err = TheDb.Exec(TheSqlTexLen);
       
  1057 		TEST2(err, 1);
       
  1058 		}
       
  1059 	err = TheDb.Exec(_L("COMMIT"));
       
  1060 	TEST(err >= 0);
       
  1061 	//Step 2: Delete some records to free some space
       
  1062 	err = TheDb.Exec(_L("DELETE FROM A WHERE (I % 2) = 0"));
       
  1063 	TEST(err > 0);
       
  1064 	//Step 3: Close the database
       
  1065 	TheDb.Close();
       
  1066 	//Step 4: Corrupt the database
       
  1067     RFs fs;
       
  1068 	err = fs.Connect();
       
  1069 	TEST2(err, KErrNone);
       
  1070 	RFile file;
       
  1071 	err = file.Open(fs, KDbName, EFileRead | EFileWrite); 
       
  1072 	TEST2(err, KErrNone);
       
  1073 	TInt pos = 5000;
       
  1074 	err = file.Seek(ESeekStart, pos);
       
  1075 	TEST2(err, KErrNone);
       
  1076 	TheSqlQuery.SetLength(1000);
       
  1077 	for(TInt i=0;i<30;++i)
       
  1078 		{
       
  1079 		err = file.Write(TheSqlQuery);
       
  1080 		TEST2(err, KErrNone);
       
  1081 		}
       
  1082 	file.Close();
       
  1083 	//Step 5: Check the background compaction. Wait 10 seconds allowing the SQL server to try to compact the
       
  1084 	//        database. The SQL server should detect that the SQL database is corrupted and should stop trying to
       
  1085 	//        compact the database.
       
  1086 	err = TheDb.Open(KDbName);
       
  1087 	TEST2(err, KErrNone);
       
  1088 	User::After(10000000);
       
  1089 	//
       
  1090 	TheDb.Close();
       
  1091 	(void)RSqlDatabase::Delete(KDbName);
       
  1092 	}
       
  1093 
  1022 void DoTestsL()
  1094 void DoTestsL()
  1023 	{
  1095 	{
  1024 	CreateTestDatabase8();
  1096 	CreateTestDatabase8();
  1025 	CalculateMaxCompaction8();
  1097 	CalculateMaxCompaction8();
  1026 	CreateTestDatabase16();
  1098 	CreateTestDatabase16();
  1047 	TheTest.Next(_L(" @SYMTestCaseID:SYSLIB-SQL-UT-4070 Background compaction - load test"));	
  1119 	TheTest.Next(_L(" @SYMTestCaseID:SYSLIB-SQL-UT-4070 Background compaction - load test"));	
  1048 	BackgroundCompactionLoadTest();
  1120 	BackgroundCompactionLoadTest();
  1049 
  1121 
  1050 	TheTest.Next(_L(" @SYMTestCaseID:SYSLIB-SQL-UT-4071 Background compaction activated inside a DDL transaction - test"));	
  1122 	TheTest.Next(_L(" @SYMTestCaseID:SYSLIB-SQL-UT-4071 Background compaction activated inside a DDL transaction - test"));	
  1051 	BackgroundCompactionInDDLTransactionTest();
  1123 	BackgroundCompactionInDDLTransactionTest();
       
  1124 	
       
  1125 	TheTest.Next(_L(" @SYMTestCaseID:PDS-SQL-CT-4209 Corrupted database background compaction test"));	
       
  1126 	CorruptedDbBckgCompactionTest();
  1052 	}
  1127 	}
  1053 
  1128 
  1054 TInt E32Main()
  1129 TInt E32Main()
  1055 	{
  1130 	{
  1056 	TheTest.Title();
  1131 	TheTest.Title();