[activemq-artemis] branch master updated: ARTEMIS-2215 Fixing LiveCrashOnBAckupSyncTest"

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

[activemq-artemis] branch master updated: ARTEMIS-2215 Fixing LiveCrashOnBAckupSyncTest"

clebertsuconic-2
This is an automated email from the ASF dual-hosted git repository.

clebertsuconic pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/activemq-artemis.git


The following commit(s) were added to refs/heads/master by this push:
     new 5ae3dba  ARTEMIS-2215 Fixing LiveCrashOnBAckupSyncTest"
5ae3dba is described below

commit 5ae3dba0729e1523cb43173c19adf2c6c5667e01
Author: Clebert Suconic <[hidden email]>
AuthorDate: Fri Jan 11 14:00:40 2019 -0500

    ARTEMIS-2215 Fixing LiveCrashOnBAckupSyncTest"
---
 .../failover/LiveCrashOnBackupSyncTest.java        | 79 ++++++++++------------
 1 file changed, 34 insertions(+), 45 deletions(-)

diff --git a/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/cluster/failover/LiveCrashOnBackupSyncTest.java b/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/cluster/failover/LiveCrashOnBackupSyncTest.java
index c3692ea..db414b8 100644
--- a/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/cluster/failover/LiveCrashOnBackupSyncTest.java
+++ b/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/cluster/failover/LiveCrashOnBackupSyncTest.java
@@ -47,60 +47,63 @@ import org.apache.activemq.artemis.core.settings.impl.AddressSettings;
 import org.apache.activemq.artemis.junit.Wait;
 import org.apache.activemq.artemis.spi.core.security.ActiveMQJAASSecurityManager;
 import org.apache.activemq.artemis.spi.core.security.jaas.InVMLoginModule;
+import org.apache.activemq.artemis.tests.util.ActiveMQTestBase;
 import org.apache.activemq.artemis.tests.util.SpawnedVMSupport;
 import org.apache.activemq.artemis.utils.actors.ArtemisExecutor;
-import org.junit.After;
 import org.junit.Assert;
 import org.junit.Before;
 import org.junit.Test;
 
 import java.io.File;
-import java.io.FileNotFoundException;
-import java.io.IOException;
 import java.lang.management.ManagementFactory;
 import java.util.ArrayList;
 import java.util.Collection;
 import java.util.Set;
 import java.util.TreeSet;
 import java.util.concurrent.ScheduledExecutorService;
+import java.util.concurrent.TimeUnit;
 
-public class LiveCrashOnBackupSyncTest {
+public class LiveCrashOnBackupSyncTest extends ActiveMQTestBase {
 
    static int OK = 2;
-   public static String instancePth = System.getProperty("java.io.tmpdir");
+
+   public File liveDir;
+   public File backupDir;
 
    @Before
-   public void setUp() throws Exception {
-      deleteFile(new File(instancePth + "live"));
-      deleteFile(new File(instancePth + "backup"));
+   public void setupDirectories() throws Exception {
+
+      liveDir = temporaryFolder.newFolder("live");
+      backupDir = temporaryFolder.newFolder("backup");
+      liveDir.mkdirs();
+      backupDir.mkdirs();
    }
 
    @Test
    public void liveCrashOnBackupSyncLargeMessageTest() throws Exception {
-      Process process = SpawnedVMSupport.spawnVM(LiveCrashOnBackupSyncTest.class.getCanonicalName());
-      Assert.assertEquals(OK, process.waitFor());
-
-      Configuration liveConfiguration = createLiveConfiguration();
-      ActiveMQServer liveServer = ActiveMQServers.newActiveMQServer(liveConfiguration);
-      liveServer.start();
-      Wait.waitFor(() -> liveServer.isStarted());
+      Process process = SpawnedVMSupport.spawnVM(LiveCrashOnBackupSyncTest.class.getCanonicalName(), backupDir.getAbsolutePath(), liveDir.getAbsolutePath());
+      try {
+         Assert.assertEquals(OK, process.waitFor());
 
-      File liveLMDir = liveServer.getConfiguration().getLargeMessagesLocation();
-      Set<Long> liveLM = getAllMessageFileIds(liveLMDir);
-      Assert.assertEquals("we really ought to delete these after delivery", 0, liveLM.size());
-      liveServer.stop();
-   }
+         Configuration liveConfiguration = createLiveConfiguration();
+         ActiveMQServer liveServer = ActiveMQServers.newActiveMQServer(liveConfiguration);
+         liveServer.start();
+         Wait.waitFor(() -> liveServer.isStarted());
 
-   @After
-   public void tearDown() throws FileNotFoundException {
-      deleteFile(new File(instancePth + "live"));
-      deleteFile(new File(instancePth + "backup"));
+         File liveLMDir = liveServer.getConfiguration().getLargeMessagesLocation();
+         Set<Long> liveLM = getAllMessageFileIds(liveLMDir);
+         Assert.assertEquals("we really ought to delete these after delivery", 0, liveLM.size());
+         liveServer.stop();
+      } finally {
+         process.destroy();
+         Assert.assertTrue(process.waitFor(5, TimeUnit.SECONDS));
+         Assert.assertFalse(process.isAlive());
+      }
    }
 
    private Configuration createLiveConfiguration() throws Exception {
       Configuration conf = new ConfigurationImpl();
       conf.setName("localhost::live");
-      File liveDir = newFolder("live");
       conf.setBrokerInstance(liveDir);
       conf.addAcceptorConfiguration("live", "tcp://localhost:61616");
       conf.addConnectorConfiguration("backup", "tcp://localhost:61617");
@@ -124,7 +127,6 @@ public class LiveCrashOnBackupSyncTest {
    private Configuration createBackupConfiguration() throws Exception {
       Configuration conf = new ConfigurationImpl();
       conf.setName("localhost::backup");
-      File backupDir = newFolder("backup");
       conf.setBrokerInstance(backupDir);
       ReplicaPolicyConfiguration haPolicy = new ReplicaPolicyConfiguration();
       haPolicy.setClusterName("cluster");
@@ -144,25 +146,6 @@ public class LiveCrashOnBackupSyncTest {
       return conf;
    }
 
-   private File newFolder(String live) throws IOException {
-      File file = new File(instancePth + live);
-      if (!file.exists()) {
-         file.mkdirs();
-      }
-      return file;
-   }
-
-   private void deleteFile(File path) throws FileNotFoundException {
-      if (!path.exists())
-         return;
-      if (path.isDirectory()) {
-         for (File f : path.listFiles()) {
-            deleteFile(f);
-         }
-      }
-      path.delete();
-   }
-
    private void createProducerSendSomeLargeMessages(int msgCount) throws Exception {
       byte[] buffer = new byte[100 * 1024];
       ServerLocator locator = ServerLocatorImpl.newLocator("tcp://localhost:61616");
@@ -214,7 +197,13 @@ public class LiveCrashOnBackupSyncTest {
 
    public static void main(String[] arg) {
       try {
+         if (arg.length < 2) {
+            System.err.println("Expected backup and live as parameters");
+            System.exit(-1);
+         }
          LiveCrashOnBackupSyncTest stop = new LiveCrashOnBackupSyncTest();
+         stop.backupDir = new File(arg[0]);
+         stop.liveDir = new File(arg[1]);
          Configuration liveConfiguration = stop.createLiveConfiguration();
          ActiveMQServer liveServer = new ActiveMQServerImpl(liveConfiguration, ManagementFactory.getPlatformMBeanServer(), new ActiveMQJAASSecurityManager(InVMLoginModule.class.getName(), new SecurityConfiguration())) {
             @Override