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
.junit
.After
;
40 import org
.junit
.Before
;
41 import org
.junit
.Test
;
42 import org
.osgi
.framework
.FrameworkUtil
;
45 * The class {@link TraceControlKernelSessionTest} contains Kernel
46 * session/channel/event handling test cases.
48 public class TraceControlCreateSessionTest
{
50 // ------------------------------------------------------------------------
52 // ------------------------------------------------------------------------
53 private static final String TEST_STREAM
= "CreateSessionTest.cfg";
54 private static final String SCEN_SCENARIO_FILE_PROTO_TEST
= "CreateSessionFileProto";
55 private static final String SCEN_SCENARIO_CONTROL_DATA_TEST
= "CreateSessionControlData";
56 private static final String SCEN_SCENARIO_NETWORK_TEST
= "CreateSessionNetwork";
57 private static final String SCEN_SCENARIO_NETWORK2_TEST
= "CreateSessionNetwork2";
59 private static final String SESSION
= "mysession";
61 // ------------------------------------------------------------------------
63 // ------------------------------------------------------------------------
64 private TraceControlTestFacility fFacility
;
65 private IRemoteConnection fHost
= TmfRemoteConnectionFactory
.getLocalConnection();
66 private @NonNull TestRemoteSystemProxy fProxy
= new TestRemoteSystemProxy(fHost
);
67 private String fTestFile
;
69 // ------------------------------------------------------------------------
71 // ------------------------------------------------------------------------
74 * Perform pre-test initialization.
77 * if the initialization fails for some reason
80 public void setUp() throws Exception
{
81 fFacility
= TraceControlTestFacility
.getInstance();
83 URL location
= FileLocator
.find(FrameworkUtil
.getBundle(this.getClass()), new Path(TraceControlTestFacility
.DIRECTORY
+ File
.separator
+ getTestStream()), null);
84 File testfile
= new File(FileLocator
.toFileURL(location
).toURI());
85 fTestFile
= testfile
.getAbsolutePath();
89 * Get the test stream file name to use for the test suite
91 * @return the name of the test stream file
93 protected String
getTestStream() {
98 * Perform post-test clean-up.
101 public void tearDown() {
106 * Run the TraceControlComponent.
112 public void testTraceSessionTree() throws Exception
{
114 fProxy
.setTestFile(fTestFile
);
115 fProxy
.setScenario(TraceControlTestFacility
.SCEN_INIT_TEST
);
117 ITraceControlComponent root
= fFacility
.getControlView().getTraceControlRoot();
119 TargetNodeComponent node
= new TargetNodeComponent("myNode", root
, fProxy
);
122 fFacility
.waitForJobs();
124 fFacility
.executeCommand(node
, "connect");
126 while ((i
< 10) && (node
.getTargetNodeState() != TargetNodeState
.CONNECTED
)) {
128 fFacility
.delay(TraceControlTestFacility
.GUI_REFESH_DELAY
);
131 // Verify that node is connected
132 assertEquals(TargetNodeState
.CONNECTED
, node
.getTargetNodeState());
134 ILttngControlService controleService
= node
.getControlService();
136 // Get provider groups
137 ITraceControlComponent
[] groups
= node
.getChildren();
138 assertNotNull(groups
);
139 assertEquals(2, groups
.length
);
141 // Initialize dialog implementations for command execution
142 CreateSessionDialogStub sessionDialogStub
= new CreateSessionDialogStub();
143 TraceControlDialogFactory
.getInstance().setCreateSessionDialog(sessionDialogStub
);
144 TraceControlDialogFactory
.getInstance().setConfirmDialog(new DestroyConfirmDialogStub());
146 // ------------------------------------------------------------------------
147 // Create session (--U file://...) and destroy
148 // ------------------------------------------------------------------------
149 // Initialize session handling scenario
150 fProxy
.setScenario(SCEN_SCENARIO_FILE_PROTO_TEST
);
152 sessionDialogStub
.setNetworkUrl("file:///tmp");
153 sessionDialogStub
.setStreamedTrace(true);
154 TraceSessionComponent session
= fFacility
.createSession(groups
[1]);
156 // Verify that session was created
157 assertNotNull(session
);
158 assertEquals(getSessionName(), session
.getName());
159 if (controleService
.isVersionSupported("2.6.0")) {
160 assertEquals("/tmp", session
.getSessionPath());
162 assertEquals("file:///tmp", session
.getSessionPath());
165 assertTrue(!session
.isStreamedTrace());
166 assertEquals(TraceSessionState
.INACTIVE
, session
.getSessionState());
167 sessionDialogStub
.setNetworkUrl(null);
168 sessionDialogStub
.setStreamedTrace(false);
170 fFacility
.destroySession(session
);
172 // Verify that no more session components exist
173 assertEquals(0, groups
[1].getChildren().length
);
175 // ------------------------------------------------------------------------
176 // Create session (--U file://,,, and destroy
177 // ------------------------------------------------------------------------
178 // Initialize session handling scenario
179 fProxy
.setScenario(SCEN_SCENARIO_CONTROL_DATA_TEST
);
181 sessionDialogStub
.setControlUrl("tcp://172.0.0.1");
182 sessionDialogStub
.setDataUrl("tcp://172.0.0.1:5343");
183 sessionDialogStub
.setStreamedTrace(true);
185 session
= fFacility
.createSession(groups
[1]);
187 // Verify that session was created
188 assertNotNull(session
);
189 assertEquals(getSessionName(), session
.getName());
190 if (controleService
.isVersionSupported("2.6.0")) {
191 assertEquals("tcp4://172.0.0.1:5342/ [data: 5343]", session
.getSessionPath());
193 assertEquals("tcp://172.0.0.1:5342 [data: 5343]", session
.getSessionPath());
195 assertTrue(session
.isStreamedTrace());
196 assertEquals(TraceSessionState
.INACTIVE
, session
.getSessionState());
197 sessionDialogStub
.setControlUrl(null);
198 sessionDialogStub
.setDataUrl(null);
199 sessionDialogStub
.setStreamedTrace(false);
201 fFacility
.destroySession(session
);
203 // Verify that no more session components exist
204 assertEquals(0, groups
[1].getChildren().length
);
206 // ------------------------------------------------------------------------
207 // Create session (--U file://... and destroy
208 // ------------------------------------------------------------------------
209 // Initialize session handling scenario
210 fProxy
.setScenario(SCEN_SCENARIO_NETWORK_TEST
);
212 sessionDialogStub
.setNetworkUrl("net://172.0.0.1:1234:2345");
213 sessionDialogStub
.setStreamedTrace(true);
215 session
= fFacility
.createSession(groups
[1]);
217 // Verify that session was created
218 assertNotNull(session
);
219 assertEquals(getSessionName(), session
.getName());
220 if (controleService
.isVersionSupported("2.6.0")) {
221 assertEquals("tcp4://172.0.0.1:1234/mysession-20140820-153527 [data: 2345]", session
.getSessionPath());
223 assertEquals("net://172.0.0.1:1234 [data: 2345]", session
.getSessionPath());
225 assertTrue(session
.isStreamedTrace());
226 assertEquals(TraceSessionState
.INACTIVE
, session
.getSessionState());
227 sessionDialogStub
.setNetworkUrl(null);
229 fFacility
.destroySession(session
);
231 // Verify that no more session components exist
232 assertEquals(0, groups
[1].getChildren().length
);
234 // ------------------------------------------------------------------------
235 // Create session (--U net6://[...] and destroy
236 // ------------------------------------------------------------------------
237 // Initialize session handling scenario
238 fProxy
.setScenario(SCEN_SCENARIO_NETWORK2_TEST
);
240 sessionDialogStub
.setNetworkUrl("net6://[ffff::eeee:dddd:cccc:0]");
241 sessionDialogStub
.setStreamedTrace(true);
243 session
= fFacility
.createSession(groups
[1]);
245 // Verify that session was created
246 assertNotNull(session
);
247 assertEquals(getSessionName(), session
.getName());
248 if (controleService
.isVersionSupported("2.6.0")) {
249 assertEquals("tcp6://[ffff::eeee:dddd:cccc:0]:5342/mysession-20140820-153801 [data: 5343]", session
.getSessionPath());
251 assertEquals("net://[ffff::eeee:dddd:cccc:0]:5342/mysession-20130221-144451 [data: 5343]", session
.getSessionPath());
253 assertTrue(session
.isStreamedTrace());
254 assertEquals(TraceSessionState
.INACTIVE
, session
.getSessionState());
255 sessionDialogStub
.setNetworkUrl(null);
257 fFacility
.destroySession(session
);
259 // Verify that no more session components exist
260 assertEquals(0, groups
[1].getChildren().length
);
262 // -------------------------------------------------------------------------
264 // -------------------------------------------------------------------------
265 fFacility
.executeCommand(node
, "disconnect");
266 assertEquals(TargetNodeState
.DISCONNECTED
, node
.getTargetNodeState());
268 // -------------------------------------------------------------------------
270 // -------------------------------------------------------------------------
272 fFacility
.executeCommand(node
, "delete");
273 assertEquals(0, fFacility
.getControlView().getTraceControlRoot().getChildren().length
);
276 private static String
getSessionName() {