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
CommitLineData
f3b33d40 1/**********************************************************************
533d0bc3 2 * Copyright (c) 2013, 2015 Ericsson
f3b33d40
BH
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
7fa45c7f 11 * Jonathan Rajotte - Support for LTTng 2.6
b732adaa 12 * Markus Schorn - Bug 448058: Use org.eclipse.remote in favor of RSE
f3b33d40 13 **********************************************************************/
7fa45c7f 14
9bc60be7 15package org.eclipse.tracecompass.lttng2.control.ui.tests.model.component;
f3b33d40
BH
16
17import static org.junit.Assert.assertEquals;
18import static org.junit.Assert.assertNotNull;
19import static org.junit.Assert.assertTrue;
20
8e8c0226
AM
21import java.io.File;
22import java.net.URL;
23
f3b33d40
BH
24import org.eclipse.core.runtime.FileLocator;
25import org.eclipse.core.runtime.Path;
d8a4fd60 26import org.eclipse.jdt.annotation.NonNull;
b732adaa 27import org.eclipse.remote.core.IRemoteConnection;
9bc60be7
AM
28import org.eclipse.tracecompass.internal.lttng2.control.core.model.TargetNodeState;
29import org.eclipse.tracecompass.internal.lttng2.control.core.model.TraceSessionState;
30import org.eclipse.tracecompass.internal.lttng2.control.stubs.dialogs.CreateSessionDialogStub;
31import org.eclipse.tracecompass.internal.lttng2.control.stubs.dialogs.DestroyConfirmDialogStub;
32import org.eclipse.tracecompass.internal.lttng2.control.stubs.service.TestRemoteSystemProxy;
33import org.eclipse.tracecompass.internal.lttng2.control.ui.views.dialogs.TraceControlDialogFactory;
34import org.eclipse.tracecompass.internal.lttng2.control.ui.views.model.ITraceControlComponent;
35import org.eclipse.tracecompass.internal.lttng2.control.ui.views.model.impl.TargetNodeComponent;
36import org.eclipse.tracecompass.internal.lttng2.control.ui.views.model.impl.TraceSessionComponent;
37import org.eclipse.tracecompass.internal.lttng2.control.ui.views.service.ILttngControlService;
b6b4e8b4 38import org.eclipse.tracecompass.tmf.remote.core.proxy.TmfRemoteConnectionFactory;
f3023b37 39import org.eclipse.tracecompass.tmf.ui.tests.shared.WaitUtils;
f3b33d40
BH
40import org.junit.After;
41import org.junit.Before;
42import org.junit.Test;
43import org.osgi.framework.FrameworkUtil;
44
45/**
b0d2c558 46 * The class {@link TraceControlKernelSessionTest} contains Kernel
7fa45c7f 47 * session/channel/event handling test cases.
f3b33d40 48 */
b0d2c558 49public class TraceControlCreateSessionTest {
f3b33d40
BH
50
51 // ------------------------------------------------------------------------
52 // Constants
53 // ------------------------------------------------------------------------
54 private static final String TEST_STREAM = "CreateSessionTest.cfg";
f3b33d40
BH
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";
a30e79fe 58 private static final String SCEN_SCENARIO_NETWORK2_TEST = "CreateSessionNetwork2";
f3b33d40 59
7fa45c7f
JRJ
60 private static final String SESSION = "mysession";
61
f3b33d40
BH
62 // ------------------------------------------------------------------------
63 // Test data
64 // ------------------------------------------------------------------------
65 private TraceControlTestFacility fFacility;
b6b4e8b4 66 private IRemoteConnection fHost = TmfRemoteConnectionFactory.getLocalConnection();
d8a4fd60 67 private @NonNull TestRemoteSystemProxy fProxy = new TestRemoteSystemProxy(fHost);
f3b33d40
BH
68 private String fTestFile;
69
70 // ------------------------------------------------------------------------
71 // Housekeeping
72 // ------------------------------------------------------------------------
73
74 /**
75 * Perform pre-test initialization.
76 *
77 * @throws Exception
7fa45c7f 78 * if the initialization fails for some reason
f3b33d40
BH
79 */
80 @Before
81 public void setUp() throws Exception {
82 fFacility = TraceControlTestFacility.getInstance();
a30e79fe 83 fFacility.init();
7fa45c7f 84 URL location = FileLocator.find(FrameworkUtil.getBundle(this.getClass()), new Path(TraceControlTestFacility.DIRECTORY + File.separator + getTestStream()), null);
f3b33d40
BH
85 File testfile = new File(FileLocator.toFileURL(location).toURI());
86 fTestFile = testfile.getAbsolutePath();
87 }
88
89 /**
7fa45c7f 90 * Get the test stream file name to use for the test suite
f3b33d40 91 *
7fa45c7f
JRJ
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.
f3b33d40
BH
100 */
101 @After
102 public void tearDown() {
13f36900 103 fFacility.dispose();
f3b33d40
BH
104 }
105
106 /**
107 * Run the TraceControlComponent.
7fa45c7f
JRJ
108 *
109 * @throws Exception
110 * on internal error
f3b33d40
BH
111 */
112 @Test
113 public void testTraceSessionTree() throws Exception {
114
115 fProxy.setTestFile(fTestFile);
116 fProxy.setScenario(TraceControlTestFacility.SCEN_INIT_TEST);
117
13f36900 118 ITraceControlComponent root = fFacility.getControlView().getTraceControlRoot();
f3b33d40 119
d8a4fd60 120 TargetNodeComponent node = new TargetNodeComponent("myNode", root, fProxy);
f3b33d40
BH
121
122 root.addChild(node);
123 fFacility.waitForJobs();
124
125 fFacility.executeCommand(node, "connect");
f3023b37 126 WaitUtils.waitUntil(new TargetNodeConnectedCondition(node));
f3b33d40
BH
127
128 // Verify that node is connected
129 assertEquals(TargetNodeState.CONNECTED, node.getTargetNodeState());
130
7fa45c7f
JRJ
131 ILttngControlService controleService = node.getControlService();
132
f3b33d40
BH
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
f3b33d40 143 // ------------------------------------------------------------------------
a30e79fe 144 // Create session (--U file://...) and destroy
f3b33d40
BH
145 // ------------------------------------------------------------------------
146 // Initialize session handling scenario
a30e79fe 147 fProxy.setScenario(SCEN_SCENARIO_FILE_PROTO_TEST);
f3b33d40 148
a30e79fe
BH
149 sessionDialogStub.setNetworkUrl("file:///tmp");
150 sessionDialogStub.setStreamedTrace(true);
151 TraceSessionComponent session = fFacility.createSession(groups[1]);
f3b33d40
BH
152
153 // Verify that session was created
154 assertNotNull(session);
7fa45c7f
JRJ
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
a30e79fe 162 assertTrue(!session.isStreamedTrace());
f3b33d40 163 assertEquals(TraceSessionState.INACTIVE, session.getSessionState());
a30e79fe
BH
164 sessionDialogStub.setNetworkUrl(null);
165 sessionDialogStub.setStreamedTrace(false);
f3b33d40
BH
166
167 fFacility.destroySession(session);
168
169 // Verify that no more session components exist
170 assertEquals(0, groups[1].getChildren().length);
171
172 // ------------------------------------------------------------------------
a30e79fe 173 // Create session (--U file://,,, and destroy
f3b33d40
BH
174 // ------------------------------------------------------------------------
175 // Initialize session handling scenario
a30e79fe 176 fProxy.setScenario(SCEN_SCENARIO_CONTROL_DATA_TEST);
f3b33d40 177
a30e79fe
BH
178 sessionDialogStub.setControlUrl("tcp://172.0.0.1");
179 sessionDialogStub.setDataUrl("tcp://172.0.0.1:5343");
f3b33d40 180 sessionDialogStub.setStreamedTrace(true);
a30e79fe 181
f3b33d40
BH
182 session = fFacility.createSession(groups[1]);
183
184 // Verify that session was created
185 assertNotNull(session);
7fa45c7f
JRJ
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 }
f3b33d40
BH
192 assertTrue(session.isStreamedTrace());
193 assertEquals(TraceSessionState.INACTIVE, session.getSessionState());
a30e79fe
BH
194 sessionDialogStub.setControlUrl(null);
195 sessionDialogStub.setDataUrl(null);
f3b33d40
BH
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 // ------------------------------------------------------------------------
a30e79fe 204 // Create session (--U file://... and destroy
f3b33d40
BH
205 // ------------------------------------------------------------------------
206 // Initialize session handling scenario
a30e79fe 207 fProxy.setScenario(SCEN_SCENARIO_NETWORK_TEST);
f3b33d40 208
a30e79fe 209 sessionDialogStub.setNetworkUrl("net://172.0.0.1:1234:2345");
f3b33d40
BH
210 sessionDialogStub.setStreamedTrace(true);
211
212 session = fFacility.createSession(groups[1]);
213
214 // Verify that session was created
215 assertNotNull(session);
7fa45c7f
JRJ
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 }
f3b33d40
BH
222 assertTrue(session.isStreamedTrace());
223 assertEquals(TraceSessionState.INACTIVE, session.getSessionState());
a30e79fe 224 sessionDialogStub.setNetworkUrl(null);
f3b33d40
BH
225
226 fFacility.destroySession(session);
227
228 // Verify that no more session components exist
229 assertEquals(0, groups[1].getChildren().length);
230
231 // ------------------------------------------------------------------------
a30e79fe 232 // Create session (--U net6://[...] and destroy
f3b33d40
BH
233 // ------------------------------------------------------------------------
234 // Initialize session handling scenario
a30e79fe 235 fProxy.setScenario(SCEN_SCENARIO_NETWORK2_TEST);
f3b33d40 236
a30e79fe 237 sessionDialogStub.setNetworkUrl("net6://[ffff::eeee:dddd:cccc:0]");
f3b33d40
BH
238 sessionDialogStub.setStreamedTrace(true);
239
240 session = fFacility.createSession(groups[1]);
241
242 // Verify that session was created
243 assertNotNull(session);
7fa45c7f
JRJ
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 }
f3b33d40
BH
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
7fa45c7f 259 // -------------------------------------------------------------------------
f3b33d40 260 // Disconnect node
7fa45c7f 261 // -------------------------------------------------------------------------
f3b33d40
BH
262 fFacility.executeCommand(node, "disconnect");
263 assertEquals(TargetNodeState.DISCONNECTED, node.getTargetNodeState());
264
7fa45c7f 265 // -------------------------------------------------------------------------
f3b33d40 266 // Delete node
7fa45c7f 267 // -------------------------------------------------------------------------
f3b33d40
BH
268
269 fFacility.executeCommand(node, "delete");
7fa45c7f
JRJ
270 assertEquals(0, fFacility.getControlView().getTraceControlRoot().getChildren().length);
271 }
272
273 private static String getSessionName() {
274 return SESSION;
f3b33d40
BH
275 }
276
a30e79fe 277}
This page took 0.091972 seconds and 5 git commands to generate.