use of io.vertx.proton.streams.Tracker in project vertx-proton by vert-x3.
the class TrackerSubscriberWhiteboxVerificationTckTest method createSubscriber.
@Override
public Subscriber<Tracker> createSubscriber(WhiteboxSubscriberProbe<Tracker> probe) {
int actualPort = server.actualPort();
ProtonClient client = ProtonClient.create(vertx);
AtomicReference<Subscriber<Tracker>> 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
ProtonSubscriber<Tracker> stream = new ProtonSubscriberImpl("myAddress", (ProtonConnectionImpl) conn) {
@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(Tracker 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();
}
use of io.vertx.proton.streams.Tracker in project vertx-proton by vert-x3.
the class ProtonSubscriberIntTest method testCreateUseAndCancelSubscriber.
// TODO: test retrieve delivery state from tracker [other than accept]
@Test(timeout = 20000)
public void testCreateUseAndCancelSubscriber(TestContext context) throws Exception {
server.close();
final Async serverLinkOpenAsync = context.async();
final Async serverReceivedMessageAsync = context.async();
final Async serverLinkCloseAsync = context.async();
ProtonServer protonServer = null;
try {
protonServer = createServer((serverConnection) -> {
serverConnection.openHandler(result -> {
serverConnection.open();
});
serverConnection.sessionOpenHandler(session -> session.open());
serverConnection.receiverOpenHandler(serverReceiver -> {
LOG.trace("Server receiver opened");
serverReceiver.handler((delivery, msg) -> {
// We got the message that was sent, complete the test
if (LOG.isTraceEnabled()) {
LOG.trace("Server got msg: " + getMessageBody(context, msg));
}
validateMessage(context, 1, "1", msg);
serverReceivedMessageAsync.complete();
});
serverReceiver.closeHandler(x -> {
serverReceiver.close();
serverLinkCloseAsync.complete();
});
// Set the local terminus details [naively]
serverReceiver.setTarget(serverReceiver.getRemoteTarget().copy());
serverReceiver.open();
serverLinkOpenAsync.complete();
});
});
// ===== Client Handling =====
ProtonClient client = ProtonClient.create(vertx);
client.connect("localhost", protonServer.actualPort(), res -> {
context.assertTrue(res.succeeded());
ProtonConnection connection = res.result();
connection.open();
ProtonSubscriber<Tracker> subscriber = ProtonStreams.createTrackerProducer(connection, "myAddress");
Tracker tracker = Tracker.create(message("1"), t -> {
context.assertTrue(t.isAccepted(), "msg should be accepted");
context.assertTrue(t.isRemotelySettled(), "msg should be remotely settled");
});
Publisher<Tracker> producer = Flowable.just(tracker);
producer.subscribe(subscriber);
});
serverLinkOpenAsync.awaitSuccess();
serverReceivedMessageAsync.awaitSuccess();
serverLinkCloseAsync.awaitSuccess();
} finally {
if (protonServer != null) {
protonServer.close();
}
}
}
use of io.vertx.proton.streams.Tracker in project vertx-proton by vert-x3.
the class ProtonSubscriberIntTest method testSubCancelledOnConnectionEnd.
@Test(timeout = 20000)
public void testSubCancelledOnConnectionEnd(TestContext context) throws Exception {
server.close();
final Async serverLinkOpenAsync = context.async();
final Async subCancelled = context.async();
ProtonServer protonServer = null;
try {
protonServer = createServer((serverConnection) -> {
serverConnection.openHandler(result -> {
serverConnection.open();
});
serverConnection.sessionOpenHandler(session -> session.open());
serverConnection.receiverOpenHandler(serverReceiver -> {
LOG.trace("Server receiver opened");
// Set the local terminus details [naively]
serverReceiver.setTarget(serverReceiver.getRemoteTarget().copy());
serverReceiver.open();
serverLinkOpenAsync.complete();
});
});
// ===== Client Handling =====
ProtonClient client = ProtonClient.create(vertx);
client.connect("localhost", protonServer.actualPort(), res -> {
context.assertTrue(res.succeeded());
ProtonConnection connection = res.result();
connection.open();
ProtonSubscriber<Tracker> subscriber = ProtonStreams.createTrackerProducer(connection, "myAddress");
// Create a Publisher that doesn't produce elements, but indicates when its subscription is cancelled.
Publisher<Tracker> producer = Flowable.<Tracker>never().doOnCancel(() -> {
LOG.trace("Cancelled!");
subCancelled.complete();
});
producer.subscribe(subscriber);
});
serverLinkOpenAsync.awaitSuccess();
context.assertFalse(subCancelled.isCompleted());
protonServer.close();
protonServer = null;
subCancelled.awaitSuccess();
} finally {
if (protonServer != null) {
protonServer.close();
}
}
}
use of io.vertx.proton.streams.Tracker in project vertx-proton by vert-x3.
the class ProtonSubscriberIntTest method testSubCancelledOnLinkClose.
@Test(timeout = 20000)
public void testSubCancelledOnLinkClose(TestContext context) throws Exception {
server.close();
final Async serverLinkOpenAsync = context.async();
final Async clientLinkCloseAsync = context.async();
ProtonServer protonServer = null;
try {
protonServer = createServer((serverConnection) -> {
serverConnection.openHandler(result -> {
serverConnection.open();
});
serverConnection.sessionOpenHandler(session -> session.open());
serverConnection.receiverOpenHandler(serverReceiver -> {
LOG.trace("Server receiver opened");
// Set the local terminus details [naively]
serverReceiver.setTarget(serverReceiver.getRemoteTarget().copy());
serverReceiver.open();
serverLinkOpenAsync.complete();
serverReceiver.close();
});
});
// ===== Client Handling =====
ProtonClient client = ProtonClient.create(vertx);
client.connect("localhost", protonServer.actualPort(), res -> {
context.assertTrue(res.succeeded());
ProtonConnection connection = res.result();
connection.open();
ProtonSubscriber<Tracker> subscriber = ProtonStreams.createTrackerProducer(connection, "myAddress");
// Create a Publisher that doesn't produce elements, but indicates when its subscription is cancelled.
Publisher<Tracker> producer = Flowable.<Tracker>never().doOnCancel(() -> {
LOG.trace("Cancelled!");
clientLinkCloseAsync.complete();
});
producer.subscribe(subscriber);
});
serverLinkOpenAsync.awaitSuccess();
clientLinkCloseAsync.awaitSuccess();
} finally {
if (protonServer != null) {
protonServer.close();
}
}
}
use of io.vertx.proton.streams.Tracker in project vertx-proton by vert-x3.
the class ProtonSubscriberIntTest method testAlternativeDispositionStates.
@Test(timeout = 20000)
public void testAlternativeDispositionStates(TestContext context) throws Exception {
server.close();
final Async serverLinkOpenAsync = context.async();
final Async serverReceivedMessageAsync = context.async();
final Async serverLinkCloseAsync = context.async();
int messageCount = 4;
ProtonServer protonServer = null;
try {
protonServer = createServer((serverConnection) -> {
serverConnection.openHandler(result -> {
serverConnection.open();
});
serverConnection.sessionOpenHandler(session -> session.open());
AtomicInteger counter = new AtomicInteger(0);
serverConnection.receiverOpenHandler(serverReceiver -> {
LOG.trace("Server receiver opened");
serverReceiver.setAutoAccept(false);
serverReceiver.handler((delivery, msg) -> {
int msgNum = counter.incrementAndGet();
// We got the message that was sent, validate it
if (LOG.isTraceEnabled()) {
LOG.trace("Server got msg: " + getMessageBody(context, msg));
}
validateMessage(context, msgNum, String.valueOf(msgNum), msg);
switch(msgNum) {
case 1:
{
delivery.disposition(Accepted.getInstance(), true);
break;
}
case 2:
{
delivery.disposition(Released.getInstance(), true);
break;
}
case 3:
{
delivery.disposition(new Rejected(), true);
break;
}
case 4:
{
delivery.disposition(new Modified(), true);
break;
}
}
if (msgNum == messageCount) {
// Received all the messages
serverReceivedMessageAsync.complete();
}
});
serverReceiver.closeHandler(x -> {
serverReceiver.close();
serverLinkCloseAsync.complete();
});
// Set the local terminus details [naively]
serverReceiver.setTarget(serverReceiver.getRemoteTarget().copy());
serverReceiver.open();
serverLinkOpenAsync.complete();
});
});
// ===== Client Handling =====
ProtonClient client = ProtonClient.create(vertx);
client.connect("localhost", protonServer.actualPort(), res -> {
context.assertTrue(res.succeeded());
ProtonConnection connection = res.result();
connection.open();
ProtonSubscriber<Tracker> subscriber = ProtonStreams.createTrackerProducer(connection, "myAddress");
Tracker tracker1 = Tracker.create(message("1"), t -> {
context.assertTrue(t.isAccepted(), "msg should be accepted");
context.assertTrue(t.isRemotelySettled(), "msg should be remotely settled");
});
Tracker tracker2 = Tracker.create(message("2"), t -> {
context.assertFalse(t.isAccepted(), "msg should not be accepted");
context.assertTrue(t.getRemoteState() instanceof Released, "unexpected remote state: " + t.getRemoteState());
context.assertTrue(t.isRemotelySettled(), "msg should be remotely settled");
});
Tracker tracker3 = Tracker.create(message("3"), t -> {
context.assertFalse(t.isAccepted(), "msg should not be accepted");
context.assertTrue(t.getRemoteState() instanceof Rejected, "unexpected remote state: " + t.getRemoteState());
context.assertTrue(t.isRemotelySettled(), "msg should be remotely settled");
});
Tracker tracker4 = Tracker.create(message("4"), t -> {
context.assertFalse(t.isAccepted(), "msg should not be accepted");
context.assertTrue(t.getRemoteState() instanceof Modified, "unexpected remote state: " + t.getRemoteState());
context.assertTrue(t.isRemotelySettled(), "msg should be remotely settled");
});
Publisher<Tracker> producer = Flowable.just(tracker1, tracker2, tracker3, tracker4);
producer.subscribe(subscriber);
});
serverLinkOpenAsync.awaitSuccess();
serverReceivedMessageAsync.awaitSuccess();
serverLinkCloseAsync.awaitSuccess();
} finally {
if (protonServer != null) {
protonServer.close();
}
}
}
Aggregations