1 /**********************************************************************
2 * Copyright (c) 2013, 2014 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 **********************************************************************/
14 package org
.eclipse
.linuxtools
.lttng2
.control
.ui
.tests
.model
.component
;
16 import static org
.junit
.Assert
.assertEquals
;
17 import static org
.junit
.Assert
.assertNotNull
;
18 import static org
.junit
.Assert
.assertTrue
;
23 import org
.eclipse
.core
.runtime
.FileLocator
;
24 import org
.eclipse
.core
.runtime
.Path
;
25 import org
.eclipse
.linuxtools
.internal
.lttng2
.control
.core
.model
.TargetNodeState
;
26 import org
.eclipse
.linuxtools
.internal
.lttng2
.control
.core
.model
.TraceSessionState
;
27 import org
.eclipse
.linuxtools
.internal
.lttng2
.control
.stubs
.dialogs
.CreateSessionDialogStub
;
28 import org
.eclipse
.linuxtools
.internal
.lttng2
.control
.stubs
.dialogs
.DestroyConfirmDialogStub
;
29 import org
.eclipse
.linuxtools
.internal
.lttng2
.control
.stubs
.service
.TestRemoteSystemProxy
;
30 import org
.eclipse
.linuxtools
.internal
.lttng2
.control
.ui
.views
.dialogs
.TraceControlDialogFactory
;
31 import org
.eclipse
.linuxtools
.internal
.lttng2
.control
.ui
.views
.model
.ITraceControlComponent
;
32 import org
.eclipse
.linuxtools
.internal
.lttng2
.control
.ui
.views
.model
.impl
.TargetNodeComponent
;
33 import org
.eclipse
.linuxtools
.internal
.lttng2
.control
.ui
.views
.model
.impl
.TraceSessionComponent
;
34 import org
.eclipse
.linuxtools
.internal
.lttng2
.control
.ui
.views
.service
.ILttngControlService
;
35 import org
.eclipse
.rse
.core
.RSECorePlugin
;
36 import org
.eclipse
.rse
.core
.model
.IHost
;
37 import org
.eclipse
.rse
.core
.model
.ISystemProfile
;
38 import org
.eclipse
.rse
.core
.model
.ISystemRegistry
;
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 TraceControlKernelSessionTests} contains Kernel
46 * session/channel/event handling test cases.
48 public class TraceControlCreateSessionTests
{
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 TestRemoteSystemProxy fProxy
;
66 private String fTestFile
;
68 // ------------------------------------------------------------------------
70 // ------------------------------------------------------------------------
73 * Perform pre-test initialization.
76 * if the initialization fails for some reason
79 public void setUp() throws Exception
{
80 fFacility
= TraceControlTestFacility
.getInstance();
82 fProxy
= new TestRemoteSystemProxy();
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() {
102 fFacility
.waitForJobs();
106 * Run the TraceControlComponent.
112 public void testTraceSessionTree() throws Exception
{
114 fProxy
.setTestFile(fTestFile
);
115 fProxy
.setScenario(TraceControlTestFacility
.SCEN_INIT_TEST
);
117 ITraceControlComponent root
= TraceControlTestFacility
.getInstance().getControlView().getTraceControlRoot();
119 ISystemRegistry registry
= RSECorePlugin
.getTheSystemRegistry();
120 ISystemProfile profile
= registry
.createSystemProfile("myProfile", true);
121 IHost host
= registry
.createLocalHost(profile
, "myProfile", "user");
123 TargetNodeComponent node
= new TargetNodeComponent("myNode", root
, host
, fProxy
);
126 fFacility
.waitForJobs();
128 fFacility
.executeCommand(node
, "connect");
130 while ((i
< 10) && (node
.getTargetNodeState() != TargetNodeState
.CONNECTED
)) {
132 fFacility
.delay(TraceControlTestFacility
.GUI_REFESH_DELAY
);
135 // Verify that node is connected
136 assertEquals(TargetNodeState
.CONNECTED
, node
.getTargetNodeState());
138 ILttngControlService controleService
= node
.getControlService();
140 // Get provider groups
141 ITraceControlComponent
[] groups
= node
.getChildren();
142 assertNotNull(groups
);
143 assertEquals(2, groups
.length
);
145 // Initialize dialog implementations for command execution
146 CreateSessionDialogStub sessionDialogStub
= new CreateSessionDialogStub();
147 TraceControlDialogFactory
.getInstance().setCreateSessionDialog(sessionDialogStub
);
148 TraceControlDialogFactory
.getInstance().setConfirmDialog(new DestroyConfirmDialogStub());
150 // ------------------------------------------------------------------------
151 // Create session (--U file://...) and destroy
152 // ------------------------------------------------------------------------
153 // Initialize session handling scenario
154 fProxy
.setScenario(SCEN_SCENARIO_FILE_PROTO_TEST
);
156 sessionDialogStub
.setNetworkUrl("file:///tmp");
157 sessionDialogStub
.setStreamedTrace(true);
158 TraceSessionComponent session
= fFacility
.createSession(groups
[1]);
160 // Verify that session was created
161 assertNotNull(session
);
162 assertEquals(getSessionName(), session
.getName());
163 if (controleService
.isVersionSupported("2.6.0")) {
164 assertEquals("/tmp", session
.getSessionPath());
166 assertEquals("file:///tmp", session
.getSessionPath());
169 assertTrue(!session
.isStreamedTrace());
170 assertEquals(TraceSessionState
.INACTIVE
, session
.getSessionState());
171 sessionDialogStub
.setNetworkUrl(null);
172 sessionDialogStub
.setStreamedTrace(false);
174 fFacility
.destroySession(session
);
176 // Verify that no more session components exist
177 assertEquals(0, groups
[1].getChildren().length
);
179 // ------------------------------------------------------------------------
180 // Create session (--U file://,,, and destroy
181 // ------------------------------------------------------------------------
182 // Initialize session handling scenario
183 fProxy
.setScenario(SCEN_SCENARIO_CONTROL_DATA_TEST
);
185 sessionDialogStub
.setControlUrl("tcp://172.0.0.1");
186 sessionDialogStub
.setDataUrl("tcp://172.0.0.1:5343");
187 sessionDialogStub
.setStreamedTrace(true);
189 session
= fFacility
.createSession(groups
[1]);
191 // Verify that session was created
192 assertNotNull(session
);
193 assertEquals(getSessionName(), session
.getName());
194 if (controleService
.isVersionSupported("2.6.0")) {
195 assertEquals("tcp4://172.0.0.1:5342/ [data: 5343]", session
.getSessionPath());
197 assertEquals("tcp://172.0.0.1:5342 [data: 5343]", session
.getSessionPath());
199 assertTrue(session
.isStreamedTrace());
200 assertEquals(TraceSessionState
.INACTIVE
, session
.getSessionState());
201 sessionDialogStub
.setControlUrl(null);
202 sessionDialogStub
.setDataUrl(null);
203 sessionDialogStub
.setStreamedTrace(false);
205 fFacility
.destroySession(session
);
207 // Verify that no more session components exist
208 assertEquals(0, groups
[1].getChildren().length
);
210 // ------------------------------------------------------------------------
211 // Create session (--U file://... and destroy
212 // ------------------------------------------------------------------------
213 // Initialize session handling scenario
214 fProxy
.setScenario(SCEN_SCENARIO_NETWORK_TEST
);
216 sessionDialogStub
.setNetworkUrl("net://172.0.0.1:1234:2345");
217 sessionDialogStub
.setStreamedTrace(true);
219 session
= fFacility
.createSession(groups
[1]);
221 // Verify that session was created
222 assertNotNull(session
);
223 assertEquals(getSessionName(), session
.getName());
224 if (controleService
.isVersionSupported("2.6.0")) {
225 assertEquals("tcp4://172.0.0.1:1234/mysession-20140820-153527 [data: 2345]", session
.getSessionPath());
227 assertEquals("net://172.0.0.1:1234 [data: 2345]", session
.getSessionPath());
229 assertTrue(session
.isStreamedTrace());
230 assertEquals(TraceSessionState
.INACTIVE
, session
.getSessionState());
231 sessionDialogStub
.setNetworkUrl(null);
233 fFacility
.destroySession(session
);
235 // Verify that no more session components exist
236 assertEquals(0, groups
[1].getChildren().length
);
238 // ------------------------------------------------------------------------
239 // Create session (--U net6://[...] and destroy
240 // ------------------------------------------------------------------------
241 // Initialize session handling scenario
242 fProxy
.setScenario(SCEN_SCENARIO_NETWORK2_TEST
);
244 sessionDialogStub
.setNetworkUrl("net6://[ffff::eeee:dddd:cccc:0]");
245 sessionDialogStub
.setStreamedTrace(true);
247 session
= fFacility
.createSession(groups
[1]);
249 // Verify that session was created
250 assertNotNull(session
);
251 assertEquals(getSessionName(), session
.getName());
252 if (controleService
.isVersionSupported("2.6.0")) {
253 assertEquals("tcp6://[ffff::eeee:dddd:cccc:0]:5342/mysession-20140820-153801 [data: 5343]", session
.getSessionPath());
255 assertEquals("net://[ffff::eeee:dddd:cccc:0]:5342/mysession-20130221-144451 [data: 5343]", session
.getSessionPath());
257 assertTrue(session
.isStreamedTrace());
258 assertEquals(TraceSessionState
.INACTIVE
, session
.getSessionState());
259 sessionDialogStub
.setNetworkUrl(null);
261 fFacility
.destroySession(session
);
263 // Verify that no more session components exist
264 assertEquals(0, groups
[1].getChildren().length
);
266 // -------------------------------------------------------------------------
268 // -------------------------------------------------------------------------
269 fFacility
.executeCommand(node
, "disconnect");
270 assertEquals(TargetNodeState
.DISCONNECTED
, node
.getTargetNodeState());
272 // -------------------------------------------------------------------------
274 // -------------------------------------------------------------------------
276 fFacility
.executeCommand(node
, "delete");
277 assertEquals(0, fFacility
.getControlView().getTraceControlRoot().getChildren().length
);
280 private static String
getSessionName() {