Skip to content

Commit

Permalink
Merge branch '4.1.x' into 4.2.x
Browse files Browse the repository at this point in the history
  • Loading branch information
sdelamo committed Sep 8, 2023
2 parents ce7d0eb + 6f61f83 commit d2b172b
Show file tree
Hide file tree
Showing 7 changed files with 76 additions and 4 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ jobs:
if: startsWith(github.ref, 'refs/tags/')
steps:
- name: Checkout repository
uses: actions/checkout@c85c95e3d7251135ab7dc9ce3241c5835cc595a9 # v3.5.3
uses: actions/checkout@f43a0e5ff2bd294095638e18286ca9a3d1956744 # v3.6.0
- name: Download artifacts
uses: actions/download-artifact@9bc31d5ccc31df68ecc42ccf4149144866c47d8a # v3.0.2
with:
Expand Down
2 changes: 1 addition & 1 deletion buildSrc/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ repositories {

dependencies {
implementation "org.aim42:htmlSanityCheck:1.1.6"
implementation "io.micronaut.build.internal:micronaut-gradle-plugins:6.5.5"
implementation "io.micronaut.build.internal:micronaut-gradle-plugins:6.5.6"

implementation "org.tomlj:tomlj:1.1.0"
implementation "me.champeau.gradle:japicmp-gradle-plugin:0.4.2"
Expand Down
2 changes: 1 addition & 1 deletion gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ managed-reactive-streams = "1.0.4"
# This should be kept aligned with https://github.com/micronaut-projects/micronaut-reactor/blob/master/gradle.properties from the BOM
managed-reactor = "3.5.9"
managed-snakeyaml = "2.0"
managed-java-parser-core = "3.25.4"
managed-java-parser-core = "3.25.5"
managed-ksp = "1.8.21-1.0.11"
micronaut-docs = "2.0.0"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
package io.micronaut.http.server.tck.tests;

import io.micronaut.context.annotation.Requires;
import io.micronaut.http.HttpHeaders;
import io.micronaut.http.HttpRequest;
import io.micronaut.http.HttpStatus;
import io.micronaut.http.MediaType;
Expand Down Expand Up @@ -61,6 +62,21 @@ void headersAreCaseInsensitiveAsPerMessageHeadersSpecification() throws IOExcept
.build()));
}

/**
* Multiple Headers are properly received as list and not as single header
*/
@Test
void multipleHeadersAreReceivedAsList() throws IOException {
asserts(SPEC_NAME,
HttpRequest.GET("/foo/receive-multiple-headers")
.header(HttpHeaders.ETAG, "A")
.header(HttpHeaders.ETAG, "B"),
(server, request) -> AssertionUtils.assertDoesNotThrow(server, request, HttpResponseAssertion.builder()
.status(HttpStatus.OK)
.body("2")
.build()));
}

@Controller("/foo")
@Requires(property = "spec.name", value = SPEC_NAME)
static class ProduceController {
Expand All @@ -73,5 +89,10 @@ String getOkAsJson() {
String getFooAsJson(@Header("Foo") String foo, @Header("fOo") String foo2) {
return "{\"status\":\"" + foo + foo2 + "\"}";
}

@Get(value = "/receive-multiple-headers", processes = MediaType.TEXT_PLAIN)
String receiveMultipleHeaders(HttpRequest<?> request) {
return String.valueOf(request.getHeaders().getAll(HttpHeaders.ETAG).size());
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,11 @@ public class DefaultApplicationContext extends DefaultBeanContext implements App
private final ClassPathResourceLoader resourceLoader;
private final ApplicationContextConfiguration configuration;
private Environment environment;
/**
* True if the {@link #environment} was created by this context,
* false if the {@link #environment} was provided by {@link #setEnvironment(Environment)}
*/
private boolean environmentManaged;

/**
* Construct a new ApplicationContext for the given environment name.
Expand Down Expand Up @@ -173,6 +178,7 @@ public MutableConversionService getConversionService() {
public Environment getEnvironment() {
if (environment == null) {
environment = createEnvironment(configuration);
environmentManaged = true;
}
return environment;
}
Expand All @@ -183,6 +189,7 @@ public Environment getEnvironment() {
@Internal
public void setEnvironment(Environment environment) {
this.environment = environment;
this.environmentManaged = false;
}

@Override
Expand All @@ -201,7 +208,11 @@ protected void registerConversionService() {
public synchronized @NonNull
ApplicationContext stop() {
ApplicationContext stop = (ApplicationContext) super.stop();
if (environment != null && environmentManaged) {
environment.stop();
}
environment = null;
environmentManaged = false;
return stop;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package io.micronaut.context;

import io.micronaut.context.env.Environment;
import org.junit.jupiter.api.Test;
import spock.lang.Issue;

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

public class DefaultApplicationContextTest {
@Issue("https://github.com/micronaut-projects/micronaut-test/issues/615#issuecomment-1516355815")
@Test
public void applicationContextShouldShutDownTheEnvironmentItCreated() {
DefaultApplicationContext ctx = new DefaultApplicationContext();
ctx.start();
Environment env = ctx.getEnvironment();
assertTrue(env.isRunning());
ctx.stop();
assertFalse(env.isRunning(), "expected to be stopped");
}

@Test
public void applicationContextShouldNotStopTheEnvironmentItDidNotCreate() {
DefaultApplicationContext ctx = new DefaultApplicationContext();
// make DefaultApplicationContext create and stop it's managed environment,
// so it thinks it manages it
ctx.start();
ctx.stop();

// providing ctx with an external environment
ApplicationContext ctx2 = ApplicationContext.run();
ctx.setEnvironment(ctx2.getEnvironment());

ctx.start();
ctx.stop();
assertTrue(ctx2.getEnvironment().isRunning(), "shouldn't stop an external environment");

ctx2.stop(); //cleanup
}
}
2 changes: 1 addition & 1 deletion settings.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ pluginManagement {
}

plugins {
id 'io.micronaut.build.shared.settings' version '6.5.5'
id 'io.micronaut.build.shared.settings' version '6.5.6'
}
enableFeaturePreview("TYPESAFE_PROJECT_ACCESSORS")

Expand Down

0 comments on commit d2b172b

Please sign in to comment.