Search in sources :

Example 16 with XmlDataImporter

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

the class XmlImportExportTest method testBindingAttributes.

@Test
public void testBindingAttributes() throws Exception {
    ClientSession session = basicSetUp();
    session.createQueue("addressName1", RoutingType.MULTICAST, "queueName1", true);
    session.createQueue("addressName1", RoutingType.MULTICAST, "queueName2", "bob", true);
    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);
    ClientSession.QueueQuery queueQuery = session.queueQuery(new SimpleString("queueName1"));
    assertEquals("addressName1", queueQuery.getAddress().toString());
    assertNull(queueQuery.getFilterString());
    queueQuery = session.queueQuery(new SimpleString("queueName2"));
    assertEquals("addressName1", queueQuery.getAddress().toString());
    assertEquals("bob", queueQuery.getFilterString().toString());
    assertEquals(true, queueQuery.isDurable());
}
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) XmlDataImporter(org.apache.activemq.artemis.cli.commands.tools.xml.XmlDataImporter) Test(org.junit.Test)

Example 17 with XmlDataImporter

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

the class XmlImportExportTest method testMessageTypes.

@Test
public void testMessageTypes() 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);
    producer.send(msg);
    msg = session.createMessage(Message.DEFAULT_TYPE, true);
    producer.send(msg);
    msg = session.createMessage(Message.MAP_TYPE, true);
    producer.send(msg);
    msg = session.createMessage(Message.OBJECT_TYPE, true);
    producer.send(msg);
    msg = session.createMessage(Message.STREAM_TYPE, true);
    producer.send(msg);
    msg = session.createMessage(Message.TEXT_TYPE, true);
    producer.send(msg);
    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, 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());
    msg = consumer.receive(CONSUMER_TIMEOUT);
    assertEquals(Message.DEFAULT_TYPE, msg.getType());
    msg = consumer.receive(CONSUMER_TIMEOUT);
    assertEquals(Message.MAP_TYPE, msg.getType());
    msg = consumer.receive(CONSUMER_TIMEOUT);
    assertEquals(Message.OBJECT_TYPE, msg.getType());
    msg = consumer.receive(CONSUMER_TIMEOUT);
    assertEquals(Message.STREAM_TYPE, msg.getType());
    msg = consumer.receive(CONSUMER_TIMEOUT);
    assertEquals(Message.TEXT_TYPE, msg.getType());
    msg = consumer.receive(CONSUMER_TIMEOUT);
    assertEquals(Message.DEFAULT_TYPE, msg.getType());
}
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 18 with XmlDataImporter

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

the class XmlImportExportTest method testPartialQueue.

@Test
public void testPartialQueue() throws Exception {
    ClientSession session = basicSetUp();
    session.createQueue("myAddress", RoutingType.MULTICAST, "myQueue1", true);
    session.createQueue("myAddress", RoutingType.MULTICAST, "myQueue2", true);
    ClientProducer producer = session.createProducer("myAddress");
    ClientMessage msg = session.createMessage(true);
    producer.send(msg);
    ClientConsumer consumer = session.createConsumer("myQueue1");
    session.start();
    msg = consumer.receive(CONSUMER_TIMEOUT);
    assertNotNull(msg);
    msg.acknowledge();
    consumer.close();
    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);
    consumer = session.createConsumer("myQueue1");
    session.start();
    msg = consumer.receive(CONSUMER_TIMEOUT);
    assertNull(msg);
    consumer.close();
    consumer = session.createConsumer("myQueue2");
    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)

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