org.apache.derbyTesting.perf.basic.jdbc
Class BlobAccessTest

java.lang.Object
  extended by junit.framework.Assert
      extended by junit.framework.TestCase
          extended by org.apache.derbyTesting.junit.BaseTestCase
              extended by org.apache.derbyTesting.junit.BaseJDBCTestCase
                  extended by org.apache.derbyTesting.junit.JDBCPerfTestCase
                      extended by org.apache.derbyTesting.perf.basic.jdbc.BlobAccessTest
All Implemented Interfaces:
junit.framework.Test

public class BlobAccessTest
extends JDBCPerfTestCase

A series of tests accessing Blobs in various ways.

These tests are intended to detect Blob performance regressions. Before committing a patch that might change the Blob performance characteristics, first run these tests on a clean build and then with the patch applied. The results can only be compared when both runs are done on the same machine.

The results are the time taken to execute the test. Lower duration is better (improvement). Currently the results are printed to standard out. There is one exception, which is testConcurrency. For this test, the throughput is printed and it will always run for a fixed amount of time.

The tests are written with two axis in mind: read-only vs update and small vs large. These axis were chosen based on the Blob implementation at the time. In the context of this test, small means the Blob is represented as a string by the Derby store and large means the Blob is represtend as a stream into the Derby store. When a Blob is modified, an in-memory or on disk temporary copy is created. The performance of these temporary representations are tested with the tests that modify the Blob content.

System properties controlling test behavior:

NOTE: Currently there are no tests for the client driver (network) or for encrypted Blobs.


Field Summary
private static boolean disableConcurrencyTest
           
private static boolean disableLargeBlobs
           
private static boolean disableSmallBlobs
           
private static int FETCH_GETBINARYSTREAM
           
private static int FETCH_GETBYTES
           
private static int largeBlobSizeMB
           
 
Fields inherited from class org.apache.derbyTesting.junit.BaseTestCase
DEFAULT_DB_DIR, DERBY_LOG, ERRORSTACKTRACEFILE
 
Constructor Summary
BlobAccessTest(java.lang.String name, int iterations, int repeats)
          Instantiates a new test that will be run the specified number of iterations and repeated as specified.
 
Method Summary
private  void fetchBlobPieceByPiece(boolean modifyBlob, int fetchMode)
          Fetches a "large" Blob piece by piece using getBytes.
private static void initializeBlobData(java.sql.Statement stmt)
          Generates test data.
 void initializeConnection(java.sql.Connection conn)
          Set autocommit to false by default.
static junit.framework.Test suite()
          Generates a suite of tests.
 void testConcurrency()
          Runs a test using multiple threads.
 void testFetchLargeBlob()
          Fetches a single Blob by reading it in chunks with getBinaryStream.
 void testFetchLargeBlobModified()
          Fetches a single Blob by reading it in chunks with getBinaryStream.
 void testFetchLargeBlobOneByOneByte()
          Fetches a single Blob and reads it byte by byte.
 void testFetchLargeBlobOneByOneByteBaseline()
          Fetches a single Blob and reads it byte by byte, but utilizing a buffered stream to get a lower time bound on the read operation.
 void testFetchLargeBlobOneByOneByteModified()
          Fetches a single Blob and reads it byte by byte after it has first been modified.
 void testFetchLargeBlobPieceByPiece()
          Fetches a single Blob by reading it piece by piece with getBytes.
 void testFetchLargeBlobPieceByPieceModified()
          Fetches a single Blob by reading it piece by piece with getBytes.
 void testFetchLargeBlobs()
          Fetches a number of Blobs using a rather large read buffer with getBinaryStream.
 void testFetchSmallBlobs()
          Fetches a number of small Blobs, getting the content using getBytes.
 void testFetchSmallBlobsInaccurateLength()
          Fetches a number of small Blobs, getting the content using getBytes.
 void testLargeBlobGetLength()
          Tests if the Blob length is cached.
 void testLargeBlobGetLengthModified()
          Tests if the Blob length is cached.
 void testModifySmallBlobs()
          Test fetching the content after adding a single byte at the end.
 
Methods inherited from class org.apache.derbyTesting.junit.JDBCPerfTestCase
runBare, runTest
 
Methods inherited from class org.apache.derbyTesting.junit.BaseJDBCTestCase
assertCallError, assertCheckTable, assertCompileError, assertEquals, assertEquals, assertEquals, assertEquivalentDataType, assertGetIntError, assertNextError, assertPreparedStatementError, assertSQLExceptionEquals, assertSQLState, assertSQLState, assertStatementError, assertStatementError, assertStatementError, assertStatementError, assertTableRowCount, assertUpdateCount, assertUpdateCount, checkAllConsistency, checkEstimatedRowCount, commit, createStatement, createStatement, createStatement, dropTable, dropTable, getConnection, getDatabaseProperty, getLastSQLException, openConnection, openDefaultConnection, openDefaultConnection, openUserConnection, prepareCall, prepareCall, prepareCall, prepareStatement, prepareStatement, prepareStatement, prepareStatement, prepareStatement, prepareStatement, rollback, runScript, runScript, runSQLCommands, setAutoCommit, tearDown, usingDB2Client, usingDerbyNetClient, usingEmbedded
 
Methods inherited from class org.apache.derbyTesting.junit.BaseTestCase
alarm, assertEquals, assertEquals, assertEquals, assertExecJavaCmdAsExpected, assertSecurityManager, assertThrowableEquals, execJavaCmd, fail, getFailureFolder, getJavaExecutableName, getSystemProperty, getTestConfiguration, getTestResource, openTestResource, println, printStackTrace, readProcessOutput, removeDirectory, removeDirectory, removeSystemProperty, setSystemProperty, traceit
 
Methods inherited from class junit.framework.TestCase
countTestCases, createResult, getName, run, run, setName, setUp, toString
 
Methods inherited from class junit.framework.Assert
assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertFalse, assertFalse, assertNotNull, assertNotNull, assertNotSame, assertNotSame, assertNull, assertNull, assertSame, assertSame, assertTrue, assertTrue, fail, fail
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

disableSmallBlobs

private static final boolean disableSmallBlobs

disableLargeBlobs

private static final boolean disableLargeBlobs

disableConcurrencyTest

private static final boolean disableConcurrencyTest

largeBlobSizeMB

private static final int largeBlobSizeMB

FETCH_GETBYTES

private static final int FETCH_GETBYTES
See Also:
Constant Field Values

FETCH_GETBINARYSTREAM

private static final int FETCH_GETBINARYSTREAM
See Also:
Constant Field Values
Constructor Detail

BlobAccessTest

public BlobAccessTest(java.lang.String name,
                      int iterations,
                      int repeats)
Instantiates a new test that will be run the specified number of iterations and repeated as specified.

Parameters:
name - name of the test to instantiate
iterations - number of iterations per repetition
repeats - number of repetitions
Method Detail

initializeConnection

public void initializeConnection(java.sql.Connection conn)
                          throws java.sql.SQLException
Set autocommit to false by default.

Overrides:
initializeConnection in class BaseJDBCTestCase
Parameters:
conn - Connection to be intialized
Throws:
java.sql.SQLException - Error setting the initial state.

suite

public static junit.framework.Test suite()
Generates a suite of tests.

The required test data will be generated. Note that a subset of the tests can be disabled by using a system property.

Returns:
A suite of tests.

testFetchSmallBlobs

public void testFetchSmallBlobs()
                         throws java.sql.SQLException
Fetches a number of small Blobs, getting the content using getBytes.

The exact length of the Blob is used when getting the bytes.

Throws:
java.sql.SQLException

testFetchSmallBlobsInaccurateLength

public void testFetchSmallBlobsInaccurateLength()
                                         throws java.sql.SQLException
Fetches a number of small Blobs, getting the content using getBytes.

A too long length of the Blob is used when getting the bytes.

Throws:
java.sql.SQLException

testModifySmallBlobs

public void testModifySmallBlobs()
                          throws java.sql.SQLException,
                                 java.io.UnsupportedEncodingException
Test fetching the content after adding a single byte at the end.

Throws:
java.sql.SQLException
java.io.UnsupportedEncodingException

testFetchLargeBlobs

public void testFetchLargeBlobs()
                         throws java.io.IOException,
                                java.sql.SQLException
Fetches a number of Blobs using a rather large read buffer with getBinaryStream.

Throws:
java.io.IOException
java.sql.SQLException

testFetchLargeBlobOneByOneByteBaseline

public void testFetchLargeBlobOneByOneByteBaseline()
                                            throws java.io.IOException,
                                                   java.sql.SQLException
Fetches a single Blob and reads it byte by byte, but utilizing a buffered stream to get a lower time bound on the read operation.

Throws:
java.io.IOException
java.sql.SQLException

testFetchLargeBlobOneByOneByte

public void testFetchLargeBlobOneByOneByte()
                                    throws java.io.IOException,
                                           java.sql.SQLException
Fetches a single Blob and reads it byte by byte.

Throws:
java.io.IOException
java.sql.SQLException

testFetchLargeBlobOneByOneByteModified

public void testFetchLargeBlobOneByOneByteModified()
                                            throws java.io.IOException,
                                                   java.sql.SQLException
Fetches a single Blob and reads it byte by byte after it has first been modified.

The point of modifiying the Blob is to make Derby use the writable Blob representation (different implementation).

Throws:
java.io.IOException
java.sql.SQLException

testFetchLargeBlobPieceByPiece

public void testFetchLargeBlobPieceByPiece()
                                    throws java.io.IOException,
                                           java.sql.SQLException
Fetches a single Blob by reading it piece by piece with getBytes.

Throws:
java.io.IOException
java.sql.SQLException

testFetchLargeBlobPieceByPieceModified

public void testFetchLargeBlobPieceByPieceModified()
                                            throws java.io.IOException,
                                                   java.sql.SQLException
Fetches a single Blob by reading it piece by piece with getBytes.

Throws:
java.io.IOException
java.sql.SQLException

testFetchLargeBlob

public void testFetchLargeBlob()
                        throws java.io.IOException,
                               java.sql.SQLException
Fetches a single Blob by reading it in chunks with getBinaryStream.

Throws:
java.io.IOException
java.sql.SQLException

testFetchLargeBlobModified

public void testFetchLargeBlobModified()
                                throws java.io.IOException,
                                       java.sql.SQLException
Fetches a single Blob by reading it in chunks with getBinaryStream.

Throws:
java.io.IOException
java.sql.SQLException

fetchBlobPieceByPiece

private void fetchBlobPieceByPiece(boolean modifyBlob,
                                   int fetchMode)
                            throws java.io.IOException,
                                   java.sql.SQLException
Fetches a "large" Blob piece by piece using getBytes.

Parameters:
modifyBlob - whether to modify the Blob before fetching it (determines the internal Derby Blob representation)
Throws:
java.io.IOException
java.sql.SQLException

testLargeBlobGetLength

public void testLargeBlobGetLength()
                            throws java.sql.SQLException
Tests if the Blob length is cached.

Throws:
java.sql.SQLException

testLargeBlobGetLengthModified

public void testLargeBlobGetLengthModified()
                                    throws java.sql.SQLException
Tests if the Blob length is cached.

Throws:
java.sql.SQLException

testConcurrency

public void testConcurrency()
                     throws java.lang.InterruptedException,
                            java.sql.SQLException
Runs a test using multiple threads.

This test intends to detect problems with small Blobs and general problems with concurrency.

NOTE: To produce more reliable numbers, please run the performance client independently outside this JUnit test framework. Performance also suffers greatly with SANE builds.

Throws:
java.lang.InterruptedException
java.sql.SQLException

initializeBlobData

private static void initializeBlobData(java.sql.Statement stmt)
                                throws java.sql.SQLException,
                                       java.io.UnsupportedEncodingException
Generates test data.

Throws:
java.sql.SQLException
java.io.UnsupportedEncodingException

Built on Sat 2009-11-28 18:44:18-0800, from revision 885187

Apache Derby V10.6 Internals - Copyright © 2004,2008 The Apache Software Foundation. All Rights Reserved.