tmf: Bug 460032: Fix concurrent update of XML presentation provider
[deliverable/tracecompass.git] / org.eclipse.tracecompass.lttng2.control.ui.tests / src / org / eclipse / tracecompass / lttng2 / control / ui / tests / model / component / TraceControlCreateSessionTests.java
CommitLineData
f3b33d40 1/**********************************************************************
7fa45c7f 2 * Copyright (c) 2013, 2014 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;
b732adaa
MS
26import org.eclipse.remote.core.IRemoteConnection;
27import org.eclipse.remote.core.IRemoteConnectionManager;
28import org.eclipse.remote.core.RemoteServices;
9bc60be7
AM
29import org.eclipse.tracecompass.internal.lttng2.control.core.model.TargetNodeState;
30import org.eclipse.tracecompass.internal.lttng2.control.core.model.TraceSessionState;
31import org.eclipse.tracecompass.internal.lttng2.control.stubs.dialogs.CreateSessionDialogStub;
32import org.eclipse.tracecompass.internal.lttng2.control.stubs.dialogs.DestroyConfirmDialogStub;
33import org.eclipse.tracecompass.internal.lttng2.control.stubs.service.TestRemoteSystemProxy;
34import org.eclipse.tracecompass.internal.lttng2.control.ui.views.dialogs.TraceControlDialogFactory;
35import org.eclipse.tracecompass.internal.lttng2.control.ui.views.model.ITraceControlComponent;
36import org.eclipse.tracecompass.internal.lttng2.control.ui.views.model.impl.TargetNodeComponent;
37import org.eclipse.tracecompass.internal.lttng2.control.ui.views.model.impl.TraceSessionComponent;
38import org.eclipse.tracecompass.internal.lttng2.control.ui.views.service.ILttngControlService;
f3b33d40
BH
39import org.junit.After;
40import org.junit.Before;
41import org.junit.Test;
42import org.osgi.framework.FrameworkUtil;
43
44/**
7fa45c7f
JRJ
45 * The class {@link TraceControlKernelSessionTests} contains Kernel
46 * session/channel/event handling test cases.
f3b33d40 47 */
f3b33d40
BH
48public class TraceControlCreateSessionTests {
49
50 // ------------------------------------------------------------------------
51 // Constants
52 // ------------------------------------------------------------------------
53 private static final String TEST_STREAM = "CreateSessionTest.cfg";
f3b33d40
BH
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";
a30e79fe 57 private static final String SCEN_SCENARIO_NETWORK2_TEST = "CreateSessionNetwork2";
f3b33d40 58
7fa45c7f
JRJ
59 private static final String SESSION = "mysession";
60
f3b33d40
BH
61 // ------------------------------------------------------------------------
62 // Test data
63 // ------------------------------------------------------------------------
64 private TraceControlTestFacility fFacility;
65 private TestRemoteSystemProxy fProxy;
66 private String fTestFile;
67
68 // ------------------------------------------------------------------------
69 // Housekeeping
70 // ------------------------------------------------------------------------
71
72 /**
73 * Perform pre-test initialization.
74 *
75 * @throws Exception
7fa45c7f 76 * if the initialization fails for some reason
f3b33d40
BH
77 */
78 @Before
79 public void setUp() throws Exception {
80 fFacility = TraceControlTestFacility.getInstance();
a30e79fe 81 fFacility.init();
f3b33d40 82 fProxy = new TestRemoteSystemProxy();
7fa45c7f 83 URL location = FileLocator.find(FrameworkUtil.getBundle(this.getClass()), new Path(TraceControlTestFacility.DIRECTORY + File.separator + getTestStream()), null);
f3b33d40
BH
84 File testfile = new File(FileLocator.toFileURL(location).toURI());
85 fTestFile = testfile.getAbsolutePath();
86 }
87
88 /**
7fa45c7f 89 * Get the test stream file name to use for the test suite
f3b33d40 90 *
7fa45c7f
JRJ
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.
f3b33d40
BH
99 */
100 @After
101 public void tearDown() {
102 fFacility.waitForJobs();
103 }
104
105 /**
106 * Run the TraceControlComponent.
7fa45c7f
JRJ
107 *
108 * @throws Exception
109 * on internal error
f3b33d40
BH
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 = TraceControlTestFacility.getInstance().getControlView().getTraceControlRoot();
118
b732adaa
MS
119 IRemoteConnectionManager cm = RemoteServices.getLocalServices().getConnectionManager();
120 IRemoteConnection host = cm.getConnection(IRemoteConnectionManager.LOCAL_CONNECTION_NAME);
f3b33d40
BH
121
122 TargetNodeComponent node = new TargetNodeComponent("myNode", root, host, fProxy);
123
124 root.addChild(node);
125 fFacility.waitForJobs();
126
127 fFacility.executeCommand(node, "connect");
128 int i = 0;
129 while ((i < 10) && (node.getTargetNodeState() != TargetNodeState.CONNECTED)) {
130 i++;
131 fFacility.delay(TraceControlTestFacility.GUI_REFESH_DELAY);
132 }
133
134 // Verify that node is connected
135 assertEquals(TargetNodeState.CONNECTED, node.getTargetNodeState());
136
7fa45c7f
JRJ
137 ILttngControlService controleService = node.getControlService();
138
f3b33d40
BH
139 // Get provider groups
140 ITraceControlComponent[] groups = node.getChildren();
141 assertNotNull(groups);
142 assertEquals(2, groups.length);
143
144 // Initialize dialog implementations for command execution
145 CreateSessionDialogStub sessionDialogStub = new CreateSessionDialogStub();
146 TraceControlDialogFactory.getInstance().setCreateSessionDialog(sessionDialogStub);
147 TraceControlDialogFactory.getInstance().setConfirmDialog(new DestroyConfirmDialogStub());
148
f3b33d40 149 // ------------------------------------------------------------------------
a30e79fe 150 // Create session (--U file://...) and destroy
f3b33d40
BH
151 // ------------------------------------------------------------------------
152 // Initialize session handling scenario
a30e79fe 153 fProxy.setScenario(SCEN_SCENARIO_FILE_PROTO_TEST);
f3b33d40 154
a30e79fe
BH
155 sessionDialogStub.setNetworkUrl("file:///tmp");
156 sessionDialogStub.setStreamedTrace(true);
157 TraceSessionComponent session = fFacility.createSession(groups[1]);
f3b33d40
BH
158
159 // Verify that session was created
160 assertNotNull(session);
7fa45c7f
JRJ
161 assertEquals(getSessionName(), session.getName());
162 if (controleService.isVersionSupported("2.6.0")) {
163 assertEquals("/tmp", session.getSessionPath());
164 } else {
165 assertEquals("file:///tmp", session.getSessionPath());
166 }
167
a30e79fe 168 assertTrue(!session.isStreamedTrace());
f3b33d40 169 assertEquals(TraceSessionState.INACTIVE, session.getSessionState());
a30e79fe
BH
170 sessionDialogStub.setNetworkUrl(null);
171 sessionDialogStub.setStreamedTrace(false);
f3b33d40
BH
172
173 fFacility.destroySession(session);
174
175 // Verify that no more session components exist
176 assertEquals(0, groups[1].getChildren().length);
177
178 // ------------------------------------------------------------------------
a30e79fe 179 // Create session (--U file://,,, and destroy
f3b33d40
BH
180 // ------------------------------------------------------------------------
181 // Initialize session handling scenario
a30e79fe 182 fProxy.setScenario(SCEN_SCENARIO_CONTROL_DATA_TEST);
f3b33d40 183
a30e79fe
BH
184 sessionDialogStub.setControlUrl("tcp://172.0.0.1");
185 sessionDialogStub.setDataUrl("tcp://172.0.0.1:5343");
f3b33d40 186 sessionDialogStub.setStreamedTrace(true);
a30e79fe 187
f3b33d40
BH
188 session = fFacility.createSession(groups[1]);
189
190 // Verify that session was created
191 assertNotNull(session);
7fa45c7f
JRJ
192 assertEquals(getSessionName(), session.getName());
193 if (controleService.isVersionSupported("2.6.0")) {
194 assertEquals("tcp4://172.0.0.1:5342/ [data: 5343]", session.getSessionPath());
195 } else {
196 assertEquals("tcp://172.0.0.1:5342 [data: 5343]", session.getSessionPath());
197 }
f3b33d40
BH
198 assertTrue(session.isStreamedTrace());
199 assertEquals(TraceSessionState.INACTIVE, session.getSessionState());
a30e79fe
BH
200 sessionDialogStub.setControlUrl(null);
201 sessionDialogStub.setDataUrl(null);
f3b33d40
BH
202 sessionDialogStub.setStreamedTrace(false);
203
204 fFacility.destroySession(session);
205
206 // Verify that no more session components exist
207 assertEquals(0, groups[1].getChildren().length);
208
209 // ------------------------------------------------------------------------
a30e79fe 210 // Create session (--U file://... and destroy
f3b33d40
BH
211 // ------------------------------------------------------------------------
212 // Initialize session handling scenario
a30e79fe 213 fProxy.setScenario(SCEN_SCENARIO_NETWORK_TEST);
f3b33d40 214
a30e79fe 215 sessionDialogStub.setNetworkUrl("net://172.0.0.1:1234:2345");
f3b33d40
BH
216 sessionDialogStub.setStreamedTrace(true);
217
218 session = fFacility.createSession(groups[1]);
219
220 // Verify that session was created
221 assertNotNull(session);
7fa45c7f
JRJ
222 assertEquals(getSessionName(), session.getName());
223 if (controleService.isVersionSupported("2.6.0")) {
224 assertEquals("tcp4://172.0.0.1:1234/mysession-20140820-153527 [data: 2345]", session.getSessionPath());
225 } else {
226 assertEquals("net://172.0.0.1:1234 [data: 2345]", session.getSessionPath());
227 }
f3b33d40
BH
228 assertTrue(session.isStreamedTrace());
229 assertEquals(TraceSessionState.INACTIVE, session.getSessionState());
a30e79fe 230 sessionDialogStub.setNetworkUrl(null);
f3b33d40
BH
231
232 fFacility.destroySession(session);
233
234 // Verify that no more session components exist
235 assertEquals(0, groups[1].getChildren().length);
236
237 // ------------------------------------------------------------------------
a30e79fe 238 // Create session (--U net6://[...] and destroy
f3b33d40
BH
239 // ------------------------------------------------------------------------
240 // Initialize session handling scenario
a30e79fe 241 fProxy.setScenario(SCEN_SCENARIO_NETWORK2_TEST);
f3b33d40 242
a30e79fe 243 sessionDialogStub.setNetworkUrl("net6://[ffff::eeee:dddd:cccc:0]");
f3b33d40
BH
244 sessionDialogStub.setStreamedTrace(true);
245
246 session = fFacility.createSession(groups[1]);
247
248 // Verify that session was created
249 assertNotNull(session);
7fa45c7f
JRJ
250 assertEquals(getSessionName(), session.getName());
251 if (controleService.isVersionSupported("2.6.0")) {
252 assertEquals("tcp6://[ffff::eeee:dddd:cccc:0]:5342/mysession-20140820-153801 [data: 5343]", session.getSessionPath());
253 } else {
254 assertEquals("net://[ffff::eeee:dddd:cccc:0]:5342/mysession-20130221-144451 [data: 5343]", session.getSessionPath());
255 }
f3b33d40
BH
256 assertTrue(session.isStreamedTrace());
257 assertEquals(TraceSessionState.INACTIVE, session.getSessionState());
258 sessionDialogStub.setNetworkUrl(null);
259
260 fFacility.destroySession(session);
261
262 // Verify that no more session components exist
263 assertEquals(0, groups[1].getChildren().length);
264
7fa45c7f 265 // -------------------------------------------------------------------------
f3b33d40 266 // Disconnect node
7fa45c7f 267 // -------------------------------------------------------------------------
f3b33d40
BH
268 fFacility.executeCommand(node, "disconnect");
269 assertEquals(TargetNodeState.DISCONNECTED, node.getTargetNodeState());
270
7fa45c7f 271 // -------------------------------------------------------------------------
f3b33d40 272 // Delete node
7fa45c7f 273 // -------------------------------------------------------------------------
f3b33d40
BH
274
275 fFacility.executeCommand(node, "delete");
7fa45c7f
JRJ
276 assertEquals(0, fFacility.getControlView().getTraceControlRoot().getChildren().length);
277 }
278
279 private static String getSessionName() {
280 return SESSION;
f3b33d40
BH
281 }
282
a30e79fe 283}
This page took 0.063135 seconds and 5 git commands to generate.