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

add native test and support #18

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
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
12 changes: 8 additions & 4 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,13 @@ jobs:
uses: actions/cache@v2
with:
path: ~/.m2/repository
# refresh cache every month to avoid unlimited growth
key: maven-repo-${{ runner.os }}-${{ steps.get-date.outputs.date }}
key: ${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }}
restore-keys: |
${{ runner.os }}-maven-

- name: Build with Maven
run: mvn -B formatter:validate verify --file pom.xml
- name: Build - JVM
run: mvn -B formatter:validate install --file pom.xml

- name: Build - Native
run: mvn -B verify -Pnative --file integration-tests/pom.xml
Copy link

@famod famod Mar 31, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So you are physically limiting the Maven reactor to just this one module integration-tests, which is fine, but this will need the runtime and deployment modules of the extension in the local repo. Otherwise resolution of those modules/artifacts will fail (because they are not part of the reactor).

Therefore you will have to use install in the previous "Build - JVM" step.
To avoid having the resulting extension artifacts in the Maven cache (they should be built freshly for each run), you should add something like the following (after this step):

      - name: Delete Local Artifacts From Cache
        shell: bash
        run: rm -r ~/.m2/repository/io/quarkiverse/rsocket

/cc @gastaldi I haven't had a look at how other quarkiverse extensions work, so you might have another suggestion.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@famod that makes sense, I don't think we're doing anything like that in the other extensions too

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

my bad , I have merges 2 files from different project....
I just focused on pom files because I was thinking it come from that...


1 change: 1 addition & 0 deletions deployment/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
<dependency>
<groupId>io.quarkiverse.rsocket</groupId>
<artifactId>quarkus-rsocket</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import io.quarkus.deployment.annotations.Record;
import io.quarkus.deployment.builditem.CombinedIndexBuildItem;
import io.quarkus.deployment.builditem.FeatureBuildItem;
import io.quarkus.deployment.builditem.nativeimage.ReflectiveClassBuildItem;
import io.quarkus.runtime.RuntimeValue;
import io.rsocket.frame.FrameType;

Expand All @@ -40,6 +41,11 @@ FeatureBuildItem feature() {
return new FeatureBuildItem(FEATURE);
}

@BuildStep
void nativeSupport(BuildProducer<ReflectiveClassBuildItem> reflectives) {
reflectives.produce(new ReflectiveClassBuildItem(true, true, "sun.misc.Unsafe"));
}

@BuildStep
void configure(CombinedIndexBuildItem combinedIndexBuildItem,
BuildProducer<RSocketBuildItem> rsockets,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
package io.quarkiverse.rsocket.test;

import java.nio.ByteBuffer;
import java.nio.CharBuffer;
import java.nio.charset.StandardCharsets;
import java.util.Collections;

import org.jboss.logging.Logger;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;

import com.google.common.base.Charsets;

import io.netty.buffer.ByteBuf;
import io.netty.buffer.ByteBufAllocator;
import io.netty.buffer.CompositeByteBuf;
import io.quarkiverse.rsocket.runtime.JsonEncoder;
import io.quarkus.test.junit.NativeImageTest;
import io.rsocket.Payload;
import io.rsocket.core.RSocketConnector;
import io.rsocket.metadata.CompositeMetadataCodec;
import io.rsocket.metadata.RoutingMetadata;
import io.rsocket.metadata.TaggingMetadataCodec;
import io.rsocket.metadata.WellKnownMimeType;
import io.rsocket.transport.netty.client.TcpClientTransport;
import io.rsocket.util.DefaultPayload;

@NativeImageTest
public class RSocketTestCaseIT {
private static final Logger LOGGER = Logger.getLogger(RSocketTestCase.class);

@Test
public void testRSocketRoute() {
String hello = "Hello RSocket";
CompositeByteBuf metadata = ByteBufAllocator.DEFAULT.compositeBuffer();
RoutingMetadata routingMetadata = TaggingMetadataCodec.createRoutingMetadata(ByteBufAllocator.DEFAULT,
Collections.singletonList("/foo"));
CompositeMetadataCodec.encodeAndAddMetadata(metadata,
ByteBufAllocator.DEFAULT,
WellKnownMimeType.MESSAGE_RSOCKET_ROUTING,
routingMetadata.getContent());
ByteBuf data = ByteBufAllocator.DEFAULT.buffer().writeBytes(hello.getBytes(Charsets.UTF_8));
ByteBuffer byteBuffer = StandardCharsets.UTF_8.encode(CharBuffer.wrap(hello));
Payload rspPayload = RSocketConnector.create()
.metadataMimeType(WellKnownMimeType.MESSAGE_RSOCKET_COMPOSITE_METADATA.getString())
//.payloadDecoder(PayloadDecoder.ZERO_COPY)
.connect(TcpClientTransport.create("127.0.0.1", 7000))
.block()
.requestResponse(DefaultPayload.create(byteBuffer, metadata.nioBuffer()))
.block();
metadata.release();
Assertions.assertEquals(hello, rspPayload.getDataUtf8(), "failed to get response");
}

@Test
public void testRSocketEncoder() {

CompositeByteBuf metadata = ByteBufAllocator.DEFAULT.compositeBuffer();
RoutingMetadata routingMetadata = TaggingMetadataCodec.createRoutingMetadata(ByteBufAllocator.DEFAULT,
Collections.singletonList("/foo"));
CompositeMetadataCodec.encodeAndAddMetadata(metadata,
ByteBufAllocator.DEFAULT,
WellKnownMimeType.MESSAGE_RSOCKET_ROUTING,
routingMetadata.getContent());
Car c = new Car();
c.setName("batmobile");
JsonEncoder encoder = new JsonEncoder();
Payload payload = encoder.encode(c);
Payload rspPayload = RSocketConnector.create()
.metadataMimeType(WellKnownMimeType.MESSAGE_RSOCKET_COMPOSITE_METADATA.getString())
//.payloadDecoder(PayloadDecoder.ZERO_COPY)
.connect(TcpClientTransport.create("127.0.0.1", 7000))
.block()
.requestResponse(DefaultPayload.create(payload.getData(), metadata.nioBuffer()))
.block();
metadata.release();
Assertions.assertEquals("{\"name\":\"batmobile\"}", rspPayload.getDataUtf8(), "failed to get response");
}
}
10 changes: 0 additions & 10 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -37,16 +37,6 @@
<type>pom</type>
<scope>import</scope>
</dependency>
<dependency>
<groupId>io.quarkiverse.rsocket</groupId>
<artifactId>quarkus-rsocket</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>io.quarkiverse.rsocket</groupId>
<artifactId>quarkus-rsocket-deployment</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>io.rsocket</groupId>
<artifactId>rsocket-core</artifactId>
Expand Down