Option to performance profile SingleFeatureTest
[odlparent.git] / features-test / src / main / java / org / opendaylight / odlparent / featuretest / SingleFeatureTest.java
index 8aa7074bc78ec54f0880fad6349cc1878bd4e047..54e4726eda74919212c76bc3fb7fff3fb0fc2d51 100644 (file)
@@ -51,12 +51,15 @@ import org.slf4j.LoggerFactory;
 
 @RunWith(PerRepoTestRunner.class)
 public class SingleFeatureTest {
+
     private static final String MAVEN_REPO_LOCAL = "maven.repo.local";
     private static final String ORG_OPS4J_PAX_URL_MVN_LOCAL_REPOSITORY = "org.ops4j.pax.url.mvn.localRepository";
     private static final String ORG_OPS4J_PAX_URL_MVN_REPOSITORIES = "org.ops4j.pax.url.mvn.repositories";
     private static final String ETC_ORG_OPS4J_PAX_URL_MVN_CFG = "etc/org.ops4j.pax.url.mvn.cfg";
     private static final String ETC_ORG_OPS4J_PAX_LOGGING_CFG = "etc/org.ops4j.pax.logging.cfg";
     private static final String KEEP_UNPACK_DIRECTORY_PROP = "karaf.keep.unpack";
+    private static final String PROFILE_PROP = "karaf.featureTest.profile";
+
     private static final String LOG4J_LOGGER_ORG_OPENDAYLIGHT_YANGTOOLS_FEATURETEST =
             "log4j.logger.org.opendaylight.odlparent.featuretest";
     private static final Logger LOG = LoggerFactory.getLogger(SingleFeatureTest.class);
@@ -118,6 +121,12 @@ public class SingleFeatureTest {
             // TODO: Find a way to inherit memory limits from Maven options.
             new VMOption("-Xmx2g"),
             new VMOption("-XX:MaxPermSize=512m"),
+            when(Boolean.getBoolean(PROFILE_PROP)).useOptions(
+                new VMOption("-XX:+UnlockCommercialFeatures"),
+                new VMOption("-XX:+FlightRecorder"),
+                new VMOption("-XX:FlightRecorderOptions=defaultrecording=true,dumponexit=true,dumponexitpath="
+                               + getNewJFRFile())
+            ),
             getKarafDistroOption(),
             when(Boolean.getBoolean(KEEP_UNPACK_DIRECTORY_PROP)).useOptions(keepRuntimeFolder()),
             configureConsole().ignoreLocalConsole(),
@@ -160,7 +169,11 @@ public class SingleFeatureTest {
         };
     }
 
-    private Option standardKarafFeatures() {
+    private String getNewJFRFile() throws IOException {
+        return File.createTempFile("SingleFeatureTest-Karaf-JavaFlightRecorder", ".jfr").getAbsolutePath();
+    }
+
+    private Option standardKarafFeatures() throws IOException {
         String url = maven().groupId("org.apache.karaf.features").artifactId("standard").classifier("features").type(
                 "xml").version(getKarafVersion()).getURL();
         try {
@@ -171,8 +184,8 @@ public class SingleFeatureTest {
             }
 
             return features(url, featureNames.toArray(new String[featureNames.size()]));
-        } catch (Exception e) {
-            throw new RuntimeException("Could not obtain features from URL " + url, e);
+        } catch (IOException e) {
+            throw new IOException("Could not obtain features from URL: " + url, e);
         }
     }