Skip to content
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

Merge branch '3.9.x' into 4.0.x #8787

Merged
merged 2 commits into from
Feb 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
73 changes: 47 additions & 26 deletions .github/workflows/corretto.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: Corretto CI
on:
push:
branches:
- master
- '[1-9]+.[0-9]+.x'
jobs:
build:
runs-on: ubuntu-latest
Expand All @@ -11,28 +11,49 @@ jobs:
java: ['17']
container: amazoncorretto:${{ matrix.java }}
steps:
- name: Display Java and Linux version
run: java -version && cat /etc/system-release
- name: Install tar && gzip
run: yum install -y tar gzip
- uses: actions/checkout@v3
- uses: actions/cache@v3.0.2
with:
path: ~/.gradle/caches
key: ${{ runner.os }}-micronaut-core-gradle-${{ hashFiles('**/*.gradle') }}
restore-keys: |
${{ runner.os }}-micronaut-core-gradle-
- uses: actions/cache@v3.0.2
with:
path: ~/.gradle/wrapper
key: ${{ runner.os }}-micronaut-core-wrapper-${{ hashFiles('**/*.gradle') }}
restore-keys: |
${{ runner.os }}-micronaut-core-wrapper-
- name: Build with Gradle
env:
GH_TOKEN_PUBLIC_REPOS_READONLY: ${{ secrets.GH_TOKEN_PUBLIC_REPOS_READONLY }}
GH_USERNAME: ${{ secrets.GH_USERNAME }}
GRADLE_ENTERPRISE_ACCESS_KEY: ${{ secrets.GRADLE_ENTERPRISE_ACCESS_KEY }}
GRADLE_ENTERPRISE_CACHE_USERNAME: ${{ secrets.GRADLE_ENTERPRISE_CACHE_USERNAME }}
GRADLE_ENTERPRISE_CACHE_PASSWORD: ${{ secrets.GRADLE_ENTERPRISE_CACHE_PASSWORD }}
run: unset HOSTNAME ; LANG=en_US.utf-8 LC_ALL=en_US.utf-8 ./gradlew check --no-daemon --parallel --continue
# https://github.com/actions/virtual-environments/issues/709
- name: Free disk space
run: |
sudo rm -rf "/usr/local/share/boost"
sudo rm -rf "$AGENT_TOOLSDIRECTORY"
sudo apt-get clean
df -h
- uses: actions/checkout@v3
- name: Set up JDK
uses: actions/setup-java@v3
with:
distribution: 'corretto'
java-version: ${{ matrix.java }}
- name: Setup Gradle
uses: gradle/gradle-build-action@v2.3.3
- name: Optional setup step
env:
GRADLE_ENTERPRISE_ACCESS_KEY: ${{ secrets.GRADLE_ENTERPRISE_ACCESS_KEY }}
GRADLE_ENTERPRISE_CACHE_USERNAME: ${{ secrets.GRADLE_ENTERPRISE_CACHE_USERNAME }}
GRADLE_ENTERPRISE_CACHE_PASSWORD: ${{ secrets.GRADLE_ENTERPRISE_CACHE_PASSWORD }}
run: |
[ -f ./setup.sh ] && ./setup.sh || true
- name: Build with Gradle
id: gradle
run: |
./gradlew check --no-daemon --parallel --continue
env:
GH_TOKEN_PUBLIC_REPOS_READONLY: ${{ secrets.GH_TOKEN_PUBLIC_REPOS_READONLY }}
GH_USERNAME: ${{ secrets.GH_USERNAME }}
TESTCONTAINERS_RYUK_DISABLED: true
GRADLE_ENTERPRISE_ACCESS_KEY: ${{ secrets.GRADLE_ENTERPRISE_ACCESS_KEY }}
GRADLE_ENTERPRISE_CACHE_USERNAME: ${{ secrets.GRADLE_ENTERPRISE_CACHE_USERNAME }}
GRADLE_ENTERPRISE_CACHE_PASSWORD: ${{ secrets.GRADLE_ENTERPRISE_CACHE_PASSWORD }}
PREDICTIVE_TEST_SELECTION: "${{ github.event_name == 'pull_request' && 'true' || 'false' }}"
- name: Add build scan URL as PR comment
uses: actions/github-script@v5
if: github.event_name == 'pull_request' && failure()
with:
github-token: ${{secrets.GITHUB_TOKEN}}
script: |
github.rest.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: '❌ ${{ github.workflow }} failed: ${{ steps.gradle.outputs.build-scan-url }}'
})
2 changes: 1 addition & 1 deletion .github/workflows/release-notes.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ jobs:
id: check_release_drafter
run: |
has_release_drafter=$([ -f .github/release-drafter.yml ] && echo "true" || echo "false")
echo ::set-output name=has_release_drafter::${has_release_drafter}
echo "has_release_drafter=${has_release_drafter}" >> $GITHUB_OUTPUT

# If it has release drafter:
- uses: release-drafter/release-drafter@v5
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ jobs:
java-version: '17'
- name: Set the current release version
id: release_version
run: echo ::set-output name=release_version::${GITHUB_REF:11}
run: echo "release_version=${GITHUB_REF:11}" >> $GITHUB_OUTPUT
- name: Run pre-release
uses: micronaut-projects/github-actions/pre-release@master
env:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ final class BeanIntrospectionWriter extends AbstractAnnotationMetadataWriter {
this.introspectionName = computeIntrospectionName(name);
this.introspectionType = getTypeReferenceForName(introspectionName);
this.beanType = getTypeReferenceForName(name);
this.dispatchWriter = new DispatchWriter(introspectionType);
this.dispatchWriter = new DispatchWriter(introspectionType, Type.getType(AbstractInitializableBeanIntrospection.class));
}

/**
Expand Down Expand Up @@ -574,6 +574,7 @@ private void writeIntrospectionClass(ClassWriterOutputVisitor classWriterOutputV

dispatchWriter.buildDispatchOneMethod(classWriter);
dispatchWriter.buildDispatchMethod(classWriter);
dispatchWriter.buildGetTargetMethodByIndex(classWriter);
buildPropertyIndexOfMethod(classWriter);
buildFindIndexedProperty(classWriter);
buildGetIndexedProperties(classWriter);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -261,9 +261,8 @@ private void addExecutableMethods(ClassElement ce, BeanIntrospectionWriter write
});
}
ElementQuery<MethodElement> query = ElementQuery.of(MethodElement.class)
.onlyAccessible()
.modifiers((modifiers) -> !modifiers.contains(ElementModifier.STATIC))
.annotated((am) -> am.hasStereotype(Executable.class));
.modifiers(modifiers -> !modifiers.contains(ElementModifier.STATIC))
.annotated(am -> am.hasStereotype(Executable.class));
List<MethodElement> executableMethods = ce.getEnclosedElements(query);
for (MethodElement executableMethod : executableMethods) {
if (added.contains(executableMethod)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -267,30 +267,30 @@ public static boolean isRecordComponent(Element e) {
*/
public static Type getTypeReference(TypedElement type) {
ClassElement classElement = type.getType();
if (type.isPrimitive()) {
if (classElement.isPrimitive()) {
String internalName = NAME_TO_TYPE_MAP.get(classElement.getName());
if (type.isArray()) {
if (classElement.isArray()) {
StringBuilder name = new StringBuilder(internalName);
for (int i = 0; i < type.getArrayDimensions(); i++) {
for (int i = 0; i < classElement.getArrayDimensions(); i++) {
name.insert(0, "[");
}
return Type.getObjectType(name.toString());
} else {
return Type.getType(internalName);
}
} else {
Object nativeType = type.getNativeType();
Object nativeType = classElement.getNativeType();
if (nativeType instanceof Class<?> t) {
return Type.getType(t);
} else {
String internalName = type.getType().getName().replace('.', '/');
String internalName = classElement.getName().replace('.', '/');
if (internalName.isEmpty()) {
return Type.getType(Object.class);
}
if (type.isArray()) {
if (classElement.isArray()) {
StringBuilder name = new StringBuilder(internalName);
name.insert(0, "L");
for (int i = 0; i < type.getArrayDimensions(); i++) {
for (int i = 0; i < classElement.getArrayDimensions(); i++) {
name.insert(0, "[");
}
name.append(";");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,11 +71,19 @@ public final class DispatchWriter extends AbstractClassFileWriter implements Opc

private final List<DispatchTarget> dispatchTargets = new ArrayList<>();
private final Type thisType;

private final Type dispatchSuperType;

private boolean hasInterceptedMethod;

public DispatchWriter(Type thisType) {
this(thisType, ExecutableMethodsDefinitionWriter.SUPER_TYPE);
}

public DispatchWriter(Type thisType, Type dispatchSuperType) {
super();
this.thisType = thisType;
this.dispatchSuperType = dispatchSuperType;
}

/**
Expand Down Expand Up @@ -118,7 +126,7 @@ public int addMethod(TypedElement declaringType, MethodElement methodElement) {
* @return the target index
*/
public int addMethod(TypedElement declaringType, MethodElement methodElement, boolean useOneDispatch) {
return addDispatchTarget(new MethodDispatchTarget(declaringType, methodElement, useOneDispatch, !useOneDispatch));
return addDispatchTarget(new MethodDispatchTarget(dispatchSuperType, declaringType, methodElement, useOneDispatch, !useOneDispatch));
}

/**
Expand All @@ -136,6 +144,7 @@ public int addInterceptedMethod(TypedElement declaringType,
String interceptedProxyBridgeMethodName) {
hasInterceptedMethod = true;
return addDispatchTarget(new InterceptableMethodDispatchTarget(
dispatchSuperType,
declaringType,
methodElement,
interceptedProxyClassName,
Expand Down Expand Up @@ -475,15 +484,17 @@ public FieldElement getField() {
@Internal
@SuppressWarnings("FinalClass")
public static class MethodDispatchTarget implements DispatchTarget {
final Type dispatchSuperType;
final TypedElement declaringType;
final MethodElement methodElement;
final boolean oneDispatch;
final boolean multiDispatch;

private MethodDispatchTarget(TypedElement declaringType,
private MethodDispatchTarget(Type dispatchSuperType, TypedElement declaringType,
MethodElement methodElement,
boolean oneDispatch,
boolean multiDispatch) {
this.dispatchSuperType = dispatchSuperType;
this.declaringType = declaringType;
this.methodElement = methodElement;
this.oneDispatch = oneDispatch;
Expand Down Expand Up @@ -528,7 +539,7 @@ public void writeDispatchMulti(GeneratorAdapter writer, int methodIndex) {
}
writer.loadThis();
writer.push(methodIndex);
writer.invokeVirtual(ExecutableMethodsDefinitionWriter.SUPER_TYPE, GET_ACCESSIBLE_TARGET_METHOD);
writer.invokeVirtual(dispatchSuperType, GET_ACCESSIBLE_TARGET_METHOD);
if (hasArgs) {
writer.loadArg(2);
} else {
Expand Down Expand Up @@ -607,12 +618,13 @@ public static final class InterceptableMethodDispatchTarget extends MethodDispat
final String interceptedProxyBridgeMethodName;
final Type thisType;

private InterceptableMethodDispatchTarget(TypedElement declaringType,
private InterceptableMethodDispatchTarget(Type dispatchSuperType,
TypedElement declaringType,
MethodElement methodElement,
String interceptedProxyClassName,
String interceptedProxyBridgeMethodName,
Type thisType) {
super(declaringType, methodElement, false, true);
super(dispatchSuperType, declaringType, methodElement, false, true);
this.interceptedProxyClassName = interceptedProxyClassName;
this.interceptedProxyBridgeMethodName = interceptedProxyBridgeMethodName;
this.thisType = thisType;
Expand Down
2 changes: 1 addition & 1 deletion gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ managed-jackson = "2.14.0"
managed-jackson-databind = "2.14.1"
managed-maven-native-plugin = "0.9.13"
managed-methvin-directory-watcher = "0.16.1"
managed-netty = "4.1.86.Final"
managed-netty = "4.1.87.Final"
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.4.24"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,6 @@
import java.util.Map;
import java.util.Optional;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.atomic.AtomicReference;
import java.util.function.Function;
import java.util.function.Supplier;

Expand Down Expand Up @@ -343,18 +342,23 @@ public Object intercept(MethodInvocationContext<Object, Object> context) {
Publisher<?> csPublisher = httpClientResponsePublisher(httpClient, request, returnType, errorType, valueType);
CompletableFuture<Object> future = new CompletableFuture<>();
csPublisher.subscribe(new CompletionAwareSubscriber<Object>() {
AtomicReference<Object> reference = new AtomicReference<>();
Object message;
Subscription subscription;

@Override
protected void doOnSubscribe(Subscription subscription) {
subscription.request(1);
this.subscription = subscription;
subscription.request(Long.MAX_VALUE);
}

@Override
protected void doOnNext(Object message) {
if (Void.class != reactiveValueType) {
reference.set(message);
this.message = message;
}
// we only want the first item
subscription.cancel();
doOnComplete();
}

@Override
Expand All @@ -380,7 +384,8 @@ protected void doOnError(Throwable t) {

@Override
protected void doOnComplete() {
future.complete(reference.get());
// can be called twice
future.complete(message);
}
});
return interceptedMethod.handleResult(future);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Args = --features=io.micronaut.http.netty.graal.HttpNettyFeature
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public void onOpen(String topic, String username, WebSocketSession session) {
this.topic = topic;
this.username = username;
this.session = session;
System.out.println("Client session opened for username = " + username);
System.out.println("Client session " + session.getId() + " opened for username = " + username);
}

public String getTopic() {
Expand All @@ -72,7 +72,7 @@ public WebSocketSession getSession() {
@OnMessage
public void onMessage(
byte[] message) {
System.out.println("Client received message = " + new String(message));
System.out.println("Client " + username + " received message = " + new String(message));
replies.add(new String(message));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public void onOpen(String topic, String username, WebSocketSession session) {
if(isValid(topic, session, openSession)) {
String msg = "[" + username + "] Joined!";
System.out.println("Server sending msg = " + msg);
openSession.sendSync(msg.getBytes());
openSession.sendAsync(msg.getBytes());
}
}
}
Expand All @@ -55,7 +55,7 @@ public void onMessage(
if(isValid(topic, session, openSession)) {
String msg = "[" + username + "] " + new String(message);
System.out.println("Server sending msg = " + msg);
openSession.sendSync(msg.getBytes());
openSession.sendAsync(msg.getBytes());
}
}
}
Expand All @@ -72,7 +72,7 @@ public void onClose(
if(isValid(topic, session, openSession)) {
String msg = "[" + username + "] Disconnected!";
System.out.println("Server sending msg = " + msg);
openSession.sendSync(msg.getBytes());
openSession.sendAsync(msg.getBytes());
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,17 +34,14 @@ import jakarta.inject.Singleton
import reactor.core.publisher.Flux
import reactor.core.publisher.Mono
import spock.lang.Issue
import spock.lang.Retry
import spock.lang.Specification
import spock.util.concurrent.PollingConditions

import java.nio.ByteBuffer
import java.nio.charset.StandardCharsets

@Retry
class BinaryWebSocketSpec extends Specification {

@Retry
void "test binary websocket exchange"() {
given:
EmbeddedServer embeddedServer = ApplicationContext.builder('micronaut.server.netty.log-level':'TRACE').run(EmbeddedServer)
Expand All @@ -71,7 +68,6 @@ class BinaryWebSocketSpec extends Specification {
fred.replies.size() == 1
}


when:"A message is sent"
fred.send("Hello bob!".bytes)

Expand All @@ -88,7 +84,6 @@ class BinaryWebSocketSpec extends Specification {

then:
conditions.eventually {

fred.replies.contains("[bob] Hi fred. How are things?")
fred.replies.size() == 2
bob.replies.contains("[fred] Hello bob!")
Expand All @@ -101,8 +96,6 @@ class BinaryWebSocketSpec extends Specification {

when:
bob.close()
sleep(1000)


then:
conditions.eventually {
Expand Down
Loading