Search in sources :

Example 71 with ActiveMQBuffer

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

the class TransportConfigurationEncodingSupportTest method testTransportConfigurations.

@Test
public void testTransportConfigurations() throws Exception {
    List<Pair<TransportConfiguration, TransportConfiguration>> connectorConfigs = new ArrayList<>();
    Map<String, Object> liveParams = new HashMap<>();
    liveParams.put(TransportConstants.PORT_PROP_NAME, 5665);
    TransportConfiguration live1 = new TransportConfiguration(NettyConnectorFactory.class.getName(), liveParams);
    Map<String, Object> backupParams = new HashMap<>();
    backupParams.put(TransportConstants.PORT_PROP_NAME, 5775);
    TransportConfiguration backup1 = new TransportConfiguration(NettyConnectorFactory.class.getName(), backupParams);
    Map<String, Object> liveParams2 = new HashMap<>();
    liveParams2.put(TransportConstants.PORT_PROP_NAME, 6665);
    TransportConfiguration live2 = new TransportConfiguration(NettyConnectorFactory.class.getName(), liveParams2);
    connectorConfigs.add(new Pair<>(live1, backup1));
    connectorConfigs.add(new Pair<TransportConfiguration, TransportConfiguration>(live2, null));
    ActiveMQBuffer buffer = ActiveMQBuffers.fixedBuffer(TransportConfigurationEncodingSupport.getEncodeSize(connectorConfigs));
    TransportConfigurationEncodingSupport.encodeConfigs(buffer, connectorConfigs);
    assertEquals(buffer.capacity(), buffer.writerIndex());
    buffer.readerIndex(0);
    List<Pair<TransportConfiguration, TransportConfiguration>> decodedConfigs = TransportConfigurationEncodingSupport.decodeConfigs(buffer);
    assertNotNull(decodedConfigs);
    assertEquals(2, decodedConfigs.size());
    assertEquivalent(connectorConfigs.get(0).getA(), decodedConfigs.get(0).getA());
    assertEquivalent(connectorConfigs.get(0).getB(), decodedConfigs.get(0).getB());
    assertEquivalent(connectorConfigs.get(1).getA(), decodedConfigs.get(1).getA());
    assertNull(decodedConfigs.get(1).getB());
}
Also used : NettyConnectorFactory(org.apache.activemq.artemis.core.remoting.impl.netty.NettyConnectorFactory) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) TransportConfiguration(org.apache.activemq.artemis.api.core.TransportConfiguration) Pair(org.apache.activemq.artemis.api.core.Pair) ActiveMQBuffer(org.apache.activemq.artemis.api.core.ActiveMQBuffer) Test(org.junit.Test)

Example 72 with ActiveMQBuffer

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

the class JournalPageCountSizeTest method testPageCountRecordSize.

@Test
public void testPageCountRecordSize() throws Exception {
    long tx = server.getStorageManager().generateID();
    server.getStorageManager().storePageCounter(tx, 1, 1, 100);
    server.getStorageManager().commit(tx);
    server.getStorageManager().stop();
    JournalStorageManager journalStorageManager = (JournalStorageManager) server.getStorageManager();
    List<RecordInfo> committedRecords = new LinkedList<>();
    List<PreparedTransactionInfo> preparedTransactions = new LinkedList<>();
    try {
        journalStorageManager.getMessageJournal().start();
        journalStorageManager.getMessageJournal().load(committedRecords, preparedTransactions, transactionFailure);
        ActiveMQBuffer buff = ActiveMQBuffers.wrappedBuffer(committedRecords.get(0).data);
        PageCountRecord encoding = new PageCountRecord();
        encoding.decode(buff);
        Assert.assertEquals(100, encoding.getPersistentSize());
    } finally {
        journalStorageManager.getMessageJournal().stop();
    }
}
Also used : PageCountRecord(org.apache.activemq.artemis.core.persistence.impl.journal.codec.PageCountRecord) PreparedTransactionInfo(org.apache.activemq.artemis.core.journal.PreparedTransactionInfo) RecordInfo(org.apache.activemq.artemis.core.journal.RecordInfo) LinkedList(java.util.LinkedList) JournalStorageManager(org.apache.activemq.artemis.core.persistence.impl.journal.JournalStorageManager) ActiveMQBuffer(org.apache.activemq.artemis.api.core.ActiveMQBuffer) Test(org.junit.Test)

Example 73 with ActiveMQBuffer

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

the class JournalPageCountSizeTest method testPageCursorCounterRecordSize.

@Test
public void testPageCursorCounterRecordSize() throws Exception {
    server.getStorageManager().storePageCounterInc(1, 1, 1000);
    server.getStorageManager().stop();
    JournalStorageManager journalStorageManager = (JournalStorageManager) server.getStorageManager();
    List<RecordInfo> committedRecords = new LinkedList<>();
    List<PreparedTransactionInfo> preparedTransactions = new LinkedList<>();
    try {
        journalStorageManager.getMessageJournal().start();
        journalStorageManager.getMessageJournal().load(committedRecords, preparedTransactions, transactionFailure);
        ActiveMQBuffer buff = ActiveMQBuffers.wrappedBuffer(committedRecords.get(0).data);
        PageCountRecordInc encoding = new PageCountRecordInc();
        encoding.decode(buff);
        Assert.assertEquals(1000, encoding.getPersistentSize());
    } finally {
        journalStorageManager.getMessageJournal().stop();
    }
}
Also used : PreparedTransactionInfo(org.apache.activemq.artemis.core.journal.PreparedTransactionInfo) RecordInfo(org.apache.activemq.artemis.core.journal.RecordInfo) PageCountRecordInc(org.apache.activemq.artemis.core.persistence.impl.journal.codec.PageCountRecordInc) LinkedList(java.util.LinkedList) JournalStorageManager(org.apache.activemq.artemis.core.persistence.impl.journal.JournalStorageManager) ActiveMQBuffer(org.apache.activemq.artemis.api.core.ActiveMQBuffer) Test(org.junit.Test)

Example 74 with ActiveMQBuffer

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

the class PagingSyncTest method testOrder1.

@Test
public void testOrder1() throws Throwable {
    boolean persistentMessages = true;
    Configuration config = createDefaultInVMConfig().setJournalSyncNonTransactional(false);
    ActiveMQServer server = createServer(true, config, PAGE_SIZE, PAGE_MAX, new HashMap<String, AddressSettings>());
    server.start();
    final int messageSize = 1024;
    final int numberOfMessages = 500;
    ServerLocator locator = createInVMNonHALocator().setClientFailureCheckPeriod(1000).setConnectionTTL(2000).setReconnectAttempts(0).setBlockOnNonDurableSend(false).setBlockOnDurableSend(false).setBlockOnAcknowledge(false).setConsumerWindowSize(1024 * 1024);
    ClientSessionFactory sf = createSessionFactory(locator);
    ClientSession session = sf.createSession(false, false, false);
    server.addAddressInfo(new AddressInfo(ADDRESS, RoutingType.ANYCAST));
    server.createQueue(ADDRESS, RoutingType.ANYCAST, ADDRESS, null, true, false);
    ClientProducer producer = session.createProducer(PagingTest.ADDRESS);
    byte[] body = new byte[messageSize];
    ByteBuffer bb = ByteBuffer.wrap(body);
    for (int j = 1; j <= messageSize; j++) {
        bb.put(getSamplebyte(j));
    }
    for (int i = 0; i < numberOfMessages; i++) {
        ClientMessage message = session.createMessage(persistentMessages);
        ActiveMQBuffer bodyLocal = message.getBodyBuffer();
        bodyLocal.writeBytes(body);
        message.putIntProperty(new SimpleString("id"), i);
        producer.send(message);
    }
    session.commit();
    session.close();
}
Also used : AddressSettings(org.apache.activemq.artemis.core.settings.impl.AddressSettings) Configuration(org.apache.activemq.artemis.core.config.Configuration) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) ClientMessage(org.apache.activemq.artemis.api.core.client.ClientMessage) ByteBuffer(java.nio.ByteBuffer) AddressInfo(org.apache.activemq.artemis.core.server.impl.AddressInfo) 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) ClientProducer(org.apache.activemq.artemis.api.core.client.ClientProducer) ServerLocator(org.apache.activemq.artemis.api.core.client.ServerLocator) ActiveMQBuffer(org.apache.activemq.artemis.api.core.ActiveMQBuffer) Test(org.junit.Test)

Example 75 with ActiveMQBuffer

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

the class PagingOrderTest method testPageCounter2.

@Test
public void testPageCounter2() throws Throwable {
    boolean persistentMessages = true;
    Configuration config = createDefaultInVMConfig().setJournalSyncNonTransactional(false);
    ActiveMQServer server = createServer(true, config, PAGE_SIZE, PAGE_MAX, new HashMap<String, AddressSettings>());
    server.start();
    final int messageSize = 1024;
    final int numberOfMessages = 500;
    ServerLocator locator = createInVMNonHALocator().setClientFailureCheckPeriod(1000).setConnectionTTL(2000).setReconnectAttempts(0).setBlockOnNonDurableSend(true).setBlockOnDurableSend(true).setBlockOnAcknowledge(true).setConsumerWindowSize(1024 * 1024);
    ClientSessionFactory sf = createSessionFactory(locator);
    ClientSession session = sf.createSession(false, false, false);
    server.addAddressInfo(new AddressInfo(ADDRESS, RoutingType.ANYCAST));
    Queue q1 = server.createQueue(ADDRESS, RoutingType.MULTICAST, ADDRESS, null, true, false);
    Queue q2 = server.createQueue(ADDRESS, RoutingType.MULTICAST, new SimpleString("inactive"), null, true, false);
    ClientProducer producer = session.createProducer(PagingTest.ADDRESS);
    byte[] body = new byte[messageSize];
    ByteBuffer bb = ByteBuffer.wrap(body);
    for (int j = 1; j <= messageSize; j++) {
        bb.put(getSamplebyte(j));
    }
    final AtomicInteger errors = new AtomicInteger(0);
    Thread t1 = new Thread() {

        @Override
        public void run() {
            try {
                ServerLocator sl = createInVMNonHALocator();
                ClientSessionFactory sf = sl.createSessionFactory();
                ClientSession sess = sf.createSession(true, true, 0);
                sess.start();
                ClientConsumer cons = sess.createConsumer(ADDRESS);
                for (int i = 0; i < 100; i++) {
                    ClientMessage msg = cons.receive(5000);
                    assertNotNull(msg);
                    assertEquals(i, msg.getIntProperty("id").intValue());
                    msg.acknowledge();
                }
                sess.close();
                sl.close();
            } catch (Throwable e) {
                e.printStackTrace();
                errors.incrementAndGet();
            }
        }
    };
    for (int i = 0; i < numberOfMessages; i++) {
        ClientMessage message = session.createMessage(persistentMessages);
        ActiveMQBuffer bodyLocal = message.getBodyBuffer();
        bodyLocal.writeBytes(body);
        message.putIntProperty(new SimpleString("id"), i);
        producer.send(message);
        if (i % 20 == 0) {
            session.commit();
        }
    }
    session.commit();
    t1.start();
    t1.join();
    assertEquals(0, errors.get());
    long timeout = System.currentTimeMillis() + 10000;
    while (numberOfMessages - 100 != getMessageCount(q1) && System.currentTimeMillis() < timeout) {
        Thread.sleep(500);
    }
    assertEquals(numberOfMessages, getMessageCount(q2));
    assertEquals(numberOfMessages, getMessagesAdded(q2));
    assertEquals(numberOfMessages - 100, getMessageCount(q1));
}
Also used : 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) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) ClientMessage(org.apache.activemq.artemis.api.core.client.ClientMessage) ByteBuffer(java.nio.ByteBuffer) AddressInfo(org.apache.activemq.artemis.core.server.impl.AddressInfo) ActiveMQServer(org.apache.activemq.artemis.core.server.ActiveMQServer) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) ClientSession(org.apache.activemq.artemis.api.core.client.ClientSession) ClientSessionFactory(org.apache.activemq.artemis.api.core.client.ClientSessionFactory) ClientConsumer(org.apache.activemq.artemis.api.core.client.ClientConsumer) Queue(org.apache.activemq.artemis.core.server.Queue) ClientProducer(org.apache.activemq.artemis.api.core.client.ClientProducer) ServerLocator(org.apache.activemq.artemis.api.core.client.ServerLocator) ActiveMQBuffer(org.apache.activemq.artemis.api.core.ActiveMQBuffer) Test(org.junit.Test)

Aggregations

ActiveMQBuffer (org.apache.activemq.artemis.api.core.ActiveMQBuffer)150 Test (org.junit.Test)81 SimpleString (org.apache.activemq.artemis.api.core.SimpleString)49 ClientMessage (org.apache.activemq.artemis.api.core.client.ClientMessage)44 ClientProducer (org.apache.activemq.artemis.api.core.client.ClientProducer)39 ClientSession (org.apache.activemq.artemis.api.core.client.ClientSession)38 ClientConsumer (org.apache.activemq.artemis.api.core.client.ClientConsumer)35 ByteBuffer (java.nio.ByteBuffer)34 Configuration (org.apache.activemq.artemis.core.config.Configuration)34 StoreConfiguration (org.apache.activemq.artemis.core.config.StoreConfiguration)27 DivertConfiguration (org.apache.activemq.artemis.core.config.DivertConfiguration)25 DatabaseStorageConfiguration (org.apache.activemq.artemis.core.config.storage.DatabaseStorageConfiguration)25 ArrayList (java.util.ArrayList)21 ClientSessionFactory (org.apache.activemq.artemis.api.core.client.ClientSessionFactory)21 Queue (org.apache.activemq.artemis.core.server.Queue)18 HashMap (java.util.HashMap)17 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)16 ServerLocator (org.apache.activemq.artemis.api.core.client.ServerLocator)15 RecordInfo (org.apache.activemq.artemis.core.journal.RecordInfo)15 CoreMessage (org.apache.activemq.artemis.core.message.impl.CoreMessage)14