use of org.eclipse.hono.client.MessageSender in project hono by eclipse.
the class AbstractStandaloneApiTest method testMessageUploadSucceedsForRegisteredDevice.
/**
* Verifies that proper messages are forwarded downstream.
*
* @param ctx The vert.x test context.
*/
@Test
public void testMessageUploadSucceedsForRegisteredDevice(final TestContext ctx) {
int count = 30;
final Async messagesReceived = ctx.async(count);
downstreamAdapter.setMessageConsumer(msg -> {
messagesReceived.countDown();
LOG.debug("received message [id: {}]", msg.getMessageId());
});
String registrationAssertion = getAssertion(Constants.DEFAULT_TENANT, DEVICE_1);
LOG.debug("got registration assertion for device [{}]: {}", DEVICE_1, registrationAssertion);
final AtomicReference<MessageSender> senderRef = new AtomicReference<>();
final Async senderCreation = ctx.async();
getSender(Constants.DEFAULT_TENANT).setHandler(ctx.asyncAssertSuccess(sender -> {
senderRef.set(sender);
senderCreation.complete();
}));
senderCreation.await();
IntStream.range(0, count).forEach(i -> {
Async waitForCredit = ctx.async();
LOG.trace("sending message {}", i);
senderRef.get().send(DEVICE_1, "payload" + i, "text/plain; charset=utf-8", registrationAssertion, done -> waitForCredit.complete());
waitForCredit.await();
});
}
use of org.eclipse.hono.client.MessageSender in project hono by eclipse.
the class TelemetrySenderImplTest method testSendMessageFailsOnLackOfCredit.
/**
* Verifies that the sender fails if no credit is available.
*
* @param ctx The vert.x test context.
*/
@SuppressWarnings("unchecked")
@Test
public void testSendMessageFailsOnLackOfCredit(final TestContext ctx) {
// GIVEN a sender that has no credit
when(sender.sendQueueFull()).thenReturn(Boolean.TRUE);
MessageSender messageSender = new TelemetrySenderImpl(config, sender, "tenant", "telemetry/tenant", context);
// WHEN trying to send a message
final Future<ProtonDelivery> result = messageSender.send("device", "some payload", "application/text", "token");
// THEN the message is not sent
assertFalse(result.succeeded());
verify(sender, never()).send(any(Message.class), any(Handler.class));
}
Aggregations