Commit | Line | Data |
---|---|---|
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 |
f3b33d40 | 12 | **********************************************************************/ |
7fa45c7f | 13 | |
8e8c0226 | 14 | package org.eclipse.linuxtools.lttng2.control.ui.tests.model.component; |
f3b33d40 BH |
15 | |
16 | import static org.junit.Assert.assertEquals; | |
17 | import static org.junit.Assert.assertNotNull; | |
18 | import static org.junit.Assert.assertTrue; | |
19 | ||
8e8c0226 AM |
20 | import java.io.File; |
21 | import java.net.URL; | |
22 | ||
f3b33d40 BH |
23 | import org.eclipse.core.runtime.FileLocator; |
24 | import org.eclipse.core.runtime.Path; | |
8e8c0226 AM |
25 | import org.eclipse.linuxtools.internal.lttng2.control.core.model.TargetNodeState; |
26 | import org.eclipse.linuxtools.internal.lttng2.control.core.model.TraceSessionState; | |
27 | import org.eclipse.linuxtools.internal.lttng2.control.stubs.dialogs.CreateSessionDialogStub; | |
28 | import org.eclipse.linuxtools.internal.lttng2.control.stubs.dialogs.DestroyConfirmDialogStub; | |
29 | import org.eclipse.linuxtools.internal.lttng2.control.stubs.service.TestRemoteSystemProxy; | |
30 | import org.eclipse.linuxtools.internal.lttng2.control.ui.views.dialogs.TraceControlDialogFactory; | |
31 | import org.eclipse.linuxtools.internal.lttng2.control.ui.views.model.ITraceControlComponent; | |
32 | import org.eclipse.linuxtools.internal.lttng2.control.ui.views.model.impl.TargetNodeComponent; | |
33 | import org.eclipse.linuxtools.internal.lttng2.control.ui.views.model.impl.TraceSessionComponent; | |
7fa45c7f | 34 | import org.eclipse.linuxtools.internal.lttng2.control.ui.views.service.ILttngControlService; |
f3b33d40 BH |
35 | import org.eclipse.rse.core.RSECorePlugin; |
36 | import org.eclipse.rse.core.model.IHost; | |
37 | import org.eclipse.rse.core.model.ISystemProfile; | |
38 | import org.eclipse.rse.core.model.ISystemRegistry; | |
39 | import org.junit.After; | |
40 | import org.junit.Before; | |
41 | import org.junit.Test; | |
42 | import 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 |
48 | public 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 | ||
119 | ISystemRegistry registry = RSECorePlugin.getTheSystemRegistry(); | |
7fa45c7f | 120 | ISystemProfile profile = registry.createSystemProfile("myProfile", true); |
f3b33d40 BH |
121 | IHost host = registry.createLocalHost(profile, "myProfile", "user"); |
122 | ||
123 | TargetNodeComponent node = new TargetNodeComponent("myNode", root, host, fProxy); | |
124 | ||
125 | root.addChild(node); | |
126 | fFacility.waitForJobs(); | |
127 | ||
128 | fFacility.executeCommand(node, "connect"); | |
129 | int i = 0; | |
130 | while ((i < 10) && (node.getTargetNodeState() != TargetNodeState.CONNECTED)) { | |
131 | i++; | |
132 | fFacility.delay(TraceControlTestFacility.GUI_REFESH_DELAY); | |
133 | } | |
134 | ||
135 | // Verify that node is connected | |
136 | assertEquals(TargetNodeState.CONNECTED, node.getTargetNodeState()); | |
137 | ||
7fa45c7f JRJ |
138 | ILttngControlService controleService = node.getControlService(); |
139 | ||
f3b33d40 BH |
140 | // Get provider groups |
141 | ITraceControlComponent[] groups = node.getChildren(); | |
142 | assertNotNull(groups); | |
143 | assertEquals(2, groups.length); | |
144 | ||
145 | // Initialize dialog implementations for command execution | |
146 | CreateSessionDialogStub sessionDialogStub = new CreateSessionDialogStub(); | |
147 | TraceControlDialogFactory.getInstance().setCreateSessionDialog(sessionDialogStub); | |
148 | TraceControlDialogFactory.getInstance().setConfirmDialog(new DestroyConfirmDialogStub()); | |
149 | ||
f3b33d40 | 150 | // ------------------------------------------------------------------------ |
a30e79fe | 151 | // Create session (--U file://...) and destroy |
f3b33d40 BH |
152 | // ------------------------------------------------------------------------ |
153 | // Initialize session handling scenario | |
a30e79fe | 154 | fProxy.setScenario(SCEN_SCENARIO_FILE_PROTO_TEST); |
f3b33d40 | 155 | |
a30e79fe BH |
156 | sessionDialogStub.setNetworkUrl("file:///tmp"); |
157 | sessionDialogStub.setStreamedTrace(true); | |
158 | TraceSessionComponent session = fFacility.createSession(groups[1]); | |
f3b33d40 BH |
159 | |
160 | // Verify that session was created | |
161 | assertNotNull(session); | |
7fa45c7f JRJ |
162 | assertEquals(getSessionName(), session.getName()); |
163 | if (controleService.isVersionSupported("2.6.0")) { | |
164 | assertEquals("/tmp", session.getSessionPath()); | |
165 | } else { | |
166 | assertEquals("file:///tmp", session.getSessionPath()); | |
167 | } | |
168 | ||
a30e79fe | 169 | assertTrue(!session.isStreamedTrace()); |
f3b33d40 | 170 | assertEquals(TraceSessionState.INACTIVE, session.getSessionState()); |
a30e79fe BH |
171 | sessionDialogStub.setNetworkUrl(null); |
172 | sessionDialogStub.setStreamedTrace(false); | |
f3b33d40 BH |
173 | |
174 | fFacility.destroySession(session); | |
175 | ||
176 | // Verify that no more session components exist | |
177 | assertEquals(0, groups[1].getChildren().length); | |
178 | ||
179 | // ------------------------------------------------------------------------ | |
a30e79fe | 180 | // Create session (--U file://,,, and destroy |
f3b33d40 BH |
181 | // ------------------------------------------------------------------------ |
182 | // Initialize session handling scenario | |
a30e79fe | 183 | fProxy.setScenario(SCEN_SCENARIO_CONTROL_DATA_TEST); |
f3b33d40 | 184 | |
a30e79fe BH |
185 | sessionDialogStub.setControlUrl("tcp://172.0.0.1"); |
186 | sessionDialogStub.setDataUrl("tcp://172.0.0.1:5343"); | |
f3b33d40 | 187 | sessionDialogStub.setStreamedTrace(true); |
a30e79fe | 188 | |
f3b33d40 BH |
189 | session = fFacility.createSession(groups[1]); |
190 | ||
191 | // Verify that session was created | |
192 | assertNotNull(session); | |
7fa45c7f JRJ |
193 | assertEquals(getSessionName(), session.getName()); |
194 | if (controleService.isVersionSupported("2.6.0")) { | |
195 | assertEquals("tcp4://172.0.0.1:5342/ [data: 5343]", session.getSessionPath()); | |
196 | } else { | |
197 | assertEquals("tcp://172.0.0.1:5342 [data: 5343]", session.getSessionPath()); | |
198 | } | |
f3b33d40 BH |
199 | assertTrue(session.isStreamedTrace()); |
200 | assertEquals(TraceSessionState.INACTIVE, session.getSessionState()); | |
a30e79fe BH |
201 | sessionDialogStub.setControlUrl(null); |
202 | sessionDialogStub.setDataUrl(null); | |
f3b33d40 BH |
203 | sessionDialogStub.setStreamedTrace(false); |
204 | ||
205 | fFacility.destroySession(session); | |
206 | ||
207 | // Verify that no more session components exist | |
208 | assertEquals(0, groups[1].getChildren().length); | |
209 | ||
210 | // ------------------------------------------------------------------------ | |
a30e79fe | 211 | // Create session (--U file://... and destroy |
f3b33d40 BH |
212 | // ------------------------------------------------------------------------ |
213 | // Initialize session handling scenario | |
a30e79fe | 214 | fProxy.setScenario(SCEN_SCENARIO_NETWORK_TEST); |
f3b33d40 | 215 | |
a30e79fe | 216 | sessionDialogStub.setNetworkUrl("net://172.0.0.1:1234:2345"); |
f3b33d40 BH |
217 | sessionDialogStub.setStreamedTrace(true); |
218 | ||
219 | session = fFacility.createSession(groups[1]); | |
220 | ||
221 | // Verify that session was created | |
222 | assertNotNull(session); | |
7fa45c7f JRJ |
223 | assertEquals(getSessionName(), session.getName()); |
224 | if (controleService.isVersionSupported("2.6.0")) { | |
225 | assertEquals("tcp4://172.0.0.1:1234/mysession-20140820-153527 [data: 2345]", session.getSessionPath()); | |
226 | } else { | |
227 | assertEquals("net://172.0.0.1:1234 [data: 2345]", session.getSessionPath()); | |
228 | } | |
f3b33d40 BH |
229 | assertTrue(session.isStreamedTrace()); |
230 | assertEquals(TraceSessionState.INACTIVE, session.getSessionState()); | |
a30e79fe | 231 | sessionDialogStub.setNetworkUrl(null); |
f3b33d40 BH |
232 | |
233 | fFacility.destroySession(session); | |
234 | ||
235 | // Verify that no more session components exist | |
236 | assertEquals(0, groups[1].getChildren().length); | |
237 | ||
238 | // ------------------------------------------------------------------------ | |
a30e79fe | 239 | // Create session (--U net6://[...] and destroy |
f3b33d40 BH |
240 | // ------------------------------------------------------------------------ |
241 | // Initialize session handling scenario | |
a30e79fe | 242 | fProxy.setScenario(SCEN_SCENARIO_NETWORK2_TEST); |
f3b33d40 | 243 | |
a30e79fe | 244 | sessionDialogStub.setNetworkUrl("net6://[ffff::eeee:dddd:cccc:0]"); |
f3b33d40 BH |
245 | sessionDialogStub.setStreamedTrace(true); |
246 | ||
247 | session = fFacility.createSession(groups[1]); | |
248 | ||
249 | // Verify that session was created | |
250 | assertNotNull(session); | |
7fa45c7f JRJ |
251 | assertEquals(getSessionName(), session.getName()); |
252 | if (controleService.isVersionSupported("2.6.0")) { | |
253 | assertEquals("tcp6://[ffff::eeee:dddd:cccc:0]:5342/mysession-20140820-153801 [data: 5343]", session.getSessionPath()); | |
254 | } else { | |
255 | assertEquals("net://[ffff::eeee:dddd:cccc:0]:5342/mysession-20130221-144451 [data: 5343]", session.getSessionPath()); | |
256 | } | |
f3b33d40 BH |
257 | assertTrue(session.isStreamedTrace()); |
258 | assertEquals(TraceSessionState.INACTIVE, session.getSessionState()); | |
259 | sessionDialogStub.setNetworkUrl(null); | |
260 | ||
261 | fFacility.destroySession(session); | |
262 | ||
263 | // Verify that no more session components exist | |
264 | assertEquals(0, groups[1].getChildren().length); | |
265 | ||
7fa45c7f | 266 | // ------------------------------------------------------------------------- |
f3b33d40 | 267 | // Disconnect node |
7fa45c7f | 268 | // ------------------------------------------------------------------------- |
f3b33d40 BH |
269 | fFacility.executeCommand(node, "disconnect"); |
270 | assertEquals(TargetNodeState.DISCONNECTED, node.getTargetNodeState()); | |
271 | ||
7fa45c7f | 272 | // ------------------------------------------------------------------------- |
f3b33d40 | 273 | // Delete node |
7fa45c7f | 274 | // ------------------------------------------------------------------------- |
f3b33d40 BH |
275 | |
276 | fFacility.executeCommand(node, "delete"); | |
7fa45c7f JRJ |
277 | assertEquals(0, fFacility.getControlView().getTraceControlRoot().getChildren().length); |
278 | } | |
279 | ||
280 | private static String getSessionName() { | |
281 | return SESSION; | |
f3b33d40 BH |
282 | } |
283 | ||
a30e79fe | 284 | } |