Skip to content

Fix logging in examples and load-balancer tests #800

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

Merged
merged 1 commit into from
Apr 27, 2020
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
2 changes: 1 addition & 1 deletion rsocket-examples/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,13 @@ dependencies {
implementation project(':rsocket-core')
implementation project(':rsocket-transport-local')
implementation project(':rsocket-transport-netty')
runtimeOnly 'ch.qos.logback:logback-classic'

testImplementation project(':rsocket-test')
testImplementation 'org.junit.jupiter:junit-jupiter-api'
testImplementation 'org.mockito:mockito-core'
testImplementation 'org.assertj:assertj-core'
testImplementation 'io.projectreactor:reactor-test'
testImplementation 'ch.qos.logback:logback-classic'

// TODO: Remove after JUnit5 migration
testCompileOnly 'junit:junit'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,15 @@
import io.rsocket.util.DefaultPayload;
import java.time.Duration;
import org.reactivestreams.Publisher;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono;

public final class ChannelEchoClient {

private static final Logger logger = LoggerFactory.getLogger(ChannelEchoClient.class);

public static void main(String[] args) {
RSocketServer.create(new EchoAcceptor())
.bind(TcpServerTransport.create("localhost", 7000))
Expand All @@ -45,7 +49,7 @@ public static void main(String[] args) {
.requestChannel(
Flux.interval(Duration.ofMillis(1000)).map(i -> DefaultPayload.create("Hello")))
.map(Payload::getDataUtf8)
.doOnNext(System.out::println)
.doOnNext(logger::debug)
.take(10)
.doFinally(signalType -> socket.dispose())
.then()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,14 @@
import io.rsocket.transport.netty.client.TcpClientTransport;
import io.rsocket.transport.netty.server.TcpServerTransport;
import io.rsocket.util.DefaultPayload;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import reactor.core.publisher.Mono;

public final class HelloWorldClient {

private static final Logger logger = LoggerFactory.getLogger(HelloWorldClient.class);

public static void main(String[] args) {
RSocketServer.create(
(setupPayload, reactiveSocket) ->
Expand All @@ -39,7 +43,7 @@ public static void main(String[] args) {
public Mono<Payload> requestResponse(Payload p) {
if (fail) {
fail = false;
return Mono.error(new Throwable());
return Mono.error(new Throwable("Simulated error"));
} else {
return Mono.just(p);
}
Expand All @@ -51,26 +55,14 @@ public Mono<Payload> requestResponse(Payload p) {
RSocket socket =
RSocketConnector.connectWith(TcpClientTransport.create("localhost", 7000)).block();

socket
.requestResponse(DefaultPayload.create("Hello"))
.map(Payload::getDataUtf8)
.onErrorReturn("error")
.doOnNext(System.out::println)
.block();

socket
.requestResponse(DefaultPayload.create("Hello"))
.map(Payload::getDataUtf8)
.onErrorReturn("error")
.doOnNext(System.out::println)
.block();

socket
.requestResponse(DefaultPayload.create("Hello"))
.map(Payload::getDataUtf8)
.onErrorReturn("error")
.doOnNext(System.out::println)
.block();
for (int i = 0; i < 3; i++) {
socket
.requestResponse(DefaultPayload.create("Hello"))
.map(Payload::getDataUtf8)
.onErrorReturn("error")
.doOnNext(logger::debug)
.block();
}

socket.dispose();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,21 @@
import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;
import io.rsocket.Payload;
import java.io.*;
import java.io.BufferedInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import org.reactivestreams.Subscriber;
import org.reactivestreams.Subscription;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import reactor.core.publisher.Flux;
import reactor.core.publisher.SynchronousSink;

class Files {
private static final Logger logger = LoggerFactory.getLogger(Files.class);

public static Flux<ByteBuf> fileSource(String fileName, int chunkSizeBytes) {
return Flux.generate(
Expand All @@ -35,8 +43,7 @@ public void onNext(Payload payload) {
ByteBuf data = payload.data();
receivedBytes += data.readableBytes();
receivedCount += 1;
System.out.println(
"Received file chunk: " + receivedCount + ". Total size: " + receivedBytes);
logger.debug("Received file chunk: " + receivedCount + ". Total size: " + receivedBytes);
if (outputStream == null) {
outputStream = open(fileName);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,17 @@
import io.rsocket.transport.netty.server.TcpServerTransport;
import io.rsocket.util.DefaultPayload;
import java.time.Duration;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono;
import reactor.util.retry.Retry;

public class ResumeFileTransfer {

/*amount of file chunks requested by subscriber: n, refilled on n/2 of received items*/
private static final int PREFETCH_WINDOW_SIZE = 4;
private static final Logger logger = LoggerFactory.getLogger(ResumeFileTransfer.class);

public static void main(String[] args) {
RequestCodec requestCodec = new RequestCodec();
Expand All @@ -44,7 +48,7 @@ public static void main(String[] args) {
Retry.fixedDelay(Long.MAX_VALUE, Duration.ofSeconds(1))
.doBeforeRetry(
retrySignal ->
System.out.println("Disconnected. Trying to resume connection...")));
logger.debug("Disconnected. Trying to resume connection...")));

CloseableChannel server =
RSocketServer.create((setup, rSocket) -> Mono.just(new FileServer(requestCodec)))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,15 @@
import io.rsocket.transport.netty.server.TcpServerTransport;
import io.rsocket.util.DefaultPayload;
import java.time.Duration;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono;

public final class StreamingClient {

private static final Logger logger = LoggerFactory.getLogger(StreamingClient.class);

public static void main(String[] args) {
RSocketServer.create(new SocketAcceptorImpl())
.bind(TcpServerTransport.create("localhost", 7000))
Expand All @@ -43,7 +47,7 @@ public static void main(String[] args) {
socket
.requestStream(DefaultPayload.create("Hello"))
.map(Payload::getDataUtf8)
.doOnNext(System.out::println)
.doOnNext(logger::debug)
.take(10)
.then()
.doFinally(signalType -> socket.dispose())
Expand Down
20 changes: 0 additions & 20 deletions rsocket-examples/src/main/resources/log4j.properties

This file was deleted.

35 changes: 35 additions & 0 deletions rsocket-examples/src/main/resources/logback.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
~ Copyright 2015-2020 the original author or authors.
~
~ Licensed under the Apache License, Version 2.0 (the "License");
~ you may not use this file except in compliance with the License.
~ You may obtain a copy of the License at
~
~ http://www.apache.org/licenses/LICENSE-2.0
~
~ Unless required by applicable law or agreed to in writing, software
~ distributed under the License is distributed on an "AS IS" BASIS,
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
~ See the License for the specific language governing permissions and
~ limitations under the License.
-->

<configuration>

<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
<encoder>
<pattern>%d{dd MMM yyyy HH:mm:ss,SSS} %5p [%t] %c{1} - %m%n</pattern>
</encoder>
</appender>

<logger name="io.rsocket.examples" level="DEBUG"/>

<!-- Set this to DEBUG to log frames -->
<logger name="io.rsocket.FrameLogger" level="INFO"/>

<root level="INFO">
<appender-ref ref="STDOUT"/>
</root>

</configuration>
21 changes: 0 additions & 21 deletions rsocket-examples/src/test/resources/log4j.properties

This file was deleted.

33 changes: 33 additions & 0 deletions rsocket-examples/src/test/resources/logback-test.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
~ Copyright 2015-2020 the original author or authors.
~
~ Licensed under the Apache License, Version 2.0 (the "License");
~ you may not use this file except in compliance with the License.
~ You may obtain a copy of the License at
~
~ http://www.apache.org/licenses/LICENSE-2.0
~
~ Unless required by applicable law or agreed to in writing, software
~ distributed under the License is distributed on an "AS IS" BASIS,
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
~ See the License for the specific language governing permissions and
~ limitations under the License.
-->

<configuration>

<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
<encoder>
<pattern>%d{dd MMM yyyy HH:mm:ss,SSS} %5p [%t] %c{1} - %m%n</pattern>
</encoder>
</appender>

<logger name="io.rsocket.examples" level="DEBUG"/>
<logger name="io.rsocket.FrameLogger" level="INFO"/>

<root level="INFO">
<appender-ref ref="STDOUT"/>
</root>

</configuration>
1 change: 1 addition & 0 deletions rsocket-load-balancer/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ dependencies {
testCompileOnly 'junit:junit'
testImplementation 'org.hamcrest:hamcrest-library'
testRuntimeOnly 'org.junit.vintage:junit-vintage-engine'
testRuntimeOnly 'ch.qos.logback:logback-classic'
}

description = 'Transparent Load Balancer for RSocket'
20 changes: 0 additions & 20 deletions rsocket-load-balancer/src/test/resources/log4j.properties

This file was deleted.

33 changes: 33 additions & 0 deletions rsocket-load-balancer/src/test/resources/logback-test.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
~ Copyright 2015-2020 the original author or authors.
~
~ Licensed under the Apache License, Version 2.0 (the "License");
~ you may not use this file except in compliance with the License.
~ You may obtain a copy of the License at
~
~ http://www.apache.org/licenses/LICENSE-2.0
~
~ Unless required by applicable law or agreed to in writing, software
~ distributed under the License is distributed on an "AS IS" BASIS,
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
~ See the License for the specific language governing permissions and
~ limitations under the License.
-->

<configuration>

<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
<encoder>
<pattern>%d{dd MMM yyyy HH:mm:ss,SSS} %5p [%t] %c{1} - %m%n</pattern>
</encoder>
</appender>

<logger name="io.rsocket.examples" level="DEBUG"/>
<logger name="io.rsocket.FrameLogger" level="INFO"/>

<root level="INFO">
<appender-ref ref="STDOUT"/>
</root>

</configuration>