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