Return-Path:
Delivered-To: apmail-db-derby-commits-archive@www.apache.org
Received: (qmail 25467 invoked from network); 29 Apr 2008 20:41:45 -0000
Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.2)
by minotaur.apache.org with SMTP; 29 Apr 2008 20:41:45 -0000
Received: (qmail 25926 invoked by uid 500); 29 Apr 2008 20:41:47 -0000
Delivered-To: apmail-db-derby-commits-archive@db.apache.org
Received: (qmail 25903 invoked by uid 500); 29 Apr 2008 20:41:47 -0000
Mailing-List: contact derby-commits-help@db.apache.org; run by ezmlm
Precedence: bulk
list-help:
list-unsubscribe:
List-Post:
Reply-To: "Derby Development"
List-Id:
Delivered-To: mailing list derby-commits@db.apache.org
Received: (qmail 25892 invoked by uid 99); 29 Apr 2008 20:41:47 -0000
Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136)
by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 29 Apr 2008 13:41:47 -0700
X-ASF-Spam-Status: No, hits=-2000.0 required=10.0
tests=ALL_TRUSTED
X-Spam-Check-By: apache.org
Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4)
by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 29 Apr 2008 20:41:10 +0000
Received: by eris.apache.org (Postfix, from userid 65534)
id A2A2523889F6; Tue, 29 Apr 2008 13:41:23 -0700 (PDT)
Content-Type: text/plain; charset="utf-8"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Subject: svn commit: r652092 -
/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/StringArrayVTI.java
Date: Tue, 29 Apr 2008 20:41:23 -0000
To: derby-commits@db.apache.org
From: rhillegas@apache.org
X-Mailer: svnmailer-1.0.8
Message-Id: <20080429204123.A2A2523889F6@eris.apache.org>
X-Virus-Checked: Checked by ClamAV on apache.org
Author: rhillegas
Date: Tue Apr 29 13:41:23 2008
New Revision: 652092
URL: http://svn.apache.org/viewvc?rev=652092&view=rev
Log:
DERBY-3595: Make stack checking smarter in TableFunctionTest.
Modified:
db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/StringArrayVTI.java
Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/StringArrayVTI.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/StringArrayVTI.java?rev=652092&r1=652091&r2=652092&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/StringArrayVTI.java (original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/StringArrayVTI.java Tue Apr 29 13:41:23 2008
@@ -22,6 +22,7 @@
package org.apache.derbyTesting.functionTests.tests.lang;
import java.sql.*;
+import java.util.Arrays;
import org.apache.derby.vti.VTICosting;
import org.apache.derby.vti.VTIEnvironment;
@@ -42,6 +43,13 @@
public static final double FAKE_ROW_COUNT = 13.0;
public static final double FAKE_INSTANTIATION_COST = 3149.0;
+
+ private static final String[] EXPECTED_STACK =
+ {
+ "deduceGetXXXCaller",
+ "getRawColumn",
+ "getString",
+ };
///////////////////////////////////////////////////////////////////////////////////
//
@@ -173,16 +181,13 @@
//
private String deduceGetXXXCaller() throws SQLException
{
+ StackTraceElement[] stack = null;
try {
- StackTraceElement[] stack = (new Throwable()).getStackTrace();
- StackTraceElement callersCaller = stack[ 3 ];
- String callersCallerMethod = callersCaller.getMethodName();
-
- if ( !callersCallerMethod.startsWith( "get" ) ) { callersCallerMethod = "getString"; }
-
- return callersCallerMethod;
- } catch (Throwable t) { throw new SQLException( t.getMessage() ); }
- }
+ stack = (new Throwable()).getStackTrace();
+ } catch (Throwable t) { throw new SQLException( t.getMessage() ); }
+
+ return locateGetXXXCaller( stack );
+ }
///////////////////////////////////////////////////////////////////////////////////
//
@@ -214,6 +219,97 @@
//
///////////////////////////////////////////////////////////////////////////////////
+ /**
+ *
+ * Find the getXXX() method above us on the stack. The stack looks
+ * like this:
+ *
+ *
+ *
+ * - getXXX()
+ * - getString()
+ * - getRawColumn()
+ * - deduceGetXXXCaller()
+ *
+ *
+ *
+ * Except if the actual getXXX() method is getString()
+ *
+ */
+ private String locateGetXXXCaller( StackTraceElement[] stack ) throws SQLException
+ {
+ String[] actualMethodNames = squeezeMethodNames( stack );
+ String[] expectedMethodNames = EXPECTED_STACK;
+ int actualIdx = findIndex( "getString", actualMethodNames );
+
+ if ( actualIdx < 0 ) { throw badStack( EXPECTED_STACK, actualMethodNames ); }
+
+ String result = actualMethodNames[ ++actualIdx ];
+
+ if ( !result.startsWith( "get" ) ) { result = "getString"; }
+
+ return result;
+ }
+
+ /**
+ *
+ * Complain that we don't like the stack.
+ *
+ */
+ private SQLException badStack( String[] expected, String[] actual )
+ {
+ return new SQLException
+ ( "Expected stack to include " + stringify( expected ) + ", but the stack was actually this: " + stringify( actual ) );
+ }
+
+ /**
+ *
+ * Look for a method name on a stack and return its location as an
+ * index into the stack. Returns -1 if the expected name is not found.
+ *
+ */
+ private int findIndex( String expectedMethod, String[] actualMethodNames )
+ {
+ int count = actualMethodNames.length;
+ for ( int i = 0; i < count; i++ )
+ {
+ if ( expectedMethod.equals( actualMethodNames[ i ] ) ) { return i; }
+ }
+
+ return -1;
+ }
+
+ /**
+ *
+ * Extract the names of methods on a stack.
+ *
+ */
+ private String[] squeezeMethodNames( StackTraceElement[] stack )
+ {
+ if ( stack == null ) { stack = new StackTraceElement[] {}; }
+ int count = stack.length;
+ String[] result = new String[ count ];
+
+ for ( int i = 0; i < count; i++ )
+ {
+ result[ i ] = stack[ i ].getMethodName();
+ }
+
+ return result;
+ }
+
+
+ /**
+ *
+ * Turn an array into a printable String.
+ *
+ */
+ private String stringify( Object[] raw )
+ {
+ if ( raw == null ) { raw = new Object[] {}; }
+
+ return Arrays.asList( raw ).toString();
+ }
}