lttng: Add a diagram showing the dependencies between plugins
[deliverable/tracecompass.git] / org.eclipse.linuxtools.lttng2.ui.tests / src / org / eclipse / linuxtools / lttng2 / ui / tests / control / service / LTTngControlServiceTest.java
index d4fd95a874420c12ce0e98747c19df1dc2064561..aebad3bc5673ed8c0dfba79136fa232c2b48d351 100644 (file)
@@ -1,5 +1,5 @@
 /**********************************************************************
- * Copyright (c) 2012, 2013 Ericsson
+ * Copyright (c) 2012, 2014 Ericsson
  *
  * All rights reserved. This program and the accompanying materials are
  * made available under the terms of the Eclipse Public License v1.0 which
@@ -35,6 +35,7 @@ import org.eclipse.linuxtools.internal.lttng2.core.control.model.IDomainInfo;
 import org.eclipse.linuxtools.internal.lttng2.core.control.model.IEventInfo;
 import org.eclipse.linuxtools.internal.lttng2.core.control.model.IFieldInfo;
 import org.eclipse.linuxtools.internal.lttng2.core.control.model.ISessionInfo;
+import org.eclipse.linuxtools.internal.lttng2.core.control.model.ISnapshotInfo;
 import org.eclipse.linuxtools.internal.lttng2.core.control.model.IUstProviderInfo;
 import org.eclipse.linuxtools.internal.lttng2.core.control.model.LogLevelType;
 import org.eclipse.linuxtools.internal.lttng2.core.control.model.TraceEnablement;
@@ -43,6 +44,7 @@ import org.eclipse.linuxtools.internal.lttng2.core.control.model.TraceLogLevel;
 import org.eclipse.linuxtools.internal.lttng2.core.control.model.TraceSessionState;
 import org.eclipse.linuxtools.internal.lttng2.core.control.model.impl.BufferType;
 import org.eclipse.linuxtools.internal.lttng2.core.control.model.impl.ChannelInfo;
+import org.eclipse.linuxtools.internal.lttng2.core.control.model.impl.SessionInfo;
 import org.eclipse.linuxtools.internal.lttng2.stubs.service.CommandShellFactory;
 import org.eclipse.linuxtools.internal.lttng2.stubs.shells.LTTngToolsFileShell;
 import org.eclipse.linuxtools.internal.lttng2.ui.Activator;
@@ -100,6 +102,9 @@ public class LTTngControlServiceTest {
     private static final String SCEN_CALIBRATE_HANDLING = "CalibrateHandling";
     private static final String SCEN_CREATE_SESSION_2_1 = "CreateSessionLttng2.1";
     private static final String SCEN_CREATE_SESSION_VERBOSE_2_1 = "CreateSessionLttngVerbose2.1";
+    private static final String SCEN_CREATE_SNAPSHOT_SESSION = "CreateSessionSnapshot";
+    private static final String SCEN_CREATE_STREAMED_SNAPSHOT_SESSION = "CreateSessionStreamedSnapshot";
+    private static final String SCEN_CREATE_SNAPSHOT_SESSION_ERRORS = "CreateSessionSnapshotErrors";
 
     // ------------------------------------------------------------------------
     // Test data
@@ -707,7 +712,7 @@ public class LTTngControlServiceTest {
         try {
             fShell.setScenario(SCEN_CREATE_SESSION1);
 
-            ISessionInfo info = fService.createSession("mysession2", null, new NullProgressMonitor());
+            ISessionInfo info = fService.createSession(new SessionInfo("mysession2"), new NullProgressMonitor());
             assertNotNull(info);
             assertEquals("mysession2", info.getName());
             assertNotNull(info.getSessionPath());
@@ -726,7 +731,7 @@ public class LTTngControlServiceTest {
             fShell.setScenario(SCEN_CREATE_SESSION_WITH_PROMPT);
 
             // First line has no shell prompt before the output
-            ISessionInfo info = fService.createSession("mysession2", null, new NullProgressMonitor());
+            ISessionInfo info = fService.createSession(new SessionInfo("mysession2"), new NullProgressMonitor());
             assertNotNull(info);
             assertEquals("mysession2", info.getName());
             assertNotNull(info.getSessionPath());
@@ -743,28 +748,30 @@ public class LTTngControlServiceTest {
         fShell.setScenario(SCEN_CREATE_SESSION_VARIANTS);
 
         try {
-            fService.createSession("alreadyExist", null, new NullProgressMonitor());
+            fService.createSession(new SessionInfo("alreadyExist"), new NullProgressMonitor());
             fail("No exeption thrown");
         } catch (ExecutionException e) {
             // success
         }
 
         try {
-            fService.createSession("wrongName", null, new NullProgressMonitor());
+            fService.createSession(new SessionInfo("wrongName"), new NullProgressMonitor());
             fail("No exeption thrown");
         } catch (ExecutionException e) {
             // success
         }
 
         try {
-            fService.createSession("withPath", "/home/user/hallo", new NullProgressMonitor());
+            ISessionInfo sessionInfo = new SessionInfo("withPath");
+            sessionInfo.setSessionPath("/home/user/hallo");
+            fService.createSession(sessionInfo, new NullProgressMonitor());
             fail("No exeption thrown");
         } catch (ExecutionException e) {
             // success
         }
 
         try {
-            ISessionInfo info = fService.createSession("session with spaces", null, new NullProgressMonitor());
+            ISessionInfo info = fService.createSession(new SessionInfo("session with spaces"), new NullProgressMonitor());
             assertNotNull(info);
             assertEquals("session with spaces", info.getName());
             assertNotNull(info.getSessionPath());
@@ -776,7 +783,9 @@ public class LTTngControlServiceTest {
         }
 
         try {
-            ISessionInfo info = fService.createSession("pathWithSpaces", "/home/user/hallo user/here", new NullProgressMonitor());
+            ISessionInfo sessionInfo = new SessionInfo("pathWithSpaces");
+            sessionInfo.setSessionPath("/home/user/hallo user/here");
+            ISessionInfo info = fService.createSession(sessionInfo, new NullProgressMonitor());
             assertNotNull(info);
             assertEquals("pathWithSpaces", info.getName());
             assertNotNull(info.getSessionPath());
@@ -816,7 +825,7 @@ public class LTTngControlServiceTest {
         try {
             ((LTTngControlService)fService).setVersion("2.2.0");
             String sessionName = "mysession2";
-            List<String> list = new ArrayList<String>();
+            List<String> list = new ArrayList<>();
             String kernelChannel0 = "mychannel0";
             String kernelChannel1 = "mychannel1";
             list.add(kernelChannel0);
@@ -860,7 +869,7 @@ public class LTTngControlServiceTest {
         try {
             ((LTTngControlService)fService).setVersion("2.2.0");
             String sessionName = "mysession2";
-            List<String> list = new ArrayList<String>();
+            List<String> list = new ArrayList<>();
             String USTChannel = "ustChannel";
             list.add(USTChannel);
             fShell.setScenario(SCEN_CHANNEL_HANDLING);
@@ -887,7 +896,7 @@ public class LTTngControlServiceTest {
         try {
             ((LTTngControlService)fService).setVersion("2.2.0");
             String sessionName = "mysession2";
-            List<String> list = new ArrayList<String>();
+            List<String> list = new ArrayList<>();
             String USTChannel = "ustChannel";
             list.add(USTChannel);
             fShell.setScenario(SCEN_CHANNEL_HANDLING);
@@ -916,7 +925,7 @@ public class LTTngControlServiceTest {
         try {
 
             String sessionName = "mysession2";
-            List<String> list = new ArrayList<String>();
+            List<String> list = new ArrayList<>();
             String kernelChannel0 = "mychannel0";
             String kernelChannel1 = "mychannel1";
             list.add(kernelChannel0);
@@ -939,7 +948,7 @@ public class LTTngControlServiceTest {
         try {
 
             String sessionName = "mysession2";
-            List<String> list = new ArrayList<String>();
+            List<String> list = new ArrayList<>();
             String kernelChannel0 = "mychannel0";
             String kernelChannel1 = "mychannel1";
             list.add(kernelChannel0);
@@ -964,7 +973,7 @@ public class LTTngControlServiceTest {
         try {
             // 1) session name, channel = null, 3 event names, kernel
             String sessionName = "mysession2";
-            List<String> list = new ArrayList<String>();
+            List<String> list = new ArrayList<>();
             String eventName0 = "block_rq_remap";
             String eventName1 = "block_bio_remap";
             String eventName2 = "softirq_entry";
@@ -1073,7 +1082,7 @@ public class LTTngControlServiceTest {
             String sessionName = "mysession2";
             String channelName = "mychannel";
             String eventName = "ust_tests_hello:tptest_sighandler";
-            List<String> contexts = new ArrayList<String>();
+            List<String> contexts = new ArrayList<>();
             contexts.add("prio");
             contexts.add("pid");
 
@@ -1084,7 +1093,7 @@ public class LTTngControlServiceTest {
             assertEquals(12, availContexts.size());
 
             // A very "hard-coded" way to verify but it works ...
-            Set<String> expectedContexts = new HashSet<String>();
+            Set<String> expectedContexts = new HashSet<>();
             expectedContexts.add("pid");
             expectedContexts.add("procname");
             expectedContexts.add("prio");
@@ -1115,7 +1124,7 @@ public class LTTngControlServiceTest {
         String sessionName = "mysession2";
         String channelName = "mychannel";
         String eventName = "ust_tests_hello:tptest_sighandler";
-        List<String> contexts = new ArrayList<String>();
+        List<String> contexts = new ArrayList<>();
         contexts.add("prio");
         contexts.add("pid");
         fShell.setScenario(SCEN_CONTEXT_ERROR_HANDLING);
@@ -1162,35 +1171,51 @@ public class LTTngControlServiceTest {
         try {
             fShell.setScenario(SCEN_CREATE_SESSION_2_1);
 
-            ISessionInfo info = fService.createSession("mysession", "net://172.0.0.1", null, null, new NullProgressMonitor());
+            ISessionInfo sessionInfo = new SessionInfo("mysession");
+            sessionInfo.setNetworkUrl("net://172.0.0.1");
+            sessionInfo.setStreamedTrace(true);
+            ISessionInfo info = fService.createSession(sessionInfo, new NullProgressMonitor());
             assertNotNull(info);
             assertEquals("mysession", info.getName());
             assertEquals("net://172.0.0.1", info.getSessionPath());
             assertTrue(info.isStreamedTrace());
             fService.destroySession("mysession", new NullProgressMonitor());
 
-            info = fService.createSession("mysession", "file:///tmp", null, null, new NullProgressMonitor());
+            sessionInfo = new SessionInfo("mysession");
+            sessionInfo.setStreamedTrace(true);
+            sessionInfo.setNetworkUrl("file:///tmp");
+            info = fService.createSession(sessionInfo, new NullProgressMonitor());
             assertNotNull(info);
             assertEquals("mysession", info.getName());
             assertEquals("file:///tmp", info.getSessionPath());
             assertTrue(!info.isStreamedTrace());
             fService.destroySession("mysession", new NullProgressMonitor());
 
-            info = fService.createSession("mysession", "file:///tmp", null, null, new NullProgressMonitor());
+            sessionInfo = new SessionInfo("mysession");
+            sessionInfo.setStreamedTrace(true);
+            sessionInfo.setNetworkUrl("file:///tmp");
+            info = fService.createSession(sessionInfo, new NullProgressMonitor());
             assertNotNull(info);
             assertEquals("mysession", info.getName());
             assertEquals("file:///tmp", info.getSessionPath());
             assertTrue(!info.isStreamedTrace());
             fService.destroySession("mysession", new NullProgressMonitor());
 
-            info = fService.createSession("mysession", null, "tcp://172.0.0.1", "tcp://172.0.0.1:5343", new NullProgressMonitor());
+            sessionInfo = new SessionInfo("mysession");
+            sessionInfo.setStreamedTrace(true);
+            sessionInfo.setControlUrl("tcp://172.0.0.1");
+            sessionInfo.setDataUrl("tcp://172.0.0.1:5343");
+            info = fService.createSession(sessionInfo, new NullProgressMonitor());
             assertNotNull(info);
             assertEquals("mysession", info.getName());
             assertEquals("", info.getSessionPath()); // the complete network path is not available at this point
             assertTrue(info.isStreamedTrace());
             fService.destroySession("mysession", new NullProgressMonitor());
 
-            info = fService.createSession("mysession", "net://172.0.0.1:1234:2345", null, null, new NullProgressMonitor());
+            sessionInfo = new SessionInfo("mysession");
+            sessionInfo.setStreamedTrace(true);
+            sessionInfo.setNetworkUrl("net://172.0.0.1:1234:2345");
+            info = fService.createSession(sessionInfo, new NullProgressMonitor());
             assertNotNull(info);
             assertEquals("mysession", info.getName());
             assertEquals("net://172.0.0.1:1234:2345", info.getSessionPath());
@@ -1199,7 +1224,10 @@ public class LTTngControlServiceTest {
 
             // verbose
             enableVerbose();
-            info = fService.createSession("mysession", "net://172.0.0.1", null, null, new NullProgressMonitor());
+            sessionInfo = new SessionInfo("mysession");
+            sessionInfo.setStreamedTrace(true);
+            sessionInfo.setNetworkUrl("net://172.0.0.1");
+            info = fService.createSession(sessionInfo, new NullProgressMonitor());
             assertNotNull(info);
             assertEquals("mysession", info.getName());
             assertEquals("net://172.0.0.1", info.getSessionPath());
@@ -1219,7 +1247,10 @@ public class LTTngControlServiceTest {
             fShell.setScenario(SCEN_CREATE_SESSION_VERBOSE_2_1);
 
             enableVerbose();
-            ISessionInfo info = fService.createSession("mysession", "net://172.0.0.1", null, null, new NullProgressMonitor());
+            ISessionInfo sessionInfo = new SessionInfo("mysession");
+            sessionInfo.setStreamedTrace(true);
+            sessionInfo.setNetworkUrl("net://172.0.0.1");
+            ISessionInfo info = fService.createSession(sessionInfo, new NullProgressMonitor());
             assertNotNull(info);
             assertEquals("mysession", info.getName());
             assertEquals("net://172.0.0.1", info.getSessionPath());
@@ -1232,6 +1263,116 @@ public class LTTngControlServiceTest {
         }
     }
 
+    @Test
+    public void testCreateSnapshotSession() {
+        try {
+            fShell.setScenario(SCEN_CREATE_SNAPSHOT_SESSION);
+            ISessionInfo params = new SessionInfo("mysession");
+            params.setSnapshot(true);
+            ISessionInfo sessionInfo = fService.createSession(params, new NullProgressMonitor());
+            assertNotNull(sessionInfo);
+            assertEquals("mysession", sessionInfo.getName());
+            assertTrue(sessionInfo.isSnapshotSession());
+            assertEquals("", sessionInfo.getSessionPath());
+            assertTrue(!sessionInfo.isStreamedTrace());
+
+            assertEquals(TraceSessionState.INACTIVE, sessionInfo.getSessionState());
+
+            String[] names = fService.getSessionNames(new NullProgressMonitor());
+            assertEquals(names[0], "mysession");
+
+            ISnapshotInfo snapshotInfo = fService.getSnapshotInfo("mysession", new NullProgressMonitor());
+            assertNotNull(snapshotInfo);
+            assertEquals("snapshot-1", snapshotInfo.getName());
+            assertEquals("/home/user/lttng-traces/mysession-20130913-141651", snapshotInfo.getSnapshotPath());
+            assertEquals(1, snapshotInfo.getId());
+            assertTrue(!snapshotInfo.isStreamedSnapshot());
+
+            // we need to set the snapshotInfo to so that the session path is set correctly
+            sessionInfo.setSnapshotInfo(snapshotInfo);
+            assertEquals("/home/user/lttng-traces/mysession-20130913-141651", sessionInfo.getSessionPath());
+
+            fService.recordSnapshot("mysession", new NullProgressMonitor());
+
+            fService.destroySession("mysession", new NullProgressMonitor());
+
+        } catch (ExecutionException e) {
+            fail(e.toString());
+        }
+    }
+
+    public void testCreateStreamedSnapshotSession() {
+        try {
+            fShell.setScenario(SCEN_CREATE_STREAMED_SNAPSHOT_SESSION);
+
+            ISessionInfo params = new SessionInfo("mysession");
+            params.setNetworkUrl("net://172.0.0.1");
+            ISessionInfo sessionInfo = fService.createSession(params, new NullProgressMonitor());
+            assertNotNull(sessionInfo);
+            assertEquals("mysession", sessionInfo.getName());
+            assertTrue(sessionInfo.isSnapshotSession());
+
+            assertEquals(TraceSessionState.INACTIVE, sessionInfo.getSessionState());
+            assertTrue(sessionInfo.isStreamedTrace());
+
+            String[] names = fService.getSessionNames(new NullProgressMonitor());
+            assertEquals(names[0], "mysession");
+
+
+            ISnapshotInfo snapshotInfo = sessionInfo.getSnapshotInfo();
+            assertNotNull(sessionInfo);
+            assertEquals("snapshot-2", snapshotInfo.getName());
+            assertEquals("net4://172.0.0.1:5342/", snapshotInfo.getSnapshotPath());
+            assertEquals(2, snapshotInfo.getId());
+            assertTrue(snapshotInfo.isStreamedSnapshot());
+
+            // we need to set the snapshotInfo to so that the session path is set correctly
+            sessionInfo.setSnapshotInfo(snapshotInfo);
+            assertEquals("net4://172.0.0.1:5342/", sessionInfo.getSessionPath());
+
+            fService.recordSnapshot("mysession", new NullProgressMonitor());
+
+            fService.destroySession("mysession", new NullProgressMonitor());
+
+        } catch (ExecutionException e) {
+            fail(e.toString());
+        }
+    }
+
+
+    @Test
+    public void testCreateSnapshotSessionErrors() {
+        try {
+            fShell.setScenario(SCEN_CREATE_SNAPSHOT_SESSION_ERRORS);
+
+            String[] names = fService.getSessionNames(new NullProgressMonitor());
+            assertEquals(names[0], "mysession");
+        } catch (ExecutionException e) {
+            fail(e.toString());
+        }
+
+        try {
+            fService.getSnapshotInfo("blabla", new NullProgressMonitor());
+            fail("getSnapshoInfo() didn't fail");
+        } catch (ExecutionException e) {
+            // successful
+        }
+
+        try {
+            fService.recordSnapshot("blabla", new NullProgressMonitor());
+            fail("getSnapshoInfo() didn't fail");
+        } catch (ExecutionException e) {
+            // successful
+        }
+
+        try {
+            fService.recordSnapshot("mysession", new NullProgressMonitor());
+            fail("getSnapshoInfo() didn't fail");
+        } catch (ExecutionException e) {
+            // successful
+        }
+    }
+
     private static void enableVerbose() {
         // verbose
         ControlCommandLogger.init(ControlPreferences.getInstance().getLogfilePath(), false);
This page took 0.031716 seconds and 5 git commands to generate.