use of org.apache.activemq.artemis.cli.commands.tools.xml.XmlDataExporter 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();
}
use of org.apache.activemq.artemis.cli.commands.tools.xml.XmlDataExporter 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());
}
use of org.apache.activemq.artemis.cli.commands.tools.xml.XmlDataExporter 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);
}
}
use of org.apache.activemq.artemis.cli.commands.tools.xml.XmlDataExporter 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);
}
use of org.apache.activemq.artemis.cli.commands.tools.xml.XmlDataExporter 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);
}
Aggregations