Skip to content

Commit

Permalink
lint fix
Browse files Browse the repository at this point in the history
  • Loading branch information
sfc-gh-ext-simba-jy committed Jun 11, 2024
1 parent 81dbac2 commit 440334c
Show file tree
Hide file tree
Showing 8 changed files with 109 additions and 128 deletions.
18 changes: 8 additions & 10 deletions src/test/java/net/snowflake/client/core/QueryContextCacheTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@

import org.junit.Test;

import java.sql.Timestamp;

public class QueryContextCacheTest {
private QueryContextCache qcc = null;
private long BASE_READ_TIMESTAMP = 1668727958;
Expand Down Expand Up @@ -232,27 +230,27 @@ public void testQueryContextEntroDTO() throws Exception {
QueryContextEntryDTO queryContextEntryDTO = new QueryContextEntryDTO();
OpaqueContextDTO opaqueContextDTO = mock(OpaqueContextDTO.class);
queryContextEntryDTO.setId(1);
assertEquals(queryContextEntryDTO.getId(),1);
assertEquals(queryContextEntryDTO.getId(), 1);
queryContextEntryDTO.setTimestamp(2);
assertEquals(queryContextEntryDTO.getTimestamp(),2);
assertEquals(queryContextEntryDTO.getTimestamp(), 2);
queryContextEntryDTO.setPriority(3);
assertEquals(queryContextEntryDTO.getPriority(),3);
assertEquals(queryContextEntryDTO.getPriority(), 3);
queryContextEntryDTO.setContext(opaqueContextDTO);
assertEquals(queryContextEntryDTO.getContext(),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);
assertEquals(queryContextEntryDTO.getId(), 1);
queryContextEntryDTO.setTimestamp(2);
assertEquals(queryContextEntryDTO.getTimestamp(),2);
assertEquals(queryContextEntryDTO.getTimestamp(), 2);
queryContextEntryDTO.setPriority(3);
assertEquals(queryContextEntryDTO.getPriority(),3);
assertEquals(queryContextEntryDTO.getPriority(), 3);
queryContextEntryDTO.setContext(opaqueContextDTO);
assertEquals(queryContextEntryDTO.getContext(),opaqueContextDTO);
assertEquals(queryContextEntryDTO.getContext(), opaqueContextDTO);
}

private void assertCacheData() {
Expand Down
101 changes: 45 additions & 56 deletions src/test/java/net/snowflake/client/core/SQLInputOutputTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,68 +2,57 @@

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

import net.snowflake.client.core.json.Converters;
import net.snowflake.client.jdbc.BaseJDBCTest;
import net.snowflake.common.core.SqlState;
import org.junit.Test;
import org.junit.experimental.categories.Category;
import org.mockito.MockedStatic;
import org.mockito.MockedStatic.Verification;
import org.mockito.Mockito;

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");
}
@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");
}
}
}


2 changes: 1 addition & 1 deletion src/test/java/net/snowflake/client/jdbc/BaseJDBCTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ protected void expectFeatureSFException(MethodRaisesSFException f) {
try {
f.run();
fail("must raise exception");
} catch (SFException | SQLException ex ) {
} catch (SFException | SQLException ex) {
assertTrue(ex instanceof SFException);
}
}
Expand Down
10 changes: 4 additions & 6 deletions src/test/java/net/snowflake/client/jdbc/ConnectionIT.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
import static org.hamcrest.MatcherAssert.assertThat;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import static org.junit.Assume.assumeTrue;

Expand Down Expand Up @@ -1032,12 +1032,10 @@ public void testFailOverOrgAccount() throws SQLException {

@Test
public void testSFBaseSession() throws SQLException {
try(Connection con = getConnection()) {
try (Connection con = getConnection()) {
assertNull(con.unwrap(SFBaseSession.class).getServerUrl());
expectFeatureSFException(() ->
con.unwrap(SFBaseSession.class).addProperty("user","a"));

}
expectFeatureSFException(() -> con.unwrap(SFBaseSession.class).addProperty("user", "a"));
}
}

private class ConcurrentConnections implements Runnable {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,40 +1,40 @@
package net.snowflake.client.jdbc;

import org.junit.Test;

import java.util.List;

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

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

public class SnowflakeColumnMetadataTest {

@Test
public void testSnowflakeColumnMetaData() {
SnowflakeColumnMetadata metadata = new SnowflakeColumnMetadata("mock",1,true,2,3,4,"fake",true,null,null,null,null,true);
List<FieldMetadata> list = mock(List.class);
metadata.setName("test");
metadata.setType(10);
metadata.setNullable(false);
metadata.setLength(12);
metadata.setPrecision(13);
metadata.setScale(14);
metadata.setTypeName("type");
metadata.setFixed(false);
metadata.setFields(list);
metadata.setAutoIncrement(false);
@Test
public void testSnowflakeColumnMetaData() {
SnowflakeColumnMetadata metadata =
new SnowflakeColumnMetadata(
"mock", 1, true, 2, 3, 4, "fake", true, null, null, null, null, true);
List<FieldMetadata> list = mock(List.class);
metadata.setName("test");
metadata.setType(10);
metadata.setNullable(false);
metadata.setLength(12);
metadata.setPrecision(13);
metadata.setScale(14);
metadata.setTypeName("type");
metadata.setFixed(false);
metadata.setFields(list);
metadata.setAutoIncrement(false);

assertEquals(metadata.getName(),"test");
assertEquals(metadata.getType(),10);
assertFalse(metadata.isNullable());
assertEquals(metadata.getLength(),12);
assertEquals(metadata.getPrecision(),13);
assertEquals(metadata.getScale(),14);
assertEquals(metadata.getTypeName(),"type");
assertFalse(metadata.isFixed());
assertEquals(metadata.getFields(),list);
assertFalse(metadata.isAutoIncrement());
}
assertEquals(metadata.getName(), "test");
assertEquals(metadata.getType(), 10);
assertFalse(metadata.isNullable());
assertEquals(metadata.getLength(), 12);
assertEquals(metadata.getPrecision(), 13);
assertEquals(metadata.getScale(), 14);
assertEquals(metadata.getTypeName(), "type");
assertFalse(metadata.isFixed());
assertEquals(metadata.getFields(), list);
assertFalse(metadata.isAutoIncrement());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,9 @@
import static org.junit.Assert.*;
import static org.mockito.Mockito.*;

import com.microsoft.azure.storage.blob.ListBlobItem;
import java.sql.Connection;
import java.sql.SQLException;

import com.microsoft.azure.storage.blob.ListBlobItem;
import net.snowflake.client.ConditionalIgnoreRule;
import net.snowflake.client.RunningOnGithubAction;
import net.snowflake.client.core.SFSession;
Expand Down Expand Up @@ -44,8 +43,8 @@ public void testCloudExceptionTest() {
Iterable<ListBlobItem> mockList = null;
AzureObjectSummariesIterator iterator = new AzureObjectSummariesIterator(mockList);
AzureObjectSummariesIterator spyIterator = spy(iterator);
UnsupportedOperationException ex = assertThrows(UnsupportedOperationException.class, () -> spyIterator.remove());
UnsupportedOperationException ex =
assertThrows(UnsupportedOperationException.class, () -> spyIterator.remove());
assertEquals(ex.getMessage(), "remove() method not supported");

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ public void testLogicalConnectionAlreadyClosed() throws SQLException {
expectConnectionAlreadyClosedException(() -> logicalConnection.setSchema("fakedb"));
expectConnectionAlreadyClosedException(
() -> logicalConnection.setTransactionIsolation(Connection.TRANSACTION_READ_COMMITTED));
expectConnectionAlreadyClosedException(
() -> logicalConnection.createArrayOf("faketype",null));
expectConnectionAlreadyClosedException(() -> logicalConnection.createArrayOf("faketype", null));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,11 @@
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.assertThrows;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import static org.mockito.Mockito.*;


import java.sql.CallableStatement;
import java.sql.Clob;
import java.sql.Connection;
Expand All @@ -30,7 +29,6 @@
import net.snowflake.client.jdbc.SnowflakeDriver;
import org.junit.Test;
import org.junit.experimental.categories.Category;
import org.mockito.Mockito;

@Category(TestCategoryConnection.class)
public class LogicalConnectionLatestIT extends BaseJDBCTest {
Expand Down Expand Up @@ -381,25 +379,25 @@ public void testExceptions() throws SQLException {
when(snowflakePooledConnection.getPhysicalConnection()).thenReturn(connection);
SQLException sqlException = new SQLException("mocking error");
when(connection.createStatement()).thenThrow(sqlException);
when(connection.createStatement(1,2,3)).thenThrow(sqlException);
when(connection.createStatement(1, 2, 3)).thenThrow(sqlException);

when(connection.prepareStatement("mocksql")).thenThrow(sqlException);
when(connection.prepareCall("mocksql")).thenThrow(sqlException);
when(connection.prepareCall("mocksql",1,2,3)).thenThrow(sqlException);
when(connection.prepareCall("mocksql", 1, 2, 3)).thenThrow(sqlException);
when(connection.nativeSQL("mocksql")).thenThrow(sqlException);
when(connection.getAutoCommit()).thenThrow(sqlException);
when(connection.getMetaData()).thenThrow(sqlException);
when(connection.isReadOnly()).thenThrow(sqlException);
when(connection.getCatalog()).thenThrow(sqlException);
when(connection.getTransactionIsolation()).thenThrow(sqlException);
when(connection.getWarnings()).thenThrow(sqlException);
when(connection.prepareCall("mocksql",1,2)).thenThrow(sqlException);
when(connection.prepareCall("mocksql", 1, 2)).thenThrow(sqlException);
when(connection.getTypeMap()).thenThrow(sqlException);
when(connection.getHoldability()).thenThrow(sqlException);
when(connection.createClob()).thenThrow(sqlException);
when(connection.getClientInfo("mocksql")).thenThrow(sqlException);
when(connection.getClientInfo()).thenThrow(sqlException);
when(connection.createArrayOf("mock",null)).thenThrow(sqlException);
when(connection.createArrayOf("mock", null)).thenThrow(sqlException);
when(connection.getSchema()).thenThrow(sqlException);
when(connection.getNetworkTimeout()).thenThrow(sqlException);
when(connection.isWrapperFor(Connection.class)).thenThrow(sqlException);
Expand All @@ -411,38 +409,38 @@ public void testExceptions() throws SQLException {
doThrow(sqlException).when(connection).clearWarnings();
doThrow(sqlException).when(connection).setSchema(null);
doThrow(sqlException).when(connection).abort(null);
doThrow(sqlException).when(connection).setNetworkTimeout(null,1);
doThrow(sqlException).when(connection).setNetworkTimeout(null, 1);

LogicalConnection logicalConnection = new LogicalConnection(snowflakePooledConnection);

assertThrows(SQLException.class, logicalConnection::createStatement);
assertThrows(SQLException.class, ()->logicalConnection.createStatement(1,2,3));
assertThrows(SQLException.class, ()->logicalConnection.nativeSQL("mocksql"));
assertThrows(SQLException.class, () -> logicalConnection.createStatement(1, 2, 3));
assertThrows(SQLException.class, () -> logicalConnection.nativeSQL("mocksql"));
assertThrows(SQLException.class, logicalConnection::getAutoCommit);
assertThrows(SQLException.class, logicalConnection::getMetaData);
assertThrows(SQLException.class, logicalConnection::isReadOnly);
assertThrows(SQLException.class, logicalConnection::getCatalog);
assertThrows(SQLException.class, logicalConnection::getTransactionIsolation);
assertThrows(SQLException.class, logicalConnection::getWarnings);
assertThrows(SQLException.class, ()->logicalConnection.prepareCall("mocksql"));
assertThrows(SQLException.class, () -> logicalConnection.prepareCall("mocksql"));
assertThrows(SQLException.class, logicalConnection::getTypeMap);
assertThrows(SQLException.class, logicalConnection::getHoldability);
assertThrows(SQLException.class, logicalConnection::createClob);
assertThrows(SQLException.class, ()->logicalConnection.getClientInfo("mocksql"));
assertThrows(SQLException.class, () -> logicalConnection.getClientInfo("mocksql"));
assertThrows(SQLException.class, logicalConnection::getClientInfo);
assertThrows(SQLException.class, ()->logicalConnection.createArrayOf("mock",null));
assertThrows(SQLException.class, () -> logicalConnection.createArrayOf("mock", null));
assertThrows(SQLException.class, logicalConnection::getSchema);
assertThrows(SQLException.class, logicalConnection::getNetworkTimeout);
assertThrows(SQLException.class, ()->logicalConnection.isWrapperFor(Connection.class));
assertThrows(SQLException.class, ()->logicalConnection.setAutoCommit(false));
assertThrows(SQLException.class, () -> logicalConnection.isWrapperFor(Connection.class));
assertThrows(SQLException.class, () -> logicalConnection.setAutoCommit(false));
assertThrows(SQLException.class, logicalConnection::rollback);
assertThrows(SQLException.class, ()->logicalConnection.setReadOnly(false));
assertThrows(SQLException.class, () -> logicalConnection.setReadOnly(false));
assertThrows(SQLException.class, logicalConnection::clearWarnings);
assertThrows(SQLException.class, ()->logicalConnection.setSchema(null));
assertThrows(SQLException.class, ()->logicalConnection.abort(null));
assertThrows(SQLException.class, ()->logicalConnection.setNetworkTimeout(null,1));
assertThrows(SQLException.class, () -> logicalConnection.setSchema(null));
assertThrows(SQLException.class, () -> logicalConnection.abort(null));
assertThrows(SQLException.class, () -> logicalConnection.setNetworkTimeout(null, 1));

verify(snowflakePooledConnection,times(26)).fireConnectionErrorEvent(sqlException);
verify(snowflakePooledConnection, times(26)).fireConnectionErrorEvent(sqlException);
}

private SnowflakeConnectionPoolDataSource setProperties(
Expand Down

0 comments on commit 440334c

Please sign in to comment.