Repository: activemq-artemis
Updated Branches:
  refs/heads/master 8fc8ae2ad -> 2a72923e8


ARTEMIS-1652 XmlDataImporter forgets delete tmp files

When using the tool to import more than one large messages
from xml exported file, this utility class will create some
tmp files, each for one large message. However it only delete
one of the tmp files. All the rest of tmp files won't get
cleaned up.


Project: http://git-wip-us.apache.org/repos/asf/activemq-artemis/repo
Commit: http://git-wip-us.apache.org/repos/asf/activemq-artemis/commit/17db696e
Tree: http://git-wip-us.apache.org/repos/asf/activemq-artemis/tree/17db696e
Diff: http://git-wip-us.apache.org/repos/asf/activemq-artemis/diff/17db696e

Branch: refs/heads/master
Commit: 17db696e8b43ea461b8cbaa6010538f2e20af549
Parents: 8fc8ae2
Author: Howard Gao <howard....@gmail.com>
Authored: Thu Feb 1 22:36:57 2018 +0800
Committer: Clebert Suconic <clebertsuco...@apache.org>
Committed: Fri Feb 2 12:11:37 2018 -0500

----------------------------------------------------------------------
 .../cli/commands/tools/xml/XmlDataImporter.java | 13 +--
 .../persistence/XmlImportExportTest.java        | 87 ++++++++++++++++++++
 2 files changed, 94 insertions(+), 6 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/17db696e/artemis-cli/src/main/java/org/apache/activemq/artemis/cli/commands/tools/xml/XmlDataImporter.java
----------------------------------------------------------------------
diff --git 
a/artemis-cli/src/main/java/org/apache/activemq/artemis/cli/commands/tools/xml/XmlDataImporter.java
 
b/artemis-cli/src/main/java/org/apache/activemq/artemis/cli/commands/tools/xml/XmlDataImporter.java
index 1f4062e..102cf5a 100644
--- 
a/artemis-cli/src/main/java/org/apache/activemq/artemis/cli/commands/tools/xml/XmlDataImporter.java
+++ 
b/artemis-cli/src/main/java/org/apache/activemq/artemis/cli/commands/tools/xml/XmlDataImporter.java
@@ -273,7 +273,7 @@ public final class XmlDataImporter extends ActionAbstract {
 
          if (sort) {
             for (MessageTemp msgtmp : messages) {
-               sendMessage(msgtmp.queues, msgtmp.message);
+               sendMessage(msgtmp.queues, msgtmp.message, msgtmp.tempFileName);
             }
          }
 
@@ -354,9 +354,9 @@ public final class XmlDataImporter extends ActionAbstract {
       }
 
       if (sort) {
-         messages.add(new MessageTemp(id, queues, message));
+         messages.add(new MessageTemp(id, queues, message, tempFileName));
       } else {
-         sendMessage(queues, message);
+         sendMessage(queues, message, tempFileName);
       }
    }
 
@@ -365,12 +365,14 @@ public final class XmlDataImporter extends ActionAbstract 
{
       long id;
       List<String> queues;
       Message message;
+      String tempFileName;
 
-      MessageTemp(long id, List<String> queues, Message message) {
+      MessageTemp(long id, List<String> queues, Message message, String 
tempFileName) {
          this.message = message;
          this.queues = queues;
          this.message = message;
          this.id = id;
+         this.tempFileName = tempFileName;
       }
    }
 
@@ -399,7 +401,7 @@ public final class XmlDataImporter extends ActionAbstract {
       return type;
    }
 
-   private void sendMessage(List<String> queues, Message message) throws 
Exception {
+   private void sendMessage(List<String> queues, Message message, String 
tempFileName) throws Exception {
       StringBuilder logMessage = new StringBuilder();
       String destination = addressMap.get(queues.get(0));
 
@@ -451,7 +453,6 @@ public final class XmlDataImporter extends ActionAbstract {
          if (!tempFile.delete()) {
             ActiveMQServerLogger.LOGGER.couldNotDeleteTempFile(tempFileName);
          }
-         tempFileName = "";
       }
    }
 

http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/17db696e/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/persistence/XmlImportExportTest.java
----------------------------------------------------------------------
diff --git 
a/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/persistence/XmlImportExportTest.java
 
b/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/persistence/XmlImportExportTest.java
index a041619..3ef2380 100644
--- 
a/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/persistence/XmlImportExportTest.java
+++ 
b/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/persistence/XmlImportExportTest.java
@@ -25,6 +25,7 @@ import javax.jms.Session;
 import javax.jms.TextMessage;
 import java.io.ByteArrayInputStream;
 import java.io.ByteArrayOutputStream;
+import java.io.File;
 import java.util.Arrays;
 import java.util.Collection;
 import java.util.EnumSet;
@@ -521,6 +522,92 @@ public class XmlImportExportTest extends ActiveMQTestBase {
    }
 
    @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"));
+      }
+   }
+
+   @Test
    public void testLargeJmsTextMessage() throws Exception {
       basicSetUp();
       ConnectionFactory cf = 
ActiveMQJMSClient.createConnectionFactory("vm://0", "test");

Reply via email to