Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
10 changes: 10 additions & 0 deletions config/spotbugs/exclude.xml
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,14 @@
<Class name="~.*PipelineRules.*"/>
<Bug code="CT"/>
</Match>

<!--
Mockito's doReturn(x).when(mock).method() idiom syntactically invokes mock.method() with the
return value ignored. SpotBugs flags this as a no-side-effect call whose result is discarded,
even though Mockito intercepts the invocation to record the stub. False positive in test code.
-->
<Match>
<Source name="~.*Test\.java"/>
<Bug pattern="RV_RETURN_VALUE_IGNORED_NO_SIDE_EFFECT"/>
</Match>
</FindBugsFilter>
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

import org.junit.jupiter.api.Test;

import java.util.List;
import java.util.Map;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertNull;
Expand Down Expand Up @@ -77,7 +80,7 @@ void toStringOmitsSelfOwnerWhenOnlyOneFieldSet() {

@Test
void targetGenericTypeIsPreserved() {
Source source = new Source("db", java.util.List.of("schema", "tbl"), java.util.Map.of());
Source source = new Source("db", List.of("schema", "tbl"), Map.of());
PendingDelete<Source> pd = new PendingDelete<>(source);
Source unwrapped = pd.target();
assertEquals("tbl", unwrapped.table());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;

Expand Down Expand Up @@ -90,11 +91,10 @@ protected Map<String, Table> getTableMap() {
CalciteSchema calciteSchema = CalciteSchema.createRootSchema(false, false, "root", innerSchema);

// Mock the SchemaPlus: tables() returns newTable; unwrap returns the CalciteSchema with originalTable
@SuppressWarnings("unchecked")
Lookup<Table> tableLookup = mock(Lookup.class);
when(tableLookup.getNames(any())).thenReturn(Set.of("MY_TABLE"));
when(tableLookup.get("MY_TABLE")).thenReturn(newTable);
when(schema.tables()).thenReturn(tableLookup);
Lookup<?> tableLookup = mock(Lookup.class);
doReturn(Set.of("MY_TABLE")).when(tableLookup).getNames(any());
doReturn(newTable).when(tableLookup).get("MY_TABLE");
doReturn(tableLookup).when(schema).tables();
when(schema.unwrap(CalciteSchema.class)).thenReturn(calciteSchema);

AvroTableValidator validator = new AvroTableValidator(schema);
Expand Down Expand Up @@ -128,11 +128,10 @@ protected Map<String, Table> getTableMap() {
};
CalciteSchema calciteSchema = CalciteSchema.createRootSchema(false, false, "root", innerSchema);

@SuppressWarnings("unchecked")
Lookup<Table> tableLookup = mock(Lookup.class);
when(tableLookup.getNames(any())).thenReturn(Set.of("MY_TABLE"));
when(tableLookup.get("MY_TABLE")).thenReturn(sameTable);
when(schema.tables()).thenReturn(tableLookup);
Lookup<?> tableLookup = mock(Lookup.class);
doReturn(Set.of("MY_TABLE")).when(tableLookup).getNames(any());
doReturn(sameTable).when(tableLookup).get("MY_TABLE");
doReturn(tableLookup).when(schema).tables();
when(schema.unwrap(CalciteSchema.class)).thenReturn(calciteSchema);

AvroTableValidator validator = new AvroTableValidator(schema);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,6 @@ void testGetSchemasWithSchemaPatternFiltersNonMatching() throws SQLException {
}

@Test
@SuppressWarnings("unchecked")
void testGetSchemasExpandsCatalogWhenSchemaNull() throws SQLException {
ResultSet mockRs = mock(ResultSet.class);
when(mockRs.next()).thenReturn(true, false);
Expand All @@ -168,13 +167,13 @@ void testGetSchemasExpandsCatalogWhenSchemaNull() throws SQLException {
when(mockPreparedStatement.executeQuery()).thenReturn(mockRs);

SchemaPlus mockRootSchema = mock(SchemaPlus.class);
Lookup<SchemaPlus> mockRootSubSchemas = mock(Lookup.class);
Lookup<?> mockRootSubSchemas = mock(Lookup.class);
SchemaPlus mockCatalogSchema = mock(SchemaPlus.class);
Lookup<SchemaPlus> mockCatalogSubSchemas = mock(Lookup.class);
Lookup<?> mockCatalogSubSchemas = mock(Lookup.class);

when(mockCalciteConnection.getRootSchema()).thenReturn(mockRootSchema);
doReturn(mockRootSubSchemas).when(mockRootSchema).subSchemas();
when(mockRootSubSchemas.get("myCatalog")).thenReturn(mockCatalogSchema);
doReturn(mockCatalogSchema).when(mockRootSubSchemas).get("myCatalog");
doReturn(mockCatalogSubSchemas).when(mockCatalogSchema).subSchemas();
doReturn(Set.of("subSchema1")).when(mockCatalogSubSchemas).getNames(any());

Expand All @@ -187,7 +186,6 @@ void testGetSchemasExpandsCatalogWhenSchemaNull() throws SQLException {
}

@Test
@SuppressWarnings("unchecked")
void testGetSchemasExpandsCatalogWithNullSubSchema() throws SQLException {
ResultSet mockRs = mock(ResultSet.class);
when(mockRs.next()).thenReturn(true, false);
Expand All @@ -199,11 +197,11 @@ void testGetSchemasExpandsCatalogWithNullSubSchema() throws SQLException {
when(mockPreparedStatement.executeQuery()).thenReturn(mockRs);

SchemaPlus mockRootSchema = mock(SchemaPlus.class);
Lookup<SchemaPlus> mockRootSubSchemas = mock(Lookup.class);
Lookup<?> mockRootSubSchemas = mock(Lookup.class);

when(mockCalciteConnection.getRootSchema()).thenReturn(mockRootSchema);
doReturn(mockRootSubSchemas).when(mockRootSchema).subSchemas();
when(mockRootSubSchemas.get("missingCatalog")).thenReturn(null);
doReturn(null).when(mockRootSubSchemas).get("missingCatalog");

ResultSet rs = metaData.getSchemas(null, null);

Expand Down Expand Up @@ -265,7 +263,6 @@ void testGetSchemasWithCatalogFiltersSetsParameter() throws SQLException {
}

@Test
@SuppressWarnings("unchecked")
void testGetTablesReturnsResultSet() throws SQLException {
// Mock getSchemas to return one schema row
ResultSet mockSchemaRs = mock(ResultSet.class);
Expand All @@ -281,20 +278,20 @@ void testGetTablesReturnsResultSet() throws SQLException {
SchemaPlus mockRootSchema = mock(SchemaPlus.class);
SchemaPlus mockCatalogSchema = mock(SchemaPlus.class);
SchemaPlus mockDbSchema = mock(SchemaPlus.class);
Lookup<SchemaPlus> mockRootSubSchemas = mock(Lookup.class);
Lookup<SchemaPlus> mockCatSubSchemas = mock(Lookup.class);
Lookup<Table> mockTablesLookup = mock(Lookup.class);
Lookup<?> mockRootSubSchemas = mock(Lookup.class);
Lookup<?> mockCatSubSchemas = mock(Lookup.class);
Lookup<?> mockTablesLookup = mock(Lookup.class);

when(mockCalciteConnection.getRootSchema()).thenReturn(mockRootSchema);
doReturn(mockRootSubSchemas).when(mockRootSchema).subSchemas();
when(mockRootSubSchemas.get("myCat")).thenReturn(mockCatalogSchema);
doReturn(mockCatalogSchema).when(mockRootSubSchemas).get("myCat");
doReturn(mockCatSubSchemas).when(mockCatalogSchema).subSchemas();
when(mockCatSubSchemas.get("mySchema")).thenReturn(mockDbSchema);
doReturn(mockDbSchema).when(mockCatSubSchemas).get("mySchema");
doReturn(mockTablesLookup).when(mockDbSchema).tables();
doReturn(Set.of("table1")).when(mockTablesLookup).getNames(any());

Table mockTable = mock(Table.class);
when(mockTablesLookup.get("table1")).thenReturn(mockTable);
doReturn(mockTable).when(mockTablesLookup).get("table1");
when(mockTable.getJdbcTableType()).thenReturn(Schema.TableType.TABLE);

ResultSet rs = metaData.getTables("myCat", "mySchema", null, null);
Expand All @@ -308,7 +305,6 @@ void testGetTablesReturnsResultSet() throws SQLException {
}

@Test
@SuppressWarnings("unchecked")
void testGetTablesWithTypeFilter() throws SQLException {
ResultSet mockSchemaRs = mock(ResultSet.class);
when(mockSchemaRs.next()).thenReturn(true, false);
Expand All @@ -322,20 +318,20 @@ void testGetTablesWithTypeFilter() throws SQLException {
SchemaPlus mockRootSchema = mock(SchemaPlus.class);
SchemaPlus mockCatalogSchema = mock(SchemaPlus.class);
SchemaPlus mockDbSchema = mock(SchemaPlus.class);
Lookup<SchemaPlus> mockRootSub = mock(Lookup.class);
Lookup<SchemaPlus> mockCatSub = mock(Lookup.class);
Lookup<Table> mockTables = mock(Lookup.class);
Lookup<?> mockRootSub = mock(Lookup.class);
Lookup<?> mockCatSub = mock(Lookup.class);
Lookup<?> mockTables = mock(Lookup.class);

when(mockCalciteConnection.getRootSchema()).thenReturn(mockRootSchema);
doReturn(mockRootSub).when(mockRootSchema).subSchemas();
when(mockRootSub.get("cat")).thenReturn(mockCatalogSchema);
doReturn(mockCatalogSchema).when(mockRootSub).get("cat");
doReturn(mockCatSub).when(mockCatalogSchema).subSchemas();
when(mockCatSub.get("sch")).thenReturn(mockDbSchema);
doReturn(mockDbSchema).when(mockCatSub).get("sch");
doReturn(mockTables).when(mockDbSchema).tables();
doReturn(Set.of("t1")).when(mockTables).getNames(any());

Table mockTable = mock(Table.class);
when(mockTables.get("t1")).thenReturn(mockTable);
doReturn(mockTable).when(mockTables).get("t1");
when(mockTable.getJdbcTableType()).thenReturn(Schema.TableType.VIEW);

// Filter by TABLE type only - should exclude VIEW
Expand All @@ -346,7 +342,6 @@ void testGetTablesWithTypeFilter() throws SQLException {
}

@Test
@SuppressWarnings("unchecked")
void testGetTablesWithMatchingTypeFilter() throws SQLException {
ResultSet mockSchemaRs = mock(ResultSet.class);
when(mockSchemaRs.next()).thenReturn(true, false);
Expand All @@ -360,20 +355,20 @@ void testGetTablesWithMatchingTypeFilter() throws SQLException {
SchemaPlus mockRootSchema = mock(SchemaPlus.class);
SchemaPlus mockCatalogSchema = mock(SchemaPlus.class);
SchemaPlus mockDbSchema = mock(SchemaPlus.class);
Lookup<SchemaPlus> mockRootSub = mock(Lookup.class);
Lookup<SchemaPlus> mockCatSub = mock(Lookup.class);
Lookup<Table> mockTables = mock(Lookup.class);
Lookup<?> mockRootSub = mock(Lookup.class);
Lookup<?> mockCatSub = mock(Lookup.class);
Lookup<?> mockTables = mock(Lookup.class);

when(mockCalciteConnection.getRootSchema()).thenReturn(mockRootSchema);
doReturn(mockRootSub).when(mockRootSchema).subSchemas();
when(mockRootSub.get("cat")).thenReturn(mockCatalogSchema);
doReturn(mockCatalogSchema).when(mockRootSub).get("cat");
doReturn(mockCatSub).when(mockCatalogSchema).subSchemas();
when(mockCatSub.get("sch")).thenReturn(mockDbSchema);
doReturn(mockDbSchema).when(mockCatSub).get("sch");
doReturn(mockTables).when(mockDbSchema).tables();
doReturn(Set.of("t1")).when(mockTables).getNames(any());

Table mockTable = mock(Table.class);
when(mockTables.get("t1")).thenReturn(mockTable);
doReturn(mockTable).when(mockTables).get("t1");
when(mockTable.getJdbcTableType()).thenReturn(Schema.TableType.TABLE);

// Filter by TABLE type - should include
Expand Down Expand Up @@ -447,7 +442,6 @@ void testGetSchemasWithWildcardPatternMatchesAll() throws SQLException {
}

@Test
@SuppressWarnings("unchecked")
void testGetTablesWithViewTypeFilterIncludesViewExcludesTable() throws SQLException {
// Tests that types=["VIEW"] only returns view tables
ResultSet mockSchemaRs = mock(ResultSet.class);
Expand All @@ -462,20 +456,20 @@ void testGetTablesWithViewTypeFilterIncludesViewExcludesTable() throws SQLExcept
SchemaPlus mockRootSchema = mock(SchemaPlus.class);
SchemaPlus mockCatalogSchema = mock(SchemaPlus.class);
SchemaPlus mockDbSchema = mock(SchemaPlus.class);
Lookup<SchemaPlus> mockRootSub = mock(Lookup.class);
Lookup<SchemaPlus> mockCatSub = mock(Lookup.class);
Lookup<Table> mockTables = mock(Lookup.class);
Lookup<?> mockRootSub = mock(Lookup.class);
Lookup<?> mockCatSub = mock(Lookup.class);
Lookup<?> mockTables = mock(Lookup.class);

when(mockCalciteConnection.getRootSchema()).thenReturn(mockRootSchema);
doReturn(mockRootSub).when(mockRootSchema).subSchemas();
when(mockRootSub.get("cat")).thenReturn(mockCatalogSchema);
doReturn(mockCatalogSchema).when(mockRootSub).get("cat");
doReturn(mockCatSub).when(mockCatalogSchema).subSchemas();
when(mockCatSub.get("sch")).thenReturn(mockDbSchema);
doReturn(mockDbSchema).when(mockCatSub).get("sch");
doReturn(mockTables).when(mockDbSchema).tables();
doReturn(Set.of("v1")).when(mockTables).getNames(any());

Table mockView = mock(Table.class);
when(mockTables.get("v1")).thenReturn(mockView);
doReturn(mockView).when(mockTables).get("v1");
when(mockView.getJdbcTableType()).thenReturn(Schema.TableType.VIEW);

// Filter by VIEW — should include the view
Expand All @@ -489,7 +483,6 @@ void testGetTablesWithViewTypeFilterIncludesViewExcludesTable() throws SQLExcept
}

@Test
@SuppressWarnings("unchecked")
void testGetTablesSchemaPatternFiltersNonMatchingSchemas() throws SQLException {
// Tests that non-matching schemaPattern yields empty result
ResultSet mockSchemaRs = mock(ResultSet.class);
Expand All @@ -506,7 +499,6 @@ void testGetTablesSchemaPatternFiltersNonMatchingSchemas() throws SQLException {
}

@Test
@SuppressWarnings("unchecked")
void testGetTablesWithNullTypesIncludesBothTablesAndViews() throws SQLException {
// types=null means all types — tests the `types != null && types.length > 0` condition
ResultSet mockSchemaRs = mock(ResultSet.class);
Expand All @@ -521,20 +513,20 @@ void testGetTablesWithNullTypesIncludesBothTablesAndViews() throws SQLException
SchemaPlus mockRootSchema = mock(SchemaPlus.class);
SchemaPlus mockCatalogSchema = mock(SchemaPlus.class);
SchemaPlus mockDbSchema = mock(SchemaPlus.class);
Lookup<SchemaPlus> mockRootSub = mock(Lookup.class);
Lookup<SchemaPlus> mockCatSub = mock(Lookup.class);
Lookup<Table> mockTables = mock(Lookup.class);
Lookup<?> mockRootSub = mock(Lookup.class);
Lookup<?> mockCatSub = mock(Lookup.class);
Lookup<?> mockTables = mock(Lookup.class);

when(mockCalciteConnection.getRootSchema()).thenReturn(mockRootSchema);
doReturn(mockRootSub).when(mockRootSchema).subSchemas();
when(mockRootSub.get("cat")).thenReturn(mockCatalogSchema);
doReturn(mockCatalogSchema).when(mockRootSub).get("cat");
doReturn(mockCatSub).when(mockCatalogSchema).subSchemas();
when(mockCatSub.get("sch")).thenReturn(mockDbSchema);
doReturn(mockDbSchema).when(mockCatSub).get("sch");
doReturn(mockTables).when(mockDbSchema).tables();
doReturn(Set.of("t1")).when(mockTables).getNames(any());

Table mockTable = mock(Table.class);
when(mockTables.get("t1")).thenReturn(mockTable);
doReturn(mockTable).when(mockTables).get("t1");
when(mockTable.getJdbcTableType()).thenReturn(Schema.TableType.VIEW);

// types=null — VIEW should still be included
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.linkedin.hoptimator.jdbc;

import com.linkedin.hoptimator.Database;
import com.linkedin.hoptimator.Deployer;
import com.linkedin.hoptimator.Job;
import com.linkedin.hoptimator.Pipeline;
Expand All @@ -9,6 +10,7 @@
import com.linkedin.hoptimator.jdbc.ddl.SqlCreateDatabase;
import com.linkedin.hoptimator.jdbc.ddl.SqlCreateMaterializedView;
import com.linkedin.hoptimator.jdbc.ddl.SqlCreateTable;
import com.linkedin.hoptimator.util.planner.HoptimatorJdbcTable;
import com.linkedin.hoptimator.util.planner.PipelineRel;
import org.apache.calcite.jdbc.CalcitePrepare;
import org.apache.calcite.jdbc.CalciteSchema;
Expand Down Expand Up @@ -1189,8 +1191,7 @@ void processCreateMaterializedViewThrowsWhenOverwritingHoptimatorJdbcTable() thr
.add("TEST_JDBC_DB", new TestDatabaseSchema("test-jdbc-db"));

// Create a mock HoptimatorJdbcTable and register it
com.linkedin.hoptimator.util.planner.HoptimatorJdbcTable jdbcTable =
mock(com.linkedin.hoptimator.util.planner.HoptimatorJdbcTable.class);
HoptimatorJdbcTable jdbcTable = mock(HoptimatorJdbcTable.class);
jdbcDbSchema.add("physicalTable", jdbcTable);

// replace=false, ifNotExists=false, but we're trying to overwrite a HoptimatorJdbcTable
Expand Down Expand Up @@ -1592,8 +1593,7 @@ void specifyFromSqlForCreateDatabaseReturnsEmptySpecsWhenNoDeployersRegistered()
}
}

static class TestDatabaseSchema extends AbstractSchema
implements com.linkedin.hoptimator.Database {
static class TestDatabaseSchema extends AbstractSchema implements Database {
private final String name;

TestDatabaseSchema(String name) {
Expand Down Expand Up @@ -1628,7 +1628,7 @@ void removeTableFromSchemaRemovesFromRootWhenNoSchema() throws SQLException {

HoptimatorDdlUtils.removeTableFromSchema(connection, null, null, "ROOT_TMP");

assertEquals(null, rootSchema.tables().get("ROOT_TMP"));
assertNull(rootSchema.tables().get("ROOT_TMP"));
}
}

Expand All @@ -1649,7 +1649,7 @@ void removeTableFromSchemaRemovesFromTierSchema() throws SQLException {

HoptimatorDdlUtils.removeTableFromSchema(connection, null, "KAFKA", "my_topic");

assertEquals(null, tierSchema.tables().get("my_topic"));
assertNull(tierSchema.tables().get("my_topic"));
}
}

Expand All @@ -1669,7 +1669,7 @@ void removeTableFromSchemaRemovesFromCatalogAndSchema() throws SQLException {

HoptimatorDdlUtils.removeTableFromSchema(connection, "CAT", "DB", "t");

assertEquals(null, dbSchema.tables().get("t"));
assertNull(dbSchema.tables().get("t"));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.lenient;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
Expand Down Expand Up @@ -78,16 +79,15 @@ void deleteThrowsWhenResponseIsErrorStatus() throws ApiException {
}

@Test
@SuppressWarnings("unchecked")
void updateThrowsWhenResponseIsErrorStatusOnFinalUpdate() throws ApiException {
V1alpha1Pipeline pipeline = makePipeline("bad-pipeline", "test-ns");
V1alpha1Pipeline existing = makePipeline("bad-pipeline", "test-ns");
existing.getMetadata().setResourceVersion("rv1");

KubernetesApiResponse<V1alpha1Pipeline> existingResp = mock(KubernetesApiResponse.class);
KubernetesApiResponse<?> existingResp = mock(KubernetesApiResponse.class);
when(existingResp.isSuccess()).thenReturn(true);
when(existingResp.getObject()).thenReturn(existing);
when(mockErrApi.get(eq("test-ns"), eq("bad-pipeline"))).thenReturn(existingResp);
doReturn(existing).when(existingResp).getObject();
doReturn(existingResp).when(mockErrApi).get(eq("test-ns"), eq("bad-pipeline"));

ApiException apiEx = new ApiException(500, "Internal Server Error");
when(mockErrApi.update(any(V1alpha1Pipeline.class))).thenReturn(mockErrResponse);
Expand Down
Loading
Loading