Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 42ae95c

Browse files
committed
fix static test data creation
renamed InformationSchemaQueryTest to StaticInformationSchemaQueryTes and fixed the optimization to only create the tables once for the class. It didn't really work because Test classes are instantiated for each test method.
1 parent e86b3fc commit 42ae95c

2 files changed

Lines changed: 253 additions & 212 deletions

File tree

sql/src/test/java/io/crate/integrationtests/InformationSchemaQueryTest.java

Lines changed: 7 additions & 212 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
* you may not use this file except in compliance with the License. You may
77
* obtain a copy of the License at
88
*
9-
* http://www.apache.org/licenses/LICENSE-2.0
9+
* http://www.apache.org/licenses/LICENSE-2.0
1010
*
1111
* Unless required by applicable law or agreed to in writing, software
1212
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
@@ -21,232 +21,27 @@
2121

2222
package io.crate.integrationtests;
2323

24-
import io.crate.action.sql.SQLActionException;
25-
import io.crate.action.sql.SQLResponse;
2624
import io.crate.test.integration.CrateIntegrationTest;
2725
import org.elasticsearch.action.admin.indices.close.CloseIndexRequest;
28-
import org.junit.Before;
29-
import org.junit.Rule;
3026
import org.junit.Test;
31-
import org.junit.rules.ExpectedException;
32-
3327

3428
@CrateIntegrationTest.ClusterScope(scope = CrateIntegrationTest.Scope.GLOBAL)
3529
public class InformationSchemaQueryTest extends SQLTransportIntegrationTest {
3630

37-
static {
38-
ClassLoader.getSystemClassLoader().setDefaultAssertionStatus(true);
39-
}
40-
41-
@Rule
42-
public ExpectedException expectedException = ExpectedException.none();
43-
44-
private boolean createdTables = false;
45-
private SQLResponse response;
46-
47-
@Before
48-
public void tableCreation() throws Exception {
49-
synchronized (InformationSchemaQueryTest.class) {
50-
if (!createdTables) {
51-
52-
execute("create table t1 (col1 integer, col2 string) clustered into 7 shards");
53-
execute("create table t2 (col1 integer, col2 string) clustered into 10 shards");
54-
execute("create table t3 (col1 integer, col2 string) with (number_of_replicas=8)");
55-
56-
createdTables = true;
57-
}
58-
}
59-
}
60-
61-
public SQLResponse exec(String stmt) {
62-
response = execute(stmt);
63-
return response;
64-
}
65-
66-
@Test
67-
public void testSelectZeroLimit() throws Exception {
68-
exec("select * from information_schema.columns limit 0");
69-
assertEquals(0L, response.rowCount());
70-
}
71-
72-
@Test
73-
public void testSelectSysColumnsFromInformationSchema() throws Exception {
74-
expectedException.expect(SQLActionException.class);
75-
expectedException.expectMessage("Cannot resolve relation 'sys.nodes'");
76-
execute("select sys.nodes.id, table_name, number_of_replicas from information_schema.tables");
77-
}
78-
79-
@Test
80-
public void testGroupByOnInformationSchema() throws Exception {
81-
exec("select count(*) from information_schema.columns where schema_name = 'doc' group by table_name order by count(*) desc");
82-
assertEquals(3L, response.rowCount());
83-
84-
exec("select count(*) from information_schema.columns where schema_name = 'doc' group by column_name order by count(*) desc");
85-
assertEquals(2L, response.rowCount());
86-
assertEquals(3L, response.rows()[0][0]);
87-
}
88-
89-
@Test
90-
public void testSelectStar() throws Exception {
91-
exec("select * from information_schema.tables where schema_name = 'doc'");
92-
assertEquals(3L, response.rowCount());
93-
}
94-
95-
@Test
96-
public void testLike() throws Exception {
97-
exec("select * from information_schema.tables where schema_name = 'doc' and table_name like 't%'");
98-
assertEquals(3L, response.rowCount());
99-
}
100-
101-
@Test
102-
public void testIsNull() throws Exception {
103-
exec("select * from information_schema.tables where table_name is null");
104-
assertEquals(0L, response.rowCount());
105-
}
106-
107-
@Test
108-
public void testIsNotNull() throws Exception {
109-
exec("select * from information_schema.tables where table_name is not null and schema_name = 'doc'");
110-
assertEquals(3L, response.rowCount());
111-
}
112-
113-
@Test
114-
public void testWhereAnd() throws Exception {
115-
exec("select table_name from information_schema.tables where table_name='t1' and " +
116-
"number_of_shards > 0");
117-
assertEquals(1L, response.rowCount());
118-
assertEquals("t1", response.rows()[0][0]);
119-
}
120-
121-
@Test
122-
public void testWhereAnd2() throws Exception {
123-
exec("select table_name from information_schema.tables where number_of_shards >= 7 and " +
124-
"number_of_replicas != '8' order by table_name asc");
125-
assertEquals(2L, response.rowCount());
126-
assertEquals("t1", response.rows()[0][0]);
127-
assertEquals("t2", response.rows()[1][0]);
128-
}
129-
130-
@Test
131-
public void testWhereAnd3() throws Exception {
132-
exec("select table_name from information_schema.tables where table_name is not null and " +
133-
"number_of_shards > 6 order by table_name asc");
134-
assertEquals(2L, response.rowCount());
135-
assertEquals("t1", response.rows()[0][0]);
136-
assertEquals("t2", response.rows()[1][0]);
137-
}
138-
139-
@Test
140-
public void testWhereOr() throws Exception {
141-
exec("select table_name from information_schema.tables where table_name='t1' or table_name='t3' " +
142-
"order by table_name asc");
143-
assertEquals(2L, response.rowCount());
144-
assertEquals("t1", response.rows()[0][0]);
145-
assertEquals("t3", response.rows()[1][0]);
146-
}
147-
148-
@Test
149-
public void testWhereOr2() throws Exception {
150-
exec("select table_name from information_schema.tables where table_name='t1' or table_name='t3' " +
151-
"or table_name='t2'" +
152-
"order by table_name desc");
153-
assertEquals(3L, response.rowCount());
154-
assertEquals("t3", response.rows()[0][0]);
155-
assertEquals("t2", response.rows()[1][0]);
156-
assertEquals("t1", response.rows()[2][0]);
157-
}
158-
159-
@Test
160-
public void testWhereIn() throws Exception {
161-
exec("select table_name from information_schema.tables where table_name in ('t1', 't2') order by table_name asc");
162-
assertEquals(2L, response.rowCount());
163-
assertEquals("t1", response.rows()[0][0]);
164-
assertEquals("t2", response.rows()[1][0]);
165-
}
166-
167-
@Test
168-
public void testNotEqualsString() throws Exception {
169-
exec("select table_name from information_schema.tables where schema_name = 'doc' and table_name != 't1'");
170-
assertEquals(2L, response.rowCount());
171-
assertTrue(!response.rows()[0][0].equals("t1"));
172-
assertTrue(!response.rows()[1][0].equals("t1"));
173-
}
174-
175-
@Test
176-
public void testNotEqualsNumber() throws Exception {
177-
exec("select table_name, number_of_shards from information_schema.tables where schema_name = 'doc' and number_of_shards != 7");
178-
assertEquals(2L, response.rowCount());
179-
assertTrue((int)response.rows()[0][1] != 7);
180-
assertTrue((int) response.rows()[1][1] != 7);
181-
}
182-
183-
@Test
184-
public void testEqualsNumber() throws Exception {
185-
exec("select table_name from information_schema.tables where schema_name = 'doc' and number_of_shards = 7");
186-
assertEquals(1L, response.rowCount());
187-
assertEquals("t1", response.rows()[0][0]);
188-
}
189-
190-
@Test
191-
public void testEqualsString() throws Exception {
192-
exec("select table_name from information_schema.tables where table_name = 't1'");
193-
assertEquals(1L, response.rowCount());
194-
assertEquals("t1", response.rows()[0][0]);
195-
}
196-
197-
@Test
198-
public void testGtNumber() throws Exception {
199-
exec("select table_name from information_schema.tables where number_of_shards > 7");
200-
assertEquals(1L, response.rowCount());
201-
assertEquals("t2", response.rows()[0][0]);
202-
}
203-
204-
@Test
205-
public void testOrderByStringAndLimit() throws Exception {
206-
exec("select table_name, number_of_shards, number_of_replicas from information_schema.tables " +
207-
" where schema_name = 'doc' order by table_name desc limit 2");
208-
assertEquals(2L, response.rowCount());
209-
assertEquals("t3", response.rows()[0][0]);
210-
assertEquals("t2", response.rows()[1][0]);
211-
}
212-
213-
@Test
214-
public void testOrderByNumberAndLimit() throws Exception {
215-
exec("select table_name, number_of_shards, number_of_replicas from information_schema.tables " +
216-
" order by number_of_shards desc limit 2");
217-
assertEquals(2L, response.rowCount());
218-
assertEquals(10, response.rows()[0][1]);
219-
assertEquals("t2", response.rows()[0][0]);
220-
assertEquals(7, response.rows()[1][1]);
221-
assertEquals("t1", response.rows()[1][0]);
222-
}
223-
224-
@Test
225-
public void testLimit1() throws Exception {
226-
exec("select * from information_schema.tables limit 1");
227-
assertEquals(1L, response.rowCount());
228-
}
229-
230-
@Test
231-
public void testSelectUnknownTableFromInformationSchema() throws Exception {
232-
expectedException.expect(SQLActionException.class);
233-
expectedException.expectMessage("Table 'information_schema.non_existent' unknown");
234-
exec("select * from information_schema.non_existent");
235-
}
236-
23731
@Test
23832
public void testIgnoreClosedTables() throws Exception {
239-
execute("drop table t1");
240-
execute("drop table t2");
33+
execute("create table t3 (col1 integer, col2 string) with (number_of_replicas=8)");
24134
execute("create table t1 (col1 integer, col2 string) with (number_of_replicas=0)");
35+
24236
client().admin().indices().close(new CloseIndexRequest("t3"));
24337
ensureGreen();
244-
exec("select * from information_schema.tables where schema_name = 'doc'");
38+
39+
execute("select * from information_schema.tables where schema_name = 'doc'");
24540
assertEquals(1L, response.rowCount());
246-
exec("select * from information_schema.columns where table_name = 't3'");
41+
execute("select * from information_schema.columns where table_name = 't3'");
24742
assertEquals(0, response.rowCount());
24843

249-
exec("select * from sys.shards");
44+
execute("select * from sys.shards");
25045
assertEquals(5L, response.rowCount()); // t3 isn't included
25146
}
25247
}

0 commit comments

Comments
 (0)