]> review.fuel-infra Code Review - packages/trusty/mysql-wsrep-5.6.git/blob
4a365e657c8d8d76d6b2c513dcd626322b41f295
[packages/trusty/mysql-wsrep-5.6.git] /
1 /*
2  *  Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
3  *
4  *  This program is free software; you can redistribute it and/or modify
5  *  it under the terms of the GNU General Public License as published by
6  *  the Free Software Foundation; version 2 of the License.
7  *
8  *  This program is distributed in the hope that it will be useful,
9  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
10  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11  *  GNU General Public License for more details.
12  *
13  *  You should have received a copy of the GNU General Public License
14  *  along with this program; if not, write to the Free Software
15  *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301  USA
16 */
17
18 package testsuite.clusterj;
19
20 import java.sql.PreparedStatement;
21 import java.sql.ResultSet;
22 import java.sql.SQLException;
23 import java.util.List;
24
25 import testsuite.clusterj.model.IdBase;
26 import testsuite.clusterj.model.VarbinaryTypes;
27
28 /** Test that Timestamps can be read and written. 
29  * case 1: Write using JDBC, read using NDB.
30  * case 2: Write using NDB, read using JDBC.
31  * Schema
32  *
33 drop table if exists varbinarytypes;
34 create table varbinarytypes (
35  id int not null primary key,
36
37  binary1 varbinary(1),
38  binary2 varbinary(2),
39  binary4 varbinary(4),
40  binary8 varbinary(8),
41  binary16 varbinary(16),
42  binary32 varbinary(32),
43  binary64 varbinary(64),
44  binary128 varbinary(128),
45  binary256 varbinary(256),
46  binary512 varbinary(512),
47  binary1024 varbinary(1024),
48  binary2048 varbinary(2048)
49
50 ) ENGINE=ndbcluster DEFAULT CHARSET=latin1;
51
52  */
53 public class VarbinaryTypesTest extends AbstractClusterJModelTest {
54
55     static int NUMBER_OF_INSTANCES = 10;
56
57     @Override
58     protected boolean getDebug() {
59         return false;
60     }
61
62     @Override
63     protected int getNumberOfInstances() {
64         return NUMBER_OF_INSTANCES;
65     }
66
67     @Override
68     protected String getTableName() {
69         return "varbinarytypes";
70     }
71
72     /** Subclasses override this method to provide the model class for the test */
73     @Override
74     Class<? extends IdBase> getModelClass() {
75         return VarbinaryTypes.class;
76     }
77
78     /** Subclasses override this method to provide values for rows (i) and columns (j) */
79     @Override
80     protected Object getColumnValue(int i, int j) {
81         // first calculate the length of the data
82         int length = (int)Math.pow(2, j);
83         byte[] data = new byte[length];
84         // fill in the data, increasing by one for each row, column, and byte in the byte[]
85         for (int d = 0; d < length; ++d) {
86             data[d] = (byte)(i + j + d);
87         }
88         return data;
89     }
90
91     /** Verify that the actual results match the expected results. If not, use the multiple error
92      * reporting method errorIfNotEqual defined in the superclass.
93      * @param where the location of the verification of results, normally the name of the test method
94      * @param expecteds the expected results
95      * @param actuals the actual results
96      */
97     @Override
98     protected void verify(String where, List<Object[]> expecteds, List<Object[]> actuals) {
99         for (int i = 0; i < expecteds.size(); ++i) {
100             Object[] expected = expecteds.get(i);
101             Object[] actual = actuals.get(i);
102             errorIfNotEqual(where + " got failure on id for row " + i, i, actual[0]);
103             for (int j = 1; j < expected.length; ++j) {
104                 // verify each object in the array
105                 byte[] expectedColumn = (byte[])(expected)[j];
106                 byte[] actualColumn = (byte[])(actual)[j];
107                 errorIfNotEqual(where + " got failure on length of data for row " + i,
108                         expectedColumn.length, actualColumn.length);
109                 if (expectedColumn.length == actualColumn.length) {
110                     // now compare byte by byte
111                     for (j = 0; j < expectedColumn.length; ++j)
112                         errorIfNotEqual(where + " got failure on comparison of data for row "
113                                 + i + " column " + j,
114                                 expectedColumn[j], actualColumn[j]);
115                 }
116             }
117         }
118     }
119
120     public void testWriteJDBCReadNDB() {
121         writeJDBCreadNDB();
122         failOnError();
123     }
124
125     public void testWriteNDBReadJDBC() {
126         writeNDBreadJDBC();
127         failOnError();
128    }
129
130    static ColumnDescriptor binary1 = new ColumnDescriptor
131             ("binary1", new InstanceHandler() {
132         public void setFieldValue(IdBase instance, Object value) {
133             ((VarbinaryTypes)instance).setBinary1((byte[])value);
134         }
135         public Object getFieldValue(IdBase instance) {
136             return ((VarbinaryTypes)instance).getBinary1();
137         }
138         public void setPreparedStatementValue(PreparedStatement preparedStatement, int j, Object value)
139                 throws SQLException {
140             preparedStatement.setBytes(j, (byte[])value);
141         }
142         public Object getResultSetValue(ResultSet rs, int j) throws SQLException {
143             return rs.getBytes(j);
144         }
145     });
146
147    static ColumnDescriptor binary2 = new ColumnDescriptor
148             ("binary2", new InstanceHandler() {
149         public void setFieldValue(IdBase instance, Object value) {
150             ((VarbinaryTypes)instance).setBinary2((byte[])value);
151         }
152         public Object getFieldValue(IdBase instance) {
153             return ((VarbinaryTypes)instance).getBinary2();
154         }
155         public void setPreparedStatementValue(PreparedStatement preparedStatement, int j, Object value)
156                 throws SQLException {
157             preparedStatement.setBytes(j, (byte[])value);
158         }
159         public Object getResultSetValue(ResultSet rs, int j) throws SQLException {
160             return rs.getBytes(j);
161         }
162     });
163
164    static ColumnDescriptor binary4 = new ColumnDescriptor
165             ("binary4", new InstanceHandler() {
166         public void setFieldValue(IdBase instance, Object value) {
167             ((VarbinaryTypes)instance).setBinary4((byte[])value);
168         }
169         public Object getFieldValue(IdBase instance) {
170             return ((VarbinaryTypes)instance).getBinary4();
171         }
172         public void setPreparedStatementValue(PreparedStatement preparedStatement, int j, Object value)
173                 throws SQLException {
174             preparedStatement.setBytes(j, (byte[])value);
175         }
176         public Object getResultSetValue(ResultSet rs, int j) throws SQLException {
177             return rs.getBytes(j);
178         }
179     });
180
181    static ColumnDescriptor binary8 = new ColumnDescriptor
182             ("binary8", new InstanceHandler() {
183         public void setFieldValue(IdBase instance, Object value) {
184             ((VarbinaryTypes)instance).setBinary8((byte[])value);
185         }
186         public Object getFieldValue(IdBase instance) {
187             return ((VarbinaryTypes)instance).getBinary8();
188         }
189         public void setPreparedStatementValue(PreparedStatement preparedStatement, int j, Object value)
190                 throws SQLException {
191             preparedStatement.setBytes(j, (byte[])value);
192         }
193         public Object getResultSetValue(ResultSet rs, int j) throws SQLException {
194             return rs.getBytes(j);
195         }
196     });
197
198     static ColumnDescriptor binary16 = new ColumnDescriptor
199             ("binary16", new InstanceHandler() {
200         public void setFieldValue(IdBase instance, Object value) {
201             ((VarbinaryTypes)instance).setBinary16((byte[])value);
202         }
203         public Object getFieldValue(IdBase instance) {
204             return ((VarbinaryTypes)instance).getBinary16();
205         }
206         public void setPreparedStatementValue(PreparedStatement preparedStatement, int j, Object value)
207                 throws SQLException {
208             preparedStatement.setBytes(j, (byte[])value);
209         }
210         public Object getResultSetValue(ResultSet rs, int j) throws SQLException {
211             return rs.getBytes(j);
212         }
213     });
214
215     static ColumnDescriptor binary32 = new ColumnDescriptor
216             ("binary32", new InstanceHandler() {
217         public void setFieldValue(IdBase instance, Object value) {
218             ((VarbinaryTypes)instance).setBinary32((byte[])value);
219         }
220         public Object getFieldValue(IdBase instance) {
221             return ((VarbinaryTypes)instance).getBinary32();
222         }
223         public void setPreparedStatementValue(PreparedStatement preparedStatement, int j, Object value)
224                 throws SQLException {
225             preparedStatement.setBytes(j, (byte[])value);
226         }
227         public Object getResultSetValue(ResultSet rs, int j) throws SQLException {
228             return rs.getBytes(j);
229         }
230     });
231
232     static ColumnDescriptor binary64 = new ColumnDescriptor
233             ("binary64", new InstanceHandler() {
234         public void setFieldValue(IdBase instance, Object value) {
235             ((VarbinaryTypes)instance).setBinary64((byte[])value);
236         }
237         public Object getFieldValue(IdBase instance) {
238             return ((VarbinaryTypes)instance).getBinary64();
239         }
240         public void setPreparedStatementValue(PreparedStatement preparedStatement, int j, Object value)
241                 throws SQLException {
242             preparedStatement.setBytes(j, (byte[])value);
243         }
244         public Object getResultSetValue(ResultSet rs, int j) throws SQLException {
245             return rs.getBytes(j);
246         }
247     });
248
249     static ColumnDescriptor binary128 = new ColumnDescriptor
250         ("binary128", new InstanceHandler() {
251             public void setFieldValue(IdBase instance, Object value) {
252                 ((VarbinaryTypes)instance).setBinary128((byte[])value);
253              }
254              public Object getFieldValue(IdBase instance) {
255                 return ((VarbinaryTypes)instance).getBinary128();
256              }
257              public void setPreparedStatementValue(PreparedStatement preparedStatement, int j, Object value)
258                     throws SQLException {
259                 preparedStatement.setBytes(j, (byte[])value);
260              }
261              public Object getResultSetValue(ResultSet rs, int j) throws SQLException {
262                 return rs.getBytes(j);
263         }
264     });
265
266     static ColumnDescriptor binary256 = new ColumnDescriptor
267        ("binary256", new InstanceHandler() {
268            public void setFieldValue(IdBase instance, Object value) {
269                ((VarbinaryTypes)instance).setBinary256((byte[])value);
270             }
271             public Object getFieldValue(IdBase instance) {
272                return ((VarbinaryTypes)instance).getBinary256();
273             }
274             public void setPreparedStatementValue(PreparedStatement preparedStatement, int j, Object value)
275                    throws SQLException {
276                preparedStatement.setBytes(j, (byte[])value);
277             }
278             public Object getResultSetValue(ResultSet rs, int j) throws SQLException {
279                return rs.getBytes(j);
280         }
281     });
282
283     static ColumnDescriptor binary512 = new ColumnDescriptor
284         ("binary512", new InstanceHandler() {
285             public void setFieldValue(IdBase instance, Object value) {
286                 ((VarbinaryTypes)instance).setBinary512((byte[])value);
287              }
288              public Object getFieldValue(IdBase instance) {
289                 return ((VarbinaryTypes)instance).getBinary512();
290              }
291              public void setPreparedStatementValue(PreparedStatement preparedStatement, int j, Object value)
292                     throws SQLException {
293                 preparedStatement.setBytes(j, (byte[])value);
294              }
295              public Object getResultSetValue(ResultSet rs, int j) throws SQLException {
296                 return rs.getBytes(j);
297         }
298     });
299
300     static ColumnDescriptor binary1024 = new ColumnDescriptor
301         ("binary1024", new InstanceHandler() {
302             public void setFieldValue(IdBase instance, Object value) {
303                 ((VarbinaryTypes)instance).setBinary1024((byte[])value);
304              }
305              public Object getFieldValue(IdBase instance) {
306                 return ((VarbinaryTypes)instance).getBinary1024();
307              }
308              public void setPreparedStatementValue(PreparedStatement preparedStatement, int j, Object value)
309                     throws SQLException {
310                 preparedStatement.setBytes(j, (byte[])value);
311              }
312              public Object getResultSetValue(ResultSet rs, int j) throws SQLException {
313                 return rs.getBytes(j);
314          }
315      });
316
317     static ColumnDescriptor binary2048 = new ColumnDescriptor
318         ("binary2048", new InstanceHandler() {
319             public void setFieldValue(IdBase instance, Object value) {
320                 ((VarbinaryTypes)instance).setBinary2048((byte[])value);
321              }
322              public Object getFieldValue(IdBase instance) {
323                 return ((VarbinaryTypes)instance).getBinary2048();
324              }
325              public void setPreparedStatementValue(PreparedStatement preparedStatement, int j, Object value)
326                     throws SQLException {
327                 preparedStatement.setBytes(j, (byte[])value);
328              }
329              public Object getResultSetValue(ResultSet rs, int j) throws SQLException {
330                 return rs.getBytes(j);
331         }
332     });
333
334     protected static ColumnDescriptor[] columnDescriptors = new ColumnDescriptor[] {
335             binary1,
336             binary2,
337             binary4,
338             binary8,
339             binary16,
340             binary32,
341             binary64,
342             binary128,
343             binary256,
344             binary512,
345             binary1024,
346             binary2048
347         };
348
349     @Override
350     protected ColumnDescriptor[] getColumnDescriptors() {
351         return columnDescriptors;
352     }
353
354 }