a5710b5237348bafbff6bdf86f15f1365dd2b604
[deliverable/tracecompass.git] / lttng / org.eclipse.tracecompass.lttng2.control.ui.tests / src / org / eclipse / tracecompass / lttng2 / control / ui / tests / model / component / TraceControlCreateSessionTest.java
1 /**********************************************************************
2 * Copyright (c) 2013, 2015 Ericsson
3 *
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
8 *
9 * Contributors:
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 **********************************************************************/
14
15 package org.eclipse.tracecompass.lttng2.control.ui.tests.model.component;
16
17 import static org.junit.Assert.assertEquals;
18 import static org.junit.Assert.assertNotNull;
19 import static org.junit.Assert.assertTrue;
20
21 import java.io.File;
22 import java.net.URL;
23
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;
43
44 /**
45 * The class {@link TraceControlKernelSessionTest} contains Kernel
46 * session/channel/event handling test cases.
47 */
48 public class TraceControlCreateSessionTest {
49
50 // ------------------------------------------------------------------------
51 // Constants
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";
58
59 private static final String SESSION = "mysession";
60
61 // ------------------------------------------------------------------------
62 // Test data
63 // ------------------------------------------------------------------------
64 private TraceControlTestFacility fFacility;
65 private IRemoteConnection fHost = TmfRemoteConnectionFactory.getLocalConnection();
66 private @NonNull TestRemoteSystemProxy fProxy = new TestRemoteSystemProxy(fHost);
67 private String fTestFile;
68
69 // ------------------------------------------------------------------------
70 // Housekeeping
71 // ------------------------------------------------------------------------
72
73 /**
74 * Perform pre-test initialization.
75 *
76 * @throws Exception
77 * if the initialization fails for some reason
78 */
79 @Before
80 public void setUp() throws Exception {
81 fFacility = TraceControlTestFacility.getInstance();
82 fFacility.init();
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();
86 }
87
88 /**
89 * Get the test stream file name to use for the test suite
90 *
91 * @return the name of the test stream file
92 */
93 protected String getTestStream() {
94 return TEST_STREAM;
95 }
96
97 /**
98 * Perform post-test clean-up.
99 */
100 @After
101 public void tearDown() {
102 fFacility.dispose();
103 }
104
105 /**
106 * Run the TraceControlComponent.
107 *
108 * @throws Exception
109 * on internal error
110 */
111 @Test
112 public void testTraceSessionTree() throws Exception {
113
114 fProxy.setTestFile(fTestFile);
115 fProxy.setScenario(TraceControlTestFacility.SCEN_INIT_TEST);
116
117 ITraceControlComponent root = fFacility.getControlView().getTraceControlRoot();
118
119 TargetNodeComponent node = new TargetNodeComponent("myNode", root, fProxy);
120
121 root.addChild(node);
122 fFacility.waitForJobs();
123
124 fFacility.executeCommand(node, "connect");
125 int i = 0;
126 while ((i < 10) && (node.getTargetNodeState() != TargetNodeState.CONNECTED)) {
127 i++;
128 fFacility.delay(TraceControlTestFacility.GUI_REFESH_DELAY);
129 }
130
131 // Verify that node is connected
132 assertEquals(TargetNodeState.CONNECTED, node.getTargetNodeState());
133
134 ILttngControlService controleService = node.getControlService();
135
136 // Get provider groups
137 ITraceControlComponent[] groups = node.getChildren();
138 assertNotNull(groups);
139 assertEquals(2, groups.length);
140
141 // Initialize dialog implementations for command execution
142 CreateSessionDialogStub sessionDialogStub = new CreateSessionDialogStub();
143 TraceControlDialogFactory.getInstance().setCreateSessionDialog(sessionDialogStub);
144 TraceControlDialogFactory.getInstance().setConfirmDialog(new DestroyConfirmDialogStub());
145
146 // ------------------------------------------------------------------------
147 // Create session (--U file://...) and destroy
148 // ------------------------------------------------------------------------
149 // Initialize session handling scenario
150 fProxy.setScenario(SCEN_SCENARIO_FILE_PROTO_TEST);
151
152 sessionDialogStub.setNetworkUrl("file:///tmp");
153 sessionDialogStub.setStreamedTrace(true);
154 TraceSessionComponent session = fFacility.createSession(groups[1]);
155
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());
161 } else {
162 assertEquals("file:///tmp", session.getSessionPath());
163 }
164
165 assertTrue(!session.isStreamedTrace());
166 assertEquals(TraceSessionState.INACTIVE, session.getSessionState());
167 sessionDialogStub.setNetworkUrl(null);
168 sessionDialogStub.setStreamedTrace(false);
169
170 fFacility.destroySession(session);
171
172 // Verify that no more session components exist
173 assertEquals(0, groups[1].getChildren().length);
174
175 // ------------------------------------------------------------------------
176 // Create session (--U file://,,, and destroy
177 // ------------------------------------------------------------------------
178 // Initialize session handling scenario
179 fProxy.setScenario(SCEN_SCENARIO_CONTROL_DATA_TEST);
180
181 sessionDialogStub.setControlUrl("tcp://172.0.0.1");
182 sessionDialogStub.setDataUrl("tcp://172.0.0.1:5343");
183 sessionDialogStub.setStreamedTrace(true);
184
185 session = fFacility.createSession(groups[1]);
186
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());
192 } else {
193 assertEquals("tcp://172.0.0.1:5342 [data: 5343]", session.getSessionPath());
194 }
195 assertTrue(session.isStreamedTrace());
196 assertEquals(TraceSessionState.INACTIVE, session.getSessionState());
197 sessionDialogStub.setControlUrl(null);
198 sessionDialogStub.setDataUrl(null);
199 sessionDialogStub.setStreamedTrace(false);
200
201 fFacility.destroySession(session);
202
203 // Verify that no more session components exist
204 assertEquals(0, groups[1].getChildren().length);
205
206 // ------------------------------------------------------------------------
207 // Create session (--U file://... and destroy
208 // ------------------------------------------------------------------------
209 // Initialize session handling scenario
210 fProxy.setScenario(SCEN_SCENARIO_NETWORK_TEST);
211
212 sessionDialogStub.setNetworkUrl("net://172.0.0.1:1234:2345");
213 sessionDialogStub.setStreamedTrace(true);
214
215 session = fFacility.createSession(groups[1]);
216
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());
222 } else {
223 assertEquals("net://172.0.0.1:1234 [data: 2345]", session.getSessionPath());
224 }
225 assertTrue(session.isStreamedTrace());
226 assertEquals(TraceSessionState.INACTIVE, session.getSessionState());
227 sessionDialogStub.setNetworkUrl(null);
228
229 fFacility.destroySession(session);
230
231 // Verify that no more session components exist
232 assertEquals(0, groups[1].getChildren().length);
233
234 // ------------------------------------------------------------------------
235 // Create session (--U net6://[...] and destroy
236 // ------------------------------------------------------------------------
237 // Initialize session handling scenario
238 fProxy.setScenario(SCEN_SCENARIO_NETWORK2_TEST);
239
240 sessionDialogStub.setNetworkUrl("net6://[ffff::eeee:dddd:cccc:0]");
241 sessionDialogStub.setStreamedTrace(true);
242
243 session = fFacility.createSession(groups[1]);
244
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());
250 } else {
251 assertEquals("net://[ffff::eeee:dddd:cccc:0]:5342/mysession-20130221-144451 [data: 5343]", session.getSessionPath());
252 }
253 assertTrue(session.isStreamedTrace());
254 assertEquals(TraceSessionState.INACTIVE, session.getSessionState());
255 sessionDialogStub.setNetworkUrl(null);
256
257 fFacility.destroySession(session);
258
259 // Verify that no more session components exist
260 assertEquals(0, groups[1].getChildren().length);
261
262 // -------------------------------------------------------------------------
263 // Disconnect node
264 // -------------------------------------------------------------------------
265 fFacility.executeCommand(node, "disconnect");
266 assertEquals(TargetNodeState.DISCONNECTED, node.getTargetNodeState());
267
268 // -------------------------------------------------------------------------
269 // Delete node
270 // -------------------------------------------------------------------------
271
272 fFacility.executeCommand(node, "delete");
273 assertEquals(0, fFacility.getControlView().getTraceControlRoot().getChildren().length);
274 }
275
276 private static String getSessionName() {
277 return SESSION;
278 }
279
280 }
This page took 0.039997 seconds and 4 git commands to generate.