23 #include "SqlSrvStatementUtil.h" |
23 #include "SqlSrvStatementUtil.h" |
24 #include "SqlPanic.h" |
24 #include "SqlPanic.h" |
25 #include "SqlCompact.h" |
25 #include "SqlCompact.h" |
26 #include "SqlCompactConn.h" |
26 #include "SqlCompactConn.h" |
27 #include "SqlCompactEntry.h" |
27 #include "SqlCompactEntry.h" |
|
28 #include "SqlUtil.h" |
28 |
29 |
29 const TInt KOperationCount = 20; |
30 const TInt KOperationCount = 20; |
30 const TInt KFreePageThresholdKb = 5; |
31 const TInt KFreePageThresholdKb = 5; |
31 const TInt KFreePageThreshold = 5; |
32 const TInt KFreePageThreshold = 5; |
32 |
33 |
218 static void New(); |
219 static void New(); |
219 virtual ~CSqlCompactTestActive(); |
220 virtual ~CSqlCompactTestActive(); |
220 void OomTest(); |
221 void OomTest(); |
221 void FileIoErrTest(); |
222 void FileIoErrTest(); |
222 void PerformanceTest(); |
223 void PerformanceTest(); |
|
224 void FreePageUpdateTest(); |
223 |
225 |
224 protected: |
226 protected: |
225 virtual void DoCancel(); |
227 virtual void DoCancel(); |
226 virtual void RunL(); |
228 virtual void RunL(); |
227 virtual TInt RunError(TInt aError); |
229 virtual TInt RunError(TInt aError); |
230 CSqlCompactTestActive(); |
232 CSqlCompactTestActive(); |
231 void Complete(TCommand aNextCommand); |
233 void Complete(TCommand aNextCommand); |
232 void Schedule(TCommand aNextCommand, TTimeIntervalMicroSeconds32 aInterval); |
234 void Schedule(TCommand aNextCommand, TTimeIntervalMicroSeconds32 aInterval); |
233 |
235 |
234 void CreateTestDatabase(); |
236 void CreateTestDatabase(); |
|
237 void CreateTestDatabase2(); |
|
238 void PrepareDb(TBool aNewDb); |
235 void InsertTestRecords(TInt aOpCount = KOperationCount); |
239 void InsertTestRecords(TInt aOpCount = KOperationCount); |
236 void UpdateTestRecords(TInt aOpCount = KOperationCount); |
240 void UpdateTestRecords(TInt aOpCount = KOperationCount); |
237 void DeleteTestRecords(TInt aOpCount = KOperationCount); |
241 void DeleteTestRecords(TInt aOpCount = KOperationCount); |
238 void DeleteTestRecords2(); |
242 void DeleteTestRecords2(); |
239 void TestEnd(); |
243 void TestEnd(); |
389 TEST2(err, KErrNone); |
392 TEST2(err, KErrNone); |
390 ::FinalizeStmtHandle(stmtHandle); |
393 ::FinalizeStmtHandle(stmtHandle); |
391 } |
394 } |
392 } |
395 } |
393 |
396 |
|
397 //Creates a test database (with KDbName name). |
|
398 void CSqlCompactTestActive::CreateTestDatabase2() |
|
399 { |
|
400 //Create the database |
|
401 const TInt KPageSize = 1024; |
|
402 _LIT8(KConfigStr, "page_size="); |
|
403 TBuf8<100> config; |
|
404 config.Copy(KConfigStr); |
|
405 config.AppendNum(KPageSize); |
|
406 TInt err = KErrNone; |
|
407 err = ::CreateDbHandle8(::FileNameZ8(TheDbName), TheDbHandle); |
|
408 TEST2(err, KErrNone); |
|
409 _LIT8(KCreateTableSql, "CREATE TABLE A(I INTEGER, T TEXT)\x0"); |
|
410 err = ::DbExecStmt8(TheDbHandle, KCreateTableSql); |
|
411 TEST2(err, KErrNone); |
|
412 } |
|
413 |
|
414 //Insert 1000 records. The record size is such that there is only two records per page. |
|
415 void CSqlCompactTestActive::PrepareDb(TBool aDeleteRecords) |
|
416 { |
|
417 //Insert records |
|
418 const TInt KRecordCount = 1000; |
|
419 const TInt KTextLen = 400; |
|
420 TBuf<KTextLen> TheText; |
|
421 TBuf<KTextLen + 100> TheSqlBuf; |
|
422 TheText.SetLength(TheText.MaxLength()); |
|
423 TheText.Fill(TChar('A')); |
|
424 for(TInt i=0;i<KRecordCount;++i) |
|
425 { |
|
426 TheSqlBuf.Format(_L("INSERT INTO A VALUES(%d, '%S')"), i + 1, &TheText); |
|
427 _LIT(KZero, "\x0"); |
|
428 TheSqlBuf.Append(KZero); |
|
429 TInt err = ::DbExecStmt16(TheDbHandle, TheSqlBuf); |
|
430 TEST2(err, KErrNone); |
|
431 } |
|
432 if(aDeleteRecords) |
|
433 { |
|
434 //Delete all records to make a lot of free pages. |
|
435 _LIT(KDeleteAll, "DELETE FROM A WHERE 1\x0"); |
|
436 TheSqlBuf = KDeleteAll; |
|
437 TInt err = ::DbExecStmt16(TheDbHandle, TheSqlBuf); |
|
438 TEST2(err, KErrNone); |
|
439 } |
|
440 } |
|
441 |
394 void CSqlCompactTestActive::UpdateTestRecords(TInt aOpCount) |
442 void CSqlCompactTestActive::UpdateTestRecords(TInt aOpCount) |
395 { |
443 { |
396 for(TInt i=0;i<aOpCount;++i) |
444 for(TInt i=0;i<aOpCount;++i) |
397 { |
445 { |
398 _LIT8(KUpdateSql, "UPDATE A SET B=x'1122' WHERE I=%d\x0"); |
446 _LIT8(KUpdateSql, "UPDATE A SET B=x'1122' WHERE I=%d\x0"); |
917 TheDbHandle = NULL; |
965 TheDbHandle = NULL; |
918 (void)TheFs.Delete(TheDbName); |
966 (void)TheFs.Delete(TheDbName); |
919 PrintInfo(processedPages, KMediaTypeNames[driveInfo.iType], start, end); |
967 PrintInfo(processedPages, KMediaTypeNames[driveInfo.iType], start, end); |
920 } |
968 } |
921 |
969 |
|
970 /** |
|
971 @SYMTestCaseID PDS-SQL-CT-4239 |
|
972 @SYMTestCaseDesc Free page update test. |
|
973 The test creates a database with some records and deletes them all. The records are inserted such that when |
|
974 they get deleted, it leaves a great deal of free pages. |
|
975 Then the test refill the pages which ware empty. After that, the test call ::DbCompact(...) with the number of free |
|
976 pages previously. The free page count should be updated with "0" since all free pages have been refilled since. |
|
977 @SYMTestPriority Medium |
|
978 @SYMTestExpectedResults Test must not fail |
|
979 */ |
|
980 void CSqlCompactTestActive::FreePageUpdateTest() |
|
981 { |
|
982 (void)TheFs.Delete(TheDbName); |
|
983 |
|
984 //Create the database with 1000 records and then delete all of them |
|
985 CreateTestDatabase2(); |
|
986 |
|
987 CSqlCompactor* compactor = NULL; |
|
988 TRAPD(err, compactor = CSqlCompactor::NewL(&SqlCreateCompactConnL, KCompactStepInterval)); |
|
989 TEST2(err, KErrNone); |
|
990 TRAP(err, compactor->AddEntryL(TheDbName, TheCompactionSettings)); |
|
991 TEST2(err, KErrNone); |
|
992 |
|
993 PrepareDb(ETrue); |
|
994 TInt freePageCount = ::FreePageCount(); |
|
995 TEST(freePageCount > KSqlCompactFreePageThresholdKb); |
|
996 TheTest.Printf(_L(" Free pages count = %d\r\n"), freePageCount); |
|
997 |
|
998 //Refill the database |
|
999 PrepareDb(EFalse); |
|
1000 |
|
1001 CSqlCompactEntry* impl = compactor->iEntries[0]; |
|
1002 impl->iPageCount = freePageCount; |
|
1003 err = impl->Compact(); |
|
1004 TEST2(err, KErrNone); |
|
1005 TEST2(impl->iPageCount, 0); |
|
1006 |
|
1007 compactor->ReleaseEntry(TheDbName); |
|
1008 delete compactor; |
|
1009 ::CloseDbHandle(TheDbHandle); |
|
1010 TheDbHandle = NULL; |
|
1011 (void)TheFs.Delete(TheDbName); |
|
1012 } |
|
1013 |
922 ////////////////////////////////////////////////////////////////////////////////////////////////// |
1014 ////////////////////////////////////////////////////////////////////////////////////////////////// |
923 |
1015 |
924 void DoTests() |
1016 void DoTests() |
925 { |
1017 { |
926 CActiveScheduler* scheduler = new CActiveScheduler; |
1018 CActiveScheduler* scheduler = new CActiveScheduler; |
937 TheTest.Next(_L(" @SYMTestCaseID:SYSLIB-SQL-UT-4051 \"File I/O\" error simulation test")); |
1029 TheTest.Next(_L(" @SYMTestCaseID:SYSLIB-SQL-UT-4051 \"File I/O\" error simulation test")); |
938 TheTestActive->FileIoErrTest(); |
1030 TheTestActive->FileIoErrTest(); |
939 |
1031 |
940 TheTest.Next(_L(" @SYMTestCaseID:SYSLIB-SQL-UT-4052 Compaction - performance test")); |
1032 TheTest.Next(_L(" @SYMTestCaseID:SYSLIB-SQL-UT-4052 Compaction - performance test")); |
941 TheTestActive->PerformanceTest(); |
1033 TheTestActive->PerformanceTest(); |
|
1034 |
|
1035 TheTest.Next(_L(" @SYMTestCaseID:PDS-SQL-CT-4239 Free page update test")); |
|
1036 TheTestActive->FreePageUpdateTest(); |
942 |
1037 |
943 CActiveScheduler::Start(); |
1038 CActiveScheduler::Start(); |
944 |
1039 |
945 delete TheTestActive; |
1040 delete TheTestActive; |
946 TheTestActive = NULL; |
1041 TheTestActive = NULL; |