db-derby-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rhille...@apache.org
Subject svn commit: r907509 - in /db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang: FakeByteArray.java IntArray.java UDTTest.java
Date Sun, 07 Feb 2010 22:52:39 GMT
Author: rhillegas
Date: Sun Feb  7 22:52:38 2010
New Revision: 907509

URL: http://svn.apache.org/viewvc?rev=907509&view=rev
Log:
DERBY-651: Add tests for big UDTs.

Added:
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/FakeByteArray.java
  (with props)
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/IntArray.java
  (with props)
Modified:
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/UDTTest.java

Added: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/FakeByteArray.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/FakeByteArray.java?rev=907509&view=auto
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/FakeByteArray.java
(added)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/FakeByteArray.java
Sun Feb  7 22:52:38 2010
@@ -0,0 +1,106 @@
+/*
+
+   Derby - Class org.apache.derbyTesting.functionTests.tests.lang.FakeByteArray
+
+   Licensed to the Apache Software Foundation (ASF) under one or more
+   contributor license agreements.  See the NOTICE file distributed with
+   this work for additional information regarding copyright ownership.
+   The ASF licenses this file to you under the Apache License, Version 2.0
+   (the "License"); you may not use this file except in compliance with
+   the License.  You may obtain a copy of the License at
+
+     http://www.apache.org/licenses/LICENSE-2.0
+
+   Unless required by applicable law or agreed to in writing, software
+   distributed under the License is distributed on an "AS IS" BASIS,
+   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+   See the License for the specific language governing permissions and
+   limitations under the License.
+
+ */
+
+/**
+ * A UDT which can serialize a lot of bytes.
+ */
+package org.apache.derbyTesting.functionTests.tests.lang;
+
+import java.io.Externalizable;
+import java.io.IOException;
+import java.io.ObjectOutput;
+import java.io.ObjectInput;
+
+public class FakeByteArray implements Externalizable
+{
+    ///////////////////////////////////////////////////////////////////////////////////
+    //
+    // CONSTANTS
+    //
+    ///////////////////////////////////////////////////////////////////////////////////
+
+    ///////////////////////////////////////////////////////////////////////////////////
+    //
+    // STATE
+    //
+    ///////////////////////////////////////////////////////////////////////////////////
+
+    private int _length;
+    private byte _fill;
+    
+    ///////////////////////////////////////////////////////////////////////////////////
+    //
+    // CONSTRUCTOR
+    //
+    ///////////////////////////////////////////////////////////////////////////////////
+
+    public FakeByteArray() {}
+
+    public FakeByteArray( int length, int fill )
+    {
+        _length = length;
+        _fill = (byte) fill;
+    }
+
+    ///////////////////////////////////////////////////////////////////////////////////
+    //
+    // FUNCTIONS
+    //
+    ///////////////////////////////////////////////////////////////////////////////////
+
+    public static FakeByteArray makeFakeByteArray( int length, int biggestByte )
+    {
+        return new FakeByteArray( length, biggestByte );
+    }
+
+    public static String toString( FakeByteArray data ) { return data.toString(); }
+    
+    ///////////////////////////////////////////////////////////////////////////////////
+    //
+    // Externalizable BEHAVIOR
+    //
+    ///////////////////////////////////////////////////////////////////////////////////
+
+    public void writeExternal( ObjectOutput out ) throws IOException
+    {
+        out.writeInt( _length );
+
+        for ( int i = 0; i < _length; i++ ) { out.write( _fill ); }
+    }
+
+    public void readExternal( ObjectInput in ) throws IOException
+    {
+        _length = in.readInt();
+
+        for ( int i = 0; i < _length; i++ ) { _fill = (byte) in.read(); }
+    }
+
+    ///////////////////////////////////////////////////////////////////////////////////
+    //
+    // OTHER Object OVERRIDES
+    //
+    ///////////////////////////////////////////////////////////////////////////////////
+
+    public String toString()
+    {
+        return "[ " + _length + ", " + _fill + " ]";
+    }
+}

Propchange: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/FakeByteArray.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/IntArray.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/IntArray.java?rev=907509&view=auto
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/IntArray.java
(added)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/IntArray.java
Sun Feb  7 22:52:38 2010
@@ -0,0 +1,175 @@
+/*
+
+   Derby - Class org.apache.derbyTesting.functionTests.tests.lang.IntArray
+
+   Licensed to the Apache Software Foundation (ASF) under one or more
+   contributor license agreements.  See the NOTICE file distributed with
+   this work for additional information regarding copyright ownership.
+   The ASF licenses this file to you under the Apache License, Version 2.0
+   (the "License"); you may not use this file except in compliance with
+   the License.  You may obtain a copy of the License at
+
+     http://www.apache.org/licenses/LICENSE-2.0
+
+   Unless required by applicable law or agreed to in writing, software
+   distributed under the License is distributed on an "AS IS" BASIS,
+   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+   See the License for the specific language governing permissions and
+   limitations under the License.
+
+ */
+
+/**
+ * A UDT which contains an array of ints.
+ */
+package org.apache.derbyTesting.functionTests.tests.lang;
+
+import java.io.Externalizable;
+import java.io.IOException;
+import java.io.ObjectOutput;
+import java.io.ObjectInput;
+
+public class IntArray implements Externalizable, Comparable
+{
+    ///////////////////////////////////////////////////////////////////////////////////
+    //
+    // CONSTANTS
+    //
+    ///////////////////////////////////////////////////////////////////////////////////
+
+    ///////////////////////////////////////////////////////////////////////////////////
+    //
+    // STATE
+    //
+    ///////////////////////////////////////////////////////////////////////////////////
+
+    private int[] _data;
+    
+    ///////////////////////////////////////////////////////////////////////////////////
+    //
+    // CONSTRUCTOR
+    //
+    ///////////////////////////////////////////////////////////////////////////////////
+
+    public IntArray() {}
+
+    public IntArray( int[] data )
+    {
+        _data = data;
+    }
+
+    ///////////////////////////////////////////////////////////////////////////////////
+    //
+    // FUNCTIONS
+    //
+    ///////////////////////////////////////////////////////////////////////////////////
+
+    public static IntArray makeIntArray( int length )
+    {
+        return new IntArray( new int[ length ] );
+    }
+
+    public static IntArray setCell( IntArray array, int cellNumber, int cellValue )
+    {
+        array._data[ cellNumber ] = cellValue;
+
+        return array;
+    }
+
+    public static int getCell( IntArray array, int cellNumber ) { return array._data[ cellNumber
]; }
+    
+    ///////////////////////////////////////////////////////////////////////////////////
+    //
+    // Externalizable BEHAVIOR
+    //
+    ///////////////////////////////////////////////////////////////////////////////////
+
+    public void writeExternal( ObjectOutput out ) throws IOException
+    {
+        int length = _data.length;
+
+        out.writeInt( length );
+
+        for ( int i = 0; i < length; i++ ) { out.writeInt( _data[ i ] ); }
+    }
+
+    public void readExternal( ObjectInput in ) throws IOException
+    {
+        int length = in.readInt();
+
+        _data = new int[ length ];
+
+        for ( int i = 0; i < length; i++ ) { _data[ i ] = in.readInt(); }
+    }
+
+    ///////////////////////////////////////////////////////////////////////////////////
+    //
+    // Comparable BEHAVIOR
+    //
+    ///////////////////////////////////////////////////////////////////////////////////
+
+    public int compareTo( Object other )
+    {
+        if ( other == null ) { return -1; }
+        if ( !( other instanceof IntArray) ) { return -1; }
+
+        IntArray that = (IntArray) other;
+
+        int minLength = (this._data.length <= that._data.length) ? this._data.length :
that._data.length;
+
+        int result;
+        for ( int i = 0; i < minLength; i++ )
+        {
+            result = this._data[ i ] - that._data[ i ];
+
+            if ( result != 0 ) { return result; }
+        }
+
+        result = this._data.length - that._data.length;
+
+        return result;
+    }
+
+    public boolean equals( Object other ) { return ( compareTo( other ) == 0 ); }
+
+    public int hashCode()
+    {
+        int firstValue;
+        int secondValue;
+
+        if ( _data.length== 0 )
+        {
+            firstValue = 1;
+            secondValue = 1;
+        }
+        else
+        {
+            firstValue = _data[ 0 ];
+            secondValue = _data[ _data.length -1 ];
+        }
+
+        return firstValue^secondValue;
+    }
+    
+    ///////////////////////////////////////////////////////////////////////////////////
+    //
+    // OTHER Object OVERRIDES
+    //
+    ///////////////////////////////////////////////////////////////////////////////////
+
+    public String toString()
+    {
+        StringBuffer buffer = new StringBuffer();
+        int length = _data.length;
+
+        buffer.append( "[ " );
+        for ( int i = 0; i < length; i++ )
+        {
+            if ( i > 0 ) { buffer.append( ", " ); }
+            buffer.append( _data[ i ] );
+        }
+        buffer.append( " ]" );
+
+        return buffer.toString();
+    }
+}

Propchange: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/IntArray.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/UDTTest.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/UDTTest.java?rev=907509&r1=907508&r2=907509&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/UDTTest.java
(original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/UDTTest.java
Sun Feb  7 22:52:38 2010
@@ -823,6 +823,86 @@
              );
     }
 
+    /**
+     * <p>
+     * Verify that you can store large objects in UDT columns.
+     * </p>
+     */
+    public void test_12_largeUDTs() throws Exception
+    {
+        Connection conn = getConnection();
+
+        //
+        // Store and retrieve a UDT which is more than 90K bytes long
+        //
+        goodStatement( conn, "create type IntArray external name 'org.apache.derbyTesting.functionTests.tests.lang.IntArray'
language java\n" );
+        goodStatement
+            ( conn,
+              "create function makeIntArray( arrayLength int ) returns IntArray\n" +
+              "language java parameter style java no sql external name 'org.apache.derbyTesting.functionTests.tests.lang.IntArray.makeIntArray'\n"
);
+        goodStatement
+            ( conn,
+              "create function setCell( array IntArray, cellNumber int, cellValue int ) returns
IntArray\n" +
+              "language java parameter style java no sql external name 'org.apache.derbyTesting.functionTests.tests.lang.IntArray.setCell'\n"
);
+        goodStatement
+            ( conn,
+              "create function getCell( array IntArray, cellNumber int ) returns int\n" +
+              "language java parameter style java no sql external name 'org.apache.derbyTesting.functionTests.tests.lang.IntArray.getCell'\n"
);
+        goodStatement( conn, "create table t_12( id int generated always as identity, data
IntArray )\n" );
+        goodStatement( conn, "insert into t_12( data ) values ( setCell( makeIntArray( 3
), 1, 5 ) )\n" );
+        goodStatement( conn, "insert into t_12( data ) values ( setCell( makeIntArray( 100000
), 90000, 3 ) )\n" );
+
+        assertResults
+            (
+             conn,
+             "select getCell( data, 1 ), getCell( data, 2 ) from t_12 where id = 1",
+             new String[][]
+             {
+                 { "5" ,         "0" },
+             },
+             true
+             );
+
+        assertResults
+            (
+             conn,
+             "select getCell( data, 1 ), getCell( data, 90000 ) from t_12 where id = 2",
+             new String[][]
+             {
+                 { "0" ,         "3" },
+             },
+             true
+             );
+        
+        //
+        // Store and retrieve a UDT which is more than 1000K bytes long
+        //
+        goodStatement( conn, "create type FakeByteArray external name 'org.apache.derbyTesting.functionTests.tests.lang.FakeByteArray'
language java\n" );
+        goodStatement
+            ( conn,
+              "create function makeFakeByteArray( l int, f int ) returns FakeByteArray\n"
+
+              "language java parameter style java no sql external name 'org.apache.derbyTesting.functionTests.tests.lang.FakeByteArray.makeFakeByteArray'\n"
);
+        goodStatement
+            ( conn,
+              "create function toString( arg FakeByteArray ) returns varchar( 30 )\n" +
+              "language java parameter style java no sql external name 'org.apache.derbyTesting.functionTests.tests.lang.FakeByteArray.toString'\n"
);
+        goodStatement( conn, "create table t_12_a( id int generated always as identity, data
FakeByteArray )\n" );
+        goodStatement( conn, "insert into t_12_a( data ) values ( makeFakeByteArray( 3, 33
) )\n" );
+        goodStatement( conn, "insert into t_12_a( data ) values ( makeFakeByteArray( 1000000,
44 ) )\n" );
+
+        assertResults
+            (
+             conn,
+             "select id, toString( data ) from t_12_a order by id",
+             new String[][]
+             {
+                 { "1" ,         "[ 3, 33 ]" },
+                 { "2" ,         "[ 1000000, 44 ]" },
+             },
+             true
+             );
+    }
+    
     ///////////////////////////////////////////////////////////////////////////////////
     //
     // PROCEDURES AND FUNCTIONS



Mime
View raw message