]> review.fuel-infra Code Review - packages/trusty/mysql-wsrep-5.6.git/blob
b0d8de8233651bfd339e77278147d782b6ff4990
[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 testsuite.clusterj.model.ByteArrayTypes;
21 import testsuite.clusterj.model.IdBase;
22
23 /** Derived from QueryStringTypesTest.
24  */
25 public class QueryLikeByteArrayTypesTest extends AbstractQueryTest {
26
27     @Override
28     public Class<?> getInstanceType() {
29         return ByteArrayTypes.class;
30     }
31
32     @Override
33     void createInstances(int number) {
34         createAllByteArrayTypesInstances(number);
35     }
36
37     static byte[][] bytes = new byte[][] {
38         new byte[] {'a', 'a', 'a', 'a'},
39         new byte[] {'a', 'a', 'a', 'b'},
40         new byte[] {'a', 'a', 'b', 'a'},
41         new byte[] {'a', 'a', 'b', 'b'},
42         new byte[] {'a', 'b', 'a', 'a'},
43         new byte[] {'a', 'b', 'a', 'b'},
44         new byte[] {'a', 'b', 'b', 'a'},
45         new byte[] {'a', 'b', 'b', 'b'},
46         new byte[] {'b', 'a', 'a', 'a'},
47         new byte[] {'b', 'a', 'a', 'b'},
48     };
49
50     /** Schema
51     *
52 drop table if exists bytestype;
53 create table bytestype (
54  id int not null primary key,
55
56  bytes_null_hash varbinary(8),
57  bytes_null_btree varbinary(8),
58  bytes_null_both varbinary(8),
59  bytes_null_none varbinary(8),
60 key idx_bytes_null_btree (bytes_null_btree),
61 unique key idx_bytes_null_both (bytes_null_both),
62 unique key idx_bytes_null_hash (bytes_null_hash) using hash
63
64 ) ENGINE=ndbcluster DEFAULT CHARSET=latin1;
65
66     */
67     public void test() {
68         btreeIndexScanString();
69         hashIndexScanString();
70         bothIndexScanString();
71         noneIndexScanString();
72         failOnError();
73     }
74
75     public void btreeIndexScanString() {
76         likeQuery("bytes_null_btree", "none", new byte[] {(byte)'%'}, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9);
77         likeQuery("bytes_null_btree", "none", new byte[] {(byte)'_'});
78         likeQuery("bytes_null_btree", "none", new byte[] {(byte)'_', (byte)'_', (byte)'_', (byte)'_'}, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9);
79         likeQuery("bytes_null_btree", "none", new byte[] {(byte)'_', (byte)'a', (byte)'a', (byte)'a'}, 0, 8);
80         likeQuery("bytes_null_btree", "none", new byte[] {(byte)'a', (byte)'b', (byte)'a', (byte)'a'}, 4);
81         likeQuery("bytes_null_btree", "none", new byte[] {(byte)'a', (byte)'b', (byte)'a', (byte)'%'}, 4, 5);
82         likeQuery("bytes_null_btree", "none", new byte[] {(byte)'a', (byte)'b', (byte)'%'}, 4, 5, 6, 7);
83         greaterEqualAndLikeQuery("bytes_null_btree", "idx_bytes_null_btree", getBytes(4), new byte[] {(byte)'%'}, 4, 5, 6, 7, 8, 9);
84         greaterEqualAndLikeQuery("bytes_null_btree", "idx_bytes_null_btree", getBytes(4), new byte[] {(byte)'a', (byte)'%', (byte)'b'}, 5, 7);
85         greaterThanAndLikeQuery("bytes_null_btree", "idx_bytes_null_btree", getBytes(4), new byte[] {(byte)'%', (byte)'b', (byte)'b', (byte)'%'}, 6, 7);
86     }
87
88     public void hashIndexScanString() {
89         greaterEqualAndLikeQuery("bytes_null_hash", "none", getBytes(3), new byte[] {(byte)'%', (byte)'b', (byte)'b', (byte)'%'}, 3, 6, 7);
90         greaterThanAndLikeQuery("bytes_null_hash", "none", getBytes(3), new byte[] {(byte)'%', (byte)'b', (byte)'b', (byte)'%'}, 6, 7);
91     }
92
93     public void bothIndexScanString() {
94         greaterEqualAndLikeQuery("bytes_null_both", "idx_bytes_null_both", getBytes(3), new byte[] {(byte)'%', (byte)'b', (byte)'b', (byte)'%'}, 3, 6, 7);
95         greaterThanAndLikeQuery("bytes_null_both", "idx_bytes_null_both", getBytes(3), new byte[] {(byte)'%', (byte)'b', (byte)'b', (byte)'%'}, 6, 7);
96     }
97
98     public void noneIndexScanString() {
99         greaterEqualAndLikeQuery("bytes_null_none", "none", getBytes(3), new byte[] {(byte)'%', (byte)'b', (byte)'b', (byte)'%'}, 3, 6, 7);
100         greaterThanAndLikeQuery("bytes_null_none", "none", getBytes(3), new byte[] {(byte)'%', (byte)'b', (byte)'b', (byte)'%'}, 6, 7);
101     }
102
103     private void createAllByteArrayTypesInstances(int number) {
104         for (int i = 0; i < number; ++i) {
105             ByteArrayTypes instance = session.newInstance(ByteArrayTypes.class);
106             instance.setId(i);
107             instance.setBytes_null_hash(getBytes(i));
108             instance.setBytes_null_btree(getBytes(i));
109             instance.setBytes_null_both(getBytes(i));
110             instance.setBytes_null_none(getBytes(i));
111             instances.add(instance);
112         }
113     }
114
115     protected byte[] getBytes(int number) {
116         return bytes[number];
117     }
118
119     /** Print the results of a query for debugging.
120      *
121      * @param instance the instance to print
122      */
123     @Override
124     protected void printResultInstance(IdBase instance) {
125         if (instance instanceof ByteArrayTypes) {
126             @SuppressWarnings("unused")
127             ByteArrayTypes stringType = (ByteArrayTypes)instance;
128 //            System.out.println(toString(stringType));
129         }
130     }
131
132 }