Search in sources :

Example 86 with AddressSettings

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();
}
Also used : Binding(org.apache.activemq.artemis.core.postoffice.Binding) AddressSettings(org.apache.activemq.artemis.core.settings.impl.AddressSettings) LastValueQueue(org.apache.activemq.artemis.core.server.impl.LastValueQueue) ClientSession(org.apache.activemq.artemis.api.core.client.ClientSession) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) Test(org.junit.Test)

Example 87 with AddressSettings

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();
}
Also used : AddressSettings(org.apache.activemq.artemis.core.settings.impl.AddressSettings) ServerSession(org.apache.activemq.artemis.core.server.ServerSession) ActiveMQDisconnectedException(org.apache.activemq.artemis.api.core.ActiveMQDisconnectedException) ClientMessage(org.apache.activemq.artemis.api.core.client.ClientMessage) ClientProducerImpl(org.apache.activemq.artemis.core.client.impl.ClientProducerImpl) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) ClientSession(org.apache.activemq.artemis.api.core.client.ClientSession) ServerSessionImpl(org.apache.activemq.artemis.core.server.impl.ServerSessionImpl) ClientSessionFactory(org.apache.activemq.artemis.api.core.client.ClientSessionFactory) ClientConsumer(org.apache.activemq.artemis.api.core.client.ClientConsumer) Test(org.junit.Test)

Example 88 with AddressSettings

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();
}
Also used : AddressSettings(org.apache.activemq.artemis.core.settings.impl.AddressSettings) ClientSession(org.apache.activemq.artemis.api.core.client.ClientSession) ClientMessage(org.apache.activemq.artemis.api.core.client.ClientMessage) ClientConsumer(org.apache.activemq.artemis.api.core.client.ClientConsumer) Test(org.junit.Test)

Example 89 with AddressSettings

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);
    }
}
Also used : ActiveMQServer(org.apache.activemq.artemis.core.server.ActiveMQServer) AddressSettings(org.apache.activemq.artemis.core.settings.impl.AddressSettings) Configuration(org.apache.activemq.artemis.core.config.Configuration) TransportConfiguration(org.apache.activemq.artemis.api.core.TransportConfiguration) HashMap(java.util.HashMap) TransportConfiguration(org.apache.activemq.artemis.api.core.TransportConfiguration)

Example 90 with AddressSettings

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!");
}
Also used : AddressSettings(org.apache.activemq.artemis.core.settings.impl.AddressSettings) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) ClientMessage(org.apache.activemq.artemis.api.core.client.ClientMessage) ClientConsumer(org.apache.activemq.artemis.api.core.client.ClientConsumer) ClientProducer(org.apache.activemq.artemis.api.core.client.ClientProducer) Test(org.junit.Test)

Aggregations

AddressSettings (org.apache.activemq.artemis.core.settings.impl.AddressSettings)273 SimpleString (org.apache.activemq.artemis.api.core.SimpleString)162 Test (org.junit.Test)161 ClientMessage (org.apache.activemq.artemis.api.core.client.ClientMessage)103 ClientProducer (org.apache.activemq.artemis.api.core.client.ClientProducer)103 ClientConsumer (org.apache.activemq.artemis.api.core.client.ClientConsumer)88 ClientSession (org.apache.activemq.artemis.api.core.client.ClientSession)81 ClientSessionFactory (org.apache.activemq.artemis.api.core.client.ClientSessionFactory)65 ActiveMQServer (org.apache.activemq.artemis.core.server.ActiveMQServer)54 Configuration (org.apache.activemq.artemis.core.config.Configuration)52 HashMap (java.util.HashMap)31 ServerLocator (org.apache.activemq.artemis.api.core.client.ServerLocator)30 Queue (org.apache.activemq.artemis.core.server.Queue)24 TransportConfiguration (org.apache.activemq.artemis.api.core.TransportConfiguration)21 Before (org.junit.Before)19 Session (javax.jms.Session)18 Message (org.apache.activemq.artemis.api.core.Message)18 ArrayList (java.util.ArrayList)15 PagingStore (org.apache.activemq.artemis.core.paging.PagingStore)15 ActiveMQBuffer (org.apache.activemq.artemis.api.core.ActiveMQBuffer)14