<commit_before>/*
// $Id$
// Farrago is an extensible data management system.
// Copyright (C) 2005-2005 The Eigenbase Project
// Copyright (C) 2005-2005 Disruptive Tech
// Copyright (C) 2005-2005 LucidEra, Inc.
// Portions Copyright (C) 2003-2005 <NAME>
//
// This program is free software; you can redistribute it and/or modify it
// under the terms of the GNU General Public License as published by the Free
// Software Foundation; either version 2 of the License, or (at your option)
// any later version approved by The Eigenbase Project.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
*/
package net.sf.farrago.test;

import java.io.InputStream;
import java.io.Reader;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.math.BigDecimal;
import java.math.BigInteger;
import java.sql.*;
import java.util.*;
import java.util.regex.Pattern;

import junit.framework.Assert;
import junit.framework.Test;

import java.sql.Date;

import org.eigenbase.util14.NumberUtil;

/**
 * FarragoJdbcTest tests specifics of the Farrago implementation of the JDBC
 * API.  See also unitsql/jdbc/*.sql.
 *
 * todo: test:
 * 1. string too long for char/varchar field
 * 2. value which converted to char/varchar is too long
 * 3. various numeric values out of range, e.g. put 65537 in a tinyint
 * 4. assign boolean to integer columns (becomes 0/1)
 * 5. assign numerics to boolean
 *    5a. small enough
 *    5b out of range (not 0 or 1)
 *
 * @author <NAME>
 * @author <NAME>
 * @version $Id$
 */
public class FarragoJdbcTest extends FarragoTestCase
{
    //~ Static fields/initializers --------------------------------------------

    // Constants used by testDataTypes
    private static final byte minByte = Byte.MIN_VALUE;
    private static final byte maxByte = Byte.MAX_VALUE;
    private static final short minShort = Short.MIN_VALUE;
    private static final short maxShort = Short.MAX_VALUE;
    private static final int minInt = Integer.MIN_VALUE;
    private static final int maxInt = Integer.MAX_VALUE;
    private static final long minLong = Long.MIN_VALUE;
    private static final long maxLong = Long.MAX_VALUE;
    private static final float minFloat = Float.MIN_VALUE;
    private static final float maxFloat = Float.MAX_VALUE;
    private static final double minDouble = Double.MIN_VALUE;
    private static final double maxDouble = Double.MAX_VALUE;
    private static final boolean boolValue = true;
    private static final BigDecimal bigDecimalValue =
        new BigDecimal(maxDouble);
    private static final String stringValue = "0";
    private static final byte [] bytes = { 127, -34, 56, 29, 56, 49 };

    /**
     * A point of time in Sydney, Australia. (The timezone is deliberately not
     * PST, where the test is likely to be run, or GMT, and should be in
     * daylight-savings time in December.)
     *
     * 4:22:33.456 PM on 21st December 2004 Japan (GMT+9)
     * is 9 hours earlier in GMT, namely
     * 7:22:33.456 AM on 21st December 2004 GMT
     * and is another 8 hours earlier in PST:
     * 11:22:33.456 PM on 20th December 2004 PST (GMT-8)
     */
    private static final Calendar sydneyCal =
        makeCalendar("JST", 2004, 11, 21, 16, 22, 33, 456);
    private static final Time time = new Time(sydneyCal.getTime().getTime());
    private static final Date date = new Date(sydneyCal.getTime().getTime());

    static {
        // Sanity check, assuming local time is PST
        String tzID = TimeZone.getDefault().getID();
        if (tzID.equals("America/Tijuana")) {
            String t = time.toString();
            assert t.equals("23:22:33") : t;
            String d = date.toString();
            assert d.equals("2004-12-20") : d;
        }
    }

    private static final Timestamp timestamp =
        new Timestamp(sydneyCal.getTime().getTime());
    private static final Byte tinyIntObj = new Byte(minByte);
    private static final Short smallIntObj = new Short(maxShort);
    private static final Integer integerObj = new Integer(minInt);
    private static final Long bigIntObj = new Long(maxLong);
    private static final Float floatObj = new Float(maxFloat);
    private static final Double doubleObj = new Double(maxDouble);
    private static final Boolean boolObj = Boolean.FALSE;
    private static final BigDecimal decimalObj =
        new BigDecimal(13412342124143241D);
    private static final BigDecimal decimal73Obj =
        new BigDecimal(64.2341);
    private static final String charObj = "CHAR test string";
    private static final String varcharObj = "VARCHAR test string";
    private static final int TINYINT = 2;
    private static final int SMALLINT = 3;
    private static final int INTEGER = 4;
    private static final int BIGINT = 5;
    private static final int REAL = 6;
    private static final int FLOAT = 7;
    private static final int DOUBLE = 8;
    private static final int BOOLEAN = 9;
    private static final int CHAR = 10;
    private static final int VARCHAR = 11;
    private static final int BINARY = 12;
    private static final int VARBINARY = 13;
    private static final int TIME = 14;
    private static final int DATE = 15;
    private static final int TIMESTAMP = 16;
    private static final int DECIMAL = 17;
    private static final int DECIMAL73 = 18;
    private static boolean schemaExists = false;
    private static final String [] columnNames =
        new String[TestSqlType.all.length];
    private static String columnTypeStr = "";
    private static String columnStr = "";
    private static String paramStr = "";

    static {
        for (int i = 0; i < TestSqlType.all.length; i++) {
            final TestSqlType sqlType = TestSqlType.all[i];
            assert sqlType.ordinal == (i + 2);
            columnNames[i] =
                "\"Column " + (i + 1) + ": " + sqlType.string + "\"";
            if (i > 0) {
                columnTypeStr += ", ";
                columnStr += ", ";
                paramStr += ", ";
            }
            columnTypeStr += (columnNames[i] + " " + sqlType.string);
            columnStr += columnNames[i];
            paramStr += "?";
        }
        columnTypeStr = "id integer primary key, " + columnTypeStr;
        columnStr = "id, " + columnStr;
        paramStr = "( ?, " + paramStr + ")";
    }

    // Flags indicating whether bugs have been fixed. (It's better to 'if'
    // out than to comment out code, because commented out code doesn't get
    // refactored.)
    private static final boolean todo = false;

    //~ Instance fields -------------------------------------------------------

    private Object [] values;

    //~ Constructors ----------------------------------------------------------

    /**
     * Creates a new FarragoJdbcTest object.
     */
    public FarragoJdbcTest(String testName)
        throws Exception
    {
        super(testName);
    }

    //~ Methods ---------------------------------------------------------------

    // implement TestCase
    public static Test suite()
    {
        return wrappedSuite(FarragoJdbcTest.class);
    }

    /**
     * Creates a calendar.
     */
    private static Calendar makeCalendar(
        String tz,
        int year,
        int month,
        int date,
        int hour,
        int minute,
        int second,
        int millis)
    {
        final Calendar cal = Calendar.getInstance();
        cal.clear();
        cal.set(year, month, date, hour, minute, second);
        cal.set(Calendar.MILLISECOND, millis);
        TimeZone timeZone = TimeZone.getTimeZone(tz);
        cal.setTimeZone(timeZone);
        return cal;
    }

    public void testJavaQuerySynchronousCancel()
        throws Exception
    {
        testQueryCancel(true, "JAVA");
    }
    
    public void testJavaQueryAsynchronousCancel()
        throws Exception
    {
        testQueryCancel(false, "JAVA");
    }

    public void testFennelQuerySynchronousCancel()
        throws Exception
    {
        testQueryCancel(true, "FENNEL");
    }
    
    public void testFennelQueryAsynchronousCancel()
        throws Exception
    {
        testQueryCancel(false, "FENNEL");
    }

    public void testUdxSynchronousCancel()
        throws Exception
    {
        testUdxCancel(true);
    }
    
    public void testUdxAsynchronousCancel()
        throws Exception
    {
        testUdxCancel(false);
    }

    private void testQueryCancel(boolean synchronous, String executorType)
        throws Exception
    {
        // cleanup<commit_msg>FARRAGO:  disable UDX asynchronous cancel test due to sporadic  NullPointerException<commit_after>/*
// $Id$
// Farrago is an extensible data management system.
// Copyright (C) 2005-2005 The Eigenbase Project
// Copyright (C) 2005-2005 Disruptive Tech
// Copyright (C) 2005-2005 LucidEra, Inc.
// Portions Copyright (C) 2003-2005 <NAME>
//
// This program is free software; you can redistribute it and/or modify it
// under the terms of the GNU General Public License as published by the Free
// Software Foundation; either version 2 of the License, or (at your option)
// any later version approved by The Eigenbase Project.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
*/
package net.sf.farrago.test;

import java.io.InputStream;
import java.io.Reader;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.math.BigDecimal;
import java.math.BigInteger;
import java.sql.*;
import java.util.*;
import java.util.regex.Pattern;

import junit.framework.Assert;
import junit.framework.Test;

import java.sql.Date;

import org.eigenbase.util14.NumberUtil;

/**
 * FarragoJdbcTest tests specifics of the Farrago implementation of the JDBC
 * API.  See also unitsql/jdbc/*.sql.
 *
 * todo: test:
 * 1. string too long for char/varchar field
 * 2. value which converted to char/varchar is too long
 * 3. various numeric values out of range, e.g. put 65537 in a tinyint
 * 4. assign boolean to integer columns (becomes 0/1)
 * 5. assign numerics to boolean
 *    5a. small enough
 *    5b out of range (not 0 or 1)
 *
 * @author <NAME>
 * @author <NAME>
 * @version $Id$
 */
public class FarragoJdbcTest extends FarragoTestCase
{
    //~ Static fields/initializers --------------------------------------------

    // Constants used by testDataTypes
    private static final byte minByte = Byte.MIN_VALUE;
    private static final byte maxByte = Byte.MAX_VALUE;
    private static final short minShort = Short.MIN_VALUE;
    private static final short maxShort = Short.MAX_VALUE;
    private static final int minInt = Integer.MIN_VALUE;
    private static final int maxInt = Integer.MAX_VALUE;
    private static final long minLong = Long.MIN_VALUE;
    private static final long maxLong = Long.MAX_VALUE;
    private static final float minFloat = Float.MIN_VALUE;
    private static final float maxFloat = Float.MAX_VALUE;
    private static final double minDouble = Double.MIN_VALUE;
    private static final double maxDouble = Double.MAX_VALUE;
    private static final boolean boolValue = true;
    private static final BigDecimal bigDecimalValue =
        new BigDecimal(maxDouble);
    private static final String stringValue = "0";
    private static final byte [] bytes = { 127, -34, 56, 29, 56, 49 };

    /**
     * A point of time in Sydney, Australia. (The timezone is deliberately not
     * PST, where the test is likely to be run, or GMT, and should be in
     * daylight-savings time in December.)
     *
     * 4:22:33.456 PM on 21st December 2004 Japan (GMT+9)
     * is 9 hours earlier in GMT, namely
     * 7:22:33.456 AM on 21st December 2004 GMT
     * and is another 8 hours earlier in PST:
     * 11:22:33.456 PM on 20th December 2004 PST (GMT-8)
     */
    private static final Calendar sydneyCal =
        makeCalendar("JST", 2004, 11, 21, 16, 22, 33, 456);
    private static final Time time = new Time(sydneyCal.getTime().getTime());
    private static final Date date = new Date(sydneyCal.getTime().getTime());

    static {
        // Sanity check, assuming local time is PST
        String tzID = TimeZone.getDefault().getID();
        if (tzID.equals("America/Tijuana")) {
            String t = time.toString();
            assert t.equals("23:22:33") : t;
            String d = date.toString();
            assert d.equals("2004-12-20") : d;
        }
    }

    private static final Timestamp timestamp =
        new Timestamp(sydneyCal.getTime().getTime());
    private static final Byte tinyIntObj = new Byte(minByte);
    private static final Short smallIntObj = new Short(maxShort);
    private static final Integer integerObj = new Integer(minInt);
    private static final Long bigIntObj = new Long(maxLong);
    private static final Float floatObj = new Float(maxFloat);
    private static final Double doubleObj = new Double(maxDouble);
    private static final Boolean boolObj = Boolean.FALSE;
    private static final BigDecimal decimalObj =
        new BigDecimal(13412342124143241D);
    private static final BigDecimal decimal73Obj =
        new BigDecimal(64.2341);
    private static final String charObj = "CHAR test string";
    private static final String varcharObj = "VARCHAR test string";
    private static final int TINYINT = 2;
    private static final int SMALLINT = 3;
    private static final int INTEGER = 4;
    private static final int BIGINT = 5;
    private static final int REAL = 6;
    private static final int FLOAT = 7;
    private static final int DOUBLE = 8;
    private static final int BOOLEAN = 9;
    private static final int CHAR = 10;
    private static final int VARCHAR = 11;
    private static final int BINARY = 12;
    private static final int VARBINARY = 13;
    private static final int TIME = 14;
    private static final int DATE = 15;
    private static final int TIMESTAMP = 16;
    private static final int DECIMAL = 17;
    private static final int DECIMAL73 = 18;
    private static boolean schemaExists = false;
    private static final String [] columnNames =
        new String[TestSqlType.all.length];
    private static String columnTypeStr = "";
    private static String columnStr = "";
    private static String paramStr = "";

    static {
        for (int i = 0; i < TestSqlType.all.length; i++) {
            final TestSqlType sqlType = TestSqlType.all[i];
            assert sqlType.ordinal == (i + 2);
            columnNames[i] =
                "\"Column " + (i + 1) + ": " + sqlType.string + "\"";
            if (i > 0) {
                columnTypeStr += ", ";
                columnStr += ", ";
                paramStr += ", ";
            }
            columnTypeStr += (columnNames[i] + " " + sqlType.string);
            columnStr += columnNames[i];
            paramStr += "?";
        }
        columnTypeStr = "id integer primary key, " + columnTypeStr;
        columnStr = "id, " + columnStr;
        paramStr = "( ?, " + paramStr + ")";
    }

    // Flags indicating whether bugs have been fixed. (It's better to 'if'
    // out than to comment out code, because commented out code doesn't get
    // refactored.)
    private static final boolean todo = false;

    //~ Instance fields -------------------------------------------------------

    private Object [] values;

    //~ Constructors ----------------------------------------------------------

    /**
     * Creates a new FarragoJdbcTest object.
     */
    public FarragoJdbcTest(String testName)
        throws Exception
    {
        super(testName);
    }

    //~ Methods ---------------------------------------------------------------

    // implement TestCase
    public static Test suite()
    {
        return wrappedSuite(FarragoJdbcTest.class);
    }

    /**
     * Creates a calendar.
     */
    private static Calendar makeCalendar(
        String tz,
        int year,
        int month,
        int date,
        int hour,
        int minute,
        int second,
        int millis)
    {
        final Calendar cal = Calendar.getInstance();
        cal.clear();
        cal.set(year, month, date, hour, minute, second);
        cal.set(Calendar.MILLISECOND, millis);
        TimeZone timeZone = TimeZone.getTimeZone(tz);
        cal.setTimeZone(timeZone);
        return cal;
    }

    public void testJavaQuerySynchronousCancel()
        throws Exception
    {
        testQueryCancel(true, "JAVA");
    }
    
    public void testJavaQueryAsynchronousCancel()
        throws Exception
    {
        testQueryCancel(false, "JAVA");
    }

    public void testFennelQuerySynchronousCancel()
        throws Exception
    {
        testQueryCancel(true, "FENNEL");
    }
    
    public void testFennelQueryAsynchronousCancel()
        throws Exception
    {
        testQueryCancel(false, "FENNEL");
    }

    public void testUdxSynchronousCancel()
        throws Exception
    {
        testUdxCancel(true);
    }

    private static final boolean frg31Fixed = false;

    public void testUdxAsynchronousCancel()
        throws Exception
    {
        if (frg31Fixed) {
            testUdxCancel(false);
        }
    }

    private void testQueryCancel(boolean synchronous, String executorType)
        throws Exception
    {
        // cleanup
{'fraction_non_alphanumeric': 0.11022443890274314, 'fraction_numerical': 0.023940149625935162, 'mean_word_length': 2.3997739261492086, 'pattern_counts': {'":': 2, '<': 11, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3828838', 'n_tokens_mistral': 5310, 'n_tokens_neox': 4840, 'n_words': 1790}