18
18
19
19
import com .jd .jdbc .table .TableTestUtil ;
20
20
import java .sql .Connection ;
21
+ import java .sql .PreparedStatement ;
21
22
import java .sql .ResultSet ;
22
23
import java .sql .SQLException ;
24
+ import java .sql .SQLFeatureNotSupportedException ;
23
25
import java .sql .Statement ;
26
+ import java .util .ArrayList ;
27
+ import java .util .List ;
28
+ import lombok .AllArgsConstructor ;
29
+ import lombok .ToString ;
24
30
import org .junit .After ;
25
31
import org .junit .Assert ;
26
32
import org .junit .Before ;
@@ -56,8 +62,7 @@ public void close() throws SQLException {
56
62
if (stmt2 != null ) {
57
63
stmt2 .close ();
58
64
}
59
- closeConnection (conn );
60
- closeConnection (conn2 );
65
+ closeConnection (conn , conn2 );
61
66
TableTestUtil .setDefaultTableConfig ();
62
67
}
63
68
@@ -75,6 +80,88 @@ public void testSequenceAsTindex() throws SQLException {
75
80
testSequence (stmt2 );
76
81
}
77
82
83
+ @ Ignore
84
+ @ Test
85
+ public void testEachTableSequence () {
86
+ List <TestCase > testCaseList = new ArrayList <>();
87
+ testCaseList .add (new TestCase ("insert into table_seq_test (id, f_key) values (null, '11')" , null ));
88
+ testCaseList .add (new TestCase ("insert into table_seq_test (id, f_key) values (null, ?)" , 22 ));
89
+ testCaseList .add (new TestCase ("insert into table_seq_test (id, f_key) values (101, '11')" , null ));
90
+ testCaseList .add (new TestCase ("insert into table_seq_test (id, f_key) values (101, ?)" , 22 ));
91
+ testCaseList .add (new TestCase ("insert into table_seq_test (f_key, f_tinyint) values ('22' , 1)" , null ));
92
+ testCaseList .add (new TestCase ("insert into table_seq_test (f_key, f_tinyint) values ('22' , ?)" , 55 ));
93
+
94
+ testCaseList .add (new TestCase ("insert into table_split_seq_test (id, f_key) values (null, '11')" , null ));
95
+ testCaseList .add (new TestCase ("insert into table_split_seq_test (id, f_key) values (null, ?)" , 22 ));
96
+ testCaseList .add (new TestCase ("insert into table_split_seq_test (id, f_key) values (101, '11')" , null ));
97
+ testCaseList .add (new TestCase ("insert into table_split_seq_test (id, f_key) values (101, ?)" , 22 ));
98
+ testCaseList .add (new TestCase ("insert into table_split_seq_test (f_key, f_tinyint) values ('22' , 1)" , null ));
99
+ testCaseList .add (new TestCase ("insert into table_split_seq_test (f_key, f_tinyint) values ('22' , ?)" , 55 ));
100
+
101
+ TableTestUtil .setSplitTableConfig ("engine/tableengine/split-table-seq.yml" );
102
+ for (TestCase testCase : testCaseList ) {
103
+ try {
104
+ if (testCase .var != null ) {
105
+ PreparedStatement prepareStatement = conn2 .prepareStatement (testCase .sql );
106
+ prepareStatement .setInt (1 , testCase .var );
107
+ prepareStatement .execute ();
108
+ } else {
109
+ Statement statement = conn2 .createStatement ();
110
+ statement .execute (testCase .sql );
111
+ }
112
+ } catch (SQLException e ) {
113
+ if (e instanceof SQLFeatureNotSupportedException && e .getMessage ().equals ("Unsupported to use seq for each table on split table" )) {
114
+ printOk (testCase .toString ());
115
+ } else {
116
+ Assert .fail ();
117
+ }
118
+ }
119
+ }
120
+ }
121
+
122
+ @ Test
123
+ public void testEachTableSequenceAsTindex () {
124
+ List <TestCase > testCaseList = new ArrayList <>();
125
+ testCaseList .add (new TestCase ("insert into table_seq_test (id, f_key) values (null, '11')" , null ));
126
+ testCaseList .add (new TestCase ("insert into table_seq_test (id, f_key) values (null, ?)" , 22 ));
127
+ testCaseList .add (new TestCase ("insert into table_seq_test (id, f_key) values (101, '11')" , null ));
128
+ testCaseList .add (new TestCase ("insert into table_seq_test (id, f_key) values (101, ?)" , 22 ));
129
+ testCaseList .add (new TestCase ("insert into table_seq_test (id, f_key, f_tinyint) values (null, '22', 1)" , null ));
130
+ testCaseList .add (new TestCase ("insert into table_seq_test (id, f_key, f_tinyint) values (null, '22', ?)" , 55 ));
131
+ testCaseList .add (new TestCase ("insert into table_seq_test (id, f_key, f_tinyint) values (101, '22', 1)" , null ));
132
+ testCaseList .add (new TestCase ("insert into table_seq_test (id, f_key, f_tinyint) values (101, '22', ?)" , 55 ));
133
+
134
+ testCaseList .add (new TestCase ("insert into table_split_seq_test (id, f_key) values (null, '11')" , null ));
135
+ testCaseList .add (new TestCase ("insert into table_split_seq_test (id, f_key) values (null, ?)" , 22 ));
136
+ testCaseList .add (new TestCase ("insert into table_split_seq_test (id, f_key) values (101, '11')" , null ));
137
+ testCaseList .add (new TestCase ("insert into table_split_seq_test (id, f_key) values (101, ?)" , 22 ));
138
+ testCaseList .add (new TestCase ("insert into table_split_seq_test (id, f_key, f_tinyint) values (null, '22', 1)" , null ));
139
+ testCaseList .add (new TestCase ("insert into table_split_seq_test (id, f_key, f_tinyint) values (null, '22', ?)" , 55 ));
140
+ testCaseList .add (new TestCase ("insert into table_split_seq_test (id, f_key, f_tinyint) values (101, '22', 1)" , null ));
141
+ testCaseList .add (new TestCase ("insert into table_split_seq_test (id, f_key, f_tinyint) values (101, '22', ?)" , 55 ));
142
+
143
+ TableTestUtil .setSplitTableConfig ("engine/tableengine/split-table-seq-tindex.yml" );
144
+ for (TestCase testCase : testCaseList ) {
145
+ try {
146
+ if (testCase .var != null ) {
147
+ PreparedStatement prepareStatement = conn2 .prepareStatement (testCase .sql );
148
+ prepareStatement .setInt (1 , testCase .var );
149
+ prepareStatement .execute ();
150
+ } else {
151
+ Statement statement = conn2 .createStatement ();
152
+ statement .execute (testCase .sql );
153
+ }
154
+ } catch (SQLException e ) {
155
+ if (e instanceof SQLFeatureNotSupportedException && e .getMessage ().equals ("Unsupported to use seq for each table on split table" )) {
156
+ printOk (testCase .toString ());
157
+ } else {
158
+ e .printStackTrace ();
159
+ Assert .fail ();
160
+ }
161
+ }
162
+ }
163
+ }
164
+
78
165
private void testSequence (Statement stmt ) throws SQLException {
79
166
int num = 120 ;
80
167
stmt .executeUpdate ("delete from table_engine_test" );
@@ -94,19 +181,27 @@ private void testSequence(Statement stmt) throws SQLException {
94
181
checkByCount (stmt , num , "table_engine_test" );
95
182
}
96
183
97
- public void checkByCountDistinct (Statement stmt , final int expected , String tableName , String column ) throws SQLException {
184
+ private void checkByCountDistinct (Statement stmt , final int expected , String tableName , String column ) throws SQLException {
98
185
ResultSet resultSet = stmt .executeQuery ("select count(distinct(" + column + ")) from " + tableName );
99
186
Assert .assertTrue (resultSet .next ());
100
187
int actual = resultSet .getInt (1 );
101
188
Assert .assertEquals (printFail ("[FAIL]" ), expected , actual );
102
189
Assert .assertFalse (resultSet .next ());
103
190
}
104
191
105
- public void checkByCount (Statement stmt , final int expected , String tableName ) throws SQLException {
192
+ private void checkByCount (Statement stmt , final int expected , String tableName ) throws SQLException {
106
193
ResultSet resultSet = stmt .executeQuery ("select count(*) from " + tableName );
107
194
Assert .assertTrue (resultSet .next ());
108
195
int actual = resultSet .getInt (1 );
109
196
Assert .assertEquals (printFail ("[FAIL]" ), expected , actual );
110
197
Assert .assertFalse (resultSet .next ());
111
198
}
199
+
200
+ @ AllArgsConstructor
201
+ @ ToString
202
+ class TestCase {
203
+ private String sql ;
204
+
205
+ private Integer var ;
206
+ }
112
207
}
0 commit comments