use of org.apache.activemq.artemis.core.settings.impl.AddressSettings in project activemq-artemis by apache.
the class SessionCreateAndDeleteQueueTest method testAddressSettingUSed.
@Test
public void testAddressSettingUSed() throws Exception {
server.getAddressSettingsRepository().addMatch(address.toString(), new AddressSettings().setDefaultLastValueQueue(true));
ClientSession session = createSessionFactory(locator).createSession(false, true, true);
SimpleString filterString = new SimpleString("x=y");
session.createQueue(address, queueName, filterString, false);
Binding binding = server.getPostOffice().getBinding(queueName);
Assert.assertTrue(binding.getBindable() instanceof LastValueQueue);
session.close();
}
use of org.apache.activemq.artemis.core.settings.impl.AddressSettings in project activemq-artemis by apache.
the class TemporaryQueueTest method testBlockingWithTemporaryQueue.
@Test
public void testBlockingWithTemporaryQueue() throws Exception {
AddressSettings setting = new AddressSettings().setAddressFullMessagePolicy(AddressFullMessagePolicy.BLOCK).setMaxSizeBytes(1024 * 1024);
server.getAddressSettingsRepository().addMatch("TestAD", setting);
ClientSessionFactory consumerCF = createSessionFactory(locator);
ClientSession consumerSession = consumerCF.createSession(true, true);
consumerSession.addMetaData("consumer", "consumer");
consumerSession.createTemporaryQueue("TestAD", "Q1");
consumerSession.createConsumer("Q1");
consumerSession.start();
final ClientProducerImpl prod = (ClientProducerImpl) session.createProducer("TestAD");
final AtomicInteger errors = new AtomicInteger(0);
final AtomicInteger msgs = new AtomicInteger(0);
final int TOTAL_MSG = 1000;
Thread t = new Thread() {
@Override
public void run() {
try {
for (int i = 0; i < TOTAL_MSG; i++) {
ClientMessage msg = session.createMessage(false);
msg.getBodyBuffer().writeBytes(new byte[1024]);
prod.send(msg);
msgs.incrementAndGet();
}
} catch (Throwable e) {
e.printStackTrace();
errors.incrementAndGet();
}
System.out.println("done");
}
};
t.start();
while (msgs.get() == 0) {
Thread.sleep(100);
}
int blockedTime = 0;
// https://issues.apache.org/jira/browse/ARTEMIS-368
while (t.isAlive() && errors.get() == 0 && (!prod.getProducerCredits().isBlocked() || blockedTime < 60)) {
if (prod.getProducerCredits().isBlocked()) {
blockedTime++;
} else {
blockedTime = 0;
}
Thread.sleep(100);
}
assertEquals(0, errors.get());
ClientSessionFactory newConsumerCF = createSessionFactory(locator);
ClientSession newConsumerSession = newConsumerCF.createSession(true, true);
newConsumerSession.createTemporaryQueue("TestAD", "Q2");
ClientConsumer newConsumer = newConsumerSession.createConsumer("Q2");
newConsumerSession.start();
int toReceive = TOTAL_MSG - msgs.get();
for (ServerSession sessionIterator : server.getSessions()) {
if (sessionIterator.getMetaData("consumer") != null) {
System.out.println("Failing session");
ServerSessionImpl impl = (ServerSessionImpl) sessionIterator;
impl.getRemotingConnection().fail(new ActiveMQDisconnectedException("failure e"));
}
}
int secondReceive = 0;
ClientMessage msg = null;
while (secondReceive < toReceive && (msg = newConsumer.receive(5000)) != null) {
msg.acknowledge();
secondReceive++;
}
assertNull(newConsumer.receiveImmediate());
assertEquals(toReceive, secondReceive);
t.join();
}
use of org.apache.activemq.artemis.core.settings.impl.AddressSettings in project activemq-artemis by apache.
the class ClientCrashTest method testCrashClient2.
@Test
public void testCrashClient2() throws Exception {
// set the redelivery delay to avoid an attempt to redeliver the message to the dead client
AddressSettings addressSettings = new AddressSettings().setRedeliveryDelay(ClientCrashTest.CONNECTION_TTL + ClientCrashTest.PING_PERIOD);
server.getAddressSettingsRepository().addMatch(ClientCrashTest.QUEUE2.toString(), addressSettings);
assertActiveConnections(1);
ClientSession session = sf.createSession(false, true, true);
session.createQueue(ClientCrashTest.QUEUE2, ClientCrashTest.QUEUE2, null, false);
// spawn a JVM that creates a Core client, which sends a message
Process p = SpawnedVMSupport.spawnVM(CrashClient2.class.getName());
ClientCrashTest.log.debug("waiting for the client VM to crash ...");
p.waitFor();
assertEquals(9, p.exitValue());
System.out.println("VM Exited");
long timeout = ClientCrashTest.CONNECTION_TTL + ClientCrashTest.PING_PERIOD + 10000;
assertActiveConnections(1, timeout);
assertActiveSession(1, timeout);
ClientConsumer consumer = session.createConsumer(ClientCrashTest.QUEUE2);
session.start();
// receive a message from the queue
ClientMessage messageFromClient = consumer.receive(timeout);
assertNotNull("no message received", messageFromClient);
assertEquals(ClientCrashTest.MESSAGE_TEXT_FROM_CLIENT, messageFromClient.getBodyBuffer().readString());
assertEquals("delivery count", 2, messageFromClient.getDeliveryCount());
consumer.close();
session.close();
}
use of org.apache.activemq.artemis.core.settings.impl.AddressSettings in project activemq-artemis by apache.
the class NIOvsOIOTest method testPerf.
private void testPerf(boolean nio) throws Exception {
Configuration config = createDefaultInVMConfig();
Map<String, Object> params = new HashMap<>();
params.put(TransportConstants.USE_NIO_PROP_NAME, nio);
config.getAcceptorConfigurations().add(new TransportConfiguration(NETTY_ACCEPTOR_FACTORY, params));
ActiveMQServer server = addServer(ActiveMQServers.newActiveMQServer(config, false));
AddressSettings addressSettings = new AddressSettings().setAddressFullMessagePolicy(AddressFullMessagePolicy.BLOCK).setMaxSizeBytes(10 * 1024 * 1024);
final String dest = "test-destination";
HierarchicalRepository<AddressSettings> repos = server.getAddressSettingsRepository();
repos.addMatch(dest, addressSettings);
server.start();
for (int i = 0; i < 2; i++) {
doTest(dest);
}
}
use of org.apache.activemq.artemis.core.settings.impl.AddressSettings in project activemq-artemis by apache.
the class NewDeadLetterAddressTest method testSendToDLAWhenNoRoute.
@Test
public void testSendToDLAWhenNoRoute() throws Exception {
SimpleString dla = new SimpleString("DLA");
SimpleString address = new SimpleString("empty_address");
AddressSettings addressSettings = new AddressSettings().setDeadLetterAddress(dla).setSendToDLAOnNoRoute(true);
server.getAddressSettingsRepository().addMatch(address.toString(), addressSettings);
SimpleString dlq = new SimpleString("DLQ1");
clientSession.createQueue(dla, dlq, null, false);
ClientProducer producer = clientSession.createProducer(address);
producer.send(createTextMessage(clientSession, "heyho!"));
clientSession.start();
ClientConsumer clientConsumer = clientSession.createConsumer(dlq);
ClientMessage m = clientConsumer.receive(500);
m.acknowledge();
Assert.assertNotNull(m);
Assert.assertEquals(m.getBodyBuffer().readString(), "heyho!");
}
Aggregations