Ejemplo n.º 1
0
    void CreateTestJournal()
    {
        CAutoPtr<Journal> pJournal;
        KLJRNL_CreateJournal( & pJournal, true );
		
        wstring wstrJrnlPath;
        //KLSTD_GetTempFile( wstrJrnlPath );
        wstrJrnlPath = L"c:\\test\\jrnl\\cool.txt";
        KLSTD_TRACE1(1, L"Will create test journal at \"%s\".\n", wstrJrnlPath.c_str() );
		
        CreationInfo creationInfo;
        creationInfo.bLimitPages = false;
        creationInfo.bBinaryFormat = true;
        creationInfo.pageLimitType = pltRecCount;
        creationInfo.nMaxRecordsInPage = 10000;
		
        pJournal->Open( wstrJrnlPath, CF_OPEN_ALWAYS, ACCESS_FLAGS( AF_WRITE | AF_READ ), creationInfo );
		
        char * szLongBuf = new char[1024];
        Cool2 cool2;
        {
            for( int i = 0; i < 1024; i++ )
            {
#ifdef N_PLAT_NLM
                szLongBuf[i] = 30 + stlp_std::div( i, 30 ).rem;
#else
                szLongBuf[i] = 30 + div( i, 30 ).rem;
#endif
            }
        }
        szLongBuf[1023] = 0;
		
        char szBuf[100];
		
        unsigned long dwTickCount = KLSTD::GetSysTickCount();
		
        for( int i = 0; i < 100000; i++ )
        {
            sprintf( szBuf, "%d", i );
            memcpy( szLongBuf, szBuf, strlen(szBuf) );
            cool2.str = szLongBuf;
            long nId = pJournal->Add( & cool2 );
            pJournal->Flush();
        }
		
        KLSTD_TRACE1( 1, L"Time with flush: %d msec\n", KLSTD::GetSysTickCount() - dwTickCount );
    }
Ejemplo n.º 2
0
    void DoTest( bool bBinary )
    {
		KLSTD_TRACE0(1, L"Obtaining journal object...\n" );
		
        CAutoPtr<Journal> pJournal;
        KLJRNL_CreateJournal( & pJournal, true );
		
        wstring wstrJrnlPath;
        KLSTD_GetTempFile( wstrJrnlPath );
		
        //wstrJrnlPath = L"c:\\test\\jrnl\\cool.txt";
		
        KLSTD_Unlink( wstrJrnlPath.c_str(), false );
        KLSTD_TRACE1(1, L"Will create journal at \"%s\".\n", wstrJrnlPath.c_str() );
		
        CreationInfo creationInfo;
        creationInfo.bLimitPages = false;
        creationInfo.bBinaryFormat = bBinary;
        creationInfo.pageLimitType = pltRecCount;
        creationInfo.nMaxRecordsInPage = 5;
        creationInfo.bUseRecNumIndex = true;
		
        pJournal->Open( wstrJrnlPath, CF_CREATE_ALWAYS, ACCESS_FLAGS( AF_WRITE | AF_READ ), creationInfo );
		
        CAutoPtr<Params> pParams;
        KLPAR_CreateParams( & pParams );
		
        ADD_PARAMS_VALUE( pParams, L"param0", StringValue, L"agent" );
        ADD_PARAMS_VALUE( pParams, L"param1", StringValue, L"kuku01" );
        ADD_PARAMS_VALUE( pParams, L"param2", BoolValue, false );
		
        Cool cool;
		
        cool.intVal = 1;
        cool.charVal = 'c';
        cool.wstrVal = L"Hello";
        //cool.strVal = "Kuku";
		
        for( int i = 0; i < 22; i++ )
        {
            long nId = pJournal->Add( & cool );
        }
		
        pJournal->Close();
        pJournal->Open( wstrJrnlPath, CF_OPEN_EXISTING, ACCESS_FLAGS( AF_WRITE | AF_READ ), creationInfo );
		
        AVP_longlong llSize = pJournal->GetJournalSize();
        KLSTD_TRACE1( 1, L"Journal size: %d bytes\n", long(llSize) );
		
        pJournal->Flush();
		
        KLSTD_TRACE0( 1, L"Getting records - check MoveToRecordN...\n" );
		
        pJournal->DeleteOlderThanID( 3 );
        pJournal->Flush();
		
        int nRecCount = pJournal->GetRecordCount();
		
        long nTestCount = 0;
        pJournal->MoveToRecordN( 5 );
        while( ! pJournal->IsEOF() )
        {
            long nId;
            Cool cool;
            pJournal->GetCurrent( nId, & cool );
            bool bTest = false;
            if( nId > 11 && nId < 15 )
            {
                cool.strVal = "Hello guys how you doing";
                pJournal->Update( & cool );
            }
            KLSTD_TRACE2( 1, L"Id: %d, data: %S\n", nId, cool.strVal.c_str() );
            nTestCount++;
            pJournal->Next();
        } 
		
        if( nTestCount != 14 )
        {
            KLSTD_TRACE0( 1, L"Error with MoveToRecordN\n" );
            KLSTD_THROW(STDE_BADFORMAT);
        }
		
		
        KLSTD_TRACE0( 1, L"Getting records - check SetIterator...\n" );
        pJournal->SetIterator(3);
		
        long nId;
        nTestCount = 0;
        while( ! pJournal->IsEOF() )
        {
            Cool cool;
            pJournal->GetCurrent( nId, & cool );
            KLSTD_TRACE2( 1, L"Id: %d, data: %S\n", nId, cool.strVal.c_str() );
            pJournal->Next();
            nTestCount++;
        } 
		
        if( nTestCount != 19 )
        {
            KLSTD_TRACE0( 1, L"Error with SetIterator\n" );
            KLSTD_THROW(STDE_BADFORMAT);
        }
        
        KLSTD_TRACE2( 1, L"Journal record count: %d, last id is %d\n", pJournal->GetRecordCount(), nId );
		
        //pJournal->DeleteOlderThanID( 10 );
		
        KLSTD_TRACE1( 1, L"Journal record count: %d\n", pJournal->GetRecordCount() );
		
        pJournal->ResetIterator();
        while( ! pJournal->IsEOF() )
        {
            long nId;
            Cool2 cool2;
            pJournal->GetCurrent( nId, & cool2 );
			
            KLSTD_TRACE2( 1, L"Id: %d, data: %S\n", nId, cool2.str.c_str() );
            pJournal->Next();
        }
		
        pair<long, long> range;
        vector< pair<long, long> > vectRanges;
		
        range.first = 2;
        range.second = 4;
        vectRanges.push_back( range );
		
        range.first = 21;
        range.second = 7;
        vectRanges.push_back( range );
		
		
        pJournal->DeleteRanges( vectRanges );
		
        pJournal->Flush();
		
        pJournal->DeleteAll();
		
        pJournal->DeleteOlderThanID( 10 );
		
        pJournal->CloseAndRemoveFiles();
    }
Ejemplo n.º 3
0
    void CheckSimpleJournal()
    {
		KLSTD_TRACE0(1, L"Obtaining journal object...\n" );
		
        CAutoPtr<Journal> pJournal;
        KLJRNL_CreateSimpleJournal( & pJournal, true );
		
        wstring wstrJrnlPath;
        //wstrJrnlPath = L"c:\\test\\jrnl\\cool.txt";
        KLSTD_GetTempFile( wstrJrnlPath );
        KLSTD_Unlink( wstrJrnlPath.c_str(), false );
        KLSTD_TRACE1(1, L"Will create journal at \"%s\".\n", wstrJrnlPath.c_str() );
		
        CreationInfo creationInfo;
        creationInfo.bLimitPages = false;
        creationInfo.pageLimitType = pltSize;
        creationInfo.nMaxRecordsInPage = 5;
        creationInfo.nMaxPageSize = 1024;
		
        Cool2 cool2;
		
        pJournal->Open( wstrJrnlPath, CF_OPEN_ALWAYS, ACCESS_FLAGS( AF_READ | AF_WRITE ), creationInfo );
		
        for( int i = 0; i < 20; i++ )
        {
            cool2.intVal = i;
            pJournal->Add( & cool2 );
        }
		
        AVP_longlong llSize = pJournal->GetJournalSize();
        KLSTD_TRACE1( 1, L"Journal size: %d bytes\n", long(llSize) ); 
		
        pJournal->Flush();
		
        bool bFoo = false;
        long nTestCount = 0;
		
        nTestCount = 0;
        pJournal->ResetIterator();
        KLSTD_TRACE0( 1, L"Getting records...\n" );
        while( ! pJournal->IsEOF() )
        {
            long nId;
            Cool2 cool2;
            pJournal->GetCurrent( nId, & cool2 );
			
            bFoo = nId < 5;
			
            KLSTD_TRACE2( 1, L"Id: %d, data: %S\n", nId, cool2.str.c_str() );
			
			
            if( bFoo )
            {
                pJournal->DeleteCurrent();
            } else
            {
                pJournal->Next();
            }
            nTestCount++;
        }
		
        if( nTestCount != 20 )
        {
            KLSTD_THROW(STDE_BADFORMAT);
        }
		
        nTestCount = 0;
        KLSTD_TRACE0( 1, L"Getting records - check MoveToRecordN...\n" );
        pJournal->MoveToRecordN( 30 );
        while( ! pJournal->IsEOF() )
        {
            long nId;
            Cool2 cool2;
            pJournal->GetCurrent( nId, & cool2 );
			
            KLSTD_TRACE2( 1, L"Id: %d, data: %S\n", nId, cool2.str.c_str() );
			
			
            pJournal->Next();
            nTestCount++;
        }
		
        pJournal->Flush();
		
        pJournal->DeleteOlderThanID( 14 );
		
        long nId = 0;
        nTestCount = 0;
        pJournal->ResetIterator();
        while( ! pJournal->IsEOF() )
        {
            Cool2 cool2;
            nTestCount++;
            pJournal->GetCurrent( nId, & cool2 );
            pJournal->Next();
        }
		
        if( ( nId != 20 ) || ( nTestCount != 6 ) )
        {
            KLSTD_THROW(STDE_BADFORMAT);
        }
		
        nTestCount = 0;
        pJournal->SetIterator(15);
        while( ! pJournal->IsEOF() )
        {
            Cool2 cool2;
            nTestCount++;
            pJournal->GetCurrent( nId, & cool2 );
            pJournal->Next();
        }
		
        if( ( nId != 20 ) || ( nTestCount != 6 ) )
        {
            KLSTD_THROW(STDE_BADFORMAT);
        }
		
        pJournal->Flush();
		
        nTestCount = 0;
        pJournal->ResetIterator();
        while( ! pJournal->IsEOF() )
        {
            Cool2 cool2;
            pJournal->GetCurrent( nId, & cool2 );
            if( nTestCount == 5 )
            {
                cool2.intVal = nTestCount * 100;
                pJournal->Update( & cool2 );
            }
            pJournal->Next();
            nTestCount++;
        }
		
        KLSTD_TRACE1( 1, L"Journal record count: %d\n", pJournal->GetRecordCount() );
		
        pJournal->DeleteAll();
		
        pJournal->DeleteOlderThanID( 10 );
		
        //pair<long, long>()
        //pJournal
		
        pJournal->CloseAndRemoveFiles(); 
    }