Skip to content

Commit

Permalink
fix loader
Browse files Browse the repository at this point in the history
  • Loading branch information
kgyrtkirk committed Jun 18, 2024
1 parent 9df6f33 commit e725df7
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 2 deletions.
4 changes: 3 additions & 1 deletion quidem-it/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -429,11 +429,13 @@
<type>test-jar</type>
<version>${project.parent.version}</version>
</dependency>

<dependency>
<groupId>org.apache.druid</groupId>
<groupId>org.apache.druid.extensions</groupId>
<artifactId>druid-datasketches</artifactId>
<type>test-jar</type>
<version>${project.parent.version}</version>
<scope>compile</scope>
</dependency>

<dependency>
Expand Down
47 changes: 47 additions & 0 deletions quidem-it/src/test/java/org/apache/druid/quidem/QTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,20 @@

package org.apache.druid.quidem;

import com.google.common.cache.CacheBuilder;
import com.google.common.cache.CacheLoader;
import com.google.common.cache.LoadingCache;
import org.apache.druid.sql.calcite.util.SqlTestFramework.QueryComponentSupplier;
import org.junit.jupiter.api.Test;
import org.reflections.Reflections;
import org.reflections.scanners.SubTypesScanner;
import org.reflections.util.ConfigurationBuilder;
import org.reflections.util.FilterBuilder;

import java.io.File;
import java.io.IOException;
import java.net.MalformedURLException;
import java.util.Set;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.fail;
Expand Down Expand Up @@ -51,4 +61,41 @@ public void ensureNoRecordFilesPresent() throws IOException
}
}
}

@Test
public void testQTest() throws Exception
{
LoadingCache<String, Set<Class<? extends QueryComponentSupplier>>> componentSupplierClassCache = CacheBuilder
.newBuilder()
.build(new CacheLoader<String, Set<Class<? extends QueryComponentSupplier>>>()
{
@Override
public Set<Class<? extends QueryComponentSupplier>> load(String pkg) throws MalformedURLException
{
return new Reflections(
new ConfigurationBuilder()
// .addUrls(ClasspathHelper.forPackage(pkg,
// getClass().getClassLoader()))

// .addClassLoaders(getClass().getClassLoader().getParent())
.setScanners(
new SubTypesScanner(true)

)
.filterInputsBy(
new FilterBuilder().includePackage(pkg).and(
s -> s.contains("ComponentSupplier")
)

)
.setUrls(org.reflections.util.ClasspathHelper.forJavaClassPath())

)
.getSubTypesOf(QueryComponentSupplier.class);
}
});

Set<Class<? extends QueryComponentSupplier>> a = componentSupplierClassCache.get("");
throw new RuntimeException("X" + a);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,11 @@
import org.junit.jupiter.api.extension.AfterAllCallback;
import org.junit.jupiter.api.extension.BeforeEachCallback;
import org.junit.jupiter.api.extension.ExtensionContext;
import org.reflections.Configuration;
import org.reflections.Reflections;
import org.reflections.scanners.SubTypesScanner;
import org.reflections.util.ConfigurationBuilder;
import org.reflections.util.FilterBuilder;

import javax.annotation.Nonnull;

Expand Down Expand Up @@ -506,7 +510,15 @@ public final T fromMap(Map<String, String> map) throws Exception
@Override
public Set<Class<? extends QueryComponentSupplier>> load(String pkg)
{
return new Reflections(pkg).getSubTypesOf(QueryComponentSupplier.class);
Configuration cfg = new ConfigurationBuilder()
.setScanners(new SubTypesScanner(true))
.setUrls(org.reflections.util.ClasspathHelper.forJavaClassPath())
.filterInputsBy(
new FilterBuilder()
.includePackage(pkg)
.and(s -> s.contains("ComponentSupplier"))
);
return new Reflections(cfg).getSubTypesOf(QueryComponentSupplier.class);
}
});

Expand Down

0 comments on commit e725df7

Please sign in to comment.