use of org.apache.activemq.transport.amqp.client.AmqpValidator in project activemq-artemis by apache.
the class AmqpSecurityTest method testSendAndRejected.
@Test(timeout = 60000)
public void testSendAndRejected() throws Exception {
AmqpClient client = createAmqpClient(guestUser, guestPass);
client.setValidator(new AmqpValidator() {
@Override
public void inspectOpenedResource(Sender sender) {
ErrorCondition condition = sender.getRemoteCondition();
if (condition != null && condition.getCondition() != null) {
if (!condition.getCondition().equals(AmqpError.UNAUTHORIZED_ACCESS)) {
markAsInvalid("Should have been tagged with unauthorized access error");
}
} else {
markAsInvalid("Sender should have been opened with an error");
}
}
});
AmqpConnection connection = addConnection(client.connect());
AmqpSession session = connection.createSession();
try {
try {
session.createSender(getQueueName());
fail("Should not be able to consume here.");
} catch (Exception ex) {
IntegrationTestLogger.LOGGER.info("Caught expected exception");
}
connection.getStateInspector().assertValid();
} finally {
connection.close();
}
}
use of org.apache.activemq.transport.amqp.client.AmqpValidator in project activemq-artemis by apache.
the class AmqpSecurityTest method testConsumerNotAuthorizedToCreateQueues.
@Test(timeout = 30000)
public void testConsumerNotAuthorizedToCreateQueues() throws Exception {
AmqpClient client = createAmqpClient(noprivUser, noprivPass);
client.setValidator(new AmqpValidator() {
@Override
public void inspectOpenedResource(Sender sender) {
ErrorCondition condition = sender.getRemoteCondition();
if (condition != null && condition.getCondition() != null) {
if (!condition.getCondition().equals(AmqpError.UNAUTHORIZED_ACCESS)) {
markAsInvalid("Should have been tagged with unauthorized access error");
}
} else {
markAsInvalid("Sender should have been opened with an error");
}
}
});
AmqpConnection connection = client.connect();
try {
AmqpSession session = connection.createSession();
try {
session.createReceiver(getQueueName(getPrecreatedQueueSize() + 1));
fail("Should not be able to consume here.");
} catch (Exception ex) {
IntegrationTestLogger.LOGGER.info("Caught expected exception");
}
connection.getStateInspector().assertValid();
} finally {
connection.close();
}
}
use of org.apache.activemq.transport.amqp.client.AmqpValidator in project activemq-artemis by apache.
the class AmqpSecurityTest method testReceiverNotAuthorized.
@Test(timeout = 30000)
public void testReceiverNotAuthorized() throws Exception {
AmqpClient client = createAmqpClient(noprivUser, noprivPass);
client.setValidator(new AmqpValidator() {
@Override
public void inspectOpenedResource(Receiver receiver) {
ErrorCondition condition = receiver.getRemoteCondition();
if (condition != null && condition.getCondition() != null) {
if (!condition.getCondition().equals(AmqpError.UNAUTHORIZED_ACCESS)) {
markAsInvalid("Should have been tagged with unauthorized access error");
}
} else {
markAsInvalid("Receiver should have been opened with an error");
}
}
});
AmqpConnection connection = client.connect();
try {
AmqpSession session = connection.createSession();
try {
session.createReceiver(getQueueName());
fail("Should not be able to consume here.");
} catch (Exception ex) {
IntegrationTestLogger.LOGGER.info("Caught expected exception");
}
connection.getStateInspector().assertValid();
} finally {
connection.close();
}
}
use of org.apache.activemq.transport.amqp.client.AmqpValidator in project activemq-artemis by apache.
the class AmqpSenderTest method testUnsettledSender.
@Test(timeout = 60000)
public void testUnsettledSender() throws Exception {
final int MSG_COUNT = 1000;
final CountDownLatch settled = new CountDownLatch(MSG_COUNT);
AmqpClient client = createAmqpClient();
AmqpConnection connection = addConnection(client.connect());
connection.setStateInspector(new AmqpValidator() {
@Override
public void inspectDeliveryUpdate(Sender sender, Delivery delivery) {
if (delivery.remotelySettled()) {
IntegrationTestLogger.LOGGER.trace("Remote settled message for sender: " + sender.getName());
settled.countDown();
}
}
});
AmqpSession session = connection.createSession();
AmqpSender sender = session.createSender(getQueueName(), false);
for (int i = 1; i <= MSG_COUNT; ++i) {
AmqpMessage message = new AmqpMessage();
message.setText("Test-Message: " + i);
sender.send(message);
if (i % 1000 == 0) {
IntegrationTestLogger.LOGGER.info("Sent message: " + i);
}
}
Queue queueView = getProxyToQueue(getQueueName());
Wait.assertTrue("All messages should arrive", () -> queueView.getMessageCount() == MSG_COUNT);
sender.close();
assertTrue("Remote should have settled all deliveries", settled.await(5, TimeUnit.MINUTES));
connection.close();
}
use of org.apache.activemq.transport.amqp.client.AmqpValidator in project activemq-artemis by apache.
the class AmqpSessionTest method testSessionClosedDoesNotGetReceiverDetachFromRemote.
@Test(timeout = 60000)
public void testSessionClosedDoesNotGetReceiverDetachFromRemote() throws Exception {
AmqpClient client = createAmqpClient();
assertNotNull(client);
client.setValidator(new AmqpValidator() {
@Override
public void inspectClosedResource(Session session) {
IntegrationTestLogger.LOGGER.info("Session closed: " + session.getContext());
}
@Override
public void inspectDetachedResource(Receiver receiver) {
markAsInvalid("Broker should not detach receiver linked to closed session.");
}
@Override
public void inspectClosedResource(Receiver receiver) {
markAsInvalid("Broker should not close receiver linked to closed session.");
}
});
AmqpConnection connection = addConnection(client.connect());
assertNotNull(connection);
AmqpSession session = connection.createSession();
assertNotNull(session);
AmqpReceiver receiver = session.createReceiver(getQueueName());
assertNotNull(receiver);
session.close();
connection.getStateInspector().assertValid();
connection.close();
}
Aggregations