Search in sources :

Example 56 with ClientSessionFactory

use of org.apache.activemq.artemis.api.core.client.ClientSessionFactory in project activemq-artemis by apache.

the class AckBatchSizeTest method getMessageEncodeSize.

/*ackbatchSize tests*/
/*
   * tests that wed don't acknowledge until the correct ackBatchSize is reached
   * */
private int getMessageEncodeSize(final SimpleString address) throws Exception {
    ServerLocator locator = createInVMNonHALocator();
    ClientSessionFactory cf = createSessionFactory(locator);
    ClientSession session = cf.createSession(false, true, true);
    ClientMessage message = session.createMessage(false);
    // we need to set the destination so we can calculate the encodesize correctly
    message.setAddress(address);
    int encodeSize = message.getEncodeSize();
    session.close();
    cf.close();
    return encodeSize;
}
Also used : ClientSession(org.apache.activemq.artemis.api.core.client.ClientSession) ClientSessionFactory(org.apache.activemq.artemis.api.core.client.ClientSessionFactory) ClientMessage(org.apache.activemq.artemis.api.core.client.ClientMessage) ServerLocator(org.apache.activemq.artemis.api.core.client.ServerLocator)

Example 57 with ClientSessionFactory

use of org.apache.activemq.artemis.api.core.client.ClientSessionFactory in project activemq-artemis by apache.

the class ActiveMQCrashTest method testHang.

@Test
public void testHang() throws Exception {
    Configuration configuration = createDefaultInVMConfig().setPersistenceEnabled(false);
    server = addServer(ActiveMQServers.newActiveMQServer(configuration));
    server.start();
    server.getRemotingService().addIncomingInterceptor(new AckInterceptor(server));
    // Force an ack at once - this means the send call will block
    locator.setConfirmationWindowSize(1);
    ClientSessionFactory clientSessionFactory = createSessionFactory(locator);
    ClientSession session = clientSessionFactory.createSession();
    session.setSendAcknowledgementHandler(new SendAcknowledgementHandler() {

        @Override
        public void sendAcknowledged(final Message message) {
            ackReceived = true;
        }
    });
    ClientProducer producer = session.createProducer("fooQueue");
    ClientMessage msg = session.createMessage(false);
    msg.putStringProperty("someKey", "someValue");
    producer.send(msg);
    Thread.sleep(250);
    Assert.assertFalse(ackReceived);
    session.close();
}
Also used : Configuration(org.apache.activemq.artemis.core.config.Configuration) 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) ClientSessionFactory(org.apache.activemq.artemis.api.core.client.ClientSessionFactory) ClientMessage(org.apache.activemq.artemis.api.core.client.ClientMessage) SendAcknowledgementHandler(org.apache.activemq.artemis.api.core.client.SendAcknowledgementHandler) ClientProducer(org.apache.activemq.artemis.api.core.client.ClientProducer) Test(org.junit.Test)

Example 58 with ClientSessionFactory

use of org.apache.activemq.artemis.api.core.client.ClientSessionFactory in project activemq-artemis by apache.

the class LargeMessageAvoidLargeMessagesTest method testMixedCompressionSendReceive.

@Test
public void testMixedCompressionSendReceive() throws Exception {
    ActiveMQServer server = createServer(true, isNetty());
    server.start();
    ClientSessionFactory sf = createSessionFactory(locator);
    ClientSession session = addClientSession(sf.createSession(false, false, false));
    session.createTemporaryQueue(ADDRESS, ADDRESS);
    ClientProducer producer = session.createProducer(ADDRESS);
    final int minLargeSize = locator.getMinLargeMessageSize();
    TestLargeMessageInputStream regularInput = new TestLargeMessageInputStream(minLargeSize);
    adjustLargeCompression(true, regularInput, 1024);
    TestLargeMessageInputStream largeInput = new TestLargeMessageInputStream(minLargeSize);
    largeInput.setSize(100 * minLargeSize);
    adjustLargeCompression(false, largeInput, 50 * minLargeSize);
    int num = 6;
    for (int i = 0; i < num; i++) {
        ClientMessage clientFile = session.createMessage(true);
        if (i % 2 == 0) {
            clientFile.setBodyInputStream(regularInput.clone());
        } else {
            clientFile.setBodyInputStream(largeInput.clone());
        }
        producer.send(clientFile);
    }
    session.commit();
    session.start();
    // half the messages are sent as large
    validateNoFilesOnLargeDir(server.getConfiguration().getLargeMessagesDirectory(), num / 2);
    ClientConsumer consumer = session.createConsumer(ADDRESS);
    for (int j = 0; j < num; j++) {
        ClientMessage msg1 = consumer.receive(1000);
        Assert.assertNotNull(msg1);
        if (j % 2 == 0) {
            for (int i = 0; i < regularInput.getSize(); i++) {
                byte b = msg1.getBodyBuffer().readByte();
                Assert.assertEquals("incorrect char ", regularInput.getChar(i), b);
            }
        } else {
            for (int i = 0; i < largeInput.getSize(); i++) {
                byte b = msg1.getBodyBuffer().readByte();
                Assert.assertEquals("incorrect char ", largeInput.getChar(i), b);
            }
        }
        msg1.acknowledge();
    }
    session.commit();
    consumer.close();
    session.close();
}
Also used : ActiveMQServer(org.apache.activemq.artemis.core.server.ActiveMQServer) ClientSession(org.apache.activemq.artemis.api.core.client.ClientSession) ClientSessionFactory(org.apache.activemq.artemis.api.core.client.ClientSessionFactory) 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)

Example 59 with ClientSessionFactory

use of org.apache.activemq.artemis.api.core.client.ClientSessionFactory in project activemq-artemis by apache.

the class LargeMessageTest method internalTestResendMessage.

public void internalTestResendMessage(final long messageSize) throws Exception {
    clearDataRecreateServerDirs();
    ClientSession session = null;
    try {
        ActiveMQServer server = createServer(true, isNetty(), storeType);
        server.start();
        ClientSessionFactory sf = addSessionFactory(createSessionFactory(locator));
        session = sf.createSession(false, false, false);
        session.createQueue(ADDRESS, ADDRESS, true);
        SimpleString ADDRESS2 = ADDRESS.concat("-2");
        session.createQueue(ADDRESS2, ADDRESS2, true);
        ClientProducer producer = session.createProducer(ADDRESS);
        ClientProducer producer2 = session.createProducer(ADDRESS2);
        Message clientFile = createLargeClientMessageStreaming(session, messageSize, false);
        producer.send(clientFile);
        session.commit();
        session.start();
        ClientConsumer consumer = session.createConsumer(ADDRESS);
        ClientConsumer consumer2 = session.createConsumer(ADDRESS2);
        ClientMessage msg1 = consumer.receive(10000);
        msg1.acknowledge();
        producer2.send(msg1);
        session.commit();
        ClientMessage msg2 = consumer2.receive(10000);
        Assert.assertNotNull(msg2);
        msg2.acknowledge();
        session.commit();
        Assert.assertEquals(messageSize, msg2.getBodySize());
        compareString(messageSize, msg2);
        session.close();
        validateNoFilesOnLargeDir();
    } finally {
        try {
            session.close();
        } catch (Throwable ignored) {
        }
    }
}
Also used : ActiveMQServer(org.apache.activemq.artemis.core.server.ActiveMQServer) 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) ClientSessionFactory(org.apache.activemq.artemis.api.core.client.ClientSessionFactory) 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)

Example 60 with ClientSessionFactory

use of org.apache.activemq.artemis.api.core.client.ClientSessionFactory in project activemq-artemis by apache.

the class LargeMessageTest method testDeleteOnDrop.

@Test
public void testDeleteOnDrop() throws Exception {
    fillAddress();
    final int messageSize = (int) (3.5 * ActiveMQClient.DEFAULT_MIN_LARGE_MESSAGE_SIZE);
    ClientSessionFactory sf = addSessionFactory(createSessionFactory(locator));
    ClientSession session = addClientSession(sf.createSession(false, true, false));
    ClientProducer producer = session.createProducer(ADDRESS);
    Message clientFile = createLargeClientMessageStreaming(session, messageSize, true);
    // Send large message which should be dropped and deleted from the filesystem
    producer.send(clientFile);
    validateNoFilesOnLargeDir();
}
Also used : 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) ClientSessionFactory(org.apache.activemq.artemis.api.core.client.ClientSessionFactory) ClientProducer(org.apache.activemq.artemis.api.core.client.ClientProducer) Test(org.junit.Test)

Aggregations

ClientSessionFactory (org.apache.activemq.artemis.api.core.client.ClientSessionFactory)601 ClientSession (org.apache.activemq.artemis.api.core.client.ClientSession)518 Test (org.junit.Test)464 ClientProducer (org.apache.activemq.artemis.api.core.client.ClientProducer)395 ClientMessage (org.apache.activemq.artemis.api.core.client.ClientMessage)372 ClientConsumer (org.apache.activemq.artemis.api.core.client.ClientConsumer)350 ServerLocator (org.apache.activemq.artemis.api.core.client.ServerLocator)277 SimpleString (org.apache.activemq.artemis.api.core.SimpleString)254 ActiveMQServer (org.apache.activemq.artemis.core.server.ActiveMQServer)206 ActiveMQException (org.apache.activemq.artemis.api.core.ActiveMQException)108 Configuration (org.apache.activemq.artemis.core.config.Configuration)78 AddressSettings (org.apache.activemq.artemis.core.settings.impl.AddressSettings)65 TransportConfiguration (org.apache.activemq.artemis.api.core.TransportConfiguration)63 CountDownLatch (java.util.concurrent.CountDownLatch)54 Queue (org.apache.activemq.artemis.core.server.Queue)49 ArrayList (java.util.ArrayList)44 HashMap (java.util.HashMap)43 HashSet (java.util.HashSet)42 ActiveMQJAASSecurityManager (org.apache.activemq.artemis.spi.core.security.ActiveMQJAASSecurityManager)42 Message (org.apache.activemq.artemis.api.core.Message)41