org.apache.derbyTesting.functionTests.tests.jdbc4
Class BlobTest

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.functionTests.tests.jdbc4.BlobTest
All Implemented Interfaces:
junit.framework.Test

public class BlobTest
extends BaseJDBCTestCase


Field Summary
private  java.sql.Blob blob
          Default Blob object used by the tests.
private static ExemptBlobMD[] emd
           
private  java.util.HashMap<java.lang.reflect.Method,ExemptBlobMD> excludedMethodSet
           
private static java.lang.String LOCK_TIMEOUT
           
 
Fields inherited from class org.apache.derbyTesting.junit.BaseTestCase
DEFAULT_DB_DIR, DERBY_LOG, ERRORSTACKTRACEFILE
 
Constructor Summary
BlobTest(java.lang.String name)
          Create the test with the given name.
 
Method Summary
(package private)  void buildHashSet()
          Builds the HashSet which will be used to test whether the given methods can be exempted or not
(package private)  void buildMethodList(java.lang.Object LOB)
           
(package private)  boolean checkIfExempted(java.lang.reflect.Method m)
          Checks if the method throws a SQLFeatureNotSupportedException
(package private)  boolean checkIfMethodThrowsSQLException(java.lang.Object LOB, java.lang.reflect.Method method)
          Checks if the invocation of the method throws a SQLExceptio as expected.
private  void executeParallelUpdate(int id, boolean timeoutExpected)
          Try to update the row with the given error.
static int getLastByteInStream(java.io.InputStream is, int expectedCount)
          Drains the stream and returns the last byte read from the stream.
(package private)  java.lang.Object getNullValueForType(java.lang.Class type)
           
(package private)  java.lang.Object[] getNullValues(java.lang.Class<?>[] params)
           
private  int initializeLongBlob()
          Insert a row with a large blob into the test table.
 void setUp()
           
static junit.framework.Test suite()
          Create test suite for this test.
protected  void tearDown()
          Tear down this fixture, sub-classes should call super.tearDown().
 void testFreeandMethodsAfterCallingFree()
          Tests the implementation for the free() method in the Blob interface.
 void testGetBinaryStreamBlobUpdates()
          Tests that the data updated in a Blob is always reflected in the InputStream got.
 void testGetBinaryStreamCreateBlob()
          Tests that the InputStream got from a empty Blob reflects new data in the underlying Blob.
 void testGetBinaryStreamLong()
          Tests the implementation of the method getBinaryStream(long pos, long length).
 void testGetBinaryStreamLongDrain()
          Tests that draining a "sub-stream" from the Blob works.
 void testGetBinaryStreamLongExceptionConditions()
          Tests the exceptions thrown by the getBinaryStream (long pos, long length) for the following conditions a) pos <= 0 b) pos > (length of LOB) c) length < 0 d) pos + length > (length of LOB).
 void testGetBinaryStreamLongLastByte()
          Obtains a binary stream and tries to drain it to read the last byte in the Blob.
 void testLockingAfterFree()
          Test that a lock held on the corresponding row is released when free() is called on the Blob object.
 void testLockingAfterFreeWithDirtyReads()
          Test that a lock held on the corresponding row is released when free() is called on the Blob object if the isolation level is Read Uncommitted
 void testLockingAfterFreeWithRR()
          Test that a lock held on the corresponding row is NOT released when free() is called on the Blob object if the isolation level is Repeatable Read
 void testSetBytesReturnValueLarge()
          Tests the return count on insertion when the Blob is represented as a temporary file on disk.
 void testSetBytesReturnValueLargeStateChange()
          Tests the return count on insertion when the Blob is fetched from the database and then modified.
 void testSetBytesReturnValueSmall()
          Tests the return count on insertion when the Blob is represented as a byte array in memory.
static void transferAlphabetData(java.io.OutputStream writer, long length)
          Transfers the specified number of bytes generated from the modern latin alphabet (lowercase) to the destination stream.
 
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, initializeConnection, openConnection, openDefaultConnection, openDefaultConnection, openUserConnection, prepareCall, prepareCall, prepareCall, prepareStatement, prepareStatement, prepareStatement, prepareStatement, prepareStatement, prepareStatement, rollback, runScript, runScript, runSQLCommands, setAutoCommit, 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, runBare, setSystemProperty, traceit
 
Methods inherited from class junit.framework.TestCase
countTestCases, createResult, getName, run, run, runTest, setName, 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

blob

private java.sql.Blob blob
Default Blob object used by the tests.


emd

private static final ExemptBlobMD[] emd

excludedMethodSet

private java.util.HashMap<java.lang.reflect.Method,ExemptBlobMD> excludedMethodSet

LOCK_TIMEOUT

private static final java.lang.String LOCK_TIMEOUT
See Also:
Constant Field Values
Constructor Detail

BlobTest

public BlobTest(java.lang.String name)
Create the test with the given name.

Parameters:
name - name of the test.
Method Detail

setUp

public void setUp()
           throws java.sql.SQLException
Overrides:
setUp in class junit.framework.TestCase
Throws:
java.sql.SQLException

tearDown

protected void tearDown()
                 throws java.lang.Exception
Description copied from class: BaseJDBCTestCase
Tear down this fixture, sub-classes should call super.tearDown(). This cleanups & closes the connection if it is open and any statement objects returned through the utility methods.

Overrides:
tearDown in class BaseJDBCTestCase
Throws:
java.lang.Exception

buildHashSet

void buildHashSet()
Builds the HashSet which will be used to test whether the given methods can be exempted or not


testFreeandMethodsAfterCallingFree

public void testFreeandMethodsAfterCallingFree()
                                        throws java.sql.SQLException
Tests the implementation for the free() method in the Blob interface.

Throws:
java.sql.SQLException - if an error occurs during releasing the Blob resources

buildMethodList

void buildMethodList(java.lang.Object LOB)

checkIfExempted

boolean checkIfExempted(java.lang.reflect.Method m)
Checks if the method throws a SQLFeatureNotSupportedException

Parameters:
m - The method object that needs to be verified to see if it is exempted
Returns:
true if the given method does not throw the required SQLException

checkIfMethodThrowsSQLException

boolean checkIfMethodThrowsSQLException(java.lang.Object LOB,
                                        java.lang.reflect.Method method)
Checks if the invocation of the method throws a SQLExceptio as expected.

Parameters:
LOB - the Object that implements the Blob interface
method - the method that needs to be tested to ensure that it throws the correct exception
Returns:
true If the method throws the SQLException required after the free method has been called on the LOB object

getNullValues

java.lang.Object[] getNullValues(java.lang.Class<?>[] params)

getNullValueForType

java.lang.Object getNullValueForType(java.lang.Class type)

testGetBinaryStreamLong

public void testGetBinaryStreamLong()
                             throws java.lang.Exception
Tests the implementation of the method getBinaryStream(long pos, long length).

Throws:
java.lang.Exception

testGetBinaryStreamLongLastByte

public void testGetBinaryStreamLongLastByte()
                                     throws java.io.IOException,
                                            java.sql.SQLException
Obtains a binary stream and tries to drain it to read the last byte in the Blob.

See DERBY-4060.

Throws:
java.io.IOException - if reading from a stream fails
java.sql.SQLException - if something goes wrong

testGetBinaryStreamLongExceptionConditions

public void testGetBinaryStreamLongExceptionConditions()
                                                throws java.sql.SQLException
Tests the exceptions thrown by the getBinaryStream (long pos, long length) for the following conditions a) pos <= 0 b) pos > (length of LOB) c) length < 0 d) pos + length > (length of LOB).

Throws:
SQLException.
java.sql.SQLException

testGetBinaryStreamLongDrain

public void testGetBinaryStreamLongDrain()
                                  throws java.io.IOException,
                                         java.sql.SQLException
Tests that draining a "sub-stream" from the Blob works. This is a repro for DERBY-4061, where we ended up with an infinite loop.

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

testGetBinaryStreamCreateBlob

public void testGetBinaryStreamCreateBlob()
                                   throws java.lang.Exception
Tests that the InputStream got from a empty Blob reflects new data in the underlying Blob.

Throws:
java.lang.Exception

testGetBinaryStreamBlobUpdates

public void testGetBinaryStreamBlobUpdates()
                                    throws java.lang.Exception
Tests that the data updated in a Blob is always reflected in the InputStream got. Here we do updates in the Blob both using Blob.setBytes and using the OutputStream obtained from the Blob.

Throws:
java.lang.Exception

testSetBytesReturnValueSmall

public void testSetBytesReturnValueSmall()
                                  throws java.sql.SQLException
Tests the return count on insertion when the Blob is represented as a byte array in memory.

Throws:
java.sql.SQLException

testSetBytesReturnValueLarge

public void testSetBytesReturnValueLarge()
                                  throws java.io.IOException,
                                         java.sql.SQLException
Tests the return count on insertion when the Blob is represented as a temporary file on disk.

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

testSetBytesReturnValueLargeStateChange

public void testSetBytesReturnValueLargeStateChange()
                                             throws java.io.IOException,
                                                    java.sql.SQLException
Tests the return count on insertion when the Blob is fetched from the database and then modified.

The main point for this test is to provoke the transition from a read-only internal representation to a writable representation. For a Blob of "considerable" size, this involved going from a store stream representation to a LOBStreamControl representation using a temporary file.

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

testLockingAfterFree

public void testLockingAfterFree()
                          throws java.sql.SQLException
Test that a lock held on the corresponding row is released when free() is called on the Blob object.

Throws:
java.sql.SQLException

testLockingAfterFreeWithRR

public void testLockingAfterFreeWithRR()
                                throws java.sql.SQLException
Test that a lock held on the corresponding row is NOT released when free() is called on the Blob object if the isolation level is Repeatable Read

Throws:
java.sql.SQLException

testLockingAfterFreeWithDirtyReads

public void testLockingAfterFreeWithDirtyReads()
                                        throws java.sql.SQLException
Test that a lock held on the corresponding row is released when free() is called on the Blob object if the isolation level is Read Uncommitted

Throws:
java.sql.SQLException

initializeLongBlob

private int initializeLongBlob()
                        throws java.sql.SQLException
Insert a row with a large blob into the test table. Read the row from the database and assign the blob value to blob.

Returns:
The id of the row that was inserted
Throws:
java.sql.SQLException

executeParallelUpdate

private void executeParallelUpdate(int id,
                                   boolean timeoutExpected)
                            throws java.sql.SQLException
Try to update the row with the given error. Flag a failure if a timeout occurs when not expected, and vice versa.

Parameters:
id - The id of the row to be updated
timeoutExpected - true if it is expected that the update times out
Throws:
java.sql.SQLException

transferAlphabetData

public static void transferAlphabetData(java.io.OutputStream writer,
                                        long length)
                                 throws java.io.IOException
Transfers the specified number of bytes generated from the modern latin alphabet (lowercase) to the destination stream.

Parameters:
writer - the destination
length - number of bytes to write
Throws:
java.io.IOException - if writing to the destination stream fails

getLastByteInStream

public static int getLastByteInStream(java.io.InputStream is,
                                      int expectedCount)
                               throws java.io.IOException
Drains the stream and returns the last byte read from the stream.

Parameters:
is - stream to drain
expectedCount - expected number of bytes (remaining) in the stream
Returns:
The last byte read.
Throws:
java.lang.AssertionError - if there are too many/few bytes in the stream
java.io.IOException - if reading from the stream fails

suite

public static junit.framework.Test suite()
Create test suite for this test.


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.