Skip to content

Commit

Permalink
Merge pull request #1135 from michalvavrik/feature/clean-up-17-refact…
Browse files Browse the repository at this point in the history
…oring

Refactoring to leverage Java 17 and avoid deprecated classes
  • Loading branch information
jedla97 authored May 21, 2024
2 parents 548ed51 + 654e878 commit 95b2fdf
Show file tree
Hide file tree
Showing 29 changed files with 67 additions and 119 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public void shouldFindPropertyFromCustomSource() {
app.given().get("/api/from-custom-source").then().statusCode(HttpStatus.SC_OK).body(is("Hello Config Source!"));
}

protected static final void onLoadConfigureConsul(Service service) {
protected static void onLoadConfigureConsul(Service service) {
consul.loadPropertiesFromFile(KEY, "application.properties");
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import jakarta.enterprise.event.Observes;

import org.eclipse.microprofile.config.inject.ConfigProperty;
import org.jboss.logging.Logger;

import io.quarkus.runtime.StartupEvent;

Expand All @@ -14,8 +13,6 @@ public class ValidateCustomProperty {
public static final String DISALLOW_PROPERTY_VALUE = "WRONG!";
public static final String CUSTOM_PROPERTY = "custom.property.name";

private static final Logger LOG = Logger.getLogger(ValidateCustomProperty.class.getName());

@ConfigProperty(name = CUSTOM_PROPERTY)
String value;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public void shouldBeStopped() {
@Order(2)
@Test
public void shouldFailOnStart() {
assertThrows(AssertionError.class, () -> app.start(),
assertThrows(AssertionError.class, app::start,
"Should fail because runtime exception in ValidateCustomProperty");
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import jakarta.inject.Inject;

import org.infinispan.client.hotrod.RemoteCacheManager;
import org.infinispan.commons.configuration.XMLStringConfiguration;
import org.infinispan.commons.configuration.StringConfiguration;

import io.quarkus.runtime.StartupEvent;

Expand All @@ -23,7 +23,7 @@ public class BookCacheInitializer {

void onStart(@Observes StartupEvent ev) {
cacheManager.administration().getOrCreateCache(CACHE_NAME,
new XMLStringConfiguration(String.format(CACHE_CONFIG, CACHE_NAME)));
new StringConfiguration(String.format(CACHE_CONFIG, CACHE_NAME)));

}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package io.quarkus.qe.books;

import org.infinispan.protostream.GeneratedSchema;
import org.infinispan.protostream.annotations.AutoProtoSchemaBuilder;
import org.infinispan.protostream.annotations.ProtoSchema;

@AutoProtoSchemaBuilder(includeClasses = Book.class, schemaPackageName = "book_sample")
@ProtoSchema(includeClasses = Book.class, schemaPackageName = "book_sample")
interface BookSchema extends GeneratedSchema {
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public class StockPriceProducer {
@OnOverflow(value = OnOverflow.Strategy.DROP)
Emitter<StockPrice> emitter;

private Random random = new Random();
private final Random random = new Random();

public Uni<Void> generate() {
IntStream.range(0, config.batchSize()).forEach(next -> {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

package io.quarkus.qe;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertTrue;

import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;
Expand Down Expand Up @@ -44,7 +44,7 @@ public void producerConsumesTest() throws InterruptedException {
source.register(inboundSseEvent -> latch.countDown());
source.open();
boolean completed = latch.await(5, TimeUnit.MINUTES);
assertEquals(true, completed);
assertTrue(completed);
source.close();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public class PriceGenerator {

private static final int MAX_PRICE = 100;

private Random random = new Random();
private final Random random = new Random();

@Outgoing("generated-price")
public Multi<Integer> generate() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public Process runOnDev(Path servicePath, File logOutput, Map<String, String> ar
cmd.add("dev");
cmd.addAll(arguments.entrySet().stream()
.map(e -> "-D" + e.getKey() + "=" + e.getValue())
.collect(Collectors.toList()));
.toList());
return runCli(servicePath, logOutput, cmd.toArray(new String[cmd.size()]));
}

Expand Down Expand Up @@ -99,7 +99,7 @@ public QuarkusCliRestService createApplication(String name, CreateApplicationReq
}
// Extra args
if (request.extraArgs != null && request.extraArgs.length > 0) {
Stream.of(request.extraArgs).forEach(args::add);
args.addAll(Arrays.asList(request.extraArgs));
}

Result result = runCliAndWait(serviceContext.getServiceFolder().getParent(), args.toArray(new String[args.size()]));
Expand Down Expand Up @@ -136,7 +136,7 @@ public QuarkusCliDefaultService createExtension(String name, CreateExtensionRequ
}
// Extra args
if (request.extraArgs != null && request.extraArgs.length > 0) {
Stream.of(request.extraArgs).forEach(args::add);
args.addAll(Arrays.asList(request.extraArgs));
}

Result result = runCliAndWait(serviceContext.getServiceFolder().getParent(), args.toArray(new String[args.size()]));
Expand Down Expand Up @@ -177,7 +177,7 @@ private Process runCli(Path workingDirectory, File logOutput, String... args) {
cmd.add(format("-D%s=%s", QUARKUS_ANALYTICS_DISABLED_LOCAL_PROP_KEY, Boolean.TRUE));
}

Log.info(cmd.stream().collect(Collectors.joining(" ")));
Log.info(String.join(" ", cmd));
try {
return ProcessBuilderProvider.command(cmd)
.redirectErrorStream(true)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,10 @@

public class QuarkusCliExtensionBootstrap implements ExtensionBootstrap {

private ScenarioContext context;
private QuarkusCliClient client;

@Override
public boolean appliesFor(ScenarioContext context) {
this.context = context;
return context.isAnnotationPresent(QuarkusScenario.class);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ public enum Protocol {
MANAGEMENT("management", 9000), //can be either http or https
NONE(null, -1);

private String value;
private int port;
private final String value;
private final int port;

Protocol(String value, int port) {
this.value = value;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@ private void initLookupService(TestContext context, Field fieldToInject) {
.filter(field -> field.getName().equals(fieldToInject.getName())
&& !field.isAnnotationPresent(LookupService.class))
.findAny();
if (!fieldService.isPresent()) {
if (fieldService.isEmpty()) {
fail("Could not lookup service with name " + fieldToInject.getName());
}

Expand All @@ -271,7 +271,7 @@ private Object getParameter(String name, Class<?> clazz) {
.map(Optional::get)
.findFirst();

if (!parameter.isPresent()) {
if (parameter.isEmpty()) {
fail("Failed to inject: " + name);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,18 +25,6 @@ public final class ScenarioContext {
this.id = generateScenarioId(testContext);
}

private ScenarioContext(TestContext testContext, String id, boolean failed, boolean debug) {
this.testContext = testContext;
this.id = id;
this.failed = failed;
this.debug = debug;
}

public ScenarioContext toClassScenarioContext() {
// drop test method name
return new ScenarioContext(new TestContextImpl(testContext, null), id, failed, debug);
}

public String getId() {
return id;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ public abstract class LoggingHandler implements Closeable {
private static final long TIMEOUT_IN_MILLIS = 4000;
private static final String ANY = ".*";

private final List<String> logs = new CopyOnWriteArrayList<>();
private Thread innerThread;
private List<String> logs = new CopyOnWriteArrayList<>();
private boolean running = false;

protected abstract void handle();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public abstract class LocalhostQuarkusApplicationManagedResource extends Quarkus

private final QuarkusApplicationManagedResourceBuilder model;

private File logOutputFile;
private final File logOutputFile;
private Process process;
private LoggingHandler loggingHandler;
private int assignedHttpPort;
Expand Down Expand Up @@ -93,17 +93,11 @@ public URILike getURI(Protocol protocol) {
} else if (protocol == Protocol.GRPC && !model.isGrpcEnabled()) {
fail("gRPC was not enabled. Use: `@QuarkusApplication(grpc = true)`");
}
int port;
switch (protocol) {
case HTTPS:
port = assignedHttpsPort;
break;
case GRPC:
port = assignedGrpcPort;
break;
default:
port = assignedHttpPort;
}
int port = switch (protocol) {
case HTTPS -> assignedHttpsPort;
case GRPC -> assignedGrpcPort;
default -> assignedHttpPort;
};
if (protocol == Protocol.MANAGEMENT && model.useSeparateManagementInterface()) {
return createURI(model.useManagementSsl() ? "https" : "http",
"localhost",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -150,11 +150,7 @@ private Path tryToReuseOrBuildArtifact() {
}
}

if (artifactLocation.isEmpty()) {
return buildArtifact();
} else {
return Path.of(artifactLocation.get());
}
return artifactLocation.map(Path::of).orElseGet(this::buildArtifact);
}

private Path buildArtifact() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public final class KnownExceptionChecker {
/**
* List to store enabled handlers, which are going to be effective.
*/
private static List<Predicate<Throwable>> enabledExceptionsHandlers = new ArrayList<>();
private static final List<Predicate<Throwable>> ENABLED_EXCEPTIONS_HANDLERS = new ArrayList<>();

/*
* Read system property and assign desired handlers as enabled ones
Expand All @@ -42,7 +42,7 @@ public final class KnownExceptionChecker {
String[] splitParameters = enableHandlersParam.split(",");
for (String enableHandler : splitParameters) {
if (ALL_EXCEPTION_HANDLERS.containsKey(enableHandler.trim())) {
enabledExceptionsHandlers.add(ALL_EXCEPTION_HANDLERS.get(enableHandler.trim()));
ENABLED_EXCEPTIONS_HANDLERS.add(ALL_EXCEPTION_HANDLERS.get(enableHandler.trim()));
} else {
Log.warn("Trying to enable unknown exception handler: " + enableHandler);
}
Expand All @@ -61,7 +61,7 @@ private KnownExceptionChecker() {
* @return true if any known exception message is included, false otherwise
*/
public static boolean checkForKnownException(Throwable throwable) {
for (Predicate<Throwable> p : enabledExceptionsHandlers) {
for (Predicate<Throwable> p : ENABLED_EXCEPTIONS_HANDLERS) {
if (p.test(throwable)) {
return true;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ private static Predicate<Map.Entry<Object, Object>> propertyValueIsNotEmpty() {

private enum PropagatePropertiesStrategy {
ALL("all", name -> PROPAGATE_PROPERTIES_STRATEGY_ALL_EXCLUSIONS.getAsList()
.stream().noneMatch(exclude -> name.startsWith(exclude))),
.stream().noneMatch(name::startsWith)),
NONE("none", name -> false),
ONLY_QUARKUS("only-quarkus", name -> StringUtils.startsWith(name, QUARKUS_PROPERTY_PREFIX));

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package io.quarkus.test.utils;

import java.util.List;
import java.util.stream.Collectors;
import java.util.stream.Stream;

import org.apache.commons.lang3.StringUtils;
Expand All @@ -26,6 +25,6 @@ public List<String> installedFeatures() {
.filter(log -> log.contains(INSTALLED_FEATURES))
.flatMap(log -> Stream.of(StringUtils.substringBetween(log, OPEN_TAG, CLOSE_TAG).split(COMMA)))
.map(String::trim)
.collect(Collectors.toList());
.toList();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -129,8 +129,7 @@ public void applyServicePropertiesUsingDeploymentConfig(Service service) {
Map<String, String> enrichProperties = enrichProperties(service.getProperties(), deployment);

deployment.getSpec().getTemplate().getSpec().getContainers().forEach(container -> {
enrichProperties.entrySet().forEach(
envVar -> container.getEnv().add(new EnvVar(envVar.getKey(), envVar.getValue(), null)));
enrichProperties.forEach((key, value) -> container.getEnv().add(new EnvVar(key, value, null)));
});

client.apps().deployments().withTimeout(DEPLOYMENT_CREATION_TIMEOUT, TimeUnit.SECONDS).delete();
Expand Down Expand Up @@ -314,8 +313,7 @@ private String enrichTemplate(Service service, String template, Map<String, Stri
objMetadataLabels.put(LABEL_SCENARIO_ID, getScenarioId());
obj.getMetadata().setLabels(objMetadataLabels);

if (obj instanceof Deployment) {
Deployment deployment = (Deployment) obj;
if (obj instanceof Deployment deployment) {

// set deployment name
deployment.getMetadata().setName(service.getName());
Expand All @@ -332,13 +330,12 @@ private String enrichTemplate(Service service, String template, Map<String, Stri
Map<String, String> enrichProperties = enrichProperties(service.getProperties(), deployment);
enrichProperties.putAll(extraTemplateProperties);
deployment.getSpec().getTemplate().getSpec().getContainers()
.forEach(container -> enrichProperties.entrySet().forEach(property -> {
String key = property.getKey();
.forEach(container -> enrichProperties.forEach((key, value) -> {
EnvVar envVar = getEnvVarByKey(key, container);
if (envVar == null) {
container.getEnv().add(new EnvVar(key, property.getValue(), null));
container.getEnv().add(new EnvVar(key, value, null));
} else {
envVar.setValue(property.getValue());
envVar.setValue(value);
}
}));
}
Expand Down Expand Up @@ -576,13 +573,4 @@ private boolean setCurrentSessionNamespace(String namespaceName) {
return done;
}

private void printServiceInfo(Service service) {
try {
new Command(KUBECTL, "get", "svc", service.getName(), "-n", currentNamespace)
.outputToConsole()
.runAndWait();
} catch (Exception ignored) {
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,15 @@ public enum KubernetesDeploymentStrategy {
*/
UsingKubernetesExtension(ExtensionKubernetesQuarkusApplicationManagedResource::new);

private final Function<ProdQuarkusApplicationManagedResourceBuilder, KubernetesQuarkusApplicationManagedResource> supplier;
private final Function<ProdQuarkusApplicationManagedResourceBuilder, KubernetesQuarkusApplicationManagedResource<?>> sup;

KubernetesDeploymentStrategy(
Function<ProdQuarkusApplicationManagedResourceBuilder, KubernetesQuarkusApplicationManagedResource> supplier) {
this.supplier = supplier;
Function<ProdQuarkusApplicationManagedResourceBuilder, KubernetesQuarkusApplicationManagedResource<?>> supplier) {
this.sup = supplier;
}

public KubernetesQuarkusApplicationManagedResource getManagedResource(
public KubernetesQuarkusApplicationManagedResource<?> getManagedResource(
ProdQuarkusApplicationManagedResourceBuilder builder) {
return supplier.apply(builder);
return sup.apply(builder);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@ public class RemoteDevModeKubernetesQuarkusApplicationManagedResource extends
private static final String REMOTE_DEV_LOG_OUTPUT_FILE = "remote-dev-out.log";

private final RemoteDevModeQuarkusApplicationManagedResourceBuilder model;
private final File remoteDevLogFile;

private Process remoteDevProcess;
private File remoteDevLogFile;
private LoggingHandler remoteDevLoggingHandler;

public RemoteDevModeKubernetesQuarkusApplicationManagedResource(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

public class OperatorService<T extends Service> extends BaseService<T> {

private List<CustomResourceDefinition> crds = new ArrayList<>();
private final List<CustomResourceDefinition> crds = new ArrayList<>();

public List<CustomResourceDefinition> getCrds() {
return crds;
Expand Down
Loading

0 comments on commit 95b2fdf

Please sign in to comment.