mil.dod.th.ose.logging/test/mil/dod/th/ose/logging/TestLogWriter.java
@Test
    public void testSetBufferSize() throws Exception
    {
        BundleContext context = mock(BundleContext.class);
        Map<String, Object> props = new HashMap<String, Object>(getComponentProperties());
        //set the buffer size to something that isn't the default
        props.put("fileBufferSize", 512);
        when(context.getProperty(LogWriter.LOG_DIR_PROPERTY)).thenReturn("TempLogDir");

        // Setting key value pair
        m_SUT.activate(context, props);
        // This is to mimic the log file created during activation.
        setUpFileNaming();

        // testing that activation/openLogFile methods
        long fileLength = m_LogFile.length();

        // ensuring the file size has not changed
        LogEntry logEntry = mock(LogEntry.class);
        when(logEntry.getBundle()).thenReturn(m_Bundle);
        when(logEntry.getLevel()).thenReturn(LogService.LOG_DEBUG);
        when(logEntry.getTime()).thenReturn(1L);
        m_SUT.logged(logEntry);
        assertThat(m_LogFile.length(), is(fileLength));

        // Filling string to make message for logEntry
        String str = "";
        for (int i = 0; i < 550; i++)
        {
            str += "a";
        }
        when(logEntry.getMessage()).thenReturn(str);
        m_SUT.logged(logEntry);

        // Verify that file size has increased
        fileLength = m_LogFile.length();
        assertThat(fileLength, greaterThan(512L));
    }
/**
     * Verify that the buffer size is used to limit the amount of log messages held in memory before being written
     * to file.
     */
Verify that the buffer size is used to limit the amount of log messages held in memory before being written
to file.
Verify that the buffer size is used to limit the amount of log messages held in memory before being written to file .
@Test
    public void testSetBufferSize() throws Exception
    {
        BundleContext context = mock(BundleContext.class);
        Map<String, Object> props = new HashMap<String, Object>(getComponentProperties());
        props.put("fileBufferSize", 512);
        when(context.getProperty(LogWriter.LOG_DIR_PROPERTY)).thenReturn("TempLogDir");
        m_SUT.activate(context, props);
        setUpFileNaming();
        long fileLength = m_LogFile.length();
        LogEntry logEntry = mock(LogEntry.class);
        when(logEntry.getBundle()).thenReturn(m_Bundle);
        when(logEntry.getLevel()).thenReturn(LogService.LOG_DEBUG);
        when(logEntry.getTime()).thenReturn(1L);
        m_SUT.logged(logEntry);
        assertThat(m_LogFile.length(), is(fileLength));
        String str = "";
        for (int i = 0; i < 550; i++)
        {
            str += "a";
        }
        when(logEntry.getMessage()).thenReturn(str);
        m_SUT.logged(logEntry);
        fileLength = m_LogFile.length();
        assertThat(fileLength, greaterThan(512L));
    }
@ Test public void testSetBufferSize ( ) throws Exception { BundleContext context = mock ( BundleContext . class ) ; Map < String , Object > props = new HashMap < String , Object > ( getComponentProperties ( ) ) ; props . put ( "fileBufferSize" , 512 ) ; when ( context . getProperty ( LogWriter . LOG_DIR_PROPERTY ) ) . thenReturn ( "TempLogDir" ) ; m_SUT . activate ( context , props ) ; setUpFileNaming ( ) ; long fileLength = m_LogFile . length ( ) ; LogEntry logEntry = mock ( LogEntry . class ) ; when ( logEntry . getBundle ( ) ) . thenReturn ( m_Bundle ) ; when ( logEntry . getLevel ( ) ) . thenReturn ( LogService . LOG_DEBUG ) ; when ( logEntry . getTime ( ) ) . thenReturn ( 1L ) ; m_SUT . logged ( logEntry ) ; assertThat ( m_LogFile . length ( ) , is ( fileLength ) ) ; String str = "" ; for ( int i = 0 ; i < 550 ; i ++ ) { str += "a" ; } when ( logEntry . getMessage ( ) ) . thenReturn ( str ) ; m_SUT . logged ( logEntry ) ; fileLength = m_LogFile . length ( ) ; assertThat ( fileLength , greaterThan ( 512L ) ) ; }
Verify that the buffer size is used to limit the amount of log messages held in memory before being written
 to file.
Verify that the buffer size is used to limit the amount of log messages held in memory before being written to file .
//set the buffer size to something that isn't the default // Setting key value pair // This is to mimic the log file created during activation. // testing that activation/openLogFile methods // ensuring the file size has not changed // Filling string to make message for logEntry // Verify that file size has increased