-
Notifications
You must be signed in to change notification settings - Fork 2.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Enable dev services to be located by in-container java #41858
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
50 changes: 50 additions & 0 deletions
50
...st/resources-filtered/projects/native-agent-integration/src/main/java/org/acme/Fruit.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
package org.acme; | ||
|
||
import jakarta.persistence.Cacheable; | ||
import jakarta.persistence.Column; | ||
import jakarta.persistence.Entity; | ||
import jakarta.persistence.GeneratedValue; | ||
import jakarta.persistence.Id; | ||
import jakarta.persistence.NamedQuery; | ||
import jakarta.persistence.QueryHint; | ||
import jakarta.persistence.SequenceGenerator; | ||
import jakarta.persistence.Table; | ||
|
||
@Entity | ||
@Table(name = "known_fruits") | ||
@NamedQuery(name = "Fruits.findAll", query = "SELECT f FROM Fruit f ORDER BY f.name", hints = @QueryHint(name = "org.hibernate.cacheable", value = "true")) | ||
@Cacheable | ||
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; | ||
} | ||
|
||
} |
124 changes: 124 additions & 0 deletions
124
...rces-filtered/projects/native-agent-integration/src/main/java/org/acme/FruitResource.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,124 @@ | ||
package org.acme; | ||
|
||
import java.util.List; | ||
|
||
import jakarta.enterprise.context.ApplicationScoped; | ||
import jakarta.inject.Inject; | ||
import jakarta.persistence.EntityManager; | ||
import jakarta.transaction.Transactional; | ||
import jakarta.ws.rs.Consumes; | ||
import jakarta.ws.rs.DELETE; | ||
import jakarta.ws.rs.GET; | ||
import jakarta.ws.rs.POST; | ||
import jakarta.ws.rs.PUT; | ||
import jakarta.ws.rs.Path; | ||
import jakarta.ws.rs.Produces; | ||
import jakarta.ws.rs.WebApplicationException; | ||
import jakarta.ws.rs.core.Response; | ||
import jakarta.ws.rs.ext.ExceptionMapper; | ||
import jakarta.ws.rs.ext.Provider; | ||
|
||
import org.jboss.logging.Logger; | ||
|
||
import com.fasterxml.jackson.databind.ObjectMapper; | ||
import com.fasterxml.jackson.databind.node.ObjectNode; | ||
|
||
@Path("fruits") | ||
@ApplicationScoped | ||
@Produces("application/json") | ||
@Consumes("application/json") | ||
public class FruitResource { | ||
|
||
private static final Logger LOGGER = Logger.getLogger(FruitResource.class.getName()); | ||
|
||
@Inject | ||
EntityManager entityManager; | ||
|
||
@GET | ||
public List<Fruit> get() { | ||
return entityManager.createNamedQuery("Fruits.findAll", Fruit.class) | ||
.getResultList(); | ||
} | ||
|
||
@GET | ||
@Path("{id}") | ||
public Fruit getSingle(Integer id) { | ||
Fruit entity = entityManager.find(Fruit.class, id); | ||
if (entity == null) { | ||
throw new WebApplicationException("Fruit with id of " + id + " does not exist.", 404); | ||
} | ||
return entity; | ||
} | ||
|
||
@POST | ||
@Transactional | ||
public Response create(Fruit fruit) { | ||
if (fruit.getId() != null) { | ||
throw new WebApplicationException("Id was invalidly set on request.", 422); | ||
} | ||
|
||
entityManager.persist(fruit); | ||
return Response.ok(fruit).status(201).build(); | ||
} | ||
|
||
@PUT | ||
@Path("{id}") | ||
@Transactional | ||
public Fruit update(Integer id, Fruit fruit) { | ||
if (fruit.getName() == null) { | ||
throw new WebApplicationException("Fruit Name was not set on request.", 422); | ||
} | ||
|
||
Fruit entity = entityManager.find(Fruit.class, id); | ||
|
||
if (entity == null) { | ||
throw new WebApplicationException("Fruit with id of " + id + " does not exist.", 404); | ||
} | ||
|
||
entity.setName(fruit.getName()); | ||
|
||
return entity; | ||
} | ||
|
||
@DELETE | ||
@Path("{id}") | ||
@Transactional | ||
public Response delete(Integer id) { | ||
Fruit entity = entityManager.getReference(Fruit.class, id); | ||
if (entity == null) { | ||
throw new WebApplicationException("Fruit with id of " + id + " does not exist.", 404); | ||
} | ||
entityManager.remove(entity); | ||
return Response.status(204).build(); | ||
} | ||
|
||
@Provider | ||
public static class ErrorMapper implements ExceptionMapper<Exception> { | ||
|
||
@Inject | ||
ObjectMapper objectMapper; | ||
|
||
@Override | ||
public Response toResponse(Exception exception) { | ||
LOGGER.error("Failed to handle request", exception); | ||
|
||
int code = 500; | ||
if (exception instanceof WebApplicationException) { | ||
code = ((WebApplicationException) exception).getResponse().getStatus(); | ||
} | ||
|
||
ObjectNode exceptionJson = objectMapper.createObjectNode(); | ||
exceptionJson.put("exceptionType", exception.getClass().getName()); | ||
exceptionJson.put("code", code); | ||
|
||
if (exception.getMessage() != null) { | ||
exceptionJson.put("error", exception.getMessage()); | ||
} | ||
|
||
return Response.status(code) | ||
.entity(exceptionJson) | ||
.build(); | ||
} | ||
|
||
} | ||
} |
2 changes: 2 additions & 0 deletions
2
...rces-filtered/projects/native-agent-integration/src/main/resources/application.properties
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
quarkus.hibernate-orm.log.sql=true | ||
quarkus.hibernate-orm.sql-load-script=import.sql |
4 changes: 4 additions & 0 deletions
4
...c/test/resources-filtered/projects/native-agent-integration/src/main/resources/import.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
INSERT INTO known_fruits(id, name) VALUES (1, 'Cherry'); | ||
INSERT INTO known_fruits(id, name) VALUES (2, 'Apple'); | ||
INSERT INTO known_fruits(id, name) VALUES (3, 'Banana'); | ||
ALTER SEQUENCE known_fruits_id_seq RESTART WITH 4; |
10 changes: 10 additions & 0 deletions
10
...s-filtered/projects/native-agent-integration/src/test/java/org/acme/FruitsEndpointIT.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package org.acme; | ||
|
||
import io.quarkus.test.junit.QuarkusIntegrationTest; | ||
|
||
@QuarkusIntegrationTest | ||
public class FruitsEndpointIT extends FruitsEndpointTest { | ||
|
||
// Runs the same tests as the parent class | ||
|
||
} |
63 changes: 63 additions & 0 deletions
63
...filtered/projects/native-agent-integration/src/test/java/org/acme/FruitsEndpointTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
package org.acme; | ||
|
||
import static io.restassured.RestAssured.given; | ||
import static org.hamcrest.CoreMatchers.containsString; | ||
import static org.hamcrest.core.IsNot.not; | ||
|
||
import org.junit.jupiter.api.Test; | ||
|
||
import io.quarkus.test.junit.QuarkusTest; | ||
|
||
@QuarkusTest | ||
public class FruitsEndpointTest { | ||
|
||
@Test | ||
public void testListAllFruits() { | ||
//List all, should have all 3 fruits the database has initially: | ||
given() | ||
.when().get("/fruits") | ||
.then() | ||
.statusCode(200) | ||
.body( | ||
containsString("Cherry"), | ||
containsString("Apple"), | ||
containsString("Banana")); | ||
|
||
//Delete the Cherry: | ||
given() | ||
.when().delete("/fruits/1") | ||
.then() | ||
.statusCode(204); | ||
|
||
//List all, cherry should be missing now: | ||
given() | ||
.when().get("/fruits") | ||
.then() | ||
.statusCode(200) | ||
.body( | ||
not(containsString("Cherry")), | ||
containsString("Apple"), | ||
containsString("Banana")); | ||
|
||
//Create the Pear: | ||
given() | ||
.when() | ||
.body("{\"name\" : \"Pear\"}") | ||
.contentType("application/json") | ||
.post("/fruits") | ||
.then() | ||
.statusCode(201); | ||
|
||
//List all, cherry should be missing now: | ||
given() | ||
.when().get("/fruits") | ||
.then() | ||
.statusCode(200) | ||
.body( | ||
not(containsString("Cherry")), | ||
containsString("Apple"), | ||
containsString("Banana"), | ||
containsString("Pear")); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there any way we can be avoid hardcoding the agent here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmmm, not sure with the current code base. Docker/container handling code is scattered around in many places. This is another example of surgery we have to keep doing to handle different container build/run setups.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Okay, let's keep as is for now and we can figure out something better the next time we hit this