Search in sources :

Example 6 with XmlDataExporter

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

the class XmlImportExportTest method testLargeMessagesNoTmpFiles.

@Test
public void testLargeMessagesNoTmpFiles() throws Exception {
    server = createServer(true);
    server.start();
    locator = createInVMNonHALocator();
    factory = createSessionFactory(locator);
    ClientSession session = factory.createSession(false, false);
    LargeServerMessageImpl fileMessage = new LargeServerMessageImpl((JournalStorageManager) server.getStorageManager());
    fileMessage.setMessageID(1005);
    fileMessage.setDurable(true);
    for (int i = 0; i < 2 * ActiveMQClient.DEFAULT_MIN_LARGE_MESSAGE_SIZE; i++) {
        fileMessage.addBytes(new byte[] { getSamplebyte(i) });
    }
    fileMessage.putLongProperty(Message.HDR_LARGE_BODY_SIZE, 2 * ActiveMQClient.DEFAULT_MIN_LARGE_MESSAGE_SIZE);
    fileMessage.releaseResources();
    session.createQueue("A", RoutingType.MULTICAST, "A", true);
    ClientProducer prod = session.createProducer("A");
    prod.send(fileMessage);
    prod.send(fileMessage);
    fileMessage.deleteFile();
    session.commit();
    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.sort = true;
    xmlDataImporter.validate(xmlInputStream);
    xmlInputStream.reset();
    xmlDataImporter.process(xmlInputStream, session);
    session.close();
    session = factory.createSession(false, false);
    session.start();
    ClientConsumer cons = session.createConsumer("A");
    ClientMessage msg = cons.receive(CONSUMER_TIMEOUT);
    assertNotNull(msg);
    assertEquals(2 * ActiveMQClient.DEFAULT_MIN_LARGE_MESSAGE_SIZE, msg.getBodySize());
    for (int i = 0; i < 2 * ActiveMQClient.DEFAULT_MIN_LARGE_MESSAGE_SIZE; i++) {
        assertEquals(getSamplebyte(i), msg.getBodyBuffer().readByte());
    }
    msg = cons.receive(CONSUMER_TIMEOUT);
    assertNotNull(msg);
    assertEquals(2 * ActiveMQClient.DEFAULT_MIN_LARGE_MESSAGE_SIZE, msg.getBodySize());
    for (int i = 0; i < 2 * ActiveMQClient.DEFAULT_MIN_LARGE_MESSAGE_SIZE; i++) {
        assertEquals(getSamplebyte(i), msg.getBodyBuffer().readByte());
    }
    msg.acknowledge();
    session.commit();
    // make sure there is not tmp file left
    File workingDir = new File(System.getProperty("user.dir"));
    String[] flist = workingDir.list();
    for (String fn : flist) {
        assertFalse("leftover: " + fn, fn.endsWith(".tmp"));
    }
}
Also used : LargeServerMessageImpl(org.apache.activemq.artemis.core.persistence.impl.journal.LargeServerMessageImpl) ByteArrayOutputStream(java.io.ByteArrayOutputStream) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) ClientMessage(org.apache.activemq.artemis.api.core.client.ClientMessage) XmlDataImporter(org.apache.activemq.artemis.cli.commands.tools.xml.XmlDataImporter) ByteArrayInputStream(java.io.ByteArrayInputStream) ClientSession(org.apache.activemq.artemis.api.core.client.ClientSession) ClientConsumer(org.apache.activemq.artemis.api.core.client.ClientConsumer) ClientProducer(org.apache.activemq.artemis.api.core.client.ClientProducer) File(java.io.File) XmlDataExporter(org.apache.activemq.artemis.cli.commands.tools.xml.XmlDataExporter) Test(org.junit.Test)

Example 7 with XmlDataExporter

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

the class XmlImportExportTest method testBody.

@Test
public void testBody() throws Exception {
    final String QUEUE_NAME = "A1";
    server = createServer(true);
    server.start();
    ServerLocator locator = createInVMNonHALocator();
    ClientSessionFactory factory = locator.createSessionFactory();
    ClientSession session = factory.createSession(false, true, true);
    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("bob123");
    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 = locator.createSessionFactory();
    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);
    assertEquals("bob123", msg.getBodyBuffer().readString());
    session.close();
    locator.close();
    server.stop();
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) 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) ByteArrayOutputStream(java.io.ByteArrayOutputStream) 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) 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 8 with XmlDataExporter

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

the class XmlImportExportTest method testRoutingTypes.

@Test
public void testRoutingTypes() throws Exception {
    SimpleString myAddress = SimpleString.toSimpleString("myAddress");
    ClientSession session = basicSetUp();
    EnumSet<RoutingType> routingTypes = EnumSet.of(RoutingType.ANYCAST, RoutingType.MULTICAST);
    session.createAddress(myAddress, routingTypes, false);
    session.createQueue(myAddress.toString(), RoutingType.MULTICAST, "myQueue1", true);
    session.createQueue(myAddress.toString(), RoutingType.MULTICAST, "myQueue2", true);
    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 = locator.createSessionFactory();
    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);
    assertTrue(server.getAddressInfo(myAddress).getRoutingTypes().contains(RoutingType.ANYCAST));
    assertTrue(server.getAddressInfo(myAddress).getRoutingTypes().contains(RoutingType.MULTICAST));
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) ClientSession(org.apache.activemq.artemis.api.core.client.ClientSession) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) ByteArrayOutputStream(java.io.ByteArrayOutputStream) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) XmlDataExporter(org.apache.activemq.artemis.cli.commands.tools.xml.XmlDataExporter) RoutingType(org.apache.activemq.artemis.api.core.RoutingType) XmlDataImporter(org.apache.activemq.artemis.cli.commands.tools.xml.XmlDataImporter) Test(org.junit.Test)

Example 9 with XmlDataExporter

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

the class XmlImportExportTest method testPagedMessageWithMissingBinding.

@Test
public void testPagedMessageWithMissingBinding() throws Exception {
    final String MY_ADDRESS = "myAddress";
    final String MY_QUEUE = "myQueue";
    final String MY_QUEUE2 = "myQueue2";
    server = createServer(true);
    AddressSettings defaultSetting = new AddressSettings().setPageSizeBytes(10 * 1024).setMaxSizeBytes(20 * 1024);
    server.getAddressSettingsRepository().addMatch("#", defaultSetting);
    server.start();
    ServerLocator locator = createInVMNonHALocator().setBlockOnNonDurableSend(true).setBlockOnDurableSend(true).setBlockOnAcknowledge(true);
    ClientSessionFactory factory = locator.createSessionFactory();
    ClientSession session = factory.createSession(false, true, true);
    session.createQueue(MY_ADDRESS, RoutingType.MULTICAST, MY_QUEUE, true);
    session.createQueue(MY_ADDRESS, RoutingType.MULTICAST, MY_QUEUE2, 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.deleteQueue(MY_QUEUE2);
    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 = locator.createSessionFactory();
    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);
    }
    session.close();
    locator.close();
    server.stop();
}
Also used : AddressSettings(org.apache.activemq.artemis.core.settings.impl.AddressSettings) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) ClientMessage(org.apache.activemq.artemis.api.core.client.ClientMessage) ByteArrayOutputStream(java.io.ByteArrayOutputStream) XmlDataImporter(org.apache.activemq.artemis.cli.commands.tools.xml.XmlDataImporter) ByteArrayInputStream(java.io.ByteArrayInputStream) 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) ClientProducer(org.apache.activemq.artemis.api.core.client.ClientProducer) ServerLocator(org.apache.activemq.artemis.api.core.client.ServerLocator) XmlDataExporter(org.apache.activemq.artemis.cli.commands.tools.xml.XmlDataExporter) Test(org.junit.Test)

Example 10 with XmlDataExporter

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

the class XmlImportExportTest method testLargeJmsTextMessage.

@Test
public void testLargeJmsTextMessage() throws Exception {
    basicSetUp();
    ConnectionFactory cf = ActiveMQJMSClient.createConnectionFactory("vm://0", "test");
    Connection c = cf.createConnection();
    Session s = c.createSession(false, Session.AUTO_ACKNOWLEDGE);
    server.createQueue(SimpleString.toSimpleString("A"), RoutingType.ANYCAST, SimpleString.toSimpleString("A"), null, true, false);
    MessageProducer p = s.createProducer(ActiveMQJMSClient.createQueue("A"));
    p.setDeliveryMode(DeliveryMode.PERSISTENT);
    StringBuilder stringBuilder = new StringBuilder();
    for (int i = 0; i < 1024 * 200; i++) {
        stringBuilder.append(RandomUtil.randomChar());
    }
    TextMessage textMessage = s.createTextMessage(stringBuilder.toString());
    textMessage.setStringProperty("_AMQ_DUPL_ID", String.valueOf(UUID.randomUUID()));
    p.send(textMessage);
    c.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);
    ClientSession 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);
    session.close();
    c = cf.createConnection();
    s = c.createSession();
    MessageConsumer mc = s.createConsumer(ActiveMQJMSClient.createQueue("A"));
    c.start();
    javax.jms.Message msg = mc.receive(CONSUMER_TIMEOUT);
    assertNotNull(msg);
    c.close();
}
Also used : MessageConsumer(javax.jms.MessageConsumer) Connection(javax.jms.Connection) ByteArrayOutputStream(java.io.ByteArrayOutputStream) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) XmlDataImporter(org.apache.activemq.artemis.cli.commands.tools.xml.XmlDataImporter) ConnectionFactory(javax.jms.ConnectionFactory) ByteArrayInputStream(java.io.ByteArrayInputStream) ClientSession(org.apache.activemq.artemis.api.core.client.ClientSession) MessageProducer(javax.jms.MessageProducer) TextMessage(javax.jms.TextMessage) XmlDataExporter(org.apache.activemq.artemis.cli.commands.tools.xml.XmlDataExporter) Session(javax.jms.Session) ClientSession(org.apache.activemq.artemis.api.core.client.ClientSession) 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