use of io.vertx.proton.streams.impl.ProtonSubscriberWrapperImpl in project vertx-proton by vert-x3.
the class MessageSubscriberBlackboxVerificationTckTest method createSubscriber.
@Override
public Subscriber<Message> createSubscriber() {
int actualPort = server.actualPort();
ProtonClient client = ProtonClient.create(vertx);
AtomicReference<Subscriber<Message>> ref = new AtomicReference<>();
CountDownLatch latch = new CountDownLatch(1);
client.connect("localhost", actualPort, result -> {
if (result.succeeded()) {
ProtonConnection conn = result.result();
conn.open();
ProtonSubscriber<Message> stream = ProtonStreams.createProducer(conn, "myAddress");
((ProtonSubscriberWrapperImpl) stream).setEmitOnConnectionEnd(false);
ref.set(stream);
} else {
LOG.error("Connection failed");
}
latch.countDown();
});
try {
LOG.trace("Awaiting connection");
boolean res = latch.await(2, TimeUnit.SECONDS);
LOG.trace("Client connected: " + res);
} catch (InterruptedException e) {
throw new RuntimeException("Interrupted while creating subscriber", e);
}
return ref.get();
}
use of io.vertx.proton.streams.impl.ProtonSubscriberWrapperImpl in project vertx-proton by vert-x3.
the class MessageSubscriberWhiteboxVerificationTckTest method createSubscriber.
@Override
public Subscriber<Message> createSubscriber(WhiteboxSubscriberProbe<Message> probe) {
int actualPort = server.actualPort();
ProtonClient client = ProtonClient.create(vertx);
AtomicReference<Subscriber<Message>> ref = new AtomicReference<>();
CountDownLatch latch = new CountDownLatch(1);
client.connect("localhost", actualPort, result -> {
if (result.succeeded()) {
ProtonConnection conn = result.result();
conn.open();
// Modified stream impl, overriding methods to add test probe instrumentation
ProtonSubscriberImpl subscriber = new ProtonSubscriberImpl("myAddress", (ProtonConnectionImpl) conn);
ProtonSubscriber<Message> stream = new ProtonSubscriberWrapperImpl(subscriber) {
@Override
public void onSubscribe(final Subscription s) {
super.onSubscribe(s);
probe.registerOnSubscribe(new SubscriberPuppet() {
@Override
public void triggerRequest(long n) {
s.request(n);
}
@Override
public void signalCancel() {
s.cancel();
}
});
}
@Override
public void onNext(Message value) {
probe.registerOnNext(value);
super.onNext(value);
}
@Override
public void onError(Throwable t) {
probe.registerOnError(t);
super.onError(t);
}
@Override
public void onComplete() {
probe.registerOnComplete();
super.onComplete();
}
};
ref.set(stream);
} else {
LOG.error("Connection failed");
}
latch.countDown();
});
try {
LOG.trace("Awaiting connection");
boolean res = latch.await(2, TimeUnit.SECONDS);
LOG.trace("Client connected: " + res);
} catch (InterruptedException e) {
throw new RuntimeException("Interrupted while creating subscriber", e);
}
return ref.get();
}
Aggregations