]> review.fuel-infra Code Review - packages/trusty/mysql-wsrep-5.6.git/blob
e27becc5c33355297a3754d2770622e2f8248d80
[packages/trusty/mysql-wsrep-5.6.git] /
1 /*
2    Copyright 2010 Sun Microsystems, Inc.
3    All rights reserved. Use is subject to license terms.
4
5    This program is free software; you can redistribute it and/or modify
6    it under the terms of the GNU General Public License as published by
7    the Free Software Foundation; version 2 of the License.
8
9    This program is distributed in the hope that it will be useful,
10    but WITHOUT ANY WARRANTY; without even the implied warranty of
11    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12    GNU General Public License for more details.
13
14    You should have received a copy of the GNU General Public License
15    along with this program; if not, write to the Free Software
16    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301  USA
17 */
18
19 package testsuite.clusterj;
20
21 import testsuite.clusterj.model.TimestampAsUtilDateTypes;
22 import java.util.Date;
23
24 import testsuite.clusterj.model.IdBase;
25
26 public class QueryTimestampAsUtilDateTypesTest extends AbstractQueryTest {
27
28     @Override
29     public Class<TimestampAsUtilDateTypes> getInstanceType() {
30         return TimestampAsUtilDateTypes.class;
31     }
32
33     @Override
34     void createInstances(int number) {
35         createAllTimestampAsUtilDateTypesInstances(number);
36     }
37
38     /** Test all single- and double-predicate queries using TimestampTypes.
39 drop table if exists timestamptypes;
40 create table timestamptypes (
41  id int not null primary key,
42
43  timestamp_not_null_hash timestamp,
44  timestamp_not_null_btree timestamp,
45  timestamp_not_null_both timestamp,
46  timestamp_not_null_none timestamp
47
48 ) ENGINE=ndbcluster DEFAULT CHARSET=latin1;
49
50 create unique index idx_timestamp_not_null_hash using hash on timestamptypes(timestamp_not_null_hash);
51 create index idx_timestamp_not_null_btree on timestamptypes(timestamp_not_null_btree);
52 create unique index idx_timestamp_not_null_both on timestamptypes(timestamp_not_null_both);
53
54      */
55
56     public void test() {
57         btreeIndexScanTimestamp();
58         hashIndexScanTimestamp();
59         bothIndexScanTimestamp();
60         noneIndexScanTimestamp();
61         failOnError();
62     }
63
64     public void btreeIndexScanTimestamp() {
65         equalQuery("timestamp_not_null_btree", "idx_timestamp_not_null_btree", getUtilDateFor(8), 8);
66         greaterEqualQuery("timestamp_not_null_btree", "idx_timestamp_not_null_btree", getUtilDateFor(7), 7, 8, 9);
67         greaterThanQuery("timestamp_not_null_btree", "idx_timestamp_not_null_btree", getUtilDateFor(6), 7, 8, 9);
68         lessEqualQuery("timestamp_not_null_btree", "idx_timestamp_not_null_btree", getUtilDateFor(4), 4, 3, 2, 1, 0);
69         lessThanQuery("timestamp_not_null_btree", "idx_timestamp_not_null_btree", getUtilDateFor(4), 3, 2, 1, 0);
70         betweenQuery("timestamp_not_null_btree", "idx_timestamp_not_null_btree", getUtilDateFor(4), getUtilDateFor(6), 4, 5, 6);
71         greaterEqualAndLessEqualQuery("timestamp_not_null_btree", "idx_timestamp_not_null_btree", getUtilDateFor(4), getUtilDateFor(6), 4, 5, 6);
72         greaterThanAndLessEqualQuery("timestamp_not_null_btree", "idx_timestamp_not_null_btree", getUtilDateFor(4), getUtilDateFor(6), 5, 6);
73         greaterEqualAndLessThanQuery("timestamp_not_null_btree", "idx_timestamp_not_null_btree", getUtilDateFor(4), getUtilDateFor(6), 4, 5);
74         greaterThanAndLessThanQuery("timestamp_not_null_btree", "idx_timestamp_not_null_btree", getUtilDateFor(4), getUtilDateFor(6), 5);
75     }
76
77     public void hashIndexScanTimestamp() {
78         equalQuery("timestamp_not_null_hash", "idx_timestamp_not_null_hash", getUtilDateFor(8), 8);
79         greaterEqualQuery("timestamp_not_null_hash", "none", getUtilDateFor(7), 7, 8, 9);
80         greaterThanQuery("timestamp_not_null_hash", "none", getUtilDateFor(6), 7, 8, 9);
81         lessEqualQuery("timestamp_not_null_hash", "none", getUtilDateFor(4), 4, 3, 2, 1, 0);
82         lessThanQuery("timestamp_not_null_hash", "none", getUtilDateFor(4), 3, 2, 1, 0);
83         betweenQuery("timestamp_not_null_hash", "none", getUtilDateFor(4), getUtilDateFor(6), 4, 5, 6);
84         greaterEqualAndLessEqualQuery("timestamp_not_null_hash", "none", getUtilDateFor(4), getUtilDateFor(6), 4, 5, 6);
85         greaterThanAndLessEqualQuery("timestamp_not_null_hash", "none", getUtilDateFor(4), getUtilDateFor(6), 5, 6);
86         greaterEqualAndLessThanQuery("timestamp_not_null_hash", "none", getUtilDateFor(4), getUtilDateFor(6), 4, 5);
87         greaterThanAndLessThanQuery("timestamp_not_null_hash", "none", getUtilDateFor(4), getUtilDateFor(6), 5);
88     }
89
90     public void bothIndexScanTimestamp() {
91         equalQuery("timestamp_not_null_both", "idx_timestamp_not_null_both", getUtilDateFor(8), 8);
92         greaterEqualQuery("timestamp_not_null_both", "idx_timestamp_not_null_both", getUtilDateFor(7), 7, 8, 9);
93         greaterThanQuery("timestamp_not_null_both", "idx_timestamp_not_null_both", getUtilDateFor(6), 7, 8, 9);
94         lessEqualQuery("timestamp_not_null_both", "idx_timestamp_not_null_both", getUtilDateFor(4), 4, 3, 2, 1, 0);
95         lessThanQuery("timestamp_not_null_both", "idx_timestamp_not_null_both", getUtilDateFor(4), 3, 2, 1, 0);
96         betweenQuery("timestamp_not_null_both", "idx_timestamp_not_null_both", getUtilDateFor(4), getUtilDateFor(6), 4, 5, 6);
97         greaterEqualAndLessEqualQuery("timestamp_not_null_both", "idx_timestamp_not_null_both", getUtilDateFor(4), getUtilDateFor(6), 4, 5, 6);
98         greaterThanAndLessEqualQuery("timestamp_not_null_both", "idx_timestamp_not_null_both", getUtilDateFor(4), getUtilDateFor(6), 5, 6);
99         greaterEqualAndLessThanQuery("timestamp_not_null_both", "idx_timestamp_not_null_both", getUtilDateFor(4), getUtilDateFor(6), 4, 5);
100         greaterThanAndLessThanQuery("timestamp_not_null_both", "idx_timestamp_not_null_both", getUtilDateFor(4), getUtilDateFor(6), 5);
101     }
102
103     public void noneIndexScanTimestamp() {
104         equalQuery("timestamp_not_null_none", "none", getUtilDateFor(8), 8);
105         greaterEqualQuery("timestamp_not_null_none", "none", getUtilDateFor(7), 7, 8, 9);
106         greaterThanQuery("timestamp_not_null_none", "none", getUtilDateFor(6), 7, 8, 9);
107         lessEqualQuery("timestamp_not_null_none", "none", getUtilDateFor(4), 4, 3, 2, 1, 0);
108         lessThanQuery("timestamp_not_null_none", "none", getUtilDateFor(4), 3, 2, 1, 0);
109         betweenQuery("timestamp_not_null_none", "none", getUtilDateFor(4), getUtilDateFor(6), 4, 5, 6);
110         greaterEqualAndLessEqualQuery("timestamp_not_null_none", "none", getUtilDateFor(4), getUtilDateFor(6), 4, 5, 6);
111         greaterThanAndLessEqualQuery("timestamp_not_null_none", "none", getUtilDateFor(4), getUtilDateFor(6), 5, 6);
112         greaterEqualAndLessThanQuery("timestamp_not_null_none", "none", getUtilDateFor(4), getUtilDateFor(6), 4, 5);
113         greaterThanAndLessThanQuery("timestamp_not_null_none", "none", getUtilDateFor(4), getUtilDateFor(6), 5);
114     }
115
116     private void createAllTimestampAsUtilDateTypesInstances(int number) {
117         for (int i = 0; i < number; ++i) {
118             TimestampAsUtilDateTypes instance = session.newInstance(TimestampAsUtilDateTypes.class);
119             instance.setId(i);
120             instance.setTimestamp_not_null_hash(getUtilDateFor(i));
121             instance.setTimestamp_not_null_btree(getUtilDateFor(i));
122             instance.setTimestamp_not_null_both(getUtilDateFor(i));
123             instance.setTimestamp_not_null_none(getUtilDateFor(i));
124             instances.add(instance);
125 //            if (i%3 == 0) System.out.println(toString(instance));
126         }
127     }
128
129     private Date getUtilDateFor(int i) {
130         return new Date(getMillisFor(1980, 0, 1, 0, 0, i));
131     }
132
133     public static String toString(IdBase instance) {
134         TimestampAsUtilDateTypes timetype = (TimestampAsUtilDateTypes)instance;
135         StringBuffer buffer = new StringBuffer("TimestampTypes id: ");
136         buffer.append(timetype.getId());
137         buffer.append("; timestamp_not_null_both: ");
138         buffer.append(timetype.getTimestamp_not_null_both().toString());
139         buffer.append("; timestamp_not_null_btree: ");
140         buffer.append(timetype.getTimestamp_not_null_btree().toString());
141         buffer.append("; timestamp_not_null_hash: ");
142         buffer.append(timetype.getTimestamp_not_null_hash().toString());
143         buffer.append("; timestamp_not_null_none: ");
144         buffer.append(timetype.getTimestamp_not_null_none().toString());
145         return buffer.toString();
146     }
147 }