Skip to content

Commit

Permalink
upgrade to quarkus 3.15.1
Browse files Browse the repository at this point in the history
  • Loading branch information
Matej Pucihar committed Oct 16, 2024
1 parent 80288ad commit 30f7c76
Show file tree
Hide file tree
Showing 2 changed files with 96 additions and 1 deletion.
58 changes: 57 additions & 1 deletion src/main/java/si/puci/GreetingResource.java
Original file line number Diff line number Diff line change
@@ -1,21 +1,34 @@
package si.puci;

import java.io.IOException;
import java.time.OffsetDateTime;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.CompletionStage;

import org.eclipse.microprofile.reactive.messaging.Channel;
import org.eclipse.microprofile.reactive.messaging.Emitter;
import org.eclipse.microprofile.reactive.messaging.Message;
import org.eclipse.microprofile.rest.client.annotation.RegisterProvider;
import org.eclipse.microprofile.rest.client.inject.RegisterRestClient;
import org.eclipse.microprofile.rest.client.inject.RestClient;
import org.jboss.resteasy.reactive.client.spi.ResteasyReactiveClientRequestContext;

import io.quarkus.logging.Log;
import io.smallrye.mutiny.Uni;
import io.smallrye.reactive.messaging.MutinyEmitter;
import jakarta.enterprise.context.ApplicationScoped;
import jakarta.inject.Inject;
import jakarta.transaction.Transactional;
import jakarta.ws.rs.GET;
import jakarta.ws.rs.Path;
import jakarta.ws.rs.Produces;
import jakarta.ws.rs.client.ClientRequestContext;
import jakarta.ws.rs.client.ClientRequestFilter;
import jakarta.ws.rs.client.ClientResponseContext;
import jakarta.ws.rs.client.ClientResponseFilter;
import jakarta.ws.rs.core.MediaType;
import jakarta.ws.rs.ext.Provider;
import jakarta.ws.rs.ext.Providers;

@Path("/hello")
@Transactional
Expand All @@ -28,6 +41,8 @@ public class GreetingResource
@Inject
@Channel("emitter")
Emitter<String> emitter;
@RestClient
HelloClient helloClient;

@GET
@Path("/mutiny-emitter-send-and-await")
Expand All @@ -39,7 +54,6 @@ public String mutinyEmitterSendAndAwait()
final var myEntity = new MyEntity();
myEntity.field = OffsetDateTime.now().toString();
myEntity.persist();

mutinyEmitter.sendAndAwait(myEntity.field);

return "mutiny-emitter-send-and-await";
Expand Down Expand Up @@ -107,4 +121,46 @@ public CompletionStage<String> emitterSend()
}));
return completableFuture;
}

@GET
@Path("/rest-client-blocking")
@Produces(MediaType.TEXT_PLAIN)
public String restClientBlocking()
{
final var myEntity = new MyEntity();
myEntity.field = OffsetDateTime.now().toString();
myEntity.persist();
helloClient.hello();

return "rest-client-blocking";
}

@GET
@Path("/world")
@Produces(MediaType.TEXT_PLAIN)
public String hello()
{
return "hello";
}

@RegisterRestClient(baseUri = "http://localhost:8081")
@RegisterProvider(TestClientResponseFilter.class)
interface HelloClient
{
@GET
@Path("/hello/world")
@Produces(MediaType.TEXT_PLAIN)
String hello();
}

@Provider
public static class TestClientResponseFilter implements ClientResponseFilter
{

@Override
public void filter(ClientRequestContext requestContext, ClientResponseContext responseContext) throws IOException
{
Log.info("I know this is done on eventLoop");
}
}
}
39 changes: 39 additions & 0 deletions src/test/java/si/puci/GreetingResourceTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -145,4 +145,43 @@ void emitterSendReturnFut()
Assertions.assertFalse(failure.get());
//no error!
}

@Test
void restClient()
{
//this throws 1:1000

AtomicBoolean failure = new AtomicBoolean(false);
AtomicReference<Throwable> ex = new AtomicReference<>(null);

final var subscription = Multi.createFrom().ticks().every(Duration.of(1, ChronoUnit.MILLIS))
.onItem().invoke(i -> given()
.when().get("/hello/rest-client-blocking")
.then()
.statusCode(200)
.body(is("rest-client-blocking")))
.subscribe().with(
log::info,
err -> {
Log.error(err);
ex.set(err);
failure.set(true);
});
try
{
Thread.sleep(60000);
}
catch (InterruptedException e)
{
throw new RuntimeException(e);
}

subscription.cancel();
if (ex.get() != null)
{
Log.error(ex.get());
}
Assertions.assertFalse(failure.get());
//no error!
}
}

0 comments on commit 30f7c76

Please sign in to comment.