]> review.fuel-infra Code Review - packages/trusty/mysql-wsrep-5.6.git/blob
6cc68935e308acfb03124031c1b7538cb00309fe
[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.ByteArrayTypes;
22 import testsuite.clusterj.model.IdBase;
23
24 public class QueryByteArrayTypesTest extends AbstractQueryTest {
25
26     @Override
27     public Class getInstanceType() {
28         return ByteArrayTypes.class;
29     }
30
31     @Override
32     void createInstances(int number) {
33         createAllByteArrayTypesInstances(number);
34     }
35
36     /** Test all single- and double-predicate queries using ByteArrayTypes.
37
38 drop table if exists bytestype;
39
40 create table bytestype (
41  id int not null primary key,
42
43  bytes_null_hash varbinary(8),
44  bytes_null_btree varbinary(8),
45  bytes_null_both varbinary(8),
46  bytes_null_none varbinary(8),
47
48 key idx_bytes_null_btree (bytes_null_btree),
49 unique key idx_bytes_null_both (bytes_null_both),
50 unique key idx_bytes_null_hash (bytes_null_hash) using hash
51
52 ) ENGINE=ndbcluster DEFAULT CHARSET=latin1;
53      */
54
55     public void test() {
56         btreeIndexScanByteArray();
57         hashIndexScanByteArray();
58         bothIndexScanByteArray();
59         noneIndexScanByteArray();
60         failOnError();
61     }
62
63     public void btreeIndexScanByteArray() {
64         equalQuery("bytes_null_btree", "idx_bytes_null_btree", getByteArray(8), 8);
65         greaterEqualQuery("bytes_null_btree", "idx_bytes_null_btree", getByteArray(7), 7, 8, 9);
66         greaterThanQuery("bytes_null_btree", "idx_bytes_null_btree", getByteArray(6), 7, 8, 9);
67         lessEqualQuery("bytes_null_btree", "idx_bytes_null_btree", getByteArray(4), 4, 3, 2, 1, 0);
68         lessThanQuery("bytes_null_btree", "idx_bytes_null_btree", getByteArray(4), 3, 2, 1, 0);
69         betweenQuery("bytes_null_btree", "idx_bytes_null_btree", getByteArray(4), getByteArray(6), 4, 5, 6);
70         greaterEqualAndLessEqualQuery("bytes_null_btree", "idx_bytes_null_btree", getByteArray(4), getByteArray(6), 4, 5, 6);
71         greaterThanAndLessEqualQuery("bytes_null_btree", "idx_bytes_null_btree", getByteArray(4), getByteArray(6), 5, 6);
72         greaterEqualAndLessThanQuery("bytes_null_btree", "idx_bytes_null_btree", getByteArray(4), getByteArray(6), 4, 5);
73         greaterThanAndLessThanQuery("bytes_null_btree", "idx_bytes_null_btree", getByteArray(4), getByteArray(6), 5);
74     }
75
76     public void hashIndexScanByteArray() {
77         equalQuery("bytes_null_hash", "idx_bytes_null_hash", getByteArray(8), 8);
78         greaterEqualQuery("bytes_null_hash", "none", getByteArray(7), 7, 8, 9);
79         greaterThanQuery("bytes_null_hash", "none", getByteArray(6), 7, 8, 9);
80         lessEqualQuery("bytes_null_hash", "none", getByteArray(4), 4, 3, 2, 1, 0);
81         lessThanQuery("bytes_null_hash", "none", getByteArray(4), 3, 2, 1, 0);
82         betweenQuery("bytes_null_hash", "none", getByteArray(4), getByteArray(6), 4, 5, 6);
83         greaterEqualAndLessEqualQuery("bytes_null_hash", "none", getByteArray(4), getByteArray(6), 4, 5, 6);
84         greaterThanAndLessEqualQuery("bytes_null_hash", "none", getByteArray(4), getByteArray(6), 5, 6);
85         greaterEqualAndLessThanQuery("bytes_null_hash", "none", getByteArray(4), getByteArray(6), 4, 5);
86         greaterThanAndLessThanQuery("bytes_null_hash", "none", getByteArray(4), getByteArray(6), 5);
87     }
88
89     public void bothIndexScanByteArray() {
90         equalQuery("bytes_null_both", "idx_bytes_null_both", getByteArray(8), 8);
91         greaterEqualQuery("bytes_null_both", "idx_bytes_null_both", getByteArray(7), 7, 8, 9);
92         greaterThanQuery("bytes_null_both", "idx_bytes_null_both", getByteArray(6), 7, 8, 9);
93         lessEqualQuery("bytes_null_both", "idx_bytes_null_both", getByteArray(4), 4, 3, 2, 1, 0);
94         lessThanQuery("bytes_null_both", "idx_bytes_null_both", getByteArray(4), 3, 2, 1, 0);
95         betweenQuery("bytes_null_both", "idx_bytes_null_both", getByteArray(4), getByteArray(6), 4, 5, 6);
96         greaterEqualAndLessEqualQuery("bytes_null_both", "idx_bytes_null_both", getByteArray(4), getByteArray(6), 4, 5, 6);
97         greaterThanAndLessEqualQuery("bytes_null_both", "idx_bytes_null_both", getByteArray(4), getByteArray(6), 5, 6);
98         greaterEqualAndLessThanQuery("bytes_null_both", "idx_bytes_null_both", getByteArray(4), getByteArray(6), 4, 5);
99         greaterThanAndLessThanQuery("bytes_null_both", "idx_bytes_null_both", getByteArray(4), getByteArray(6), 5);
100     }
101
102     public void noneIndexScanByteArray() {
103         equalQuery("bytes_null_none", "none", getByteArray(8), 8);
104         greaterEqualQuery("bytes_null_none", "none", getByteArray(7), 7, 8, 9);
105         greaterThanQuery("bytes_null_none", "none", getByteArray(6), 7, 8, 9);
106         lessEqualQuery("bytes_null_none", "none", getByteArray(4), 4, 3, 2, 1, 0);
107         lessThanQuery("bytes_null_none", "none", getByteArray(4), 3, 2, 1, 0);
108         betweenQuery("bytes_null_none", "none", getByteArray(4), getByteArray(6), 4, 5, 6);
109         greaterEqualAndLessEqualQuery("bytes_null_none", "none", getByteArray(4), getByteArray(6), 4, 5, 6);
110         greaterThanAndLessEqualQuery("bytes_null_none", "none", getByteArray(4), getByteArray(6), 5, 6);
111         greaterEqualAndLessThanQuery("bytes_null_none", "none", getByteArray(4), getByteArray(6), 4, 5);
112         greaterThanAndLessThanQuery("bytes_null_none", "none", getByteArray(4), getByteArray(6), 5);
113     }
114
115
116     private void createAllByteArrayTypesInstances(int number) {
117         for (int i = 0; i < number; ++i) {
118             ByteArrayTypes instance = session.newInstance(ByteArrayTypes.class);
119             instance.setId(i);
120             instance.setBytes_null_hash(getByteArray(i));
121             instance.setBytes_null_btree(getByteArray(i));
122             instance.setBytes_null_both(getByteArray(i));
123             instance.setBytes_null_none(getByteArray(i));
124             instances.add(instance);
125         }
126     }
127
128     protected byte[] getByteArray(int number) {
129         return new byte[]{0, 0, 0, 0, 0, 0, 0, (byte)number};
130     }
131
132     public static String toString(IdBase idBase) {
133         ByteArrayTypes instance = (ByteArrayTypes)idBase;
134         StringBuffer buffer = new StringBuffer("ByteArrayTypes id: ");
135         buffer.append(instance.getId());
136         buffer.append("; bytes_null_both: ");
137         buffer.append(instance.getBytes_null_both().toString());
138         buffer.append("; bytes_null_btree: ");
139         buffer.append(instance.getBytes_null_btree().toString());
140         buffer.append("; bytes_null_hash: ");
141         buffer.append(instance.getBytes_null_hash().toString());
142         buffer.append("; bytes_null_none: ");
143         buffer.append(instance.getBytes_null_none().toString());
144         return buffer.toString();
145     }
146 }