Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
fogninid committed Jun 5, 2024
0 parents commit 8eedbd8
Show file tree
Hide file tree
Showing 6 changed files with 154 additions and 0 deletions.
61 changes: 61 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>3.3.0</version>
</parent>
<groupId>com.example</groupId>
<artifactId>spring-framework-32730</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>spring-framework-32730</name>
<description>spring-framework-32730</description>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-jersey</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<dependency>
<groupId>io.micrometer</groupId>
<artifactId>micrometer-core</artifactId>
</dependency>

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.2.5</version>
<configuration>
<argLine>-Xmx23m -XX:+HeapDumpOnOutOfMemoryError -XX:HeapDumpPath=${project.build.testOutputDirectory}/dump.hprof -XX:+ExitOnOutOfMemoryError</argLine>
</configuration>
</plugin>
</plugins>
</build>

</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package com.example.springframework32730;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

@SpringBootApplication
public class SpringFramework32730Application {

public static void main(String[] args) {
SpringApplication.run(SpringFramework32730Application.class, args);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package com.example.springframework32730;

import jakarta.annotation.PostConstruct;
import jakarta.ws.rs.ApplicationPath;
import org.glassfish.jersey.server.ResourceConfig;
import org.springframework.stereotype.Component;

@ApplicationPath("/")
@Component
public class TestApplication extends ResourceConfig {
@PostConstruct
void register() {
register(TestResource.class);
}
}
29 changes: 29 additions & 0 deletions src/main/java/com/example/springframework32730/TestResource.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package com.example.springframework32730;

import jakarta.ws.rs.GET;
import jakarta.ws.rs.Path;
import jakarta.ws.rs.QueryParam;
import jakarta.ws.rs.WebApplicationException;
import jakarta.ws.rs.container.AsyncResponse;
import jakarta.ws.rs.container.Suspended;
import jakarta.ws.rs.core.Response;

@Path("/test")
public class TestResource {
@GET
public void get(@Suspended AsyncResponse response, @QueryParam("async") Boolean async, @QueryParam("error") Boolean error) {
if (Boolean.TRUE.equals(async)) {
new Thread(() -> reply(response, error)).start();
} else {
reply(response, error);
}
}

private void reply(AsyncResponse response, Boolean error) {
if (Boolean.TRUE.equals(error)) {
response.resume(new WebApplicationException(417));
} else {
response.resume(Response.ok("success").build());
}
}
}
5 changes: 5 additions & 0 deletions src/main/resources/application.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
server.port=8999
management.server.port=8998
spring.application.name=spring-framework-32730
management.endpoint.metrics.enabled=true
management.endpoints.web.exposure.include=metrics
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package com.example.springframework32730;

import org.junit.jupiter.api.Test;
import org.slf4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.boot.test.web.client.TestRestTemplate;
import org.springframework.http.ResponseEntity;

import static org.slf4j.LoggerFactory.getLogger;

@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
class SpringFramework32730ApplicationTests {
private static final Logger LOG = getLogger(SpringFramework32730ApplicationTests.class);

@Autowired
private TestRestTemplate template;

@Test
void testGet() {
int i = 0;
while (!Thread.interrupted()) {
final ResponseEntity<String> response = template.getForEntity("/test", String.class);
if (i % 1000 == 0) {
LOG.info("response={}", response);
}
i++;
}
}
}

0 comments on commit 8eedbd8

Please sign in to comment.