Search in sources :

Example 96 with AddressSettings

use of org.apache.activemq.artemis.core.settings.impl.AddressSettings in project activemq-artemis by apache.

the class TwoWayTwoNodeClusterTest method testClusterRestartWithConfigChanged.

/*
    * This test starts 2 servers and send messages to
    * a queue until it enters into paging state. Then
    * it changes the max-size to -1, restarts the 2 servers
    * and consumes all the messages. If verifies that
    * even if the max-size has changed all the paged
    * messages will be depaged and consumed. No stuck
    * messages after restarting.
    */
@Test(timeout = 60000)
public void testClusterRestartWithConfigChanged() throws Exception {
    Configuration config0 = servers[0].getConfiguration();
    Configuration config1 = servers[1].getConfiguration();
    configureBeforeStart(config0, config1);
    startServers(0, 1);
    setupSessionFactory(0, isNetty());
    setupSessionFactory(1, isNetty());
    createQueue(0, "queues", "queue0", null, true);
    createQueue(1, "queues", "queue0", null, true);
    waitForBindings(0, "queues", 1, 0, true);
    waitForBindings(1, "queues", 1, 0, true);
    waitForBindings(0, "queues", 1, 0, false);
    waitForBindings(1, "queues", 1, 0, false);
    ClientSessionFactory sf0 = sfs[0];
    ClientSession session0 = sf0.createSession(false, false);
    ClientProducer producer = session0.createProducer("queues");
    final int numSent = 200;
    for (int i = 0; i < numSent; i++) {
        ClientMessage msg = createTextMessage(session0, true, 5000);
        producer.send(msg);
        if (i % 50 == 0) {
            session0.commit();
        }
    }
    session0.commit();
    session0.close();
    while (true) {
        long msgCount0 = getMessageCount(servers[0], "queues");
        long msgCount1 = getMessageCount(servers[1], "queues");
        if (msgCount0 + msgCount1 >= numSent) {
            break;
        }
        Thread.sleep(100);
    }
    Queue queue0 = servers[0].locateQueue(new SimpleString("queue0"));
    assertTrue(queue0.getPageSubscription().isPaging());
    closeAllSessionFactories();
    stopServers(0, 1);
    AddressSettings addressSettings0 = config0.getAddressesSettings().get("#");
    AddressSettings addressSettings1 = config1.getAddressesSettings().get("#");
    addressSettings0.setMaxSizeBytes(-1);
    addressSettings1.setMaxSizeBytes(-1);
    startServers(0, 1);
    waitForBindings(0, "queues", 1, 0, true);
    waitForBindings(1, "queues", 1, 0, true);
    waitForBindings(0, "queues", 1, 0, false);
    waitForBindings(1, "queues", 1, 0, false);
    setupSessionFactory(0, isNetty());
    addConsumer(0, 0, "queue0", null);
    waitForBindings(0, "queues", 1, 1, true);
    for (int i = 0; i < numSent; i++) {
        ClientMessage m = consumers[0].consumer.receive(5000);
        assertNotNull("failed to receive message " + i, m);
    }
}
Also used : AddressSettings(org.apache.activemq.artemis.core.settings.impl.AddressSettings) Configuration(org.apache.activemq.artemis.core.config.Configuration) ClientSession(org.apache.activemq.artemis.api.core.client.ClientSession) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) ClientSessionFactory(org.apache.activemq.artemis.api.core.client.ClientSessionFactory) ClientMessage(org.apache.activemq.artemis.api.core.client.ClientMessage) ClientProducer(org.apache.activemq.artemis.api.core.client.ClientProducer) Queue(org.apache.activemq.artemis.core.server.Queue) Test(org.junit.Test)

Example 97 with AddressSettings

use of org.apache.activemq.artemis.core.settings.impl.AddressSettings in project activemq-artemis by apache.

the class StompTest method testSendMessageToNonExistentQueueUsingExplicitDefaultRouting.

@Test
public void testSendMessageToNonExistentQueueUsingExplicitDefaultRouting() throws Exception {
    String nonExistentQueue = RandomUtil.randomString();
    server.getActiveMQServer().getAddressSettingsRepository().addMatch(nonExistentQueue, new AddressSettings().setDefaultAddressRoutingType(RoutingType.ANYCAST).setDefaultQueueRoutingType(RoutingType.ANYCAST));
    sendMessageToNonExistentQueue(getQueuePrefix(), nonExistentQueue, null);
}
Also used : AddressSettings(org.apache.activemq.artemis.core.settings.impl.AddressSettings) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) Test(org.junit.Test)

Example 98 with AddressSettings

use of org.apache.activemq.artemis.core.settings.impl.AddressSettings in project activemq-artemis by apache.

the class StompTest method testAutoCreatedAnycastAddress.

@Test
public void testAutoCreatedAnycastAddress() throws Exception {
    conn.connect(defUser, defPass);
    String queueName = UUID.randomUUID().toString();
    SimpleString simpleQueueName = SimpleString.toSimpleString(queueName);
    ActiveMQServer activeMQServer = server.getActiveMQServer();
    Assert.assertNull(activeMQServer.getAddressInfo(simpleQueueName));
    Assert.assertNull(activeMQServer.locateQueue(simpleQueueName));
    activeMQServer.getAddressSettingsRepository().addMatch(queueName, new AddressSettings().setDefaultAddressRoutingType(RoutingType.ANYCAST).setDefaultQueueRoutingType(RoutingType.ANYCAST));
    send(conn, queueName, null, "Hello ANYCAST");
    assertTrue("Address and queue should be created now", Wait.waitFor(() -> (activeMQServer.getAddressInfo(simpleQueueName) != null) && (activeMQServer.locateQueue(simpleQueueName) != null), 2000, 200));
    assertTrue(activeMQServer.getAddressInfo(simpleQueueName).getRoutingTypes().contains(RoutingType.ANYCAST));
    assertEquals(RoutingType.ANYCAST, activeMQServer.locateQueue(simpleQueueName).getRoutingType());
}
Also used : ActiveMQServer(org.apache.activemq.artemis.core.server.ActiveMQServer) AddressSettings(org.apache.activemq.artemis.core.settings.impl.AddressSettings) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) Test(org.junit.Test)

Example 99 with AddressSettings

use of org.apache.activemq.artemis.core.settings.impl.AddressSettings in project activemq-artemis by apache.

the class MultipliedDelayedMessageTest method initServer.

/**
 * @throws Exception
 */
protected void initServer() throws Exception {
    server = createServer(true, createDefaultInVMConfig());
    server.start();
    // Create settings to enable multiplied redelivery delay
    AddressSettings addressSettings = server.getAddressSettingsRepository().getMatch("*");
    AddressSettings newAddressSettings = new AddressSettings().setRedeliveryDelay(DELAY).setRedeliveryMultiplier(MULTIPLIER).setMaxRedeliveryDelay(MAX_DELAY);
    newAddressSettings.merge(addressSettings);
    server.getAddressSettingsRepository().addMatch(queueName, newAddressSettings);
    locator = createInVMNonHALocator();
}
Also used : AddressSettings(org.apache.activemq.artemis.core.settings.impl.AddressSettings)

Example 100 with AddressSettings

use of org.apache.activemq.artemis.core.settings.impl.AddressSettings in project activemq-artemis by apache.

the class ScaleDownDirectTest method testPaging.

@Test
public void testPaging() throws Exception {
    final int CHUNK_SIZE = 50;
    int messageCount = 0;
    final String addressName = "testAddress";
    final String queueName = "testQueue";
    createQueue(0, addressName, queueName, null, true);
    createQueue(1, addressName, queueName, null, true);
    ClientSessionFactory sf = sfs[0];
    ClientSession session = addClientSession(sf.createSession(false, false));
    ClientProducer producer = addClientProducer(session.createProducer(addressName));
    AddressSettings defaultSetting = new AddressSettings().setPageSizeBytes(10 * 1024).setMaxSizeBytes(20 * 1024);
    servers[0].getAddressSettingsRepository().addMatch("#", defaultSetting);
    while (!servers[0].getPagingManager().getPageStore(new SimpleString(addressName)).isPaging()) {
        for (int i = 0; i < CHUNK_SIZE; i++) {
            Message message = session.createMessage(true);
            message.getBodyBuffer().writeBytes(new byte[1024]);
            // The only purpose of this count here is for eventually debug messages on print-data / print-pages
            // message.putIntProperty("count", messageCount);
            producer.send(message);
            messageCount++;
        }
        session.commit();
    }
    assertEquals(messageCount, performScaledown());
    servers[0].stop();
    addConsumer(0, 1, queueName, null);
    for (int i = 0; i < messageCount; i++) {
        ClientMessage message = consumers[0].getConsumer().receive(500);
        Assert.assertNotNull(message);
    // Assert.assertEquals(i, message.getIntProperty("count").intValue());
    }
    Assert.assertNull(consumers[0].getConsumer().receiveImmediate());
    removeConsumer(0);
}
Also used : AddressSettings(org.apache.activemq.artemis.core.settings.impl.AddressSettings) ClientMessage(org.apache.activemq.artemis.api.core.client.ClientMessage) Message(org.apache.activemq.artemis.api.core.Message) ClientSession(org.apache.activemq.artemis.api.core.client.ClientSession) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) ClientSessionFactory(org.apache.activemq.artemis.api.core.client.ClientSessionFactory) ClientMessage(org.apache.activemq.artemis.api.core.client.ClientMessage) 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