Search in sources :

Example 26 with ActiveMQBuffer

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

the class JournalImpl method runDirectJournalBlast.

@Override
public void runDirectJournalBlast() throws Exception {
    final int numIts = 100000000;
    ActiveMQJournalLogger.LOGGER.runningJournalBlast(numIts);
    final CountDownLatch latch = new CountDownLatch(numIts * 2);
    class MyAIOCallback implements IOCompletion {

        @Override
        public void done() {
            latch.countDown();
        }

        @Override
        public void onError(final int errorCode, final String errorMessage) {
        }

        @Override
        public void storeLineUp() {
        }
    }
    final MyAIOCallback task = new MyAIOCallback();
    final int recordSize = 1024;
    final byte[] bytes = new byte[recordSize];
    class MyRecord implements EncodingSupport {

        @Override
        public void decode(final ActiveMQBuffer buffer) {
        }

        @Override
        public void encode(final ActiveMQBuffer buffer) {
            buffer.writeBytes(bytes);
        }

        @Override
        public int getEncodeSize() {
            return recordSize;
        }
    }
    MyRecord record = new MyRecord();
    for (int i = 0; i < numIts; i++) {
        appendAddRecord(i, (byte) 1, record, true, task);
        appendDeleteRecord(i, true, task);
    }
    latch.await();
}
Also used : IOCompletion(org.apache.activemq.artemis.core.journal.IOCompletion) CountDownLatch(java.util.concurrent.CountDownLatch) ActiveMQBuffer(org.apache.activemq.artemis.api.core.ActiveMQBuffer) EncodingSupport(org.apache.activemq.artemis.core.journal.EncodingSupport)

Example 27 with ActiveMQBuffer

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

the class JDBCSequentialFileFactoryTest method testCopyFile.

@Test
public void testCopyFile() throws Exception {
    JDBCSequentialFile file = (JDBCSequentialFile) factory.createSequentialFile("test.txt");
    file.open();
    // Create buffer and fill with test data
    int bufferSize = 1024;
    ActiveMQBuffer src = ActiveMQBuffers.fixedBuffer(bufferSize);
    for (int i = 0; i < bufferSize; i++) {
        src.writeByte((byte) 5);
    }
    IOCallbackCountdown callback = new IOCallbackCountdown(1);
    file.internalWrite(src, callback);
    JDBCSequentialFile copy = (JDBCSequentialFile) factory.createSequentialFile("copy.txt");
    file.copyTo(copy);
    checkData(file, src);
    checkData(copy, src);
}
Also used : JDBCSequentialFile(org.apache.activemq.artemis.jdbc.store.file.JDBCSequentialFile) ActiveMQBuffer(org.apache.activemq.artemis.api.core.ActiveMQBuffer) Test(org.junit.Test)

Example 28 with ActiveMQBuffer

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

the class JDBCSequentialFileFactoryTest method testCloneFile.

@Test
public void testCloneFile() throws Exception {
    JDBCSequentialFile file = (JDBCSequentialFile) factory.createSequentialFile("test.txt");
    file.open();
    // Create buffer and fill with test data
    int bufferSize = 1024;
    ActiveMQBuffer src = ActiveMQBuffers.fixedBuffer(bufferSize);
    for (int i = 0; i < bufferSize; i++) {
        src.writeByte((byte) 5);
    }
    IOCallbackCountdown callback = new IOCallbackCountdown(1);
    file.internalWrite(src, callback);
    assertEquals(bufferSize, file.size());
    JDBCSequentialFile copy = (JDBCSequentialFile) file.cloneFile();
    copy.open();
    assertEquals(bufferSize, copy.size());
    assertEquals(bufferSize, file.size());
}
Also used : JDBCSequentialFile(org.apache.activemq.artemis.jdbc.store.file.JDBCSequentialFile) ActiveMQBuffer(org.apache.activemq.artemis.api.core.ActiveMQBuffer) Test(org.junit.Test)

Example 29 with ActiveMQBuffer

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

the class JDBCJournalRecord method setTxData.

void setTxData(EncodingSupport txData) {
    this.txDataSize = txData.getEncodeSize();
    ActiveMQBuffer encodedBuffer = ActiveMQBuffers.fixedBuffer(txDataSize);
    txData.encode(encodedBuffer);
    this.txData = new ActiveMQBufferInputStream(encodedBuffer);
}
Also used : ActiveMQBufferInputStream(org.apache.activemq.artemis.utils.ActiveMQBufferInputStream) ActiveMQBuffer(org.apache.activemq.artemis.api.core.ActiveMQBuffer)

Example 30 with ActiveMQBuffer

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

the class CoreClientTest method testCoreClient.

private void testCoreClient(final boolean netty, ServerLocator serverLocator) throws Exception {
    final SimpleString QUEUE = new SimpleString("CoreClientTestQueue");
    ActiveMQServer server = addServer(ActiveMQServers.newActiveMQServer(createDefaultConfig(netty), false));
    server.start();
    ServerLocator locator = serverLocator == null ? createNonHALocator(netty) : serverLocator;
    ClientSessionFactory sf = createSessionFactory(locator);
    ClientSession session = sf.createSession(false, true, true);
    session.createQueue(QUEUE, QUEUE, null, false);
    ClientProducer producer = session.createProducer(QUEUE);
    final int numMessages = 1000;
    for (int i = 0; i < numMessages; i++) {
        ClientMessage message = session.createMessage(ActiveMQTextMessage.TYPE, false, 0, System.currentTimeMillis(), (byte) 1);
        message.putStringProperty("foo", "bar");
        // One way around the setting destination problem is as follows -
        // Remove destination as an attribute from client producer.
        // The destination always has to be set explicitly before sending a message
        message.setAddress(QUEUE);
        message.getBodyBuffer().writeString("testINVMCoreClient");
        producer.send(message);
    }
    CoreClientTest.log.info("sent messages");
    ClientConsumer consumer = session.createConsumer(QUEUE);
    session.start();
    for (int i = 0; i < numMessages; i++) {
        ClientMessage message2 = consumer.receive();
        ActiveMQBuffer buffer = message2.getBodyBuffer();
        Assert.assertEquals("testINVMCoreClient", buffer.readString());
        message2.acknowledge();
    }
    sf.close();
}
Also used : ActiveMQServer(org.apache.activemq.artemis.core.server.ActiveMQServer) 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) ServerLocator(org.apache.activemq.artemis.api.core.client.ServerLocator) ActiveMQBuffer(org.apache.activemq.artemis.api.core.ActiveMQBuffer)

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