db-derby-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bpendle...@apache.org
Subject svn commit: r1798290 - /db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/AutoIncrementTest.java
Date Sat, 10 Jun 2017 01:39:44 GMT
Author: bpendleton
Date: Sat Jun 10 01:39:44 2017
New Revision: 1798290

URL: http://svn.apache.org/viewvc?rev=1798290&view=rev
Log:
DERBY-6935: Test coverage for added features

This patch was contributed by Harshvardhan Gupta (harshvardhan145 at gmail dot com)

The patch adds additional test cases for the new CYCLE-related features
of the identity column support.

Modified:
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/AutoIncrementTest.java

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/AutoIncrementTest.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/AutoIncrementTest.java?rev=1798290&r1=1798289&r2=1798290&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/AutoIncrementTest.java
(original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/AutoIncrementTest.java
Sat Jun 10 01:39:44 2017
@@ -121,6 +121,7 @@ public class AutoIncrementTest extends B
 		st.execute("create table variantt2 (c21 int generated always as identity (start with 201,
increment by 5), c22 int)");
 		st.execute("create trigger variantt1tr1 after insert on variantt1 for each row insert into
variantt2 (c22) values (1)");
 		st.execute("create table restartt1 (rec11 int generated by default as identity(start with
2, increment by 2), c12 int)");
+		st.execute("create table cycle1 (rec21 int generated by default as identity(start with
2, increment by 2), c32 int)");
 		st.execute("create table t1lock(lockc11 int generated by default as identity (start with
1, increment by 1), c12 int)");
 		st.execute("create unique index t1locki1 on t1lock(lockc11)");
 		//-- Since RESTART is not a reserved keyword, we should be able to create a table with
name RESTART
@@ -1040,6 +1041,122 @@ public class AutoIncrementTest extends B
 		JDBC.assertFullResultSet(rs,expectedRows);
 
 	}
+
+	// Some simple tests of the new "[NO] CYCLE" variant of ALTER TABLE
+	// added by DERBY-6903:
+	//
+	public void testDerby6903AlterCycleSimple()
+			throws Exception
+	{
+		Statement s=createStatement();
+		ResultSet rs;
+
+		s.execute("alter table cycle1 alter column rec21 CYCLE");
+
+		rs=s.executeQuery("select COLUMNNAME, AUTOINCREMENTVALUE, AUTOINCREMENTSTART, AUTOINCREMENTINC,
AUTOINCREMENTCYCLE " +
+				"       from sys.syscolumns where COLUMNNAME = 'REC21'");
+
+		String[][] expectedRows = new String[][]{{"REC21","2","2","2","true"}};
+		JDBC.assertFullResultSet(rs,expectedRows);
+
+		// Using alter table doesn't reset cycling option from true to false.
+		s.execute("alter table cycle1 alter column rec21 RESTART WITH 10");
+
+		rs=s.executeQuery("select COLUMNNAME, AUTOINCREMENTVALUE, AUTOINCREMENTSTART, AUTOINCREMENTINC,
AUTOINCREMENTCYCLE " +
+				"       from sys.syscolumns where COLUMNNAME = 'REC21'");
+
+		expectedRows = new String[][]{{"REC21","10","10","2","true"}};
+		JDBC.assertFullResultSet(rs,expectedRows);
+
+		// Using alter table doesn't reset cycling option from true to false.
+		s.execute("alter table cycle1 alter column rec21 SET INCREMENT BY 50");
+
+		rs=s.executeQuery("select COLUMNNAME, AUTOINCREMENTVALUE, AUTOINCREMENTSTART, AUTOINCREMENTINC,
AUTOINCREMENTCYCLE " +
+				"       from sys.syscolumns where COLUMNNAME = 'REC21'");
+
+		expectedRows = new String[][]{{"REC21","50","10","50","true"}};
+		JDBC.assertFullResultSet(rs,expectedRows);
+
+
+	}
+
+
+    // Some simple tests of the new "[NO] CYCLE" variant of ALTER TABLE
+    // added by DERBY-6904:
+    //
+    public void testDerby6904AlterCycleSimple()
+        throws Exception
+    {
+		Statement s=createStatement();
+		ResultSet rs;
+
+        // Some simple syntax errors:
+		assertStatementError("42X01",s,"alter table restartt1 alter column c12 cycle cycle");
+		assertStatementError("42X01",s,"alter table restartt1 alter column c12 no");
+		assertStatementError("42X01",s,"alter table restartt1 alter column c12 restart cycle");
+		assertStatementError("42X01",s,"alter table restartt1 alter column c12 restart with cycle");
+
+        // c12 is not an autoincrement column:
+		assertStatementError("42837",s,"alter table restartt1 alter column c12 cycle");
+		assertStatementError("42837",s,"alter table restartt1 alter column c12 no cycle");
+
+        // Demonstrate that we can change column rec11 from NO CYCLE to CYCLE
+        // and back to NO CYCLE, verifying by looking at SYSCOLUMNS:
+		rs=s.executeQuery("select COLUMNNAME, AUTOINCREMENTCYCLE " +
+                          "       from sys.syscolumns where COLUMNNAME = 'REC11'");
+		String[][]expectedRows = new String[][]{{"REC11","false"}};
+		JDBC.assertFullResultSet(rs,expectedRows);
+
+        s.execute("alter table restartt1 alter column rec11 cycle");
+
+		rs=s.executeQuery("select COLUMNNAME, AUTOINCREMENTCYCLE " +
+                          "       from sys.syscolumns where COLUMNNAME = 'REC11'");
+		expectedRows = new String[][]{{"REC11","true"}};
+		JDBC.assertFullResultSet(rs,expectedRows);
+
+        s.execute("alter table restartt1 alter column rec11 no cycle");
+
+		rs=s.executeQuery("select COLUMNNAME, AUTOINCREMENTCYCLE " +
+                          "       from sys.syscolumns where COLUMNNAME = 'REC11'");
+		expectedRows = new String[][]{{"REC11","false"}};
+		JDBC.assertFullResultSet(rs,expectedRows);
+    }
+
+    // Some simple tests of the new "NO CYCLE" option on CREATE TABLE
+    // added by DERBY-6906:
+    //
+    public void testDerby6906NoCycleSimple()
+        throws Exception
+    {
+		Statement s=createStatement();
+
+        // Some simple syntax errors:
+        assertStatementError("42XAJ",s,
+		    "create table derby6906 " +
+            "(rec11 int generated by default as identity" +
+            "       (start with 2, increment by 2, cycle cycle) )");
+        assertStatementError("42X01",s,
+		    "create table derby6906 " +
+            "(rec11 int generated by default as identity" +
+            "       (start with 2, increment by 2, no) )");
+        assertStatementError("42XAJ",s,
+		    "create table derby6906 " +
+            "(rec11 int generated by default as identity" +
+            "       (start with 2, increment by 2, cycle no cycle) )");
+
+        // Demonstrate the ability to have the [NO] CYCLE clause:
+
+		s.execute("create table derby6906 " +
+            "(rec11 int generated by default as identity" +
+            "       (start with 2, increment by 2,cycle) )");
+		s.execute("drop table derby6906 ");
+
+		s.execute("create table derby6906 " +
+            "(rec11 int generated by default as identity" +
+            "       (start with 2, increment by 2,no cycle) )");
+		s.execute("drop table derby6906 ");
+    }
+
 	public void testlock()throws Exception
 	{
 		/*--following puts locks on system table SYSCOLUMNS's row for t1lock.c11



Mime
View raw message