]> review.fuel-infra Code Review - packages/trusty/mysql-wsrep-5.6.git/blob
c135ade60af6e9b10cb716cdbb676b7c3fe77e88
[packages/trusty/mysql-wsrep-5.6.git] /
1 /*
2    Copyright (c) 2010, 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.util.Properties;
21
22 import com.mysql.clusterj.Constants;
23
24 import testsuite.clusterj.model.Employee;
25
26 public class DefaultConnectValuesTest extends AbstractClusterJModelTest {
27
28     private static final int NUMBER_TO_INSERT = 1;
29
30     @Override
31     public void localSetUp() {
32         createSessionFactory();
33         session = sessionFactory.getSession();
34         createEmployeeInstances(NUMBER_TO_INSERT);
35         tx = session.currentTransaction();
36         tx.begin();
37         session.deletePersistentAll(Employee.class);
38         tx.commit();
39         addTearDownClasses(Employee.class);
40     }
41
42     /** Remove the properties that can be defaulted.
43      */
44     @Override
45     protected Properties modifyProperties() {
46         Properties modifiedProperties = new Properties();
47         modifiedProperties.putAll(props);
48         modifiedProperties.remove(Constants.PROPERTY_CLUSTER_CONNECT_DELAY);
49         modifiedProperties.remove(Constants.PROPERTY_CLUSTER_CONNECT_RETRIES);
50         modifiedProperties.remove(Constants.PROPERTY_CLUSTER_CONNECT_TIMEOUT_AFTER);
51         modifiedProperties.remove(Constants.PROPERTY_CLUSTER_CONNECT_TIMEOUT_BEFORE);
52         modifiedProperties.remove(Constants.PROPERTY_CLUSTER_CONNECT_VERBOSE);
53         modifiedProperties.remove(Constants.PROPERTY_CLUSTER_DATABASE);
54         modifiedProperties.remove(Constants.PROPERTY_CLUSTER_MAX_TRANSACTIONS);
55         return modifiedProperties;
56     }
57
58     public void testFind() {
59         // first, create instances to find
60         tx = session.currentTransaction();
61         tx.begin();
62         
63         int count = 0;
64
65         for (int i = 0; i < NUMBER_TO_INSERT; ++i) {
66             // must be done with an active transaction
67             session.makePersistent(employees.get(i));
68             ++count;
69         }
70         tx.commit();
71
72         tx.begin();
73         
74         for (int i = 0; i < NUMBER_TO_INSERT; ++i) {
75             // must be done with an active transaction
76             Employee e = session.find(Employee.class, i);
77             // make sure all fields were fetched
78             consistencyCheck(e);
79             // see if it is the right Employee
80             int actualId = e.getId();
81             if (actualId != i) {
82                 error("Expected Employee.id " + i + " but got " + actualId);
83             }
84         }
85         tx.commit();
86         failOnError();
87     }
88 }