-
Notifications
You must be signed in to change notification settings - Fork 356
Loadbalancer: closing doesn't subscribe to the underlying #148
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
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
22 changes: 22 additions & 0 deletions
22
reactivesocket-core/src/main/java/io/reactivesocket/internal/rx/EmptySubscriber.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package io.reactivesocket.internal.rx; | ||
|
||
import org.reactivestreams.Subscriber; | ||
import org.reactivestreams.Subscription; | ||
|
||
public enum EmptySubscriber implements Subscriber<Object> { | ||
INSTANCE(); | ||
|
||
@Override | ||
public void onSubscribe(Subscription s) { | ||
|
||
} | ||
|
||
@Override | ||
public void onNext(Object t) {} | ||
|
||
@Override | ||
public void onError(Throwable t) {} | ||
|
||
@Override | ||
public void onComplete() {} | ||
} |
134 changes: 134 additions & 0 deletions
134
reactivesocket-examples/src/test/java/io/reactivesocket/integration/IntegrationTest.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,134 @@ | ||
package io.reactivesocket.integration; | ||
|
||
import io.reactivesocket.*; | ||
import io.reactivesocket.client.ClientBuilder; | ||
import io.reactivesocket.internal.Publishers; | ||
import io.reactivesocket.test.TestUtil; | ||
import io.reactivesocket.transport.tcp.client.TcpReactiveSocketConnector; | ||
import io.reactivesocket.transport.tcp.server.TcpReactiveSocketServer; | ||
import io.reactivesocket.util.Unsafe; | ||
import org.junit.Test; | ||
import org.reactivestreams.Publisher; | ||
import org.reactivestreams.Subscriber; | ||
import org.reactivestreams.Subscription; | ||
|
||
import java.net.InetSocketAddress; | ||
import java.net.SocketAddress; | ||
import java.util.Collections; | ||
import java.util.List; | ||
import java.util.concurrent.ExecutionException; | ||
import java.util.concurrent.TimeUnit; | ||
import java.util.concurrent.TimeoutException; | ||
import java.util.concurrent.atomic.AtomicInteger; | ||
|
||
import static org.junit.Assert.*; | ||
import static rx.RxReactiveStreams.toObservable; | ||
|
||
public class IntegrationTest { | ||
|
||
private interface TestingServer { | ||
int requestCount(); | ||
int disconnectionCount(); | ||
SocketAddress getListeningAddress(); | ||
} | ||
|
||
private TestingServer createServer() { | ||
AtomicInteger requestCounter = new AtomicInteger(); | ||
AtomicInteger disconnectionCounter = new AtomicInteger(); | ||
|
||
ConnectionSetupHandler setupHandler = (setupPayload, reactiveSocket) -> { | ||
reactiveSocket.onClose().subscribe(new Subscriber<Void>() { | ||
@Override | ||
public void onSubscribe(Subscription s) { | ||
s.request(Long.MAX_VALUE); | ||
} | ||
|
||
@Override | ||
public void onNext(Void aVoid) {} | ||
|
||
@Override | ||
public void onError(Throwable t) {} | ||
|
||
@Override | ||
public void onComplete() { | ||
disconnectionCounter.incrementAndGet(); | ||
} | ||
}); | ||
return new RequestHandler.Builder() | ||
.withRequestResponse( | ||
payload -> subscriber -> subscriber.onSubscribe(new Subscription() { | ||
@Override | ||
public void request(long n) { | ||
requestCounter.incrementAndGet(); | ||
subscriber.onNext(TestUtil.utf8EncodedPayload("RESPONSE", "NO_META")); | ||
subscriber.onComplete(); | ||
} | ||
|
||
@Override | ||
public void cancel() {} | ||
}) | ||
) | ||
.build(); | ||
}; | ||
|
||
SocketAddress addr = new InetSocketAddress("127.0.0.1", 0); | ||
TcpReactiveSocketServer.StartedServer server = | ||
TcpReactiveSocketServer.create(addr).start(setupHandler); | ||
|
||
return new TestingServer() { | ||
@Override | ||
public int requestCount() { | ||
return requestCounter.get(); | ||
} | ||
|
||
@Override | ||
public int disconnectionCount() { | ||
return disconnectionCounter.get(); | ||
} | ||
|
||
@Override | ||
public SocketAddress getListeningAddress() { | ||
return server.getServerAddress(); | ||
} | ||
}; | ||
} | ||
|
||
private ReactiveSocket createClient(SocketAddress addr) throws InterruptedException, ExecutionException, TimeoutException { | ||
List<SocketAddress> addrs = Collections.singletonList(addr); | ||
Publisher<List<SocketAddress>> src = Publishers.just(addrs); | ||
|
||
ConnectionSetupPayload setupPayload = | ||
ConnectionSetupPayload.create("UTF-8", "UTF-8", ConnectionSetupPayload.HONOR_LEASE); | ||
TcpReactiveSocketConnector tcp = TcpReactiveSocketConnector.create(setupPayload, Throwable::printStackTrace); | ||
|
||
Publisher<ReactiveSocket> socketPublisher = | ||
ClientBuilder.<SocketAddress>instance() | ||
.withSource(src) | ||
.withConnector(tcp) | ||
.build(); | ||
|
||
return Unsafe.blockingSingleWait(socketPublisher, 5, TimeUnit.SECONDS); | ||
} | ||
|
||
@Test(timeout = 2_000L) | ||
public void testRequest() throws ExecutionException, InterruptedException, TimeoutException { | ||
TestingServer server = createServer(); | ||
ReactiveSocket client = createClient(server.getListeningAddress()); | ||
|
||
toObservable(client.requestResponse(TestUtil.utf8EncodedPayload("RESPONSE", "NO_META"))) | ||
.toBlocking() | ||
.subscribe(); | ||
assertTrue("Server see the request", server.requestCount() > 0); | ||
} | ||
|
||
@Test(timeout = 2_000L) | ||
public void testClose() throws ExecutionException, InterruptedException, TimeoutException { | ||
TestingServer server = createServer(); | ||
ReactiveSocket client = createClient(server.getListeningAddress()); | ||
|
||
toObservable(client.close()).toBlocking().subscribe(); | ||
|
||
Thread.sleep(100); | ||
assertTrue("Server see disconnection", server.disconnectionCount() > 0); | ||
} | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you're doing the same thing in the onComplete and the onError - why not just call onComplete in the onError method?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good point, it makes the code simpler.