This is an automated email from the ASF dual-hosted git repository.
jackie pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/pinot.git
The following commit(s) were added to refs/heads/master by this push:
new ac4c3d1ee2 [Minor] Reformat ClassLoaderTest (#14394)
ac4c3d1ee2 is described below
commit ac4c3d1ee21adcab2030a2c5cedccb1396dbace7
Author: Xiaotian (Jackie) Jiang <[email protected]>
AuthorDate: Tue Nov 5 16:48:00 2024 -0800
[Minor] Reformat ClassLoaderTest (#14394)
---
.../apache/pinot/spi/plugin/ClassLoaderTest.java | 150 +++++++++++----------
1 file changed, 78 insertions(+), 72 deletions(-)
diff --git
a/pinot-spi/src/test/java/org/apache/pinot/spi/plugin/ClassLoaderTest.java
b/pinot-spi/src/test/java/org/apache/pinot/spi/plugin/ClassLoaderTest.java
index 9201b16879..43448b66cf 100644
--- a/pinot-spi/src/test/java/org/apache/pinot/spi/plugin/ClassLoaderTest.java
+++ b/pinot-spi/src/test/java/org/apache/pinot/spi/plugin/ClassLoaderTest.java
@@ -22,12 +22,14 @@ import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.regex.Pattern;
-import org.testng.Assert;
import org.testng.annotations.AfterClass;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;
-import static
org.apache.pinot.spi.plugin.PluginManager.PLUGINS_DIR_PROPERTY_NAME;
+import static org.testng.Assert.assertEquals;
+import static org.testng.Assert.assertNotNull;
+import static org.testng.Assert.assertThrows;
+import static org.testng.Assert.assertTrue;
/**
@@ -41,186 +43,190 @@ import static
org.apache.pinot.spi.plugin.PluginManager.PLUGINS_DIR_PROPERTY_NAM
* most of the time just the pinot-plugin.properties for that plugin.
*/
public class ClassLoaderTest {
+ private static final String ORIGINAL_PLUGIN_DIR =
System.getProperty(PluginManager.PLUGINS_DIR_PROPERTY_NAME);
- private static final String ORIGINAL_PLUGIN_DIR =
System.getProperty(PLUGINS_DIR_PROPERTY_NAME);
-
- // relative to pinot-spi/pom.xml
- private final Path _pluginsDirectory =
Path.of("target/test-classes/plugins").toAbsolutePath();
+ // Relative to pinot-spi/pom.xml
+ private static final Path PLUGINS_DIRECTORY =
Path.of("target/test-classes/plugins").toAbsolutePath();
// MathUtils is only used in pinot framework, should not be available in
limited plugins
- private final String _commonsMathUtils =
"org.apache.commons.math3.util.MathUtils";
+ private static final String COMMONS_MATH_UTILS =
"org.apache.commons.math3.util.MathUtils";
// IOUtils exists in all realms, they should use their own version
- private final String _commonsIOUtils = "org.apache.commons.io.IOUtils";
+ private static final String COMMONS_IO_UTILS =
"org.apache.commons.io.IOUtils";
// TimeUtils exists in all realms, they should be imported from pinot
classloader
- private final String _spiTimeUtils = "org.apache.pinot.spi.utils.TimeUtils";
-
- public final String _yammerMetricsRegistry =
"org.apache.pinot.plugin.metrics.yammer.YammerMetricsRegistry";
+ private static final String SPI_TIME_UTILS =
"org.apache.pinot.spi.utils.TimeUtils";
- public final String _dropwizardMetricsRegistry =
+ private static final String YAMMER_METRICS_REGISTRY =
"org.apache.pinot.plugin.metrics.yammer.YammerMetricsRegistry";
+ private static final String DROPWIZARD_METRICS_REGISTRY =
"org.apache.pinot.plugin.metrics.dropwizard.DropwizardMetricsRegistry";
@BeforeClass
public void setup()
throws IOException {
- System.setProperty(PLUGINS_DIR_PROPERTY_NAME,
_pluginsDirectory.toString());
+ System.setProperty(PluginManager.PLUGINS_DIR_PROPERTY_NAME,
PLUGINS_DIRECTORY.toString());
}
@Test
- public void classRealms() throws Exception {
-
Assert.assertNotNull(ClassLoader.getSystemClassLoader().loadClass(_commonsMathUtils),
- "Expected " + _commonsMathUtils + " to be loadable via
SystemClassLoader");
-
Assert.assertNotNull(ClassLoader.getSystemClassLoader().loadClass(_commonsIOUtils),
- "Expected " + _commonsIOUtils + " to be loadable via
SystemClassLoader");
+ public void classRealms()
+ throws Exception {
+
assertNotNull(ClassLoader.getSystemClassLoader().loadClass(COMMONS_MATH_UTILS),
+ "Expected " + COMMONS_MATH_UTILS + " to be loadable via
SystemClassLoader");
+
assertNotNull(ClassLoader.getSystemClassLoader().loadClass(COMMONS_IO_UTILS),
+ "Expected " + COMMONS_IO_UTILS + " to be loadable via
SystemClassLoader");
}
// pinot-dropwizard is a limited plugin, meaning it cannot access every
class from the pinot realm
@Test
- public void limitedPluginRealm() throws Exception {
- final String pluginName = "pinot-dropwizard";
+ public void limitedPluginRealm()
+ throws Exception {
+ String pluginName = "pinot-dropwizard";
// Create fresh pluginManager, so it can pick up the system property for
the pluginDirectory
PluginManager pluginManager = new PluginManager();
// make sure pinot-dropwizard-0.10.0-shaded.jar has been downloaded
- Assert.assertTrue(
- Files.exists(_pluginsDirectory.resolve(pluginName +
"/pinot-dropwizard-0.10.0-shaded.jar")),
+ assertTrue(
+ Files.exists(PLUGINS_DIRECTORY.resolve(pluginName +
"/pinot-dropwizard-0.10.0-shaded.jar")),
"Plugin not found. Run 'mvn -f pinot-spi/pom.xml
generate-test-resources' once to prepare this artifact");
- Assert.assertNotNull(pluginManager.loadClass(pluginName,
_dropwizardMetricsRegistry),
+ assertNotNull(pluginManager.loadClass(pluginName,
DROPWIZARD_METRICS_REGISTRY),
"Expected o.a.p.p.m.d.DropwizardMetricsRegistry to be available");
- Assert.assertNotNull(pluginManager.createInstance(pluginName,
_dropwizardMetricsRegistry),
+ assertNotNull(pluginManager.createInstance(pluginName,
DROPWIZARD_METRICS_REGISTRY),
"Expected to be able to create instance of
o.a.p.p.m.d.DropwizardMetricsRegistry");
- Assert.assertNotNull(pluginManager.loadClass(pluginName, _spiTimeUtils),
+ assertNotNull(pluginManager.loadClass(pluginName, SPI_TIME_UTILS),
"Expected o.a.p.spi.utils.TimeUtils to be available via
dropwizard-realm");
- Assert.assertEquals(pluginManager.loadClass(pluginName, _spiTimeUtils)
+ assertEquals(pluginManager.loadClass(pluginName, SPI_TIME_UTILS)
.getProtectionDomain().getCodeSource().getLocation(),
Path.of("target/classes").toUri().toURL(),
"Expected o.a.p.spi.utils.TimeUtils to be loaded from pinot-realm");
- Assert.assertThrows("Class is part of a different plugin, so should not be
accessible",
- ClassNotFoundException.class, () ->
pluginManager.loadClass(pluginName, _yammerMetricsRegistry));
+ assertThrows("Class is part of a different plugin, so should not be
accessible",
+ ClassNotFoundException.class, () ->
pluginManager.loadClass(pluginName, YAMMER_METRICS_REGISTRY));
- Assert.assertThrows("Class is dependency of pinot-spi, but is not an
exported package",
- ClassNotFoundException.class, () ->
pluginManager.loadClass(pluginName, _commonsMathUtils));
+ assertThrows("Class is dependency of pinot-spi, but is not an exported
package",
+ ClassNotFoundException.class, () ->
pluginManager.loadClass(pluginName, COMMONS_MATH_UTILS));
- Assert.assertTrue(pluginManager.loadClass(pluginName,
_commonsIOUtils).getProtectionDomain()
+ assertTrue(pluginManager.loadClass(pluginName,
COMMONS_IO_UTILS).getProtectionDomain()
.getCodeSource().getLocation().getPath().endsWith("pinot-dropwizard-0.10.0-shaded.jar"),
"Expected o.a.c.i.IOUtils to be available via dropwizard-realm");
}
@Test
- public void unlimitedPluginRealm() throws Exception {
- final String pluginName = "pinot-yammer";
+ public void unlimitedPluginRealm()
+ throws Exception {
+ String pluginName = "pinot-yammer";
// Create fresh pluginManager, so it can pick up the system property for
the pluginDirectory
PluginManager pluginManager = new PluginManager();
// pinot-yammer is an unlimited plugin, meaning it has access to every
class from the pinot realm
- Assert.assertTrue(
- Files.exists(_pluginsDirectory.resolve(pluginName +
"/pinot-yammer-0.10.0-shaded.jar")),
+ assertTrue(
+ Files.exists(PLUGINS_DIRECTORY.resolve(pluginName +
"/pinot-yammer-0.10.0-shaded.jar")),
"Plugin not found. Run 'mvn -f pinot-spi/pom.xml
generate-test-resources' once to prepare this artifact");
- Assert.assertNotNull(pluginManager.loadClass(pluginName,
_yammerMetricsRegistry));
- Assert.assertNotNull(pluginManager.createInstance(pluginName,
_yammerMetricsRegistry));
+ assertNotNull(pluginManager.loadClass(pluginName,
YAMMER_METRICS_REGISTRY));
+ assertNotNull(pluginManager.createInstance(pluginName,
YAMMER_METRICS_REGISTRY));
- Assert.assertNotNull(pluginManager.loadClass(pluginName, _spiTimeUtils),
+ assertNotNull(pluginManager.loadClass(pluginName, SPI_TIME_UTILS),
"Expected o.a.p.spi.utils.TimeUtils to be available via yammer-realm");
- Assert.assertEquals(pluginManager.loadClass(pluginName, _spiTimeUtils)
+ assertEquals(pluginManager.loadClass(pluginName, SPI_TIME_UTILS)
.getProtectionDomain().getCodeSource().getLocation(),
Path.of("target/classes").toUri().toURL(),
"Expected o.a.p.spi.utils.TimeUtils to be loaded from pinot-realm");
- Assert.assertNotNull(pluginManager.loadClass(pluginName,
_commonsMathUtils),
+ assertNotNull(pluginManager.loadClass(pluginName, COMMONS_MATH_UTILS),
"o.a.c.m.u.MathUtils is dependency of pinot-spi, must be accessible
for unlimited plugins");
- Assert.assertTrue(pluginManager.loadClass(pluginName,
_commonsIOUtils).getProtectionDomain()
+ assertTrue(pluginManager.loadClass(pluginName,
COMMONS_IO_UTILS).getProtectionDomain()
.getCodeSource().getLocation().getPath().endsWith("pinot-yammer-0.10.0-shaded.jar"),
"This is self-first, so class should come from pinot-yammer realm");
- Assert.assertThrows("Class is part of a different plugin, so should not be
accessible",
- ClassNotFoundException.class, () ->
pluginManager.loadClass(pluginName, _dropwizardMetricsRegistry));
+ assertThrows("Class is part of a different plugin, so should not be
accessible",
+ ClassNotFoundException.class, () ->
pluginManager.loadClass(pluginName, DROPWIZARD_METRICS_REGISTRY));
}
@Test
- public void assemblyBasedRealm() throws Exception {
- final String pluginName = "assemblybased-pinot-plugin";
+ public void assemblyBasedRealm()
+ throws Exception {
+ String pluginName = "assemblybased-pinot-plugin";
// Create fresh pluginManager, so it can pick up the system property for
the pluginDirectory
PluginManager pluginManager = new PluginManager();
// pinot-yammer is an unlimited plugin, meaning it has access to every
class from the pinot realm
- Assert.assertTrue(
- Files.exists(_pluginsDirectory.resolve(
+ assertTrue(
+ Files.exists(PLUGINS_DIRECTORY.resolve(
pluginName +
"/classes/org/apache/pinot/plugin/metrics/yammer/YammerMetricsRegistry.class")),
"Class not found. Run 'mvn -f pinot-spi/pom.xml
generate-test-resources' once to prepare this artifact");
- Assert.assertNotNull(pluginManager.loadClass(pluginName,
_yammerMetricsRegistry));
- Assert.assertNotNull(pluginManager.createInstance(pluginName,
_yammerMetricsRegistry));
+ assertNotNull(pluginManager.loadClass(pluginName,
YAMMER_METRICS_REGISTRY));
+ assertNotNull(pluginManager.createInstance(pluginName,
YAMMER_METRICS_REGISTRY));
- Assert.assertNotNull(pluginManager.loadClass(pluginName, _spiTimeUtils),
+ assertNotNull(pluginManager.loadClass(pluginName, SPI_TIME_UTILS),
"Expected o.a.p.spi.utils.TimeUtils to be available via yammer-realm");
- Assert.assertEquals(pluginManager.loadClass("pinot-dropwizard",
_spiTimeUtils)
+ assertEquals(pluginManager.loadClass("pinot-dropwizard", SPI_TIME_UTILS)
.getProtectionDomain().getCodeSource().getLocation(),
Path.of("target/classes").toUri().toURL(),
"Expected o.a.p.spi.utils.TimeUtils to be loaded from pinot-realm");
- Assert.assertThrows("Class is dependency of pinot-spi, but is not an
exported package",
+ assertThrows("Class is dependency of pinot-spi, but is not an exported
package",
ClassNotFoundException.class, () -> pluginManager.loadClass(
- "pinot-dropwizard", _commonsMathUtils));
+ "pinot-dropwizard", COMMONS_MATH_UTILS));
- Assert.assertTrue(pluginManager.loadClass(pluginName,
_commonsIOUtils).getProtectionDomain()
+ assertTrue(pluginManager.loadClass(pluginName,
COMMONS_IO_UTILS).getProtectionDomain()
.getCodeSource().getLocation().getPath().endsWith("commons-io-2.11.0.jar"),
"This is self-first, so class should come from pinot-yammer realm");
- Assert.assertThrows("Class is part of a different plugin, so should not be
accessible",
- ClassNotFoundException.class, () ->
pluginManager.loadClass(pluginName, _dropwizardMetricsRegistry));
+ assertThrows("Class is part of a different plugin, so should not be
accessible",
+ ClassNotFoundException.class, () ->
pluginManager.loadClass(pluginName, DROPWIZARD_METRICS_REGISTRY));
}
@Test
- public void classicPluginClassloader() throws Exception {
- final String pluginName = "pinot-shaded-yammer";
+ public void classicPluginClassloader()
+ throws Exception {
+ String pluginName = "pinot-shaded-yammer";
// Create fresh pluginManager, so it can pick up the system property for
the pluginDirectory
PluginManager pluginManager = new PluginManager();
// pinot-shaded-yammer is a shaded jar using the legacy PluginClassloader
instead of classRealm
- Assert.assertTrue(
- Files.exists(_pluginsDirectory.resolve(pluginName +
"/pinot-yammer-0.10.0-shaded.jar")),
+ assertTrue(
+ Files.exists(PLUGINS_DIRECTORY.resolve(pluginName +
"/pinot-yammer-0.10.0-shaded.jar")),
"Plugin not found. Run 'mvn -f pinot-spi/pom.xml
generate-test-resources' once to prepare this artifact");
- Assert.assertNotNull(pluginManager.loadClass(pluginName,
_yammerMetricsRegistry),
+ assertNotNull(pluginManager.loadClass(pluginName, YAMMER_METRICS_REGISTRY),
"Expected o.a.p.p.m.y.YammerMetricsRegistry to be available");
- Assert.assertNotNull(pluginManager.createInstance(pluginName,
_yammerMetricsRegistry),
+ assertNotNull(pluginManager.createInstance(pluginName,
YAMMER_METRICS_REGISTRY),
"Expected to be able to create instance of
o.a.p.p.m.y.YammerMetricsRegistry");
- Assert.assertNotNull(pluginManager.loadClass(pluginName, _spiTimeUtils),
+ assertNotNull(pluginManager.loadClass(pluginName, SPI_TIME_UTILS),
"Expected o.a.p.spi.utils.TimeUtils to be available via yammer-realm");
- Assert.assertEquals(pluginManager.loadClass(pluginName, _spiTimeUtils)
+ assertEquals(pluginManager.loadClass(pluginName, SPI_TIME_UTILS)
.getProtectionDomain().getCodeSource().getLocation(),
Path.of("target/classes").toUri().toURL(),
"Expected o.a.p.spi.utils.TimeUtils to be loaded from pinot-realm");
- Assert.assertNotNull(pluginManager.loadClass(pluginName,
_commonsMathUtils),
+ assertNotNull(pluginManager.loadClass(pluginName, COMMONS_MATH_UTILS),
"Class is dependency of pinot-spi, must be accessible for unlimited
plugins");
// THIS IS THE MAIN REASON FOR CLASSREALMS: classes are here loaded from
pinot first, not from shaded plugin
- String urlPath = pluginManager.loadClass(pluginName, _commonsIOUtils)
+ String urlPath = pluginManager.loadClass(pluginName, COMMONS_IO_UTILS)
.getProtectionDomain().getCodeSource().getLocation().getPath();
// unpredictable version, as it depends on this pinot-spi
-
Assert.assertTrue(Pattern.matches(".*/commons-io/commons-io/[^/]+/commons-io-[\\.\\d]+.jar$",
urlPath),
+
assertTrue(Pattern.matches(".*/commons-io/commons-io/[^/]+/commons-io-[.\\d]+.jar$",
urlPath),
"This is using the PluginClassloader, so class should come from the
system class laoder");
- Assert.assertThrows("Class is part of a different plugin, so should not be
accessible",
- ClassNotFoundException.class, () ->
pluginManager.loadClass(pluginName, _dropwizardMetricsRegistry));
+ assertThrows("Class is part of a different plugin, so should not be
accessible",
+ ClassNotFoundException.class, () ->
pluginManager.loadClass(pluginName, DROPWIZARD_METRICS_REGISTRY));
}
@AfterClass
- public void tearDown() throws Exception {
+ public void tearDown()
+ throws Exception {
if (ORIGINAL_PLUGIN_DIR != null) {
- System.setProperty(PLUGINS_DIR_PROPERTY_NAME, ORIGINAL_PLUGIN_DIR);
+ System.setProperty(PluginManager.PLUGINS_DIR_PROPERTY_NAME,
ORIGINAL_PLUGIN_DIR);
} else {
- System.clearProperty(PLUGINS_DIR_PROPERTY_NAME);
+ System.clearProperty(PluginManager.PLUGINS_DIR_PROPERTY_NAME);
}
}
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]