1 /**********************************************************************
2 * Copyright (c) 2013, 2015 Ericsson
4 * All rights reserved. This program and the accompanying materials are
5 * made available under the terms of the Eclipse Public License v1.0 which
6 * accompanies this distribution, and is available at
7 * http://www.eclipse.org/legal/epl-v10.html
10 * Bernd Hufmann - Initial API and implementation
11 * Jonathan Rajotte - Support for LTTng 2.6
12 * Markus Schorn - Bug 448058: Use org.eclipse.remote in favor of RSE
13 **********************************************************************/
15 package org
.eclipse
.tracecompass
.lttng2
.control
.ui
.tests
.model
.component
;
17 import static org
.junit
.Assert
.assertEquals
;
18 import static org
.junit
.Assert
.assertNotNull
;
19 import static org
.junit
.Assert
.assertTrue
;
24 import org
.eclipse
.core
.runtime
.FileLocator
;
25 import org
.eclipse
.core
.runtime
.Path
;
26 import org
.eclipse
.jdt
.annotation
.NonNull
;
27 import org
.eclipse
.remote
.core
.IRemoteConnection
;
28 import org
.eclipse
.tracecompass
.internal
.lttng2
.control
.core
.model
.TargetNodeState
;
29 import org
.eclipse
.tracecompass
.internal
.lttng2
.control
.core
.model
.TraceSessionState
;
30 import org
.eclipse
.tracecompass
.internal
.lttng2
.control
.stubs
.dialogs
.CreateSessionDialogStub
;
31 import org
.eclipse
.tracecompass
.internal
.lttng2
.control
.stubs
.dialogs
.DestroyConfirmDialogStub
;
32 import org
.eclipse
.tracecompass
.internal
.lttng2
.control
.stubs
.service
.TestRemoteSystemProxy
;
33 import org
.eclipse
.tracecompass
.internal
.lttng2
.control
.ui
.views
.dialogs
.TraceControlDialogFactory
;
34 import org
.eclipse
.tracecompass
.internal
.lttng2
.control
.ui
.views
.model
.ITraceControlComponent
;
35 import org
.eclipse
.tracecompass
.internal
.lttng2
.control
.ui
.views
.model
.impl
.TargetNodeComponent
;
36 import org
.eclipse
.tracecompass
.internal
.lttng2
.control
.ui
.views
.model
.impl
.TraceSessionComponent
;
37 import org
.eclipse
.tracecompass
.internal
.lttng2
.control
.ui
.views
.service
.ILttngControlService
;
38 import org
.eclipse
.tracecompass
.tmf
.remote
.core
.proxy
.TmfRemoteConnectionFactory
;
39 import org
.eclipse
.tracecompass
.tmf
.ui
.tests
.shared
.WaitUtils
;
40 import org
.junit
.After
;
41 import org
.junit
.Before
;
42 import org
.junit
.Test
;
43 import org
.osgi
.framework
.FrameworkUtil
;
46 * The class {@link TraceControlKernelSessionTest} contains Kernel
47 * session/channel/event handling test cases.
49 public class TraceControlCreateSessionTest
{
51 // ------------------------------------------------------------------------
53 // ------------------------------------------------------------------------
54 private static final String TEST_STREAM
= "CreateSessionTest.cfg";
55 private static final String SCEN_SCENARIO_FILE_PROTO_TEST
= "CreateSessionFileProto";
56 private static final String SCEN_SCENARIO_CONTROL_DATA_TEST
= "CreateSessionControlData";
57 private static final String SCEN_SCENARIO_NETWORK_TEST
= "CreateSessionNetwork";
58 private static final String SCEN_SCENARIO_NETWORK2_TEST
= "CreateSessionNetwork2";
60 private static final String SESSION
= "mysession";
62 // ------------------------------------------------------------------------
64 // ------------------------------------------------------------------------
65 private TraceControlTestFacility fFacility
;
66 private IRemoteConnection fHost
= TmfRemoteConnectionFactory
.getLocalConnection();
67 private @NonNull TestRemoteSystemProxy fProxy
= new TestRemoteSystemProxy(fHost
);
68 private String fTestFile
;
70 // ------------------------------------------------------------------------
72 // ------------------------------------------------------------------------
75 * Perform pre-test initialization.
78 * if the initialization fails for some reason
81 public void setUp() throws Exception
{
82 fFacility
= TraceControlTestFacility
.getInstance();
84 URL location
= FileLocator
.find(FrameworkUtil
.getBundle(this.getClass()), new Path(TraceControlTestFacility
.DIRECTORY
+ File
.separator
+ getTestStream()), null);
85 File testfile
= new File(FileLocator
.toFileURL(location
).toURI());
86 fTestFile
= testfile
.getAbsolutePath();
90 * Get the test stream file name to use for the test suite
92 * @return the name of the test stream file
94 protected String
getTestStream() {
99 * Perform post-test clean-up.
102 public void tearDown() {
107 * Run the TraceControlComponent.
113 public void testTraceSessionTree() throws Exception
{
115 fProxy
.setTestFile(fTestFile
);
116 fProxy
.setScenario(TraceControlTestFacility
.SCEN_INIT_TEST
);
118 ITraceControlComponent root
= fFacility
.getControlView().getTraceControlRoot();
120 TargetNodeComponent node
= new TargetNodeComponent("myNode", root
, fProxy
);
123 fFacility
.waitForJobs();
125 fFacility
.executeCommand(node
, "connect");
126 WaitUtils
.waitUntil(new TargetNodeConnectedCondition(node
));
128 // Verify that node is connected
129 assertEquals(TargetNodeState
.CONNECTED
, node
.getTargetNodeState());
131 ILttngControlService controleService
= node
.getControlService();
133 // Get provider groups
134 ITraceControlComponent
[] groups
= node
.getChildren();
135 assertNotNull(groups
);
136 assertEquals(2, groups
.length
);
138 // Initialize dialog implementations for command execution
139 CreateSessionDialogStub sessionDialogStub
= new CreateSessionDialogStub();
140 TraceControlDialogFactory
.getInstance().setCreateSessionDialog(sessionDialogStub
);
141 TraceControlDialogFactory
.getInstance().setConfirmDialog(new DestroyConfirmDialogStub());
143 // ------------------------------------------------------------------------
144 // Create session (--U file://...) and destroy
145 // ------------------------------------------------------------------------
146 // Initialize session handling scenario
147 fProxy
.setScenario(SCEN_SCENARIO_FILE_PROTO_TEST
);
149 sessionDialogStub
.setNetworkUrl("file:///tmp");
150 sessionDialogStub
.setStreamedTrace(true);
151 TraceSessionComponent session
= fFacility
.createSession(groups
[1]);
153 // Verify that session was created
154 assertNotNull(session
);
155 assertEquals(getSessionName(), session
.getName());
156 if (controleService
.isVersionSupported("2.6.0")) {
157 assertEquals("/tmp", session
.getSessionPath());
159 assertEquals("file:///tmp", session
.getSessionPath());
162 assertTrue(!session
.isStreamedTrace());
163 assertEquals(TraceSessionState
.INACTIVE
, session
.getSessionState());
164 sessionDialogStub
.setNetworkUrl(null);
165 sessionDialogStub
.setStreamedTrace(false);
167 fFacility
.destroySession(session
);
169 // Verify that no more session components exist
170 assertEquals(0, groups
[1].getChildren().length
);
172 // ------------------------------------------------------------------------
173 // Create session (--U file://,,, and destroy
174 // ------------------------------------------------------------------------
175 // Initialize session handling scenario
176 fProxy
.setScenario(SCEN_SCENARIO_CONTROL_DATA_TEST
);
178 sessionDialogStub
.setControlUrl("tcp://172.0.0.1");
179 sessionDialogStub
.setDataUrl("tcp://172.0.0.1:5343");
180 sessionDialogStub
.setStreamedTrace(true);
182 session
= fFacility
.createSession(groups
[1]);
184 // Verify that session was created
185 assertNotNull(session
);
186 assertEquals(getSessionName(), session
.getName());
187 if (controleService
.isVersionSupported("2.6.0")) {
188 assertEquals("tcp4://172.0.0.1:5342/ [data: 5343]", session
.getSessionPath());
190 assertEquals("tcp://172.0.0.1:5342 [data: 5343]", session
.getSessionPath());
192 assertTrue(session
.isStreamedTrace());
193 assertEquals(TraceSessionState
.INACTIVE
, session
.getSessionState());
194 sessionDialogStub
.setControlUrl(null);
195 sessionDialogStub
.setDataUrl(null);
196 sessionDialogStub
.setStreamedTrace(false);
198 fFacility
.destroySession(session
);
200 // Verify that no more session components exist
201 assertEquals(0, groups
[1].getChildren().length
);
203 // ------------------------------------------------------------------------
204 // Create session (--U file://... and destroy
205 // ------------------------------------------------------------------------
206 // Initialize session handling scenario
207 fProxy
.setScenario(SCEN_SCENARIO_NETWORK_TEST
);
209 sessionDialogStub
.setNetworkUrl("net://172.0.0.1:1234:2345");
210 sessionDialogStub
.setStreamedTrace(true);
212 session
= fFacility
.createSession(groups
[1]);
214 // Verify that session was created
215 assertNotNull(session
);
216 assertEquals(getSessionName(), session
.getName());
217 if (controleService
.isVersionSupported("2.6.0")) {
218 assertEquals("tcp4://172.0.0.1:1234/mysession-20140820-153527 [data: 2345]", session
.getSessionPath());
220 assertEquals("net://172.0.0.1:1234 [data: 2345]", session
.getSessionPath());
222 assertTrue(session
.isStreamedTrace());
223 assertEquals(TraceSessionState
.INACTIVE
, session
.getSessionState());
224 sessionDialogStub
.setNetworkUrl(null);
226 fFacility
.destroySession(session
);
228 // Verify that no more session components exist
229 assertEquals(0, groups
[1].getChildren().length
);
231 // ------------------------------------------------------------------------
232 // Create session (--U net6://[...] and destroy
233 // ------------------------------------------------------------------------
234 // Initialize session handling scenario
235 fProxy
.setScenario(SCEN_SCENARIO_NETWORK2_TEST
);
237 sessionDialogStub
.setNetworkUrl("net6://[ffff::eeee:dddd:cccc:0]");
238 sessionDialogStub
.setStreamedTrace(true);
240 session
= fFacility
.createSession(groups
[1]);
242 // Verify that session was created
243 assertNotNull(session
);
244 assertEquals(getSessionName(), session
.getName());
245 if (controleService
.isVersionSupported("2.6.0")) {
246 assertEquals("tcp6://[ffff::eeee:dddd:cccc:0]:5342/mysession-20140820-153801 [data: 5343]", session
.getSessionPath());
248 assertEquals("net://[ffff::eeee:dddd:cccc:0]:5342/mysession-20130221-144451 [data: 5343]", session
.getSessionPath());
250 assertTrue(session
.isStreamedTrace());
251 assertEquals(TraceSessionState
.INACTIVE
, session
.getSessionState());
252 sessionDialogStub
.setNetworkUrl(null);
254 fFacility
.destroySession(session
);
256 // Verify that no more session components exist
257 assertEquals(0, groups
[1].getChildren().length
);
259 // -------------------------------------------------------------------------
261 // -------------------------------------------------------------------------
262 fFacility
.executeCommand(node
, "disconnect");
263 assertEquals(TargetNodeState
.DISCONNECTED
, node
.getTargetNodeState());
265 // -------------------------------------------------------------------------
267 // -------------------------------------------------------------------------
269 fFacility
.executeCommand(node
, "delete");
270 assertEquals(0, fFacility
.getControlView().getTraceControlRoot().getChildren().length
);
273 private static String
getSessionName() {