use of org.apache.activemq.transport.amqp.client.AmqpSession in project activemq-artemis by apache.
the class AmqpReceiverTest method testLinkDetatchErrorIsCorrectWhenQueueDoesNotExists.
@Test(timeout = 60000)
public void testLinkDetatchErrorIsCorrectWhenQueueDoesNotExists() throws Exception {
AddressSettings value = new AddressSettings();
value.setAutoCreateQueues(false);
value.setAutoCreateAddresses(false);
server.getAddressSettingsRepository().addMatch("AnAddressThatDoesNotExist", value);
AmqpClient client = createAmqpClient();
AmqpConnection connection = addConnection(client.connect());
try {
AmqpSession session = connection.createSession();
Exception expectedException = null;
try {
session.createSender("AnAddressThatDoesNotExist");
fail("Creating a sender here on an address that doesn't exist should fail");
} catch (Exception e) {
expectedException = e;
}
assertNotNull(expectedException);
assertTrue(expectedException.getMessage().contains("amqp:not-found"));
assertTrue(expectedException.getMessage().contains("target address does not exist"));
} finally {
connection.close();
}
}
use of org.apache.activemq.transport.amqp.client.AmqpSession in project activemq-artemis by apache.
the class AmqpReceiverTest method testCreateQueueReceiverWithJMSSelector.
@Test(timeout = 60000)
public void testCreateQueueReceiverWithJMSSelector() throws Exception {
AmqpClient client = createAmqpClient();
client.setValidator(new AmqpValidator() {
@SuppressWarnings("unchecked")
@Override
public void inspectOpenedResource(Receiver receiver) {
if (receiver.getRemoteSource() == null) {
markAsInvalid("Link opened with null source.");
}
Source source = (Source) receiver.getRemoteSource();
Map<Symbol, Object> filters = source.getFilter();
if (findFilter(filters, JMS_SELECTOR_FILTER_IDS) == null) {
markAsInvalid("Broker did not return the JMS Filter on Attach");
}
}
});
AmqpConnection connection = addConnection(client.connect());
AmqpSession session = connection.createSession();
session.createReceiver(getQueueName(), "JMSPriority > 8");
connection.getStateInspector().assertValid();
connection.close();
}
use of org.apache.activemq.transport.amqp.client.AmqpSession in project activemq-artemis by apache.
the class AmqpReceiverTest method testClientIdIsSetInSubscriptionList.
@Test(timeout = 60000)
public void testClientIdIsSetInSubscriptionList() throws Exception {
server.addAddressInfo(new AddressInfo(SimpleString.toSimpleString("mytopic"), RoutingType.ANYCAST));
AmqpClient client = createAmqpClient();
AmqpConnection connection = addConnection(client.connect());
connection.setContainerId("testClient");
connection.connect();
try {
AmqpSession session = connection.createSession();
Source source = new Source();
source.setDurable(TerminusDurability.UNSETTLED_STATE);
source.setCapabilities(Symbol.getSymbol("topic"));
source.setAddress("mytopic");
session.createReceiver(source, "testSub");
SimpleString fo = new SimpleString("testClient.testSub:mytopic");
assertNotNull(server.locateQueue(fo));
} catch (Exception e) {
e.printStackTrace();
} finally {
connection.close();
}
}
use of org.apache.activemq.transport.amqp.client.AmqpSession in project activemq-artemis by apache.
the class AmqpReceiverWithFiltersTest method testSupportedFiltersAreListedAsSupported.
@Test(timeout = 60000)
public void testSupportedFiltersAreListedAsSupported() throws Exception {
AmqpClient client = createAmqpClient();
client.setValidator(new AmqpValidator() {
@SuppressWarnings("unchecked")
@Override
public void inspectOpenedResource(Receiver receiver) {
if (receiver.getRemoteSource() == null) {
markAsInvalid("Link opened with null source.");
}
Source source = (Source) receiver.getRemoteSource();
Map<Symbol, Object> filters = source.getFilter();
if (findFilter(filters, AmqpSupport.JMS_SELECTOR_FILTER_IDS) == null) {
markAsInvalid("Broker should return selector filter on attach.");
}
}
});
AmqpConnection connection = addConnection(client.connect());
AmqpSession session = connection.createSession();
session.createReceiver(getQueueName(), "color = red");
connection.getStateInspector().assertValid();
connection.close();
}
use of org.apache.activemq.transport.amqp.client.AmqpSession in project activemq-artemis by apache.
the class AmqpReceiverWithFiltersTest method testReceivedUnsignedFilter.
@Test(timeout = 60000)
public void testReceivedUnsignedFilter() throws Exception {
final int NUM_MESSAGES = 100;
AmqpClient client = createAmqpClient();
AmqpConnection connection = client.connect();
try {
// Normal Session which won't create an TXN itself
AmqpSession session = connection.createSession();
AmqpSender sender = session.createSender(getQueueName());
for (int i = 0; i < NUM_MESSAGES + 1; ++i) {
AmqpMessage message = new AmqpMessage();
message.setText("Test-Message");
message.setApplicationProperty("myNewID", new UnsignedInteger(i));
sender.send(message);
}
// Read all messages from the Queue, do not accept them yet.
AmqpReceiver receiver = session.createReceiver(getQueueName(), "myNewID < " + (NUM_MESSAGES / 2));
ArrayList<AmqpMessage> messages = new ArrayList<>(NUM_MESSAGES);
receiver.flow((NUM_MESSAGES + 2) * 2);
for (int i = 0; i < NUM_MESSAGES / 2; ++i) {
AmqpMessage message = receiver.receive(5, TimeUnit.SECONDS);
Assert.assertNotNull(message);
System.out.println("Read message: " + message.getApplicationProperty("myNewID"));
assertNotNull(message);
messages.add(message);
}
Assert.assertNull(receiver.receiveNoWait());
} finally {
connection.close();
}
}
Aggregations