Skip to content

Commit 175eae4

Browse files
committed
refactored unit tests.
1 parent 2d63ec4 commit 175eae4

File tree

5 files changed

+34
-58
lines changed

5 files changed

+34
-58
lines changed

athena-vertica/src/test/java/com/amazonaws/athena/connectors/vertica/VerticaMetadataHandlerTest.java

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,6 @@
5858
import org.junit.Before;
5959
import org.junit.Test;
6060
import org.junit.runner.RunWith;
61-
import org.mockito.Mock;
6261
import org.mockito.Mockito;
6362
import org.mockito.junit.MockitoJUnitRunner;
6463
import org.slf4j.Logger;
@@ -124,8 +123,6 @@ public class VerticaMetadataHandlerTest extends TestBase
124123
private BlockWriter blockWriter;
125124
private QueryStatusChecker queryStatusChecker;
126125
private VerticaMetadataHandler verticaMetadataHandlerMocked;
127-
@Mock
128-
private S3Client s3clientMock;
129126
private DatabaseConnectionConfig databaseConnectionConfig = new DatabaseConnectionConfig("testCatalog", VERTICA_NAME,
130127
"vertica://jdbc:vertica:thin:username/password@//127.0.0.1:1521/vrt");
131128

@@ -159,7 +156,6 @@ public void setUp() throws Exception
159156
Mockito.when(this.jdbcConnectionFactory.getConnection(nullable(CredentialsProvider.class))).thenReturn(this.connection);
160157
this.verticaMetadataHandler = new VerticaMetadataHandler(databaseConnectionConfig, this.jdbcConnectionFactory,
161158
com.google.common.collect.ImmutableMap.of(), amazonS3, verticaSchemaUtils);
162-
verticaMetadataHandlerMocked = Mockito.spy(this.verticaMetadataHandler);
163159
this.allocator = new BlockAllocatorImpl();
164160
this.databaseMetaData = this.connection.getMetaData();
165161
verticaMetadataHandlerMocked = Mockito.spy(this.verticaMetadataHandler);
@@ -257,7 +253,6 @@ public void doListSchemaNames() throws Exception
257253
@Test
258254
public void enhancePartitionSchema()
259255
{
260-
GetTableLayoutRequest req = null;
261256
Set<String> partitionCols = new HashSet<>();
262257
SchemaBuilder schemaBuilder = new SchemaBuilder();
263258

@@ -285,7 +280,7 @@ public void getPartitions() throws Exception {
285280
.addField("bigint_col", new ArrowType.Int(64, true)) // BIGINT
286281
.addField("float_col", new ArrowType.FloatingPoint(org.apache.arrow.vector.types.FloatingPointPrecision.SINGLE)) // FLOAT4
287282
.addField("double_col", new ArrowType.FloatingPoint(org.apache.arrow.vector.types.FloatingPointPrecision.DOUBLE)) // FLOAT8
288-
.addField("decimal_col", new ArrowType.Decimal(10, 2)) // DECIMAL
283+
.addField("decimal_col", new ArrowType.Decimal(10, 2, 128)) // DECIMAL
289284
.addStringField("varchar_col") // VARCHAR
290285
.addStringField("preparedStmt")
291286
.addStringField("queryId")
@@ -312,8 +307,8 @@ public void getPartitions() throws Exception {
312307
ImmutableList.of(Range.equal(allocator, new ArrowType.FloatingPoint(org.apache.arrow.vector.types.FloatingPointPrecision.SINGLE), 3.14f)), false));
313308
constraintsMap.put("double_col", SortedRangeSet.copyOf(new ArrowType.FloatingPoint(org.apache.arrow.vector.types.FloatingPointPrecision.DOUBLE),
314309
ImmutableList.of(Range.equal(allocator, new ArrowType.FloatingPoint(org.apache.arrow.vector.types.FloatingPointPrecision.DOUBLE), 3.14159)), false));
315-
constraintsMap.put("decimal_col", SortedRangeSet.copyOf(new ArrowType.Decimal(10, 2),
316-
ImmutableList.of(Range.equal(allocator, new ArrowType.Decimal(10, 2), new BigDecimal("123.45"))), false));
310+
constraintsMap.put("decimal_col", SortedRangeSet.copyOf(new ArrowType.Decimal(10, 2, 128),
311+
ImmutableList.of(Range.equal(allocator, new ArrowType.Decimal(10, 2, 128), new BigDecimal("123.45"))), false));
317312
constraintsMap.put("varchar_col", SortedRangeSet.copyOf(new ArrowType.Utf8(),
318313
ImmutableList.of(Range.equal(allocator, new ArrowType.Utf8(), "test")), false));
319314

@@ -359,7 +354,7 @@ public void getPartitions() throws Exception {
359354

360355
try (GetTableLayoutRequest req = new GetTableLayoutRequest(federatedIdentity, queryId, "default",
361356
new TableName("schema1", "table1"),
362-
new Constraints(constraintsMap, Collections.emptyList(), Collections.emptyList(), DEFAULT_NO_LIMIT),
357+
new Constraints(constraintsMap, Collections.emptyList(), Collections.emptyList(), DEFAULT_NO_LIMIT, Collections.emptyMap()),
363358
tableSchema, partitionCols);
364359
GetTableLayoutResponse res = verticaMetadataHandlerMocked.doGetTableLayout(allocator, req)) {
365360
Block partitions = res.getPartitions();
@@ -388,7 +383,7 @@ public void getPartitions() throws Exception {
388383
}
389384

390385
@Test
391-
public void doGetSplits() throws Exception
386+
public void doGetSplits()
392387
{
393388
Schema schema = SchemaBuilder.newBuilder()
394389
.addIntField("day")
@@ -485,12 +480,11 @@ public void doGetSplitsQueryPassthrough() throws Exception {
485480
GetSplitsRequest req = new GetSplitsRequest(federatedIdentity, "queryId", "catalog_name",
486481
new TableName("schema", JdbcQueryPassthrough.SCHEMA_FUNCTION_NAME), partitions, partitionCols, queryConstraints, null);
487482

488-
MetadataResponse rawResponse = verticaMetadataHandlerMocked.doGetSplits(allocator, req);
483+
GetSplitsResponse rawResponse = verticaMetadataHandlerMocked.doGetSplits(allocator, req);
489484
assertEquals(MetadataRequestType.GET_SPLITS, rawResponse.getRequestType());
490485

491-
GetSplitsResponse response = (GetSplitsResponse) rawResponse;
492-
assertEquals(1, response.getSplits().size());
493-
Split split = response.getSplits().iterator().next();
486+
assertEquals(1, rawResponse.getSplits().size());
487+
Split split = rawResponse.getSplits().iterator().next();
494488
assertEquals("query123", split.getProperty("query_id"));
495489
assertEquals("s3:", split.getProperty("exportBucket"));
496490
assertEquals("query123/part1.parquet", split.getProperty("s3ObjectKey"));

athena-vertica/src/test/java/com/amazonaws/athena/connectors/vertica/VerticaSchemaUtilsTest.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -144,10 +144,10 @@ public void formatCrtFileContents() throws Exception
144144
formatMethod.setAccessible(true);
145145
String result = (String) formatMethod.invoke(null, mockCertificate);
146146

147-
String expectedEncoded = Base64.getMimeEncoder(64, System.getProperty("line.separator").getBytes())
147+
String expectedEncoded = Base64.getMimeEncoder(64, System.lineSeparator().getBytes())
148148
.encodeToString("test-cert".getBytes());
149-
String expected = "-----BEGIN CERTIFICATE-----" + System.getProperty("line.separator") +
150-
expectedEncoded + System.getProperty("line.separator") + "-----END CERTIFICATE-----";
149+
String expected = "-----BEGIN CERTIFICATE-----" + System.lineSeparator() +
150+
expectedEncoded + System.lineSeparator() + "-----END CERTIFICATE-----";
151151
assertEquals(expected, result);
152152
}
153153

athena-vertica/src/test/java/com/amazonaws/athena/connectors/vertica/query/PredicateBuilderTest.java

Lines changed: 15 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,7 @@
3333
import org.apache.arrow.vector.types.pojo.Schema;
3434
import org.junit.After;
3535
import org.junit.Before;
36-
import org.junit.Rule;
3736
import org.junit.Test;
38-
import org.junit.rules.ExpectedException;
3937
import org.junit.runner.RunWith;
4038
import org.mockito.junit.MockitoJUnitRunner;
4139
import java.util.Collections;
@@ -55,9 +53,6 @@ public class PredicateBuilderTest {
5553
private HashMap<String, PredicateBuilder.TypeAndValue> accumulator;
5654
private BlockAllocator allocator;
5755

58-
@Rule
59-
public ExpectedException thrown = ExpectedException.none();
60-
6156
@Before
6257
public void setUp() {
6358
allocator = new BlockAllocatorImpl();
@@ -73,6 +68,7 @@ public void setUp() {
7368
public void tearDown() {
7469
allocator.close();
7570
}
71+
7672
@Test
7773
public void quote_SimpleName_ReturnsQuotedString() {
7874
assertEquals("\"simpleName\"", PredicateBuilder.quote("simpleName"));
@@ -134,15 +130,15 @@ public void toConjuncts_EmptyConstraints_ReturnsEmptyList() {
134130

135131
@Test
136132
public void toConjuncts_NonExistentColumn_ReturnsEmptyList() {
137-
Constraints constraints = createConstraints(ImmutableMap.of("non_existent_col", singleValue(col1Int.getType(), 10, false)));
133+
Constraints constraints = createConstraints(ImmutableMap.of("non_existent_col", singleValue(col1Int.getType(), 10)));
138134
List<String> conjuncts = PredicateBuilder.toConjuncts(schema.getFields(), constraints, accumulator);
139135
assertTrue(conjuncts.isEmpty());
140136
assertTrue(accumulator.isEmpty());
141137
}
142138

143139
@Test
144140
public void toConjuncts_SingleEqualValue_ReturnsEqualityPredicate() {
145-
Constraints constraints = createConstraints(ImmutableMap.of("col1", singleValue(col1Int.getType(), 123, false)));
141+
Constraints constraints = createConstraints(ImmutableMap.of("col1", singleValue(col1Int.getType(), 123)));
146142
List<String> conjuncts = PredicateBuilder.toConjuncts(schema.getFields(), constraints, accumulator);
147143
assertEquals(1, conjuncts.size());
148144
assertEquals("(\"col1\" = <col1> )", conjuncts.get(0));
@@ -173,7 +169,7 @@ public void toConjuncts_MultipleValuesWithNull_ReturnsInOrNullPredicate() {
173169

174170
@Test
175171
public void toConjuncts_GreaterThanValue_ReturnsGreaterThanPredicate() {
176-
Constraints constraints = createConstraints(ImmutableMap.of("col3", greaterThan(col3Double.getType(), 10.5, false)));
172+
Constraints constraints = createConstraints(ImmutableMap.of("col3", greaterThan(col3Double.getType(), 10.5)));
177173
List<String> conjuncts = PredicateBuilder.toConjuncts(schema.getFields(), constraints, accumulator);
178174
assertEquals(1, conjuncts.size());
179175
assertEquals("((\"col3\" > <col3> ))", conjuncts.get(0));
@@ -183,7 +179,7 @@ public void toConjuncts_GreaterThanValue_ReturnsGreaterThanPredicate() {
183179

184180
@Test
185181
public void toConjuncts_InclusiveRange_ReturnsRangePredicate() {
186-
Constraints constraints = createConstraints(ImmutableMap.of("col1", betweenInclusive(col1Int.getType(), 10, 20, false)));
182+
Constraints constraints = createConstraints(ImmutableMap.of("col1", betweenInclusive(col1Int.getType())));
187183
List<String> conjuncts = PredicateBuilder.toConjuncts(schema.getFields(), constraints, accumulator);
188184
assertEquals(1, conjuncts.size());
189185
assertEquals("((\"col1\" >= <col1> AND \"col1\" \\<= <col1> ))", conjuncts.get(0));
@@ -212,8 +208,8 @@ public void toConjuncts_NotNullValue_ReturnsIsNotNullPredicate() {
212208
@Test
213209
public void toConjuncts_MultipleColumns_ReturnsMultiplePredicates() {
214210
Map<String, ValueSet> summary = ImmutableMap.of(
215-
"col1", greaterThan(col1Int.getType(), 10, false),
216-
"col2", singleValue(col2Varchar.getType(), "ACTIVE", false)
211+
"col1", greaterThan(col1Int.getType(), 10),
212+
"col2", singleValue(col2Varchar.getType(), "ACTIVE")
217213
);
218214
Constraints constraints = createConstraints(summary);
219215
List<String> conjuncts = PredicateBuilder.toConjuncts(schema.getFields(), constraints, accumulator);
@@ -236,40 +232,26 @@ public void TypeAndValue_ValidInput_ReturnsCorrectValues() {
236232

237233

238234
private Constraints createConstraints(Map<String, ValueSet> summary) {
239-
return new Constraints(summary, Collections.emptyList(), Collections.emptyList(), Constraints.DEFAULT_NO_LIMIT);
235+
return new Constraints(summary, Collections.emptyList(), Collections.emptyList(), Constraints.DEFAULT_NO_LIMIT, Collections.emptyMap());
240236
}
241237

242-
private ValueSet singleValue(ArrowType type, Object value, boolean nullAllowed) {
238+
private ValueSet singleValue(ArrowType type, Object value) {
243239
Range range = Range.equal(allocator, type, value);
244-
return SortedRangeSet.newBuilder(type, nullAllowed)
240+
return SortedRangeSet.newBuilder(type, false)
245241
.add(range)
246242
.build();
247243
}
248244

249-
private ValueSet greaterThan(ArrowType type, Object value, boolean nullAllowed) {
245+
private ValueSet greaterThan(ArrowType type, Object value) {
250246
Range range = Range.greaterThan(allocator, type, value);
251-
return SortedRangeSet.newBuilder(type, nullAllowed)
252-
.add(range)
253-
.build();
254-
}
255-
256-
private ValueSet lessThanOrEqual(ArrowType type, Object value, boolean nullAllowed) {
257-
Range range = Range.lessThanOrEqual(allocator, type, value);
258-
return SortedRangeSet.newBuilder(type, nullAllowed)
259-
.add(range)
260-
.build();
261-
}
262-
263-
private ValueSet between(ArrowType type, Object lower, Object upper, boolean nullAllowed) {
264-
Range range = Range.range(allocator, type, lower, false, upper, false);
265-
return SortedRangeSet.newBuilder(type, nullAllowed)
247+
return SortedRangeSet.newBuilder(type, false)
266248
.add(range)
267249
.build();
268250
}
269251

270-
private ValueSet betweenInclusive(ArrowType type, Object lower, Object upper, boolean nullAllowed) {
271-
Range range = Range.range(allocator, type, lower, true, upper, true);
272-
return SortedRangeSet.newBuilder(type, nullAllowed)
252+
private ValueSet betweenInclusive(ArrowType type) {
253+
Range range = Range.range(allocator, type, 10, true, 20, true);
254+
return SortedRangeSet.newBuilder(type, false)
273255
.add(range)
274256
.build();
275257
}

athena-vertica/src/test/java/com/amazonaws/athena/connectors/vertica/query/QueryFactoryTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,8 @@
3232
@RunWith(MockitoJUnitRunner.class)
3333
public class QueryFactoryTest {
3434

35-
private String assert_not_null = "Expected non-null VerticaExportQueryBuilder";
36-
private String assert_rendered = "Rendered result should not be null";
35+
private static final String assert_not_null = "Expected non-null VerticaExportQueryBuilder";
36+
private static final String assert_rendered = "Rendered result should not be null";
3737
private QueryFactory queryFactory;
3838

3939
@Before

athena-vertica/src/test/java/com/amazonaws/athena/connectors/vertica/query/VerticaExportQueryBuilderTest.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -41,12 +41,12 @@
4141
@RunWith(MockitoJUnitRunner.class)
4242
public class VerticaExportQueryBuilderTest {
4343

44-
private String TEST_QUERY_ID = "query-123";
45-
private String TEST_BUCKET = "s3://test-bucket";
46-
private String PREPARED_SQL = "SELECT * FROM prepared_table";
47-
private String TEMPLATE_NAME = "templateVerticaExportQuery";
48-
private String QPT_TEMPLATE_NAME = "templateVerticaExportQPTQuery";
49-
private String EXPECTED_SQL_TEMPLATE = "SELECT <colNames> FROM <table> TO <s3ExportBucket> QUERYID <queryID>";
44+
private static final String TEST_QUERY_ID = "query-123";
45+
private static final String TEST_BUCKET = "s3://test-bucket";
46+
private static final String PREPARED_SQL = "SELECT * FROM prepared_table";
47+
private static final String TEMPLATE_NAME = "templateVerticaExportQuery";
48+
private static final String QPT_TEMPLATE_NAME = "templateVerticaExportQPTQuery";
49+
private static final String EXPECTED_SQL_TEMPLATE = "SELECT <colNames> FROM <table> TO <s3ExportBucket> QUERYID <queryID>";
5050

5151
@Mock private ST template;
5252
@Mock private ResultSet resultSet;

0 commit comments

Comments
 (0)