Search in sources :

Example 46 with Message

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

the class ClientCrashTest method testCrashClient.

// Constructors --------------------------------------------------
// Public --------------------------------------------------------
@Test
public void testCrashClient() throws Exception {
    assertActiveConnections(1);
    ClientSession session = sf.createSession(false, true, true);
    session.createQueue(ClientCrashTest.QUEUE, ClientCrashTest.QUEUE, null, false);
    // spawn a JVM that creates a Core client, which sends a message
    // It has to be spawned after the queue was created.
    // if the client is too fast you race the send before the queue was created, missing a message
    Process p = SpawnedVMSupport.spawnVM(CrashClient.class.getName());
    ClientConsumer consumer = session.createConsumer(ClientCrashTest.QUEUE);
    ClientProducer producer = session.createProducer(ClientCrashTest.QUEUE);
    session.start();
    // receive a message from the queue
    Message messageFromClient = consumer.receive(5000);
    assertNotNull("no message received", messageFromClient);
    assertEquals(ClientCrashTest.MESSAGE_TEXT_FROM_CLIENT, messageFromClient.getBodyBuffer().readString());
    // One local and one from the other vm
    assertActiveConnections(1 + 1);
    assertActiveSession(1 + 1);
    ClientMessage message = session.createMessage(ActiveMQTextMessage.TYPE, false, 0, System.currentTimeMillis(), (byte) 1);
    message.getBodyBuffer().writeString(ClientCrashTest.MESSAGE_TEXT_FROM_SERVER);
    producer.send(message);
    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);
    session.close();
    // the crash must have been detected and the resources cleaned up
    assertActiveConnections(1);
    assertActiveSession(0);
}
Also used : ActiveMQTextMessage(org.apache.activemq.artemis.jms.client.ActiveMQTextMessage) 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) 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 47 with Message

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

the class CompactingStressTest method internalTestCleanup.

private void internalTestCleanup(final JournalType journalType) throws Throwable {
    setupServer(journalType);
    ClientSession session = sf.createSession(false, true, true);
    ClientProducer prod = session.createProducer(CompactingStressTest.AD1);
    for (int i = 0; i < 500; i++) {
        prod.send(session.createMessage(true));
    }
    session.commit();
    prod.close();
    ClientConsumer cons = session.createConsumer(CompactingStressTest.Q2);
    prod = session.createProducer(CompactingStressTest.AD2);
    session.start();
    for (int i = 0; i < 200; i++) {
        System.out.println("Iteration " + i);
        // Sending non transactionally, so it would test non transactional stuff on the journal
        for (int j = 0; j < 1000; j++) {
            Message msg = session.createMessage(true);
            msg.getBodyBuffer().writeBytes(new byte[1024]);
            prod.send(msg);
        }
        // I need to guarantee a roundtrip to the server, to make sure everything is persisted
        session.commit();
        for (int j = 0; j < 1000; j++) {
            ClientMessage msg = cons.receive(2000);
            Assert.assertNotNull(msg);
            msg.acknowledge();
        }
        // I need to guarantee a roundtrip to the server, to make sure everything is persisted
        session.commit();
    }
    Assert.assertNull(cons.receiveImmediate());
    session.close();
    server.stop();
    setupServer(journalType);
    server.start();
    session = sf.createSession(false, true, true);
    cons = session.createConsumer(CompactingStressTest.Q1);
    session.start();
    for (int i = 0; i < 500; i++) {
        ClientMessage msg = cons.receive(1000);
        Assert.assertNotNull(msg);
        msg.acknowledge();
    }
    Assert.assertNull(cons.receiveImmediate());
    prod = session.createProducer(CompactingStressTest.AD2);
    session.close();
}
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) 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 48 with Message

use of org.apache.activemq.artemis.api.core.Message 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)

Example 49 with Message

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

the class CoreClientOverOneWaySSLTest method testOneWaySSLWithGoodClientProtocol.

@Test
public void testOneWaySSLWithGoodClientProtocol() throws Exception {
    createCustomSslServer();
    String text = RandomUtil.randomString();
    tc.getParams().put(TransportConstants.SSL_ENABLED_PROP_NAME, true);
    tc.getParams().put(TransportConstants.TRUSTSTORE_PROVIDER_PROP_NAME, storeType);
    tc.getParams().put(TransportConstants.TRUSTSTORE_PATH_PROP_NAME, CLIENT_SIDE_TRUSTSTORE);
    tc.getParams().put(TransportConstants.TRUSTSTORE_PASSWORD_PROP_NAME, PASSWORD);
    tc.getParams().put(TransportConstants.ENABLED_PROTOCOLS_PROP_NAME, "TLSv1");
    ServerLocator locator = addServerLocator(ActiveMQClient.createServerLocatorWithoutHA(tc));
    ClientSessionFactory sf = null;
    try {
        sf = createSessionFactory(locator);
        Assert.assertTrue(true);
    } catch (ActiveMQNotConnectedException e) {
        Assert.fail();
    }
    ClientSession session = sf.createSession(false, true, true);
    session.createQueue(CoreClientOverOneWaySSLTest.QUEUE, CoreClientOverOneWaySSLTest.QUEUE, false);
    ClientProducer producer = session.createProducer(CoreClientOverOneWaySSLTest.QUEUE);
    ClientMessage message = createTextMessage(session, text);
    producer.send(message);
    ClientConsumer consumer = session.createConsumer(CoreClientOverOneWaySSLTest.QUEUE);
    session.start();
    Message m = consumer.receive(1000);
    Assert.assertNotNull(m);
    Assert.assertEquals(text, m.getBodyBuffer().readString());
}
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) ActiveMQNotConnectedException(org.apache.activemq.artemis.api.core.ActiveMQNotConnectedException) 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) ServerLocator(org.apache.activemq.artemis.api.core.client.ServerLocator) Test(org.junit.Test)

Example 50 with Message

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

the class CoreClientOverOneWaySSLTest method testOneWaySSLWithGoodServerProtocol.

@Test
public void testOneWaySSLWithGoodServerProtocol() throws Exception {
    createCustomSslServer(null, "TLSv1");
    String text = RandomUtil.randomString();
    tc.getParams().put(TransportConstants.SSL_ENABLED_PROP_NAME, true);
    tc.getParams().put(TransportConstants.TRUSTSTORE_PROVIDER_PROP_NAME, storeType);
    tc.getParams().put(TransportConstants.TRUSTSTORE_PATH_PROP_NAME, CLIENT_SIDE_TRUSTSTORE);
    tc.getParams().put(TransportConstants.TRUSTSTORE_PASSWORD_PROP_NAME, PASSWORD);
    ServerLocator locator = addServerLocator(ActiveMQClient.createServerLocatorWithoutHA(tc));
    ClientSessionFactory sf = null;
    try {
        sf = createSessionFactory(locator);
        Assert.assertTrue(true);
    } catch (ActiveMQNotConnectedException e) {
        Assert.fail();
    }
    ClientSession session = sf.createSession(false, true, true);
    session.createQueue(CoreClientOverOneWaySSLTest.QUEUE, CoreClientOverOneWaySSLTest.QUEUE, false);
    ClientProducer producer = session.createProducer(CoreClientOverOneWaySSLTest.QUEUE);
    ClientMessage message = createTextMessage(session, text);
    producer.send(message);
    ClientConsumer consumer = session.createConsumer(CoreClientOverOneWaySSLTest.QUEUE);
    session.start();
    Message m = consumer.receive(1000);
    Assert.assertNotNull(m);
    Assert.assertEquals(text, m.getBodyBuffer().readString());
}
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) ActiveMQNotConnectedException(org.apache.activemq.artemis.api.core.ActiveMQNotConnectedException) 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) ServerLocator(org.apache.activemq.artemis.api.core.client.ServerLocator) Test(org.junit.Test)

Aggregations

Message (org.apache.activemq.artemis.api.core.Message)114 ClientMessage (org.apache.activemq.artemis.api.core.client.ClientMessage)56 Test (org.junit.Test)52 SimpleString (org.apache.activemq.artemis.api.core.SimpleString)51 ClientSession (org.apache.activemq.artemis.api.core.client.ClientSession)48 ClientProducer (org.apache.activemq.artemis.api.core.client.ClientProducer)46 ClientSessionFactory (org.apache.activemq.artemis.api.core.client.ClientSessionFactory)41 ClientConsumer (org.apache.activemq.artemis.api.core.client.ClientConsumer)35 ActiveMQServer (org.apache.activemq.artemis.core.server.ActiveMQServer)34 CoreMessage (org.apache.activemq.artemis.core.message.impl.CoreMessage)28 AddressSettings (org.apache.activemq.artemis.core.settings.impl.AddressSettings)18 LargeServerMessage (org.apache.activemq.artemis.core.server.LargeServerMessage)16 ArrayList (java.util.ArrayList)15 MessageReference (org.apache.activemq.artemis.core.server.MessageReference)12 ActiveMQBuffer (org.apache.activemq.artemis.api.core.ActiveMQBuffer)11 ICoreMessage (org.apache.activemq.artemis.api.core.ICoreMessage)11 ServerLocator (org.apache.activemq.artemis.api.core.client.ServerLocator)10 Transaction (org.apache.activemq.artemis.core.transaction.Transaction)10 HashMap (java.util.HashMap)9 TransactionImpl (org.apache.activemq.artemis.core.transaction.impl.TransactionImpl)8