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 aDeleteRecords); |
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(); |
388 err = ::StmtExec(stmtHandle); |
392 err = ::StmtExec(stmtHandle); |
389 TEST2(err, KErrNone); |
393 TEST2(err, KErrNone); |
390 ::FinalizeStmtHandle(stmtHandle); |
394 ::FinalizeStmtHandle(stmtHandle); |
391 } |
395 } |
392 } |
396 } |
|
397 |
|
398 //Creates a test database (with KDbName name). The page size is 1KB. |
|
399 void CSqlCompactTestActive::CreateTestDatabase2() |
|
400 { |
|
401 //Create the database |
|
402 const TInt KPageSize = 1024; |
|
403 _LIT8(KConfigStr, "page_size="); |
|
404 TBuf8<100> config; |
|
405 config.Copy(KConfigStr); |
|
406 config.AppendNum(KPageSize); |
|
407 TInt err = KErrNone; |
|
408 err = ::CreateDbHandle8(::FileNameZ8(TheDbName), TheDbHandle); |
|
409 TEST2(err, KErrNone); |
|
410 _LIT8(KCreateTableSql, "CREATE TABLE A(I INTEGER, T TEXT)\x0"); |
|
411 err = ::DbExecStmt8(TheDbHandle, KCreateTableSql); |
|
412 TEST2(err, KErrNone); |
|
413 } |
|
414 |
|
415 // Inserts 1000 records. |
|
416 // The record size is such that there are only two records per page. |
|
417 void CSqlCompactTestActive::PrepareDb(TBool aDeleteRecords) |
|
418 { |
|
419 //Insert records |
|
420 const TInt KRecordCount = 1000; |
|
421 const TInt KTextLen = 400; |
|
422 TBuf<KTextLen> TheText; |
|
423 TBuf<KTextLen + 100> TheSqlBuf; |
|
424 TheText.SetLength(TheText.MaxLength()); |
|
425 TheText.Fill(TChar('A')); |
|
426 for(TInt i=0;i<KRecordCount;++i) |
|
427 { |
|
428 TheSqlBuf.Format(_L("INSERT INTO A VALUES(%d, '%S')"), i + 1, &TheText); |
|
429 _LIT(KZero, "\x0"); |
|
430 TheSqlBuf.Append(KZero); |
|
431 TInt err = ::DbExecStmt16(TheDbHandle, TheSqlBuf); |
|
432 TEST2(err, KErrNone); |
|
433 } |
|
434 if(aDeleteRecords) |
|
435 { |
|
436 //Delete all records to make a lot of free pages. |
|
437 _LIT(KDeleteAll, "DELETE FROM A WHERE 1\x0"); |
|
438 TheSqlBuf = KDeleteAll; |
|
439 TInt err = ::DbExecStmt16(TheDbHandle, TheSqlBuf); |
|
440 TEST2(err, KErrNone); |
|
441 } |
|
442 } |
393 |
443 |
394 void CSqlCompactTestActive::UpdateTestRecords(TInt aOpCount) |
444 void CSqlCompactTestActive::UpdateTestRecords(TInt aOpCount) |
395 { |
445 { |
396 for(TInt i=0;i<aOpCount;++i) |
446 for(TInt i=0;i<aOpCount;++i) |
397 { |
447 { |
917 TheDbHandle = NULL; |
967 TheDbHandle = NULL; |
918 (void)TheFs.Delete(TheDbName); |
968 (void)TheFs.Delete(TheDbName); |
919 PrintInfo(processedPages, KMediaTypeNames[driveInfo.iType], start, end); |
969 PrintInfo(processedPages, KMediaTypeNames[driveInfo.iType], start, end); |
920 } |
970 } |
921 |
971 |
|
972 /** |
|
973 @SYMTestCaseID PDS-SQL-CT-4239 |
|
974 @SYMTestCaseDesc Free page update test. |
|
975 The test creates a database with some records and deletes them all. The records are inserted such that when |
|
976 they get deleted, it leaves a great deal of free pages. |
|
977 Then the test refill the pages which ware empty. After that, the test call ::DbCompact(...) with the number of free |
|
978 pages previously. The free page count should be updated with "0" since all free pages have been refilled since. |
|
979 @SYMTestPriority Medium |
|
980 @SYMTestExpectedResults Test must not fail |
|
981 */ |
|
982 void CSqlCompactTestActive::FreePageUpdateTest() |
|
983 { |
|
984 (void)TheFs.Delete(TheDbName); |
|
985 |
|
986 //Create the database |
|
987 CreateTestDatabase2(); |
|
988 |
|
989 CSqlCompactor* compactor = NULL; |
|
990 TRAPD(err, compactor = CSqlCompactor::NewL(&SqlCreateCompactConnL, KCompactStepInterval)); |
|
991 TEST2(err, KErrNone); |
|
992 TRAP(err, compactor->AddEntryL(TheDbName, TheCompactionSettings)); |
|
993 TEST2(err, KErrNone); |
|
994 |
|
995 //Insert 1000 records and then delete all of them |
|
996 PrepareDb(ETrue); |
|
997 TInt freePageCount = ::FreePageCount(); |
|
998 TEST(freePageCount > KSqlCompactFreePageThresholdKb); |
|
999 TheTest.Printf(_L(" Free pages count = %d\r\n"), freePageCount); |
|
1000 |
|
1001 //Refill the database |
|
1002 PrepareDb(EFalse); |
|
1003 |
|
1004 CSqlCompactEntry* impl = compactor->iEntries[0]; |
|
1005 impl->iPageCount = freePageCount; |
|
1006 err = impl->Compact(); |
|
1007 TEST2(err, KErrNone); |
|
1008 TEST2(impl->iPageCount, 0); |
|
1009 |
|
1010 compactor->ReleaseEntry(TheDbName); |
|
1011 delete compactor; |
|
1012 ::CloseDbHandle(TheDbHandle); |
|
1013 TheDbHandle = NULL; |
|
1014 (void)TheFs.Delete(TheDbName); |
|
1015 } |
|
1016 |
922 ////////////////////////////////////////////////////////////////////////////////////////////////// |
1017 ////////////////////////////////////////////////////////////////////////////////////////////////// |
923 |
1018 |
924 void DoTests() |
1019 void DoTests() |
925 { |
1020 { |
926 CActiveScheduler* scheduler = new CActiveScheduler; |
1021 CActiveScheduler* scheduler = new CActiveScheduler; |
937 TheTest.Next(_L(" @SYMTestCaseID:SYSLIB-SQL-UT-4051 \"File I/O\" error simulation test")); |
1032 TheTest.Next(_L(" @SYMTestCaseID:SYSLIB-SQL-UT-4051 \"File I/O\" error simulation test")); |
938 TheTestActive->FileIoErrTest(); |
1033 TheTestActive->FileIoErrTest(); |
939 |
1034 |
940 TheTest.Next(_L(" @SYMTestCaseID:SYSLIB-SQL-UT-4052 Compaction - performance test")); |
1035 TheTest.Next(_L(" @SYMTestCaseID:SYSLIB-SQL-UT-4052 Compaction - performance test")); |
941 TheTestActive->PerformanceTest(); |
1036 TheTestActive->PerformanceTest(); |
|
1037 |
|
1038 TheTest.Next(_L(" @SYMTestCaseID:PDS-SQL-CT-4239 Free page update test")); |
|
1039 TheTestActive->FreePageUpdateTest(); |
942 |
1040 |
943 CActiveScheduler::Start(); |
1041 CActiveScheduler::Start(); |
944 |
1042 |
945 delete TheTestActive; |
1043 delete TheTestActive; |
946 TheTestActive = NULL; |
1044 TheTestActive = NULL; |