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 28 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
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
45 changes: 45 additions & 0 deletions src/test/java/net/snowflake/client/config/SFClientConfigTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package net.snowflake.client.config;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;

import java.util.Objects;
import org.junit.Test;

public class SFClientConfigTest {
@Test
public void testSFConfigOptions() {
SFClientConfig.CommonProps props = new SFClientConfig.CommonProps();
props.setLogLevel("info");
props.setLogPath("jdbc_log");
SFClientConfig sfClientConfig = new SFClientConfig();
SFClientConfig sfClientConfig1 = new SFClientConfig(props);

assertTrue(sfClientConfig1.equals(sfClientConfig1));
assertFalse(sfClientConfig.equals(sfClientConfig1));

SFClientConfig.CommonProps props2 = new SFClientConfig.CommonProps();
props2.CommonProps("info", "jdbc_log");
sfClientConfig.setCommonProps(props2);

assertTrue(sfClientConfig.equals(sfClientConfig1));
assertEquals(sfClientConfig.hashCode(), sfClientConfig1.hashCode());
}

@Test
public void testCommonPropsAttr() {
SFClientConfig.CommonProps commonProps = new SFClientConfig.CommonProps();
SFClientConfig.CommonProps commonProps2 = new SFClientConfig.CommonProps();
commonProps.CommonProps("info", "jdbc_log");

assertTrue(commonProps.equals(commonProps));
assertFalse(commonProps.equals(commonProps2));

commonProps2.setLogLevel("info");
commonProps2.setLogPath("jdbc_log");

assertTrue(commonProps.equals(commonProps2));
assertEquals(commonProps2.hashCode(), Objects.hash("info", "jdbc_log"));
sfc-gh-dprzybysz marked this conversation as resolved.
Show resolved Hide resolved
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
package net.snowflake.client.core;

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

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() {
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);
try {
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");
} catch (ParseException ex) {
sfc-gh-dprzybysz marked this conversation as resolved.
Show resolved Hide resolved
fail("test failed");
}
}

@Test
public void testRetryLocation() {
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);
try {
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");
} catch (ParseException ex) {
sfc-gh-dprzybysz marked this conversation as resolved.
Show resolved Hide resolved
fail("test failed");
} finally {
TelemetryService.disableHTAP();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@

import static org.hamcrest.MatcherAssert.assertThat;
import static org.junit.Assert.assertEquals;
import static org.mockito.Mockito.mock;
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 +221,39 @@ public void testSerializeRequestAndDeserializeResponseDataWithNullContext() thro

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

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

@Test
public void testQueryContextEntroDTO() throws Exception {
sfc-gh-dprzybysz marked this conversation as resolved.
Show resolved Hide resolved
QueryContextEntryDTO queryContextEntryDTO = new QueryContextEntryDTO();
OpaqueContextDTO opaqueContextDTO = mock(OpaqueContextDTO.class);
sfc-gh-dprzybysz marked this conversation as resolved.
Show resolved Hide resolved
queryContextEntryDTO.setId(1);
assertEquals(queryContextEntryDTO.getId(), 1);
sfc-gh-dprzybysz marked this conversation as resolved.
Show resolved Hide resolved
queryContextEntryDTO.setTimestamp(2);
assertEquals(queryContextEntryDTO.getTimestamp(), 2);
queryContextEntryDTO.setPriority(3);
assertEquals(queryContextEntryDTO.getPriority(), 3);
queryContextEntryDTO.setContext(opaqueContextDTO);
assertEquals(queryContextEntryDTO.getContext(), opaqueContextDTO);
}

@Test
public void testQueryExecDTO() throws Exception {
QueryContextEntryDTO queryContextEntryDTO = new QueryContextEntryDTO();
OpaqueContextDTO opaqueContextDTO = mock(OpaqueContextDTO.class);
queryContextEntryDTO.setId(1);
assertEquals(queryContextEntryDTO.getId(), 1);
queryContextEntryDTO.setTimestamp(2);
assertEquals(queryContextEntryDTO.getTimestamp(), 2);
queryContextEntryDTO.setPriority(3);
assertEquals(queryContextEntryDTO.getPriority(), 3);
queryContextEntryDTO.setContext(opaqueContextDTO);
assertEquals(queryContextEntryDTO.getContext(), opaqueContextDTO);
}

private void assertCacheData() {
Expand Down
58 changes: 58 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,58 @@
package net.snowflake.client.core;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.fail;
import static org.mockito.Mockito.mock;

import java.sql.SQLData;
import java.sql.SQLException;
import net.snowflake.common.core.SqlState;
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));
}

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

private void expectSnowflakeLoggedFeatureNotSupportedException(MethodRaisesSQLException f) {
try {
f.run();
fail("must raise exception");
} catch (SQLException ex) {
assertEquals(SqlState.FEATURE_NOT_SUPPORTED, "0A000");
sfc-gh-dprzybysz marked this conversation as resolved.
Show resolved Hide resolved
}
}
}
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);
}
}
24 changes: 24 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,8 @@
import javax.xml.transform.Result;
import javax.xml.transform.Source;
import net.snowflake.client.AbstractDriverIT;
import net.snowflake.client.core.SFException;
import net.snowflake.common.core.SqlState;

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

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

protected interface MethodRaisesSQLClientInfoException {
void run() throws SQLClientInfoException;
}
Expand Down Expand Up @@ -75,6 +81,15 @@ protected void expectResultSetAlreadyClosedException(MethodRaisesSQLException f)
}
}

protected void expectSnowflakeLoggedFeatureNotSupportedException(MethodRaisesSQLException f) {
sfc-gh-dprzybysz marked this conversation as resolved.
Show resolved Hide resolved
try {
f.run();
fail("must raise exception");
} catch (SQLException ex) {
assertEquals(SqlState.FEATURE_NOT_SUPPORTED, "0A000");
sfc-gh-ext-simba-jy marked this conversation as resolved.
Show resolved Hide resolved
}
}

protected void expectFeatureNotSupportedException(MethodRaisesSQLException f) {
try {
f.run();
Expand All @@ -84,6 +99,15 @@ protected void expectFeatureNotSupportedException(MethodRaisesSQLException f) {
}
}

protected void expectFeatureSFException(MethodRaisesSFException f) {
try {
f.run();
fail("must raise exception");
} catch (SFException | SQLException ex) {
sfc-gh-dprzybysz marked this conversation as resolved.
Show resolved Hide resolved
assertTrue(ex instanceof SFException);
}
}

protected void expectSQLClientInfoException(MethodRaisesSQLClientInfoException f) {
try {
f.run();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
package net.snowflake.client.jdbc;

import static org.junit.Assert.assertEquals;

import org.junit.Test;

public class BindingParameterMetadataTest {

@Test
public void testBindParameterWithVariousConstructors() {
BindingParameterMetadata bindingParameterMetadata = new BindingParameterMetadata();
bindingParameterMetadata.setType("FLOAT");
bindingParameterMetadata.setLength(100);
bindingParameterMetadata.setByteLength(1000);
bindingParameterMetadata.setPrecision(255);
bindingParameterMetadata.setScale(20);
bindingParameterMetadata.setNullable(false);
assertEquals(bindingParameterMetadata.getType(), "FLOAT");
sfc-gh-dprzybysz marked this conversation as resolved.
Show resolved Hide resolved
assertEquals(bindingParameterMetadata.getLength(), Integer.valueOf(100));
assertEquals(bindingParameterMetadata.getByteLength(), Integer.valueOf(1000));
assertEquals(bindingParameterMetadata.getPrecision(), Integer.valueOf(255));
assertEquals(bindingParameterMetadata.getScale(), Integer.valueOf(20));
assertEquals(bindingParameterMetadata.isNullable(), false);

BindingParameterMetadata bindingParameterMetadata1 =
new BindingParameterMetadata("STRING", "NAME");
assertEquals(bindingParameterMetadata1.getName(), "NAME");
assertEquals(bindingParameterMetadata1.getType(), "STRING");

BindingParameterMetadata bindingParameterMetadata2 =
new BindingParameterMetadata("STRING", "NAME", 100, 1000, 255, 20, true);
assertEquals(bindingParameterMetadata2.getType(), "STRING");
assertEquals(bindingParameterMetadata2.getName(), "NAME");
assertEquals(bindingParameterMetadata2.getLength(), Integer.valueOf(100));
assertEquals(bindingParameterMetadata2.getByteLength(), Integer.valueOf(1000));
assertEquals(bindingParameterMetadata2.getPrecision(), Integer.valueOf(255));
assertEquals(bindingParameterMetadata2.getScale(), Integer.valueOf(20));
assertEquals(bindingParameterMetadata2.isNullable(), true);

BindingParameterMetadata bindingParameterMetadata3 =
BindingParameterMetadata.BindingParameterMetadataBuilder.bindingParameterMetadata()
.withNullable(true)
.build();
assertEquals(bindingParameterMetadata3.isNullable(), true);
}
}
Loading
Loading