Skip to content

Commit

Permalink
Merge pull request #18875 from stuartwdouglas/18299
Browse files Browse the repository at this point in the history
Disable Vert.x TCCL management
  • Loading branch information
stuartwdouglas authored Jul 27, 2021
2 parents c06023c + c3c7004 commit 8e09481
Show file tree
Hide file tree
Showing 21 changed files with 408 additions and 65 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,10 @@ public static void init(QuarkusConsole console, DevModeType devModeType) {
return;
}
initialized = true;
console.setInputHandler(INSTANCE.consumer);
INSTANCE.installBuiltins(devModeType);
if (console.isInputSupported()) {
console.setInputHandler(INSTANCE.consumer);
INSTANCE.installBuiltins(devModeType);
}
}

void installBuiltins(DevModeType devModeType) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,12 @@ public void runTests() {
long start = System.currentTimeMillis();
ClassLoader old = Thread.currentThread().getContextClassLoader();
try (QuarkusClassLoader tcl = testApplication.createDeploymentClassLoader()) {
synchronized (this) {
if (aborted) {
return;
}
testsRunning = true;
}
Thread.currentThread().setContextClassLoader(tcl);
Consumer currentTestAppConsumer = (Consumer) tcl.loadClass(CurrentTestApplication.class.getName()).newInstance();
currentTestAppConsumer.accept(testApplication);
Expand Down Expand Up @@ -408,9 +414,18 @@ public void reportingEntryPublished(TestIdentifier testIdentifier, ReportEntry e
} catch (Exception e) {
throw new RuntimeException(e);
} finally {
TracingHandler.setTracingHandler(null);
QuarkusConsole.INSTANCE.setOutputFilter(null);
Thread.currentThread().setContextClassLoader(old);
try {
TracingHandler.setTracingHandler(null);
QuarkusConsole.INSTANCE.setOutputFilter(null);
Thread.currentThread().setContextClassLoader(old);
} finally {
synchronized (this) {
testsRunning = false;
if (aborted) {
notifyAll();
}
}
}
}
}

Expand All @@ -424,6 +439,13 @@ public synchronized void abort() {
}
aborted = true;
notifyAll();
while (testsRunning) {
try {
wait();
} catch (InterruptedException e) {
//ignore
}
}
}

public synchronized void pause() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,11 @@ public void init() {
cl.addCloseTask(new Runnable() {
@Override
public void run() {
testCuratedApplication.close();
try {
stop();
} finally {
testCuratedApplication.close();
}
}
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,14 +77,6 @@ void startTesting(TestConfig config, LiveReloadBuildItem liveReloadBuildItem,
testSupport.stop();
}
}

QuarkusClassLoader cl = (QuarkusClassLoader) Thread.currentThread().getContextClassLoader();
((QuarkusClassLoader) cl.parent()).addCloseTask(new Runnable() {
@Override
public void run() {
testSupport.stop();
}
});
}

@BuildStep(onlyIf = IsTest.class)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,12 @@ public void accept(LogRecord logRecord, Consumer<LogRecord> logRecordConsumer) {
}
}
};
((QuarkusClassLoader) getClass().getClassLoader()).addCloseTask(new Runnable() {
@Override
public void run() {
CurrentAppExceptionHighlighter.THROWABLE_FORMATTER = null;
}
});
}

@BuildStep
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -156,4 +156,9 @@ public void write(byte[] buf, int off, int len) {
write(new String(buf, off, len, StandardCharsets.UTF_8));
}

@Override
public boolean isInputSupported() {
return inputSupport;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -100,4 +100,7 @@ public void setOutputFilter(Predicate<String> logHandler) {
this.outputFilter = logHandler;
}

public boolean isInputSupported() {
return true;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public static Consumer<State> getStateListener() {

public static void setStateListener(Consumer<State> stateListener) {
ContinuousTestingWebsocketListener.stateListener = stateListener;
if (lastState != null) {
if (lastState != null && stateListener != null) {
stateListener.accept(lastState);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import java.util.logging.Formatter;
import java.util.logging.Handler;
import java.util.logging.Level;
import java.util.logging.LogManager;
import java.util.logging.LogRecord;

import org.graalvm.nativeimage.ImageInfo;
Expand Down Expand Up @@ -102,30 +103,34 @@ public void accept(String loggerName, CleanupFilterConfig config) {
}
});
}
LogCleanupFilter cleanupFiler = new LogCleanupFilter(filterElements);
for (Handler handler : LogManager.getLogManager().getLogger("").getHandlers()) {
handler.setFilter(cleanupFiler);
}

final ArrayList<Handler> handlers = new ArrayList<>(3 + additionalHandlers.size());

if (config.console.enable) {
final Handler consoleHandler = configureConsoleHandler(config.console, consoleConfig, errorManager, filterElements,
final Handler consoleHandler = configureConsoleHandler(config.console, consoleConfig, errorManager, cleanupFiler,
possibleFormatters, possibleBannerSupplier, launchMode);
errorManager = consoleHandler.getErrorManager();
handlers.add(consoleHandler);
}

if (config.file.enable) {
handlers.add(configureFileHandler(config.file, errorManager, filterElements));
handlers.add(configureFileHandler(config.file, errorManager, cleanupFiler));
}

if (config.syslog.enable) {
final Handler syslogHandler = configureSyslogHandler(config.syslog, errorManager, filterElements);
final Handler syslogHandler = configureSyslogHandler(config.syslog, errorManager, cleanupFiler);
if (syslogHandler != null) {
handlers.add(syslogHandler);
}
}

if (!categories.isEmpty()) {
Map<String, Handler> namedHandlers = createNamedHandlers(config, consoleConfig, possibleFormatters, errorManager,
filterElements, launchMode);
cleanupFiler, launchMode);

Map<String, Handler> additionalNamedHandlersMap;
if (additionalNamedHandlers.isEmpty()) {
Expand Down Expand Up @@ -166,7 +171,7 @@ public void accept(String categoryName, CategoryConfig config) {
if (optional.isPresent()) {
final Handler handler = optional.get();
handler.setErrorManager(errorManager);
handler.setFilter(new LogCleanupFilter(filterElements));
handler.setFilter(cleanupFiler);
handlers.add(handler);
}
}
Expand All @@ -191,18 +196,20 @@ public static void initializeBuildTimeLogging(LogConfig config, LogBuildTimeConf
filterElements.add(
new LogCleanupFilterElement(entry.getKey(), entry.getValue().targetLevel, entry.getValue().ifStartsWith));
}
LogCleanupFilter logCleanupFilter = new LogCleanupFilter(filterElements);

final ArrayList<Handler> handlers = new ArrayList<>(3);

if (config.console.enable) {
final Handler consoleHandler = configureConsoleHandler(config.console, consoleConfig, errorManager, filterElements,
final Handler consoleHandler = configureConsoleHandler(config.console, consoleConfig, errorManager,
logCleanupFilter,
Collections.emptyList(), new RuntimeValue<>(Optional.empty()), launchMode);
errorManager = consoleHandler.getErrorManager();
handlers.add(consoleHandler);
}

Map<String, Handler> namedHandlers = createNamedHandlers(config, consoleConfig, Collections.emptyList(), errorManager,
filterElements, launchMode);
logCleanupFilter, launchMode);

for (Map.Entry<String, CategoryConfig> entry : categories.entrySet()) {
final CategoryBuildTimeConfig buildCategory = isSubsetOf(entry.getKey(), buildConfig.categories);
Expand Down Expand Up @@ -262,15 +269,15 @@ private static CategoryBuildTimeConfig isSubsetOf(String categoryName, Map<Strin

private static Map<String, Handler> createNamedHandlers(LogConfig config, ConsoleRuntimeConfig consoleRuntimeConfig,
List<RuntimeValue<Optional<Formatter>>> possibleFormatters, ErrorManager errorManager,
List<LogCleanupFilterElement> filterElements, LaunchMode launchMode) {
LogCleanupFilter cleanupFilter, LaunchMode launchMode) {
Map<String, Handler> namedHandlers = new HashMap<>();
for (Entry<String, ConsoleConfig> consoleConfigEntry : config.consoleHandlers.entrySet()) {
ConsoleConfig namedConsoleConfig = consoleConfigEntry.getValue();
if (!namedConsoleConfig.enable) {
continue;
}
final Handler consoleHandler = configureConsoleHandler(namedConsoleConfig, consoleRuntimeConfig, errorManager,
filterElements,
cleanupFilter,
possibleFormatters, null, launchMode);
addToNamedHandlers(namedHandlers, consoleHandler, consoleConfigEntry.getKey());
}
Expand All @@ -279,15 +286,15 @@ private static Map<String, Handler> createNamedHandlers(LogConfig config, Consol
if (!namedFileConfig.enable) {
continue;
}
final Handler fileHandler = configureFileHandler(namedFileConfig, errorManager, filterElements);
final Handler fileHandler = configureFileHandler(namedFileConfig, errorManager, cleanupFilter);
addToNamedHandlers(namedHandlers, fileHandler, fileConfigEntry.getKey());
}
for (Entry<String, SyslogConfig> sysLogConfigEntry : config.syslogHandlers.entrySet()) {
SyslogConfig namedSyslogConfig = sysLogConfigEntry.getValue();
if (!namedSyslogConfig.enable) {
continue;
}
final Handler syslogHandler = configureSyslogHandler(namedSyslogConfig, errorManager, filterElements);
final Handler syslogHandler = configureSyslogHandler(namedSyslogConfig, errorManager, cleanupFilter);
if (syslogHandler != null) {
addToNamedHandlers(namedHandlers, syslogHandler, sysLogConfigEntry.getKey());
}
Expand Down Expand Up @@ -341,7 +348,7 @@ public void initializeLoggingForImageBuild() {

private static Handler configureConsoleHandler(final ConsoleConfig config, ConsoleRuntimeConfig consoleRuntimeConfig,
final ErrorManager defaultErrorManager,
final List<LogCleanupFilterElement> filterElements,
final LogCleanupFilter cleanupFilter,
final List<RuntimeValue<Optional<Formatter>>> possibleFormatters,
final RuntimeValue<Optional<Supplier<String>>> possibleBannerSupplier, LaunchMode launchMode) {
Formatter formatter = null;
Expand Down Expand Up @@ -384,7 +391,7 @@ private static Handler configureConsoleHandler(final ConsoleConfig config, Conso
config.stderr ? ConsoleHandler.Target.SYSTEM_ERR : ConsoleHandler.Target.SYSTEM_OUT, formatter);
consoleHandler.setLevel(config.level);
consoleHandler.setErrorManager(defaultErrorManager);
consoleHandler.setFilter(new LogCleanupFilter(filterElements));
consoleHandler.setFilter(cleanupFilter);

Handler handler = config.async.enable ? createAsyncHandler(config.async, config.level, consoleHandler)
: consoleHandler;
Expand Down Expand Up @@ -421,7 +428,7 @@ public void close() throws SecurityException {
}

private static Handler configureFileHandler(final FileConfig config, final ErrorManager errorManager,
final List<LogCleanupFilterElement> filterElements) {
final LogCleanupFilter cleanupFilter) {
FileHandler handler = new FileHandler();
FileConfig.RotationConfig rotationConfig = config.rotation;
if ((rotationConfig.maxFileSize.isPresent() || rotationConfig.rotateOnBoot)
Expand Down Expand Up @@ -454,7 +461,7 @@ private static Handler configureFileHandler(final FileConfig config, final Error
}
handler.setErrorManager(errorManager);
handler.setLevel(config.level);
handler.setFilter(new LogCleanupFilter(filterElements));
handler.setFilter(cleanupFilter);
if (config.async.enable) {
return createAsyncHandler(config.async, config.level, handler);
}
Expand All @@ -463,7 +470,7 @@ private static Handler configureFileHandler(final FileConfig config, final Error

private static Handler configureSyslogHandler(final SyslogConfig config,
final ErrorManager errorManager,
final List<LogCleanupFilterElement> filterElements) {
final LogCleanupFilter logCleanupFilter) {
try {
final SyslogHandler handler = new SyslogHandler(config.endpoint.getHostString(), config.endpoint.getPort());
handler.setAppName(config.appName.orElse(getProcessName()));
Expand All @@ -478,7 +485,7 @@ private static Handler configureSyslogHandler(final SyslogConfig config,
final PatternFormatter formatter = new PatternFormatter(config.format);
handler.setFormatter(formatter);
handler.setErrorManager(errorManager);
handler.setFilter(new LogCleanupFilter(filterElements));
handler.setFilter(logCleanupFilter);
if (config.async.enable) {
return createAsyncHandler(config.async, config.level, handler);
}
Expand Down
2 changes: 1 addition & 1 deletion extensions/hibernate-reactive/deployment/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-resteasy-deployment</artifactId>
<artifactId>quarkus-resteasy-reactive-jsonb-deployment</artifactId>
<scope>test</scope>
</dependency>
<dependency>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
package io.quarkus.hibernate.reactive.dev;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.NamedQuery;
import javax.persistence.SequenceGenerator;
import javax.persistence.Table;

@Entity
@Table(name = "known_fruits")
@NamedQuery(name = "Fruits.findAll", query = "SELECT f FROM Fruit f ORDER BY f.name")
public class Fruit {

@Id
@SequenceGenerator(name = "fruitsSequence", sequenceName = "known_fruits_id_seq", allocationSize = 1, initialValue = 10)
@GeneratedValue(generator = "fruitsSequence")
private Integer id;

@Column(length = 40, unique = true)
private String name;

public Fruit() {
}

public Fruit(String name) {
this.name = name;
}

public Integer getId() {
return id;
}

public void setId(Integer id) {
this.id = id;
}

public String getName() {
return name;
}

public void setName(String name) {
this.name = name;
}

@Override
public String toString() {
return "Fruit{" + id + "," + name + '}';
}
}
Loading

0 comments on commit 8e09481

Please sign in to comment.