Search in sources :

Example 11 with XmlDataImporter

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

the class XmlImportExportTest method testLargeMessage.

@Test
public void testLargeMessage() 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);
    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.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.acknowledge();
    session.commit();
}
Also used : LargeServerMessageImpl(org.apache.activemq.artemis.core.persistence.impl.journal.LargeServerMessageImpl) ByteArrayInputStream(java.io.ByteArrayInputStream) ClientSession(org.apache.activemq.artemis.api.core.client.ClientSession) ByteArrayOutputStream(java.io.ByteArrayOutputStream) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) 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) 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 12 with XmlDataImporter

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

the class XmlImportExportTest method testBody2.

@Test
public void testBody2() 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(true);
    byte[] bodyTst = new byte[10];
    for (int i = 0; i < 10; i++) {
        bodyTst[i] = (byte) (i + 1);
    }
    msg.getBodyBuffer().writeBytes(bodyTst);
    assertEquals(bodyTst.length, msg.getBodySize());
    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(msg.getBodySize(), bodyTst.length);
    byte[] bodyRead = new byte[bodyTst.length];
    msg.getBodyBuffer().readBytes(bodyRead);
    assertEqualsByteArrays(bodyTst, bodyRead);
    session.close();
    locator.close();
    server.stop();
}
Also used : 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 13 with XmlDataImporter

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

the class XmlImportExportTest method testPagedLargeMessage.

@Test
public void testPagedLargeMessage() 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();
    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);
    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);
    }
    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();
    producer.send(fileMessage);
    fileMessage.deleteFile();
    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);
    }
    ClientMessage msg = consumer.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());
    }
    session.close();
    locator.close();
    server.stop();
}
Also used : AddressSettings(org.apache.activemq.artemis.core.settings.impl.AddressSettings) LargeServerMessageImpl(org.apache.activemq.artemis.core.persistence.impl.journal.LargeServerMessageImpl) 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 14 with XmlDataImporter

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

the class XmlImportExportTest method testMessageProperties.

@Test
public void testMessageProperties() throws Exception {
    ClientSession session = basicSetUp();
    session.createQueue(QUEUE_NAME, RoutingType.MULTICAST, QUEUE_NAME, true);
    ClientProducer producer = session.createProducer(QUEUE_NAME);
    StringBuilder international = new StringBuilder();
    for (char x = 800; x < 1200; x++) {
        international.append(x);
    }
    String special = "\"<>'&";
    for (int i = 0; i < 5; i++) {
        ClientMessage msg = session.createMessage(true);
        msg.getBodyBuffer().writeString("Bob the giant pig " + i);
        msg.putBooleanProperty("myBooleanProperty", Boolean.TRUE);
        msg.putByteProperty("myByteProperty", new Byte("0"));
        msg.putBytesProperty("myBytesProperty", new byte[] { 0, 1, 2, 3, 4 });
        msg.putDoubleProperty("myDoubleProperty", i * 1.6);
        msg.putFloatProperty("myFloatProperty", i * 2.5F);
        msg.putIntProperty("myIntProperty", i);
        msg.putLongProperty("myLongProperty", Long.MAX_VALUE - i);
        msg.putObjectProperty("myObjectProperty", i);
        msg.putObjectProperty("myNullObjectProperty", null);
        msg.putShortProperty("myShortProperty", new Integer(i).shortValue());
        msg.putStringProperty("myStringProperty", "myStringPropertyValue_" + i);
        msg.putStringProperty("myNullStringProperty", null);
        msg.putStringProperty("myNonAsciiStringProperty", international.toString());
        msg.putStringProperty("mySpecialCharacters", special);
        msg.putStringProperty(new SimpleString("mySimpleStringProperty"), new SimpleString("mySimpleStringPropertyValue_" + i));
        msg.putStringProperty(new SimpleString("myNullSimpleStringProperty"), (SimpleString) null);
        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();
    for (int i = 0; i < 5; i++) {
        ClientMessage msg = consumer.receive(CONSUMER_TIMEOUT);
        byte[] body = new byte[msg.getBodySize()];
        msg.getBodyBuffer().readBytes(body);
        assertTrue(new String(body).contains("Bob the giant pig " + i));
        assertEquals(msg.getBooleanProperty("myBooleanProperty"), Boolean.TRUE);
        assertEquals(msg.getByteProperty("myByteProperty"), new Byte("0"));
        byte[] bytes = msg.getBytesProperty("myBytesProperty");
        for (int j = 0; j < 5; j++) {
            assertEquals(j, bytes[j]);
        }
        assertEquals(i * 1.6, msg.getDoubleProperty("myDoubleProperty"), 0.000001);
        assertEquals(i * 2.5F, msg.getFloatProperty("myFloatProperty"), 0.000001);
        assertEquals(i, msg.getIntProperty("myIntProperty").intValue());
        assertEquals(Long.MAX_VALUE - i, msg.getLongProperty("myLongProperty").longValue());
        assertEquals(i, msg.getObjectProperty("myObjectProperty"));
        assertEquals(true, msg.getPropertyNames().contains(SimpleString.toSimpleString("myNullObjectProperty")));
        assertEquals(null, msg.getObjectProperty("myNullObjectProperty"));
        assertEquals(new Integer(i).shortValue(), msg.getShortProperty("myShortProperty").shortValue());
        assertEquals("myStringPropertyValue_" + i, msg.getStringProperty("myStringProperty"));
        assertEquals(true, msg.getPropertyNames().contains(SimpleString.toSimpleString("myNullStringProperty")));
        assertEquals(null, msg.getStringProperty("myNullStringProperty"));
        assertEquals(international.toString(), msg.getStringProperty("myNonAsciiStringProperty"));
        assertEquals(special, msg.getStringProperty("mySpecialCharacters"));
        assertEquals(new SimpleString("mySimpleStringPropertyValue_" + i), msg.getSimpleStringProperty(new SimpleString("mySimpleStringProperty")));
        assertEquals(true, msg.getPropertyNames().contains(SimpleString.toSimpleString("myNullSimpleStringProperty")));
        assertEquals(null, msg.getSimpleStringProperty("myNullSimpleStringProperty"));
    }
}
Also used : 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) 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) 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) Test(org.junit.Test)

Example 15 with XmlDataImporter

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

the class XmlImportExportTest method testMessageAttributes.

@Test
public void testMessageAttributes() throws Exception {
    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.setExpiration(Long.MAX_VALUE);
    msg.setPriority((byte) 0);
    msg.setTimestamp(Long.MAX_VALUE - 1);
    msg.setUserID(UUIDGenerator.getInstance().generateUUID());
    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(Long.MAX_VALUE, msg.getExpiration());
    assertEquals((byte) 0, msg.getPriority());
    assertEquals(Long.MAX_VALUE - 1, msg.getTimestamp());
    assertNotNull(msg.getUserID());
}
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