tmf: Bug 467751: Re-introduce fix for concurrency bug
[deliverable/tracecompass.git] / lttng / org.eclipse.tracecompass.lttng2.control.ui.tests / src / org / eclipse / tracecompass / lttng2 / control / ui / tests / model / component / TraceControlCreateSessionTests.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;
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;
b6b4e8b4 65 private IRemoteConnection fHost = TmfRemoteConnectionFactory.getLocalConnection();
d8a4fd60 66 private @NonNull TestRemoteSystemProxy fProxy = new TestRemoteSystemProxy(fHost);
f3b33d40
BH
67 private String fTestFile;
68
69 // ------------------------------------------------------------------------
70 // Housekeeping
71 // ------------------------------------------------------------------------
72
73 /**
74 * Perform pre-test initialization.
75 *
76 * @throws Exception
7fa45c7f 77 * if the initialization fails for some reason
f3b33d40
BH
78 */
79 @Before
80 public void setUp() throws Exception {
81 fFacility = TraceControlTestFacility.getInstance();
a30e79fe 82 fFacility.init();
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
d8a4fd60 119 TargetNodeComponent node = new TargetNodeComponent("myNode", root, fProxy);
f3b33d40
BH
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
7fa45c7f
JRJ
134 ILttngControlService controleService = node.getControlService();
135
f3b33d40
BH
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
f3b33d40 146 // ------------------------------------------------------------------------
a30e79fe 147 // Create session (--U file://...) and destroy
f3b33d40
BH
148 // ------------------------------------------------------------------------
149 // Initialize session handling scenario
a30e79fe 150 fProxy.setScenario(SCEN_SCENARIO_FILE_PROTO_TEST);
f3b33d40 151
a30e79fe
BH
152 sessionDialogStub.setNetworkUrl("file:///tmp");
153 sessionDialogStub.setStreamedTrace(true);
154 TraceSessionComponent session = fFacility.createSession(groups[1]);
f3b33d40
BH
155
156 // Verify that session was created
157 assertNotNull(session);
7fa45c7f
JRJ
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
a30e79fe 165 assertTrue(!session.isStreamedTrace());
f3b33d40 166 assertEquals(TraceSessionState.INACTIVE, session.getSessionState());
a30e79fe
BH
167 sessionDialogStub.setNetworkUrl(null);
168 sessionDialogStub.setStreamedTrace(false);
f3b33d40
BH
169
170 fFacility.destroySession(session);
171
172 // Verify that no more session components exist
173 assertEquals(0, groups[1].getChildren().length);
174
175 // ------------------------------------------------------------------------
a30e79fe 176 // Create session (--U file://,,, and destroy
f3b33d40
BH
177 // ------------------------------------------------------------------------
178 // Initialize session handling scenario
a30e79fe 179 fProxy.setScenario(SCEN_SCENARIO_CONTROL_DATA_TEST);
f3b33d40 180
a30e79fe
BH
181 sessionDialogStub.setControlUrl("tcp://172.0.0.1");
182 sessionDialogStub.setDataUrl("tcp://172.0.0.1:5343");
f3b33d40 183 sessionDialogStub.setStreamedTrace(true);
a30e79fe 184
f3b33d40
BH
185 session = fFacility.createSession(groups[1]);
186
187 // Verify that session was created
188 assertNotNull(session);
7fa45c7f
JRJ
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 }
f3b33d40
BH
195 assertTrue(session.isStreamedTrace());
196 assertEquals(TraceSessionState.INACTIVE, session.getSessionState());
a30e79fe
BH
197 sessionDialogStub.setControlUrl(null);
198 sessionDialogStub.setDataUrl(null);
f3b33d40
BH
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 // ------------------------------------------------------------------------
a30e79fe 207 // Create session (--U file://... and destroy
f3b33d40
BH
208 // ------------------------------------------------------------------------
209 // Initialize session handling scenario
a30e79fe 210 fProxy.setScenario(SCEN_SCENARIO_NETWORK_TEST);
f3b33d40 211
a30e79fe 212 sessionDialogStub.setNetworkUrl("net://172.0.0.1:1234:2345");
f3b33d40
BH
213 sessionDialogStub.setStreamedTrace(true);
214
215 session = fFacility.createSession(groups[1]);
216
217 // Verify that session was created
218 assertNotNull(session);
7fa45c7f
JRJ
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 }
f3b33d40
BH
225 assertTrue(session.isStreamedTrace());
226 assertEquals(TraceSessionState.INACTIVE, session.getSessionState());
a30e79fe 227 sessionDialogStub.setNetworkUrl(null);
f3b33d40
BH
228
229 fFacility.destroySession(session);
230
231 // Verify that no more session components exist
232 assertEquals(0, groups[1].getChildren().length);
233
234 // ------------------------------------------------------------------------
a30e79fe 235 // Create session (--U net6://[...] and destroy
f3b33d40
BH
236 // ------------------------------------------------------------------------
237 // Initialize session handling scenario
a30e79fe 238 fProxy.setScenario(SCEN_SCENARIO_NETWORK2_TEST);
f3b33d40 239
a30e79fe 240 sessionDialogStub.setNetworkUrl("net6://[ffff::eeee:dddd:cccc:0]");
f3b33d40
BH
241 sessionDialogStub.setStreamedTrace(true);
242
243 session = fFacility.createSession(groups[1]);
244
245 // Verify that session was created
246 assertNotNull(session);
7fa45c7f
JRJ
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 }
f3b33d40
BH
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
7fa45c7f 262 // -------------------------------------------------------------------------
f3b33d40 263 // Disconnect node
7fa45c7f 264 // -------------------------------------------------------------------------
f3b33d40
BH
265 fFacility.executeCommand(node, "disconnect");
266 assertEquals(TargetNodeState.DISCONNECTED, node.getTargetNodeState());
267
7fa45c7f 268 // -------------------------------------------------------------------------
f3b33d40 269 // Delete node
7fa45c7f 270 // -------------------------------------------------------------------------
f3b33d40
BH
271
272 fFacility.executeCommand(node, "delete");
7fa45c7f
JRJ
273 assertEquals(0, fFacility.getControlView().getTraceControlRoot().getChildren().length);
274 }
275
276 private static String getSessionName() {
277 return SESSION;
f3b33d40
BH
278 }
279
a30e79fe 280}
This page took 0.070103 seconds and 5 git commands to generate.