Skip to content

Commit fddbeb6

Browse files
viliam-durinawebashutosh
authored andcommitted
Prepare SQL tests for running them from Jet (hazelcast#17409)
1 parent ed14931 commit fddbeb6

20 files changed

+221
-46
lines changed

hazelcast-sql/pom.xml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -342,5 +342,12 @@
342342
<artifactId>guava</artifactId>
343343
<version>${guava.version}</version>
344344
</dependency>
345+
346+
<dependency>
347+
<groupId>com.googlecode.junit-toolbox</groupId>
348+
<artifactId>junit-toolbox</artifactId>
349+
<version>2.4</version>
350+
<scope>test</scope>
351+
</dependency>
345352
</dependencies>
346353
</project>

hazelcast-sql/src/test/java/com/hazelcast/sql/SqlBasicTest.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
package com.hazelcast.sql;
1818

1919
import com.hazelcast.client.config.ClientConfig;
20-
import com.hazelcast.client.test.TestHazelcastFactory;
2120
import com.hazelcast.config.Config;
2221
import com.hazelcast.config.InMemoryFormat;
2322
import com.hazelcast.config.MapConfig;
@@ -96,7 +95,7 @@ public class SqlBasicTest extends SqlTestSupport {
9695

9796
private static final int[] PAGE_SIZES = { 1, 16, 256, 4096 };
9897
private static final int[] DATA_SET_SIZES = { 1, 256, 4096 };
99-
private static final TestHazelcastFactory FACTORY = new TestHazelcastFactory(2);
98+
private static final SqlTestInstanceFactory FACTORY = SqlTestInstanceFactory.create();
10099

101100
private static HazelcastInstance member1;
102101
private static HazelcastInstance member2;

hazelcast-sql/src/test/java/com/hazelcast/sql/SqlErrorAbstractTest.java

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
package com.hazelcast.sql;
1818

1919
import com.hazelcast.client.config.ClientConfig;
20-
import com.hazelcast.client.test.TestHazelcastFactory;
2120
import com.hazelcast.core.HazelcastInstance;
2221
import com.hazelcast.map.IMap;
2322
import com.hazelcast.sql.impl.SqlErrorCode;
@@ -39,7 +38,7 @@ public class SqlErrorAbstractTest extends SqlTestSupport {
3938
protected static final String MAP_NAME = "map";
4039
private static final int DATA_SET_SIZE = 100;
4140

42-
protected final TestHazelcastFactory factory = new TestHazelcastFactory(3);
41+
protected final SqlTestInstanceFactory factory = SqlTestInstanceFactory.create();
4342

4443
protected HazelcastInstance instance1;
4544
protected HazelcastInstance instance2;
@@ -77,11 +76,13 @@ protected void checkTimeout(boolean useClient, int dataSetSize) {
7776
}
7877
});
7978

80-
blocker.unblockAfter(5000L);
81-
8279
// Execute query on the instance1.
83-
HazelcastSqlException error = assertSqlException(useClient ? client : instance1, query().setTimeoutMillis(100L));
84-
assertEquals(SqlErrorCode.TIMEOUT, error.getCode());
80+
try {
81+
HazelcastSqlException error = assertSqlException(useClient ? client : instance1, query().setTimeoutMillis(100L));
82+
assertEquals(SqlErrorCode.TIMEOUT, error.getCode());
83+
} finally {
84+
blocker.unblock();
85+
}
8586
}
8687

8788
protected void checkExecutionError(boolean useClient, boolean fromFirstMember) {

hazelcast-sql/src/test/java/com/hazelcast/sql/SqlErrorClientTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ public void testDataTypeMismatch() {
120120
@Test
121121
public void testClientConnectedToLiteMember() {
122122
factory.newHazelcastInstance(getConfig().setLiteMember(true));
123-
client = factory.newHazelcastClient();
123+
client = factory.newHazelcastClient(null);
124124

125125
HazelcastSqlException error = assertSqlException(client, query());
126126
assertEquals(SqlErrorCode.CONNECTION_PROBLEM, error.getCode());
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
/*
2+
* Copyright (c) 2008-2020, Hazelcast, Inc. All Rights Reserved.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package com.hazelcast.sql;
18+
19+
import com.googlecode.junittoolbox.WildcardPatternSuite;
20+
import org.junit.runner.RunWith;
21+
22+
/**
23+
* A test suite of all SQL integration tests. These tests are run from Jet
24+
* where the HazelcastInstance is one from a Jet cluster.
25+
*/
26+
@RunWith(WildcardPatternSuite.class)
27+
@com.googlecode.junittoolbox.SuiteClasses("**/*Test.class")
28+
public class SqlIntegrationTestSuite {
29+
}
Lines changed: 139 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,139 @@
1+
/*
2+
* Copyright (c) 2008-2020, Hazelcast, Inc. All Rights Reserved.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package com.hazelcast.sql;
18+
19+
import com.hazelcast.client.config.ClientConfig;
20+
import com.hazelcast.client.test.TestHazelcastFactory;
21+
import com.hazelcast.config.Config;
22+
import com.hazelcast.core.HazelcastInstance;
23+
24+
import javax.annotation.Nonnull;
25+
26+
/**
27+
* An abstract factory that creates either JetInstances or
28+
* HazelcastInstances, based on the {@link #isJet} flag. Used to run SQL
29+
* tests on a jet cluster from Jet.
30+
* <p>
31+
* The JetInstances are created using reflection. {@code
32+
* JetInstance.getHazelcastInstance()} is returned.
33+
*/
34+
public abstract class SqlTestInstanceFactory {
35+
36+
public static boolean isJet;
37+
38+
private SqlTestInstanceFactory() { }
39+
40+
public static SqlTestInstanceFactory create() {
41+
return isJet ? new JetInstanceFactory() : new ImdgInstanceFactory();
42+
}
43+
44+
public abstract HazelcastInstance newHazelcastInstance();
45+
public abstract HazelcastInstance newHazelcastInstance(Config config);
46+
public abstract HazelcastInstance newHazelcastClient(ClientConfig clientConfig);
47+
public abstract void shutdownAll();
48+
49+
/**
50+
* A factory for non-Jet clusters.
51+
*/
52+
private static class ImdgInstanceFactory extends SqlTestInstanceFactory {
53+
54+
private final TestHazelcastFactory factory = new TestHazelcastFactory();
55+
56+
@Override
57+
public HazelcastInstance newHazelcastInstance() {
58+
return factory.newHazelcastInstance();
59+
}
60+
61+
@Override
62+
public HazelcastInstance newHazelcastInstance(Config config) {
63+
return factory.newHazelcastInstance(config);
64+
}
65+
66+
@Override
67+
public HazelcastInstance newHazelcastClient(ClientConfig clientConfig) {
68+
return factory.newHazelcastClient(clientConfig);
69+
}
70+
71+
@Override
72+
public void shutdownAll() {
73+
factory.shutdownAll();
74+
}
75+
}
76+
77+
/**
78+
* A factory for Jet clusters.
79+
*/
80+
private static class JetInstanceFactory extends SqlTestInstanceFactory {
81+
82+
private final Object jetFactory;
83+
84+
JetInstanceFactory() {
85+
try {
86+
Class<?> jetFactoryClass = Class.forName("com.hazelcast.jet.JetTestInstanceFactory");
87+
jetFactory = jetFactoryClass.getConstructor().newInstance();
88+
} catch (Exception e) {
89+
throw new RuntimeException(e);
90+
}
91+
}
92+
93+
@Override
94+
public HazelcastInstance newHazelcastInstance() {
95+
try {
96+
Object jetInstance = jetFactory.getClass().getMethod("newMember")
97+
.invoke(jetFactory);
98+
return (HazelcastInstance) jetInstance.getClass().getMethod("getHazelcastInstance").invoke(jetInstance);
99+
} catch (Exception e) {
100+
throw new RuntimeException(e);
101+
}
102+
}
103+
104+
@Override
105+
public HazelcastInstance newHazelcastInstance(@Nonnull Config config) {
106+
try {
107+
Object jetInstance = jetFactory.getClass().getMethod("newMember", config.getClass())
108+
.invoke(jetFactory, config);
109+
return (HazelcastInstance) jetInstance.getClass().getMethod("getHazelcastInstance").invoke(jetInstance);
110+
} catch (Exception e) {
111+
throw new RuntimeException(e);
112+
}
113+
}
114+
115+
@Override
116+
public HazelcastInstance newHazelcastClient(ClientConfig clientConfig) {
117+
try {
118+
if (clientConfig != null) {
119+
clientConfig.setClusterName("jet");
120+
}
121+
Object jetInstance = jetFactory.getClass().getMethod("newClient", clientConfig.getClass())
122+
.invoke(jetFactory, clientConfig);
123+
return (HazelcastInstance) jetInstance.getClass().getMethod("getHazelcastInstance").invoke(jetInstance);
124+
} catch (Exception e) {
125+
throw new RuntimeException(e);
126+
}
127+
}
128+
129+
@Override
130+
public void shutdownAll() {
131+
try {
132+
jetFactory.getClass().getMethod("shutdownAll")
133+
.invoke(jetFactory);
134+
} catch (Exception e) {
135+
throw new RuntimeException(e);
136+
}
137+
}
138+
}
139+
}

hazelcast-sql/src/test/java/com/hazelcast/sql/impl/expression/CastEndToEndTest.java renamed to hazelcast-sql/src/test/java/com/hazelcast/sql/impl/expression/CastIntegrationTest.java

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@
4646

4747
@RunWith(HazelcastParallelClassRunner.class)
4848
@Category({QuickTest.class, ParallelJVMTest.class})
49-
public class CastEndToEndTest extends ExpressionEndToEndTestBase {
49+
public class CastIntegrationTest extends ExpressionIntegrationTestBase {
5050

5151
@Test
5252
public void testBoolean() {
@@ -81,7 +81,7 @@ public void testBoolean() {
8181
assertDataError("cast(objectString1 as boolean)", "Cannot convert VARCHAR to BOOLEAN");
8282
assertDataError("cast(objectChar1 as boolean)", "Cannot convert VARCHAR to BOOLEAN");
8383
assertDataError("cast(object as boolean)", "Cannot convert OBJECT to BOOLEAN: com.hazelcast.sql.impl.expression"
84-
+ ".ExpressionEndToEndTestBase$SerializableObject");
84+
+ ".ExpressionIntegrationTestBase$SerializableObject");
8585

8686
assertParsingError("cast(dateCol as boolean)", "Cast function cannot convert value of type DATE to type BOOLEAN");
8787
assertParsingError("cast(timeCol as boolean)", "Cast function cannot convert value of type TIME to type BOOLEAN");
@@ -130,7 +130,7 @@ public void testTinyint() {
130130
assertRow("cast(objectString1 as tinyint)", EXPR0, TINYINT, (byte) 1);
131131
assertRow("cast(objectChar1 as tinyint)", EXPR0, TINYINT, (byte) 1);
132132
assertDataError("cast(object as tinyint)", "Cannot convert OBJECT to TINYINT: com.hazelcast.sql.impl.expression"
133-
+ ".ExpressionEndToEndTestBase$SerializableObject");
133+
+ ".ExpressionIntegrationTestBase$SerializableObject");
134134

135135
assertParsingError("cast(dateCol as tinyint)", "Cast function cannot convert value of type DATE to type TINYINT");
136136
assertParsingError("cast(timeCol as tinyint)", "Cast function cannot convert value of type TIME to type TINYINT");
@@ -180,7 +180,7 @@ public void testSmallint() {
180180
assertRow("cast(objectString1 as smallint)", EXPR0, SMALLINT, (short) 1);
181181
assertRow("cast(objectChar1 as smallint)", EXPR0, SMALLINT, (short) 1);
182182
assertDataError("cast(object as smallint)", "Cannot convert OBJECT to SMALLINT: com.hazelcast.sql.impl.expression"
183-
+ ".ExpressionEndToEndTestBase$SerializableObject");
183+
+ ".ExpressionIntegrationTestBase$SerializableObject");
184184

185185
assertParsingError("cast(dateCol as smallint)", "Cast function cannot convert value of type DATE to type SMALLINT");
186186
assertParsingError("cast(timeCol as smallint)", "Cast function cannot convert value of type TIME to type SMALLINT");
@@ -229,7 +229,7 @@ public void testInteger() {
229229
assertRow("cast(objectString1 as integer)", EXPR0, INTEGER, 1);
230230
assertRow("cast(objectChar1 as integer)", EXPR0, INTEGER, 1);
231231
assertDataError("cast(object as integer)", "Cannot convert OBJECT to INTEGER: com.hazelcast.sql.impl.expression"
232-
+ ".ExpressionEndToEndTestBase$SerializableObject");
232+
+ ".ExpressionIntegrationTestBase$SerializableObject");
233233

234234
assertParsingError("cast(dateCol as integer)", "Cast function cannot convert value of type DATE to type INTEGER");
235235
assertParsingError("cast(timeCol as integer)", "Cast function cannot convert value of type TIME to type INTEGER");
@@ -278,7 +278,7 @@ public void testBigint() {
278278
assertRow("cast(objectString1 as bigint)", EXPR0, BIGINT, 1L);
279279
assertRow("cast(objectChar1 as bigint)", EXPR0, BIGINT, 1L);
280280
assertDataError("cast(object as bigint)", "Cannot convert OBJECT to BIGINT: com.hazelcast.sql.impl.expression"
281-
+ ".ExpressionEndToEndTestBase$SerializableObject");
281+
+ ".ExpressionIntegrationTestBase$SerializableObject");
282282

283283
assertParsingError("cast(dateCol as bigint)", "Cast function cannot convert value of type DATE to type BIGINT");
284284
assertParsingError("cast(timeCol as bigint)", "Cast function cannot convert value of type TIME to type BIGINT");
@@ -327,7 +327,7 @@ public void testReal() {
327327
assertRow("cast(objectString1 as real)", EXPR0, REAL, 1.0f);
328328
assertRow("cast(objectChar1 as real)", EXPR0, REAL, 1.0f);
329329
assertDataError("cast(object as real)", "Cannot convert OBJECT to REAL: com.hazelcast.sql.impl.expression"
330-
+ ".ExpressionEndToEndTestBase$SerializableObject");
330+
+ ".ExpressionIntegrationTestBase$SerializableObject");
331331

332332
assertParsingError("cast(dateCol as real)", "Cast function cannot convert value of type DATE to type REAL");
333333
assertParsingError("cast(timeCol as real)", "Cast function cannot convert value of type TIME to type REAL");
@@ -376,7 +376,7 @@ public void testDouble() {
376376
assertRow("cast(objectString1 as double)", EXPR0, DOUBLE, 1.0);
377377
assertRow("cast(objectChar1 as double)", EXPR0, DOUBLE, 1.0);
378378
assertDataError("cast(object as double)", "Cannot convert OBJECT to DOUBLE: com.hazelcast.sql.impl.expression"
379-
+ ".ExpressionEndToEndTestBase$SerializableObject");
379+
+ ".ExpressionIntegrationTestBase$SerializableObject");
380380

381381
assertParsingError("cast(dateCol as double)", "Cast function cannot convert value of type DATE to type DOUBLE");
382382
assertParsingError("cast(timeCol as double)", "Cast function cannot convert value of type TIME to type DOUBLE");
@@ -427,7 +427,7 @@ public void testDecimal() {
427427
assertRow("cast(objectString1 as decimal)", EXPR0, DECIMAL, BigDecimal.valueOf(1));
428428
assertRow("cast(objectChar1 as decimal)", EXPR0, DECIMAL, BigDecimal.valueOf(1));
429429
assertDataError("cast(object as decimal)", "Cannot convert OBJECT to DECIMAL: com.hazelcast.sql.impl.expression"
430-
+ ".ExpressionEndToEndTestBase$SerializableObject");
430+
+ ".ExpressionIntegrationTestBase$SerializableObject");
431431

432432
assertParsingError("cast(dateCol as decimal)", "Cast function cannot convert value of type DATE to type DECIMAL");
433433
assertParsingError("cast(timeCol as decimal)", "Cast function cannot convert value of type TIME to type DECIMAL");

hazelcast-sql/src/test/java/com/hazelcast/sql/impl/expression/ColumnEndToEndTest.java renamed to hazelcast-sql/src/test/java/com/hazelcast/sql/impl/expression/ColumnIntegrationTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@
5151
@RunWith(Parameterized.class)
5252
@UseParametersRunnerFactory(HazelcastParallelParametersRunnerFactory.class)
5353
@Category({QuickTest.class, ParallelJVMTest.class})
54-
public class ColumnEndToEndTest extends ExpressionEndToEndTestBase {
54+
public class ColumnIntegrationTest extends ExpressionIntegrationTestBase {
5555

5656
@Parameter
5757
public String mapName;

hazelcast-sql/src/test/java/com/hazelcast/sql/impl/expression/ExpressionEndToEndTestBase.java renamed to hazelcast-sql/src/test/java/com/hazelcast/sql/impl/expression/ExpressionIntegrationTestBase.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,13 @@
2626
import com.hazelcast.nio.serialization.Portable;
2727
import com.hazelcast.nio.serialization.PortableReader;
2828
import com.hazelcast.nio.serialization.PortableWriter;
29-
import com.hazelcast.sql.SqlColumnType;
30-
import com.hazelcast.sql.impl.SqlErrorCode;
3129
import com.hazelcast.sql.HazelcastSqlException;
30+
import com.hazelcast.sql.SqlColumnType;
3231
import com.hazelcast.sql.SqlRow;
3332
import com.hazelcast.sql.SqlService;
33+
import com.hazelcast.sql.SqlTestInstanceFactory;
34+
import com.hazelcast.sql.impl.SqlErrorCode;
3435
import com.hazelcast.sql.impl.SqlTestSupport;
35-
import com.hazelcast.test.TestHazelcastInstanceFactory;
3636
import org.junit.AfterClass;
3737
import org.junit.BeforeClass;
3838

@@ -49,13 +49,13 @@
4949
import static org.junit.Assert.assertTrue;
5050
import static org.junit.Assert.fail;
5151

52-
public abstract class ExpressionEndToEndTestBase extends SqlTestSupport {
52+
public abstract class ExpressionIntegrationTestBase extends SqlTestSupport {
5353

5454
public static final String EXPR0 = "EXPR$0";
5555

5656
protected static SqlService sql;
5757

58-
private static TestHazelcastInstanceFactory factory;
58+
private static SqlTestInstanceFactory factory;
5959

6060
private static HazelcastInstance instance;
6161

@@ -71,7 +71,7 @@ public static void beforeClass() {
7171
return new PortableRecord();
7272
});
7373

74-
factory = new TestHazelcastInstanceFactory(2);
74+
factory = SqlTestInstanceFactory.create();
7575
sql = factory.newHazelcastInstance(config).getSql();
7676
instance = factory.newHazelcastInstance(config);
7777

hazelcast-sql/src/test/java/com/hazelcast/sql/impl/expression/LiteralEndToEndTest.java renamed to hazelcast-sql/src/test/java/com/hazelcast/sql/impl/expression/LiteralIntegrationTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737

3838
@RunWith(HazelcastParallelClassRunner.class)
3939
@Category({QuickTest.class, ParallelJVMTest.class})
40-
public class LiteralEndToEndTest extends ExpressionEndToEndTestBase {
40+
public class LiteralIntegrationTest extends ExpressionIntegrationTestBase {
4141

4242
@Test
4343
public void testValid() {

0 commit comments

Comments
 (0)