]> review.fuel-infra Code Review - packages/trusty/mysql-wsrep-5.6.git/blob
e4a9eaf608b1fb8897897a65127073a5f7b09a19
[packages/trusty/mysql-wsrep-5.6.git] /
1 /*
2    Copyright (c) 2010, 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 com.mysql.clusterj.ClusterJException;
21
22 import testsuite.clusterj.model.Employee;
23
24 public class VarcharStringLengthTest extends AbstractClusterJTest {
25
26     private static String name = 
27         "11111111111111111111111111111111111111111111111111" +
28         "11111111111111111111111111111111111111111111111111" +
29         "11111111111111111111111111111111111111111111111111" +
30         "11111111111111111111111111111111111111111111111111" +
31         "11111111111111111111111111111111111111111111111111" +
32         "11111111111111111111111111111111111111111111111111" +
33         "11111111111111111111111111111111111111111111111111" +
34         "11111111111111111111111111111111111111111111111111" +
35         "11111111111111111111111111111111111111111111111111" +
36         "11111111111111111111111111111111111111111111111111";
37
38     @Override
39     public void localSetUp() {
40         createSessionFactory();
41         session = sessionFactory.getSession();
42         session.deletePersistentAll(Employee.class);
43         addTearDownClasses(Employee.class);
44     }
45
46     public void test() {
47         for (int i = 0; i < 500; ++i) {
48             Employee e = session.newInstance(Employee.class, i);
49             e.setName(name.substring(0, i));
50             e.setAge(i);
51             e.setMagic(i);
52             try {
53                 session.makePersistent(e);
54                 if (i > 32) {
55                     // unexpected success for lengths greater than varchar size
56                     error("Expected exception not thrown for: " + i);
57                 }
58             } catch (ClusterJException ex) {
59                 if (i < 33) {
60                     // unexpected error for lengths not greater than varchar size 
61                     error("Unexpected exception for: " + i + " " + ex.getMessage());
62                 }
63             }
64         }
65         failOnError();
66     }
67 }