Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SNOW-1016470: Increase code coverage in JDBC part1 #1759

Merged
merged 43 commits into from
Jun 20, 2024
Merged
Show file tree
Hide file tree
Changes from 36 commits
Commits
Show all changes
43 commits
Select commit Hold shift + click to select a range
667e3b6
codecov testing
sfc-gh-ext-simba-jy May 15, 2024
eca6d0d
testing
sfc-gh-ext-simba-jy May 15, 2024
6b17704
testing
sfc-gh-ext-simba-jy May 16, 2024
da1002c
first codecov testing
sfc-gh-ext-simba-jy May 27, 2024
ef77262
testing
sfc-gh-ext-simba-jy May 27, 2024
78ba99a
add
sfc-gh-ext-simba-jy May 27, 2024
65f2707
testing
sfc-gh-ext-simba-jy May 28, 2024
9b484b7
lint fix
sfc-gh-ext-simba-jy May 28, 2024
bc1947b
fix
sfc-gh-ext-simba-jy May 28, 2024
3032408
add codecov
sfc-gh-ext-simba-jy May 28, 2024
2c8fbee
add more testings
sfc-gh-ext-simba-jy Jun 5, 2024
81dbac2
add more testings
sfc-gh-ext-simba-jy Jun 11, 2024
440334c
lint fix
sfc-gh-ext-simba-jy Jun 11, 2024
7be0919
fix *
sfc-gh-ext-simba-jy Jun 11, 2024
968bebe
fix errors
sfc-gh-ext-simba-jy Jun 11, 2024
c35f3c8
lint fix
sfc-gh-ext-simba-jy Jun 11, 2024
d74d171
Merge branch 'master' into coverage90
sfc-gh-ext-simba-jy Jun 11, 2024
c8d1361
fix merge
sfc-gh-ext-simba-jy Jun 11, 2024
7695d5e
fix
sfc-gh-ext-simba-jy Jun 11, 2024
24581e4
lint fix
sfc-gh-ext-simba-jy Jun 11, 2024
24d268e
revert change
sfc-gh-ext-simba-jy Jun 11, 2024
5e1dabb
testing
sfc-gh-ext-simba-jy Jun 11, 2024
0564248
revert back
sfc-gh-ext-simba-jy Jun 11, 2024
bc31538
fixing
sfc-gh-ext-simba-jy Jun 11, 2024
d8d9dfa
testing
sfc-gh-ext-simba-jy Jun 11, 2024
5a28dc2
testing
sfc-gh-ext-simba-jy Jun 12, 2024
51d97ee
stopwatch testing
sfc-gh-ext-simba-jy Jun 12, 2024
ecb5c95
stopwatch testing
sfc-gh-ext-simba-jy Jun 12, 2024
6e0ba4e
applied ALLOW Errors
sfc-gh-ext-simba-jy Jun 12, 2024
c0a722b
fix
sfc-gh-ext-simba-jy Jun 12, 2024
a339153
applied 1 seconds
sfc-gh-ext-simba-jy Jun 12, 2024
83fc9e6
applied 200miliseconds gap
sfc-gh-ext-simba-jy Jun 12, 2024
0c00818
Merge branch 'master' into coverage90
sfc-gh-ext-simba-jy Jun 12, 2024
65f959b
edited some codes and removed the testing which just tests the getter…
sfc-gh-ext-simba-jy Jun 12, 2024
6ffa029
lint fix
sfc-gh-ext-simba-jy Jun 12, 2024
9bc44a6
fix
sfc-gh-ext-simba-jy Jun 12, 2024
d9bc276
fix
sfc-gh-ext-simba-jy Jun 13, 2024
75caf02
fix
sfc-gh-ext-simba-jy Jun 13, 2024
e240877
lint fix
sfc-gh-ext-simba-jy Jun 13, 2024
51657be
fix error
sfc-gh-ext-simba-jy Jun 13, 2024
06a244f
changed the test util function because of the compliation error
sfc-gh-ext-simba-jy Jun 14, 2024
41ff12b
testing
sfc-gh-ext-simba-jy Jun 20, 2024
f6e4eb2
revert back
sfc-gh-ext-simba-jy Jun 20, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ public String generateTelemetry() {
value.put("ProcessResultChunkStart", this.processResultChunk.getStart());
value.put("ProcessResultChunkEnd", this.processResultChunk.getEnd());
value.put("CreateResultSetStart", this.createResultSet.getStart());
value.put("CreatResultSetEnd", this.createResultSet.getEnd());
value.put("CreateResultSetEnd", this.createResultSet.getEnd());
value.put("QueryEnd", this.query.getEnd());
value.put("BatchID", this.batchId);
value.put("QueryID", this.queryId);
Expand Down
16 changes: 16 additions & 0 deletions src/test/java/net/snowflake/client/TestUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,15 @@
import static org.hamcrest.MatcherAssert.assertThat;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;

import java.sql.SQLException;
import java.sql.Statement;
import java.util.Arrays;
import java.util.List;
import java.util.regex.Pattern;
import net.snowflake.client.core.SFException;
import net.snowflake.client.jdbc.SnowflakeLoggedFeatureNotSupportedException;
import net.snowflake.client.jdbc.SnowflakeUtil;
import net.snowflake.client.log.SFLogger;
import net.snowflake.client.log.SFLoggerFactory;
Expand Down Expand Up @@ -128,4 +131,17 @@ public static void withRandomSchema(
statement.execute("DROP SCHEMA " + customSchema);
}
}

public interface MethodRaisesSQLException {
void run() throws SQLException;
}

public static void expectSnowflakeLoggedFeatureNotSupportedException(MethodRaisesSQLException f) {
try {
f.run();
fail("must raise exception");
} catch (SQLException ex) {
assertTrue(ex instanceof SnowflakeLoggedFeatureNotSupportedException);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ public void testLoadSFClientConfigValidPath() throws IOException {
SFClientConfigParser.loadSFClientConfig(configFilePath.toString());
assertEquals("info", actualConfig.getCommonProps().getLogLevel());
assertEquals("/jdbc.log", actualConfig.getCommonProps().getLogPath());
assertEquals("config.json", actualConfig.getConfigFilePath());
}

@Test
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
package net.snowflake.client.core;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;

import net.minidev.json.JSONObject;
import net.minidev.json.parser.JSONParser;
import net.minidev.json.parser.ParseException;
import net.snowflake.client.jdbc.telemetryOOB.TelemetryService;
import org.junit.Test;

public class ExecTimeTelemetryDataTest {

@Test
public void testExecTimeTelemetryData() throws ParseException {
ExecTimeTelemetryData execTimeTelemetryData = new ExecTimeTelemetryData();
execTimeTelemetryData.sendData = true;
execTimeTelemetryData.setBindStart();
execTimeTelemetryData.setOCSPStatus(true);
execTimeTelemetryData.setBindEnd();
execTimeTelemetryData.setHttpClientStart();
execTimeTelemetryData.setHttpClientEnd();
execTimeTelemetryData.setGzipStart();
execTimeTelemetryData.setGzipEnd();
execTimeTelemetryData.setQueryEnd();
execTimeTelemetryData.setQueryId("queryid");
execTimeTelemetryData.setProcessResultChunkStart();
execTimeTelemetryData.setProcessResultChunkEnd();
execTimeTelemetryData.setResponseIOStreamStart();
execTimeTelemetryData.setResponseIOStreamEnd();
execTimeTelemetryData.setCreateResultSetStart();
execTimeTelemetryData.setCreateResultSetEnd();
execTimeTelemetryData.incrementRetryCount();
execTimeTelemetryData.setRequestId("mockId");
execTimeTelemetryData.addRetryLocation("retry");

String telemetry = execTimeTelemetryData.generateTelemetry();
JSONParser parser = new JSONParser(JSONParser.MODE_JSON_SIMPLE);
JSONObject json = (JSONObject) parser.parse(telemetry);
assertNotNull(json.get("BindStart"));
assertNotNull(json.get("BindEnd"));
assertEquals(json.get("ocspEnabled"), true);
assertNotNull(json.get("HttpClientStart"));
assertNotNull(json.get("HttpClientEnd"));
assertNotNull(json.get("GzipStart"));
assertNotNull(json.get("GzipEnd"));
assertNotNull(json.get("QueryEnd"));
assertEquals(json.get("QueryID"), "queryid");
assertNotNull(json.get("ProcessResultChunkStart"));
assertNotNull(json.get("ProcessResultChunkEnd"));
assertNotNull(json.get("ResponseIOStreamStart"));
assertNotNull(json.get("CreateResultSetStart"));
assertNotNull(json.get("CreateResultSetEnd"));
assertNotNull(json.get("ElapsedQueryTime"));
assertNotNull(json.get("ElapsedResultProcessTime"));
assertNull(json.get("QueryFunction"));
assertNull(json.get("BatchID"));
assertEquals(((Long) json.get("RetryCount")).intValue(), 1);
assertEquals(json.get("RequestID"), "mockId");
assertEquals(json.get("RetryLocations"), "retry");
assertEquals(json.get("Urgent"), true);
assertEquals(json.get("eventType"), "ExecutionTimeRecord");
}

@Test
public void testRetryLocation() throws ParseException {
TelemetryService.enableHTAP();
ExecTimeTelemetryData execTimeTelemetryData =
new ExecTimeTelemetryData("queryFunction", "batchId");
execTimeTelemetryData.addRetryLocation("hello");
execTimeTelemetryData.addRetryLocation("world");
execTimeTelemetryData.sendData = true;
String telemetry = execTimeTelemetryData.generateTelemetry();

JSONParser parser = new JSONParser(JSONParser.MODE_JSON_SIMPLE);
JSONObject json = (JSONObject) parser.parse(telemetry);
assertEquals(json.get("QueryFunction"), "queryFunction");
assertEquals(json.get("BatchID"), "batchId");
assertNotNull(json.get("QueryStart"));
assertEquals(json.get("RetryLocations"), "hello, world");
TelemetryService.disableHTAP();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@

import static org.hamcrest.MatcherAssert.assertThat;
import static org.junit.Assert.assertEquals;
import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;

import org.junit.Test;

Expand Down Expand Up @@ -217,6 +220,11 @@ public void testSerializeRequestAndDeserializeResponseDataWithNullContext() thro

qcc.deserializeQueryContextDTO(requestData);
assertCacheDataWithContext(null);

QueryContextCache mockQcc = spy(qcc);
mockQcc.deserializeQueryContextDTO(null);
verify(mockQcc).clearCache();
verify(mockQcc, times(2)).logCacheEntries();
}

private void assertCacheData() {
Expand Down
42 changes: 42 additions & 0 deletions src/test/java/net/snowflake/client/core/SQLInputOutputTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package net.snowflake.client.core;

import static net.snowflake.client.TestUtil.expectSnowflakeLoggedFeatureNotSupportedException;
import static org.mockito.Mockito.mock;

import java.sql.SQLData;
import org.junit.Test;

public class SQLInputOutputTest {

@Test
public void testBaseSQLUnSupportedException() {
BaseSqlInput sqlInput = new ArrowSqlInput(null, null, null, null);
expectSnowflakeLoggedFeatureNotSupportedException(sqlInput::readCharacterStream);
expectSnowflakeLoggedFeatureNotSupportedException(sqlInput::readAsciiStream);
expectSnowflakeLoggedFeatureNotSupportedException(sqlInput::readBinaryStream);
expectSnowflakeLoggedFeatureNotSupportedException(sqlInput::readRef);
expectSnowflakeLoggedFeatureNotSupportedException(sqlInput::readBlob);
expectSnowflakeLoggedFeatureNotSupportedException(sqlInput::readClob);
expectSnowflakeLoggedFeatureNotSupportedException(sqlInput::readArray);
expectSnowflakeLoggedFeatureNotSupportedException(sqlInput::readURL);
expectSnowflakeLoggedFeatureNotSupportedException(sqlInput::readNClob);
expectSnowflakeLoggedFeatureNotSupportedException(sqlInput::readNString);
expectSnowflakeLoggedFeatureNotSupportedException(sqlInput::readSQLXML);
expectSnowflakeLoggedFeatureNotSupportedException(sqlInput::readRowId);
}

@Test
public void testJsonSqlOutPutUnSupportedTest() {
JsonSqlOutput sqloutput = new JsonSqlOutput(mock(SQLData.class), mock(SFBaseSession.class));
expectSnowflakeLoggedFeatureNotSupportedException(() -> sqloutput.writeRef(null));
expectSnowflakeLoggedFeatureNotSupportedException(() -> sqloutput.writeBlob(null));
expectSnowflakeLoggedFeatureNotSupportedException(() -> sqloutput.writeClob(null));
expectSnowflakeLoggedFeatureNotSupportedException(() -> sqloutput.writeStruct(null));
expectSnowflakeLoggedFeatureNotSupportedException(() -> sqloutput.writeArray(null));
expectSnowflakeLoggedFeatureNotSupportedException(() -> sqloutput.writeURL(null));
expectSnowflakeLoggedFeatureNotSupportedException(() -> sqloutput.writeNString(null));
expectSnowflakeLoggedFeatureNotSupportedException(() -> sqloutput.writeNClob(null));
expectSnowflakeLoggedFeatureNotSupportedException(() -> sqloutput.writeRowId(null));
expectSnowflakeLoggedFeatureNotSupportedException(() -> sqloutput.writeSQLXML(null));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package net.snowflake.client.core.bind;

import static org.junit.Assert.assertEquals;

import net.snowflake.client.jdbc.telemetry.TelemetryField;
import org.junit.Test;

public class BindExceptionTest {

@Test
public void testBindExceptionType() {
assertEquals(BindException.Type.SERIALIZATION.field, TelemetryField.FAILED_BIND_SERIALIZATION);
assertEquals(BindException.Type.UPLOAD.field, TelemetryField.FAILED_BIND_UPLOAD);
assertEquals(BindException.Type.OTHER.field, TelemetryField.FAILED_BIND_OTHER);
}

@Test
public void testBindExceptionConstructor() {
BindException exception = new BindException("testException", BindException.Type.SERIALIZATION);
assertEquals(exception.getMessage(), "testException");
assertEquals(exception.type.field, TelemetryField.FAILED_BIND_SERIALIZATION);
}
}
5 changes: 5 additions & 0 deletions src/test/java/net/snowflake/client/jdbc/BaseJDBCTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
import javax.xml.transform.Result;
import javax.xml.transform.Source;
import net.snowflake.client.AbstractDriverIT;
import net.snowflake.client.core.SFException;

public class BaseJDBCTest extends AbstractDriverIT {
// Test UUID unique per session
Expand All @@ -44,6 +45,10 @@ protected interface MethodRaisesSQLException {
void run() throws SQLException;
}

protected interface MethodRaisesSFException {
void run() throws SFException;
}

protected interface MethodRaisesSQLClientInfoException {
void run() throws SQLClientInfoException;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,9 @@ public class ResultSetAlreadyClosedIT extends BaseJDBCTest {
@Test
public void testQueryResultSetAlreadyClosed() throws Throwable {
try (Connection connection = getConnection();
Statement statement = connection.createStatement();
ResultSet resultSet = statement.executeQuery("select 1")) {
Statement statement = connection.createStatement()) {
ResultSet resultSet = statement.executeQuery("select 1");
resultSet.close();
checkAlreadyClosed(resultSet);
}
}
Expand All @@ -44,9 +45,18 @@ public void testMetadataResultSetAlreadyClosed() throws Throwable {
}

@Test
public void testEmptyResultSetAlreadyClosed() throws Throwable {
try (ResultSet resultSet = new SnowflakeResultSetV1.EmptyResultSet()) {
public void testResultSetAlreadyClosed() throws Throwable {
try (Connection connection = getConnection();
Statement statement = connection.createStatement();
ResultSet resultSet = statement.executeQuery("SELECT 1")) {
checkAlreadyClosed(resultSet);
}
}

@Test
public void testEmptyResultSetAlreadyClosed() throws Throwable {
try (SnowflakeResultSetV1.EmptyResultSet resultSet =
new SnowflakeResultSetV1.EmptyResultSet()) {
checkAlreadyClosedEmpty(resultSet);
}
}
Expand All @@ -68,7 +78,7 @@ private void checkAlreadyClosed(ResultSet resultSet) throws SQLException {
expectResultSetAlreadyClosedException(() -> resultSet.getDouble(1));
expectResultSetAlreadyClosedException(() -> resultSet.getBigDecimal(1));
expectResultSetAlreadyClosedException(() -> resultSet.getBytes(1));
expectResultSetAlreadyClosedException(() -> resultSet.getString(1));
expectResultSetAlreadyClosedException(() -> resultSet.getDate(1));
sfc-gh-dprzybysz marked this conversation as resolved.
Show resolved Hide resolved
expectResultSetAlreadyClosedException(() -> resultSet.getDate(1));
expectResultSetAlreadyClosedException(() -> resultSet.getTime(1));
expectResultSetAlreadyClosedException(() -> resultSet.getTimestamp(1));
Expand Down Expand Up @@ -105,7 +115,13 @@ private void checkAlreadyClosed(ResultSet resultSet) throws SQLException {
expectResultSetAlreadyClosedException(() -> resultSet.getBigDecimal("col1", 38));

expectResultSetAlreadyClosedException(resultSet::getWarnings);
expectResultSetAlreadyClosedException(
() -> resultSet.unwrap(SnowflakeBaseResultSet.class).getWarnings());

expectResultSetAlreadyClosedException(resultSet::clearWarnings);
expectResultSetAlreadyClosedException(
() -> resultSet.unwrap(SnowflakeBaseResultSet.class).clearWarnings());

expectResultSetAlreadyClosedException(resultSet::getMetaData);

expectResultSetAlreadyClosedException(() -> resultSet.findColumn("col1"));
Expand All @@ -119,11 +135,20 @@ private void checkAlreadyClosed(ResultSet resultSet) throws SQLException {
expectResultSetAlreadyClosedException(
() -> resultSet.setFetchDirection(ResultSet.FETCH_FORWARD));
expectResultSetAlreadyClosedException(() -> resultSet.setFetchSize(10));
expectResultSetAlreadyClosedException(
() -> resultSet.unwrap(SnowflakeBaseResultSet.class).setFetchSize(10));

expectResultSetAlreadyClosedException(resultSet::getFetchDirection);
expectResultSetAlreadyClosedException(resultSet::getFetchSize);
expectResultSetAlreadyClosedException(resultSet::getType);
expectResultSetAlreadyClosedException(resultSet::getConcurrency);
expectResultSetAlreadyClosedException(
resultSet.unwrap(SnowflakeBaseResultSet.class)::getConcurrency);

expectResultSetAlreadyClosedException(resultSet::getHoldability);
expectResultSetAlreadyClosedException(
resultSet.unwrap(SnowflakeBaseResultSet.class)::getHoldability);

expectResultSetAlreadyClosedException(resultSet::getStatement);
}

Expand All @@ -133,7 +158,8 @@ private void checkAlreadyClosed(ResultSet resultSet) throws SQLException {
* @param resultSet
* @throws SQLException
*/
private void checkAlreadyClosedEmpty(ResultSet resultSet) throws SQLException {
private void checkAlreadyClosedEmpty(SnowflakeResultSetV1.EmptyResultSet resultSet)
throws SQLException {
resultSet.close();
resultSet.close(); // second close won't raise exception
assertTrue(resultSet.isClosed());
Expand Down
Loading
Loading