Search in sources :

Example 1 with XmlDataImporter

use of org.apache.activemq.artemis.cli.commands.tools.xml.XmlDataImporter in project activemq-artemis by apache.

the class XmlImportExportStressTest method testHighVolume.

@Test
public void testHighVolume() throws Exception {
    final String FILE_NAME = getTestDir() + "/export.out";
    final String QUEUE_NAME = "A1";
    ActiveMQServer server = createServer(true);
    server.start();
    ServerLocator locator = createInVMNonHALocator();
    ClientSessionFactory factory = locator.createSessionFactory();
    ClientSession session = factory.createSession(false, false, false);
    session.createQueue(QUEUE_NAME, QUEUE_NAME, true);
    ClientProducer producer = session.createProducer(QUEUE_NAME);
    ClientMessage msg = session.createMessage(true);
    final int SIZE = 10240;
    final int COUNT = 20000;
    byte[] bodyTst = new byte[SIZE];
    for (int i = 0; i < SIZE; i++) {
        bodyTst[i] = (byte) (i + 1);
    }
    msg.getBodyBuffer().writeBytes(bodyTst);
    assertEquals(bodyTst.length, msg.getBodySize());
    for (int i = 0; i < COUNT; i++) {
        producer.send(msg);
        if (i % 500 == 0) {
            System.out.println("Sent " + i);
            session.commit();
        }
    }
    session.commit();
    session.close();
    locator.close();
    server.stop();
    System.out.println("Writing XML...");
    FileOutputStream xmlOutputStream = new FileOutputStream(FILE_NAME);
    BufferedOutputStream bufferOut = new BufferedOutputStream(xmlOutputStream);
    XmlDataExporter xmlDataExporter = new XmlDataExporter();
    xmlDataExporter.process(bufferOut, getBindingsDir(), getJournalDir(), getPageDir(), getLargeMessagesDir());
    bufferOut.close();
    System.out.println("Done writing XML.");
    deleteDirectory(new File(getJournalDir()));
    deleteDirectory(new File(getBindingsDir()));
    deleteDirectory(new File(getPageDir()));
    deleteDirectory(new File(getLargeMessagesDir()));
    server.start();
    locator = createInVMNonHALocator();
    factory = locator.createSessionFactory();
    session = factory.createSession(false, false, true);
    ClientSession managementSession = factory.createSession(false, true, true);
    System.out.println("Reading XML...");
    FileInputStream xmlInputStream = new FileInputStream(FILE_NAME);
    XmlDataImporter xmlDataImporter = new XmlDataImporter();
    xmlDataImporter.process(xmlInputStream, session, managementSession);
    xmlInputStream.close();
    System.out.println("Done reading XML.");
    ClientConsumer consumer = session.createConsumer(QUEUE_NAME);
    session.start();
    for (int i = 0; i < COUNT; i++) {
        msg = consumer.receive(CONSUMER_TIMEOUT);
        assertNotNull(msg);
        msg.acknowledge();
        if (i % 500 == 0) {
            System.out.println("Received " + i);
            session.commit();
        }
        assertEquals(msg.getBodySize(), bodyTst.length);
        byte[] bodyRead = new byte[bodyTst.length];
        msg.getBodyBuffer().readBytes(bodyRead);
        assertEqualsByteArrays(bodyTst, bodyRead);
    }
    session.close();
    locator.close();
    server.stop();
    File temp = new File(FILE_NAME);
    temp.delete();
}
Also used : ClientMessage(org.apache.activemq.artemis.api.core.client.ClientMessage) FileInputStream(java.io.FileInputStream) XmlDataImporter(org.apache.activemq.artemis.cli.commands.tools.xml.XmlDataImporter) ActiveMQServer(org.apache.activemq.artemis.core.server.ActiveMQServer) ClientSession(org.apache.activemq.artemis.api.core.client.ClientSession) FileOutputStream(java.io.FileOutputStream) ClientSessionFactory(org.apache.activemq.artemis.api.core.client.ClientSessionFactory) ClientConsumer(org.apache.activemq.artemis.api.core.client.ClientConsumer) ClientProducer(org.apache.activemq.artemis.api.core.client.ClientProducer) BufferedOutputStream(java.io.BufferedOutputStream) File(java.io.File) ServerLocator(org.apache.activemq.artemis.api.core.client.ServerLocator) XmlDataExporter(org.apache.activemq.artemis.cli.commands.tools.xml.XmlDataExporter) Test(org.junit.Test)

Example 2 with XmlDataImporter

use of org.apache.activemq.artemis.cli.commands.tools.xml.XmlDataImporter in project activemq-artemis by apache.

the class XmlImportExportTest method testTextMessage.

@Test
public void testTextMessage() throws Exception {
    StringBuilder data = new StringBuilder();
    for (int i = 0; i < 2608; i++) {
        data.append("X");
    }
    ClientSession session = basicSetUp();
    session.createQueue(QUEUE_NAME, RoutingType.MULTICAST, QUEUE_NAME, true);
    ClientProducer producer = session.createProducer(QUEUE_NAME);
    ClientMessage msg = session.createMessage(Message.TEXT_TYPE, true);
    msg.getBodyBuffer().writeString(data.toString());
    producer.send(msg);
    session.close();
    locator.close();
    server.stop();
    ByteArrayOutputStream xmlOutputStream = new ByteArrayOutputStream();
    XmlDataExporter xmlDataExporter = new XmlDataExporter();
    xmlDataExporter.process(xmlOutputStream, server.getConfiguration().getBindingsDirectory(), server.getConfiguration().getJournalDirectory(), server.getConfiguration().getPagingDirectory(), server.getConfiguration().getLargeMessagesDirectory());
    System.out.print(new String(xmlOutputStream.toByteArray()));
    clearDataRecreateServerDirs();
    server.start();
    checkForLongs();
    locator = createInVMNonHALocator();
    factory = createSessionFactory(locator);
    session = factory.createSession(false, true, true);
    ByteArrayInputStream xmlInputStream = new ByteArrayInputStream(xmlOutputStream.toByteArray());
    XmlDataImporter xmlDataImporter = new XmlDataImporter();
    xmlDataImporter.validate(xmlInputStream);
    xmlInputStream.reset();
    xmlDataImporter.process(xmlInputStream, session);
    ClientConsumer consumer = session.createConsumer(QUEUE_NAME);
    session.start();
    msg = consumer.receive(CONSUMER_TIMEOUT);
    assertEquals(Message.TEXT_TYPE, msg.getType());
    assertEquals(data.toString(), msg.getBodyBuffer().readString());
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) ClientSession(org.apache.activemq.artemis.api.core.client.ClientSession) ClientMessage(org.apache.activemq.artemis.api.core.client.ClientMessage) ByteArrayOutputStream(java.io.ByteArrayOutputStream) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) ClientConsumer(org.apache.activemq.artemis.api.core.client.ClientConsumer) ClientProducer(org.apache.activemq.artemis.api.core.client.ClientProducer) XmlDataExporter(org.apache.activemq.artemis.cli.commands.tools.xml.XmlDataExporter) XmlDataImporter(org.apache.activemq.artemis.cli.commands.tools.xml.XmlDataImporter) Test(org.junit.Test)

Example 3 with XmlDataImporter

use of org.apache.activemq.artemis.cli.commands.tools.xml.XmlDataImporter in project activemq-artemis by apache.

the class XmlImportExportTest method testPaging.

@Test
public void testPaging() throws Exception {
    final String MY_ADDRESS = "myAddress";
    final String MY_QUEUE = "myQueue";
    server = createServer(true);
    AddressSettings defaultSetting = new AddressSettings().setPageSizeBytes(10 * 1024).setMaxSizeBytes(20 * 1024);
    server.getAddressSettingsRepository().addMatch("#", defaultSetting);
    server.start();
    locator = createInVMNonHALocator().setBlockOnNonDurableSend(true).setBlockOnDurableSend(true).setBlockOnAcknowledge(true);
    factory = createSessionFactory(locator);
    ClientSession session = factory.createSession(false, true, true);
    session.createQueue(MY_ADDRESS, RoutingType.MULTICAST, MY_QUEUE, true);
    ClientProducer producer = session.createProducer(MY_ADDRESS);
    ClientMessage message = session.createMessage(true);
    message.getBodyBuffer().writeBytes(new byte[1024]);
    for (int i = 0; i < 200; i++) {
        producer.send(message);
    }
    session.close();
    locator.close();
    server.stop();
    ByteArrayOutputStream xmlOutputStream = new ByteArrayOutputStream();
    XmlDataExporter xmlDataExporter = new XmlDataExporter();
    xmlDataExporter.process(xmlOutputStream, server.getConfiguration().getBindingsDirectory(), server.getConfiguration().getJournalDirectory(), server.getConfiguration().getPagingDirectory(), server.getConfiguration().getLargeMessagesDirectory());
    System.out.print(new String(xmlOutputStream.toByteArray()));
    clearDataRecreateServerDirs();
    server.start();
    checkForLongs();
    locator = createInVMNonHALocator();
    factory = createSessionFactory(locator);
    session = factory.createSession(false, true, true);
    ByteArrayInputStream xmlInputStream = new ByteArrayInputStream(xmlOutputStream.toByteArray());
    XmlDataImporter xmlDataImporter = new XmlDataImporter();
    xmlDataImporter.validate(xmlInputStream);
    xmlInputStream.reset();
    xmlDataImporter.process(xmlInputStream, session);
    ClientConsumer consumer = session.createConsumer(MY_QUEUE);
    session.start();
    for (int i = 0; i < 200; i++) {
        message = consumer.receive(CONSUMER_TIMEOUT);
        assertNotNull(message);
    }
}
Also used : AddressSettings(org.apache.activemq.artemis.core.settings.impl.AddressSettings) ByteArrayInputStream(java.io.ByteArrayInputStream) ClientSession(org.apache.activemq.artemis.api.core.client.ClientSession) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) ClientMessage(org.apache.activemq.artemis.api.core.client.ClientMessage) ByteArrayOutputStream(java.io.ByteArrayOutputStream) ClientConsumer(org.apache.activemq.artemis.api.core.client.ClientConsumer) ClientProducer(org.apache.activemq.artemis.api.core.client.ClientProducer) XmlDataExporter(org.apache.activemq.artemis.cli.commands.tools.xml.XmlDataExporter) XmlDataImporter(org.apache.activemq.artemis.cli.commands.tools.xml.XmlDataImporter) Test(org.junit.Test)

Example 4 with XmlDataImporter

use of org.apache.activemq.artemis.cli.commands.tools.xml.XmlDataImporter in project activemq-artemis by apache.

the class XmlImportExportTest method testTransactional.

@Test
public void testTransactional() throws Exception {
    ClientSession session = basicSetUp();
    session.createQueue(QUEUE_NAME, RoutingType.MULTICAST, QUEUE_NAME, true);
    ClientProducer producer = session.createProducer(QUEUE_NAME);
    ClientMessage msg = session.createMessage(true);
    producer.send(msg);
    session.close();
    locator.close();
    server.stop();
    ByteArrayOutputStream xmlOutputStream = new ByteArrayOutputStream();
    XmlDataExporter xmlDataExporter = new XmlDataExporter();
    xmlDataExporter.process(xmlOutputStream, server.getConfiguration().getBindingsDirectory(), server.getConfiguration().getJournalDirectory(), server.getConfiguration().getPagingDirectory(), server.getConfiguration().getLargeMessagesDirectory());
    System.out.print(new String(xmlOutputStream.toByteArray()));
    clearDataRecreateServerDirs();
    server.start();
    checkForLongs();
    locator = createInVMNonHALocator();
    factory = createSessionFactory(locator);
    session = factory.createSession(false, false, true);
    ClientSession managementSession = factory.createSession(false, true, true);
    ByteArrayInputStream xmlInputStream = new ByteArrayInputStream(xmlOutputStream.toByteArray());
    XmlDataImporter xmlDataImporter = new XmlDataImporter();
    xmlDataImporter.validate(xmlInputStream);
    xmlInputStream.reset();
    xmlDataImporter.process(xmlInputStream, session, managementSession);
    ClientConsumer consumer = session.createConsumer(QUEUE_NAME);
    session.start();
    msg = consumer.receive(CONSUMER_TIMEOUT);
    assertNotNull(msg);
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) ClientSession(org.apache.activemq.artemis.api.core.client.ClientSession) ClientMessage(org.apache.activemq.artemis.api.core.client.ClientMessage) ByteArrayOutputStream(java.io.ByteArrayOutputStream) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) ClientConsumer(org.apache.activemq.artemis.api.core.client.ClientConsumer) ClientProducer(org.apache.activemq.artemis.api.core.client.ClientProducer) XmlDataExporter(org.apache.activemq.artemis.cli.commands.tools.xml.XmlDataExporter) XmlDataImporter(org.apache.activemq.artemis.cli.commands.tools.xml.XmlDataImporter) Test(org.junit.Test)

Example 5 with XmlDataImporter

use of org.apache.activemq.artemis.cli.commands.tools.xml.XmlDataImporter in project activemq-artemis by apache.

the class XmlImportExportTest method testBytesMessage.

@Test
public void testBytesMessage() throws Exception {
    StringBuilder data = new StringBuilder();
    for (int i = 0; i < 2610; i++) {
        data.append("X");
    }
    ClientSession session = basicSetUp();
    session.createQueue(QUEUE_NAME, RoutingType.MULTICAST, QUEUE_NAME, true);
    ClientProducer producer = session.createProducer(QUEUE_NAME);
    ClientMessage msg = session.createMessage(Message.BYTES_TYPE, true);
    msg.getBodyBuffer().writeBytes(data.toString().getBytes());
    producer.send(msg);
    session.close();
    locator.close();
    server.stop();
    ByteArrayOutputStream xmlOutputStream = new ByteArrayOutputStream();
    XmlDataExporter xmlDataExporter = new XmlDataExporter();
    xmlDataExporter.process(xmlOutputStream, server.getConfiguration().getBindingsDirectory(), server.getConfiguration().getJournalDirectory(), server.getConfiguration().getPagingDirectory(), server.getConfiguration().getLargeMessagesDirectory());
    System.out.print(new String(xmlOutputStream.toByteArray()));
    clearDataRecreateServerDirs();
    server.start();
    checkForLongs();
    locator = createInVMNonHALocator();
    factory = createSessionFactory(locator);
    session = factory.createSession(false, true, true);
    ByteArrayInputStream xmlInputStream = new ByteArrayInputStream(xmlOutputStream.toByteArray());
    XmlDataImporter xmlDataImporter = new XmlDataImporter();
    xmlDataImporter.validate(xmlInputStream);
    xmlInputStream.reset();
    xmlDataImporter.process(xmlInputStream, session);
    ClientConsumer consumer = session.createConsumer(QUEUE_NAME);
    session.start();
    msg = consumer.receive(CONSUMER_TIMEOUT);
    assertEquals(Message.BYTES_TYPE, msg.getType());
    byte[] result = new byte[msg.getBodySize()];
    msg.getBodyBuffer().readBytes(result);
    assertEquals(data.toString().getBytes().length, result.length);
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) ClientSession(org.apache.activemq.artemis.api.core.client.ClientSession) ClientMessage(org.apache.activemq.artemis.api.core.client.ClientMessage) ByteArrayOutputStream(java.io.ByteArrayOutputStream) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) ClientConsumer(org.apache.activemq.artemis.api.core.client.ClientConsumer) ClientProducer(org.apache.activemq.artemis.api.core.client.ClientProducer) XmlDataExporter(org.apache.activemq.artemis.cli.commands.tools.xml.XmlDataExporter) XmlDataImporter(org.apache.activemq.artemis.cli.commands.tools.xml.XmlDataImporter) Test(org.junit.Test)

Aggregations

ClientSession (org.apache.activemq.artemis.api.core.client.ClientSession)18 XmlDataExporter (org.apache.activemq.artemis.cli.commands.tools.xml.XmlDataExporter)18 XmlDataImporter (org.apache.activemq.artemis.cli.commands.tools.xml.XmlDataImporter)18 Test (org.junit.Test)18 ByteArrayInputStream (java.io.ByteArrayInputStream)17 ByteArrayOutputStream (java.io.ByteArrayOutputStream)17 SimpleString (org.apache.activemq.artemis.api.core.SimpleString)17 ClientConsumer (org.apache.activemq.artemis.api.core.client.ClientConsumer)15 ClientMessage (org.apache.activemq.artemis.api.core.client.ClientMessage)15 ClientProducer (org.apache.activemq.artemis.api.core.client.ClientProducer)15 ClientSessionFactory (org.apache.activemq.artemis.api.core.client.ClientSessionFactory)5 ServerLocator (org.apache.activemq.artemis.api.core.client.ServerLocator)5 LargeServerMessageImpl (org.apache.activemq.artemis.core.persistence.impl.journal.LargeServerMessageImpl)3 AddressSettings (org.apache.activemq.artemis.core.settings.impl.AddressSettings)3 File (java.io.File)2 BufferedOutputStream (java.io.BufferedOutputStream)1 FileInputStream (java.io.FileInputStream)1 FileOutputStream (java.io.FileOutputStream)1 Connection (javax.jms.Connection)1 ConnectionFactory (javax.jms.ConnectionFactory)1