-
Notifications
You must be signed in to change notification settings - Fork 348
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[#2167] refactor: refactor TestGravitinoConnector to enable StaticGua…
…rdedByInstance error-prone (#2514) <!-- 1. Title: [#<issue>] <type>(<scope>): <subject> Examples: - "[#123] feat(operator): support xxx" - "[#233] fix: check null before access result in xxx" - "[MINOR] refactor: fix typo in variable name" - "[MINOR] docs: fix typo in README" - "[#255] test: fix flaky test NameOfTheTest" Reference: https://www.conventionalcommits.org/en/v1.0.0/ 2. If the PR is unfinished, please mark this PR as draft. --> ### What changes were proposed in this pull request? `StaticGuardedByInstance` amis to avoid `public static` fields. Because this field is not thread-safe. See more details at https://errorprone.info/bugpattern/StaticGuardedByInstance. In this MR, I remove some test code in `com.datastrato.gravitino.trino.connector.GravitinoPlugin` and `com.datastrato.gravitino.trino.connector.GravitinoConnectorFactory`. At the same time, I enable `StaticGuardedByInstance` error-prone. ### Why are the changes needed? - Fix: #2167 ### Does this PR introduce _any_ user-facing change? - no ### How was this patch tested? - original unit tests.
- Loading branch information
Showing
6 changed files
with
81 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
21 changes: 21 additions & 0 deletions
21
...src/test/java/com/datastrato/gravitino/trino/connector/TestGravitinoConnectorFactory.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
/* | ||
* Copyright 2024 Datastrato Pvt Ltd. | ||
* This software is licensed under the Apache License version 2. | ||
*/ | ||
package com.datastrato.gravitino.trino.connector; | ||
|
||
import com.datastrato.gravitino.client.GravitinoAdminClient; | ||
import java.util.function.Supplier; | ||
|
||
public class TestGravitinoConnectorFactory extends GravitinoConnectorFactory { | ||
private GravitinoAdminClient gravitinoClient; | ||
|
||
public void setGravitinoClient(GravitinoAdminClient client) { | ||
this.gravitinoClient = client; | ||
} | ||
|
||
@Override | ||
Supplier<GravitinoAdminClient> clientProvider() { | ||
return () -> gravitinoClient; | ||
} | ||
} |
31 changes: 31 additions & 0 deletions
31
...connector/src/test/java/com/datastrato/gravitino/trino/connector/TestGravitinoPlugin.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
/* | ||
* Copyright 2024 Datastrato Pvt Ltd. | ||
* This software is licensed under the Apache License version 2. | ||
*/ | ||
package com.datastrato.gravitino.trino.connector; | ||
|
||
import com.datastrato.gravitino.client.GravitinoAdminClient; | ||
import com.datastrato.gravitino.trino.connector.catalog.CatalogConnectorManager; | ||
import com.google.common.collect.ImmutableList; | ||
import io.trino.spi.connector.ConnectorFactory; | ||
|
||
public class TestGravitinoPlugin extends GravitinoPlugin { | ||
private TestGravitinoConnectorFactory factory; | ||
|
||
private GravitinoAdminClient gravitinoClient; | ||
|
||
@Override | ||
public Iterable<ConnectorFactory> getConnectorFactories() { | ||
factory = new TestGravitinoConnectorFactory(); | ||
factory.setGravitinoClient(gravitinoClient); | ||
return ImmutableList.of(factory); | ||
} | ||
|
||
public void setGravitinoClient(GravitinoAdminClient client) { | ||
this.gravitinoClient = client; | ||
} | ||
|
||
public CatalogConnectorManager getCatalogConnectorManager() { | ||
return factory.getCatalogConnectorManager(); | ||
} | ||
} |