Commit | Line | Data |
---|---|---|
f3b33d40 | 1 | /********************************************************************** |
ba3a9bd2 | 2 | * Copyright (c) 2013 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 | |
11 | **********************************************************************/ | |
12 | package org.eclipse.linuxtools.lttng2.ui.tests.control.model.component; | |
13 | ||
14 | import java.io.File; | |
15 | import java.net.URL; | |
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 org.eclipse.core.runtime.FileLocator; | |
22 | import org.eclipse.core.runtime.Path; | |
23 | import org.eclipse.linuxtools.internal.lttng2.core.control.model.TargetNodeState; | |
24 | import org.eclipse.linuxtools.internal.lttng2.core.control.model.TraceSessionState; | |
25 | import org.eclipse.linuxtools.internal.lttng2.stubs.dialogs.CreateSessionDialogStub; | |
26 | import org.eclipse.linuxtools.internal.lttng2.stubs.dialogs.DestroyConfirmDialogStub; | |
27 | import org.eclipse.linuxtools.internal.lttng2.stubs.service.TestRemoteSystemProxy; | |
28 | import org.eclipse.linuxtools.internal.lttng2.ui.views.control.dialogs.TraceControlDialogFactory; | |
29 | import org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.ITraceControlComponent; | |
30 | import org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.impl.TargetNodeComponent; | |
31 | import org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.impl.TraceSessionComponent; | |
32 | import org.eclipse.rse.core.RSECorePlugin; | |
33 | import org.eclipse.rse.core.model.IHost; | |
34 | import org.eclipse.rse.core.model.ISystemProfile; | |
35 | import org.eclipse.rse.core.model.ISystemRegistry; | |
36 | import org.junit.After; | |
37 | import org.junit.Before; | |
38 | import org.junit.Test; | |
39 | import org.osgi.framework.FrameworkUtil; | |
40 | ||
41 | /** | |
42 | * The class <code>TraceControlKernelSessionTests</code> contains Kernel session/channel/event | |
43 | * handling test cases. | |
44 | */ | |
45 | ||
4e0b52e0 | 46 | @SuppressWarnings("javadoc") |
f3b33d40 BH |
47 | public class TraceControlCreateSessionTests { |
48 | ||
49 | // ------------------------------------------------------------------------ | |
50 | // Constants | |
51 | // ------------------------------------------------------------------------ | |
52 | private static final String TEST_STREAM = "CreateSessionTest.cfg"; | |
f3b33d40 BH |
53 | private static final String SCEN_SCENARIO_FILE_PROTO_TEST = "CreateSessionFileProto"; |
54 | private static final String SCEN_SCENARIO_CONTROL_DATA_TEST = "CreateSessionControlData"; | |
55 | private static final String SCEN_SCENARIO_NETWORK_TEST = "CreateSessionNetwork"; | |
a30e79fe | 56 | private static final String SCEN_SCENARIO_NETWORK2_TEST = "CreateSessionNetwork2"; |
f3b33d40 BH |
57 | |
58 | // ------------------------------------------------------------------------ | |
59 | // Test data | |
60 | // ------------------------------------------------------------------------ | |
61 | private TraceControlTestFacility fFacility; | |
62 | private TestRemoteSystemProxy fProxy; | |
63 | private String fTestFile; | |
64 | ||
65 | // ------------------------------------------------------------------------ | |
66 | // Housekeeping | |
67 | // ------------------------------------------------------------------------ | |
68 | ||
69 | /** | |
70 | * Perform pre-test initialization. | |
71 | * | |
72 | * @throws Exception | |
73 | * if the initialization fails for some reason | |
74 | * | |
75 | */ | |
76 | @Before | |
77 | public void setUp() throws Exception { | |
78 | fFacility = TraceControlTestFacility.getInstance(); | |
a30e79fe | 79 | fFacility.init(); |
f3b33d40 BH |
80 | fProxy = new TestRemoteSystemProxy(); |
81 | URL location = FileLocator.find(FrameworkUtil.getBundle(this.getClass()), new Path(TraceControlTestFacility.DIRECTORY + File.separator + TEST_STREAM), null); | |
82 | File testfile = new File(FileLocator.toFileURL(location).toURI()); | |
83 | fTestFile = testfile.getAbsolutePath(); | |
84 | } | |
85 | ||
86 | /** | |
87 | * Perform post-test clean-up. | |
88 | * | |
89 | * @throws Exception | |
90 | * if the clean-up fails for some reason | |
91 | * | |
92 | */ | |
93 | @After | |
94 | public void tearDown() { | |
95 | fFacility.waitForJobs(); | |
96 | } | |
97 | ||
98 | /** | |
99 | * Run the TraceControlComponent. | |
100 | */ | |
101 | @Test | |
102 | public void testTraceSessionTree() throws Exception { | |
103 | ||
104 | fProxy.setTestFile(fTestFile); | |
105 | fProxy.setScenario(TraceControlTestFacility.SCEN_INIT_TEST); | |
106 | ||
107 | ITraceControlComponent root = TraceControlTestFacility.getInstance().getControlView().getTraceControlRoot(); | |
108 | ||
109 | ISystemRegistry registry = RSECorePlugin.getTheSystemRegistry(); | |
110 | ISystemProfile profile = registry.createSystemProfile("myProfile", true); | |
111 | IHost host = registry.createLocalHost(profile, "myProfile", "user"); | |
112 | ||
113 | TargetNodeComponent node = new TargetNodeComponent("myNode", root, host, fProxy); | |
114 | ||
115 | root.addChild(node); | |
116 | fFacility.waitForJobs(); | |
117 | ||
118 | fFacility.executeCommand(node, "connect"); | |
119 | int i = 0; | |
120 | while ((i < 10) && (node.getTargetNodeState() != TargetNodeState.CONNECTED)) { | |
121 | i++; | |
122 | fFacility.delay(TraceControlTestFacility.GUI_REFESH_DELAY); | |
123 | } | |
124 | ||
125 | // Verify that node is connected | |
126 | assertEquals(TargetNodeState.CONNECTED, node.getTargetNodeState()); | |
127 | ||
128 | // Get provider groups | |
129 | ITraceControlComponent[] groups = node.getChildren(); | |
130 | assertNotNull(groups); | |
131 | assertEquals(2, groups.length); | |
132 | ||
133 | // Initialize dialog implementations for command execution | |
134 | CreateSessionDialogStub sessionDialogStub = new CreateSessionDialogStub(); | |
135 | TraceControlDialogFactory.getInstance().setCreateSessionDialog(sessionDialogStub); | |
136 | TraceControlDialogFactory.getInstance().setConfirmDialog(new DestroyConfirmDialogStub()); | |
137 | ||
f3b33d40 | 138 | // ------------------------------------------------------------------------ |
a30e79fe | 139 | // Create session (--U file://...) and destroy |
f3b33d40 BH |
140 | // ------------------------------------------------------------------------ |
141 | // Initialize session handling scenario | |
a30e79fe | 142 | fProxy.setScenario(SCEN_SCENARIO_FILE_PROTO_TEST); |
f3b33d40 | 143 | |
a30e79fe BH |
144 | sessionDialogStub.setNetworkUrl("file:///tmp"); |
145 | sessionDialogStub.setStreamedTrace(true); | |
146 | TraceSessionComponent session = fFacility.createSession(groups[1]); | |
f3b33d40 BH |
147 | |
148 | // Verify that session was created | |
149 | assertNotNull(session); | |
150 | assertEquals("mysession", session.getName()); | |
a30e79fe BH |
151 | assertEquals("file:///tmp", session.getSessionPath()); |
152 | assertTrue(!session.isStreamedTrace()); | |
f3b33d40 | 153 | assertEquals(TraceSessionState.INACTIVE, session.getSessionState()); |
a30e79fe BH |
154 | sessionDialogStub.setNetworkUrl(null); |
155 | sessionDialogStub.setStreamedTrace(false); | |
f3b33d40 BH |
156 | |
157 | fFacility.destroySession(session); | |
158 | ||
159 | // Verify that no more session components exist | |
160 | assertEquals(0, groups[1].getChildren().length); | |
161 | ||
162 | // ------------------------------------------------------------------------ | |
a30e79fe | 163 | // Create session (--U file://,,, and destroy |
f3b33d40 BH |
164 | // ------------------------------------------------------------------------ |
165 | // Initialize session handling scenario | |
a30e79fe | 166 | fProxy.setScenario(SCEN_SCENARIO_CONTROL_DATA_TEST); |
f3b33d40 | 167 | |
a30e79fe BH |
168 | sessionDialogStub.setControlUrl("tcp://172.0.0.1"); |
169 | sessionDialogStub.setDataUrl("tcp://172.0.0.1:5343"); | |
f3b33d40 | 170 | sessionDialogStub.setStreamedTrace(true); |
a30e79fe | 171 | |
f3b33d40 BH |
172 | session = fFacility.createSession(groups[1]); |
173 | ||
174 | // Verify that session was created | |
175 | assertNotNull(session); | |
176 | assertEquals("mysession", session.getName()); | |
a30e79fe | 177 | assertEquals("tcp://172.0.0.1:5342 [data: 5343]", session.getSessionPath()); |
f3b33d40 BH |
178 | assertTrue(session.isStreamedTrace()); |
179 | assertEquals(TraceSessionState.INACTIVE, session.getSessionState()); | |
a30e79fe BH |
180 | sessionDialogStub.setControlUrl(null); |
181 | sessionDialogStub.setDataUrl(null); | |
f3b33d40 BH |
182 | sessionDialogStub.setStreamedTrace(false); |
183 | ||
184 | fFacility.destroySession(session); | |
185 | ||
186 | // Verify that no more session components exist | |
187 | assertEquals(0, groups[1].getChildren().length); | |
188 | ||
189 | // ------------------------------------------------------------------------ | |
a30e79fe | 190 | // Create session (--U file://... and destroy |
f3b33d40 BH |
191 | // ------------------------------------------------------------------------ |
192 | // Initialize session handling scenario | |
a30e79fe | 193 | fProxy.setScenario(SCEN_SCENARIO_NETWORK_TEST); |
f3b33d40 | 194 | |
a30e79fe | 195 | sessionDialogStub.setNetworkUrl("net://172.0.0.1:1234:2345"); |
f3b33d40 BH |
196 | sessionDialogStub.setStreamedTrace(true); |
197 | ||
198 | session = fFacility.createSession(groups[1]); | |
199 | ||
200 | // Verify that session was created | |
201 | assertNotNull(session); | |
202 | assertEquals("mysession", session.getName()); | |
a30e79fe | 203 | assertEquals("net://172.0.0.1:1234 [data: 2345]", session.getSessionPath()); |
f3b33d40 BH |
204 | assertTrue(session.isStreamedTrace()); |
205 | assertEquals(TraceSessionState.INACTIVE, session.getSessionState()); | |
a30e79fe | 206 | sessionDialogStub.setNetworkUrl(null); |
f3b33d40 BH |
207 | |
208 | fFacility.destroySession(session); | |
209 | ||
210 | // Verify that no more session components exist | |
211 | assertEquals(0, groups[1].getChildren().length); | |
212 | ||
213 | // ------------------------------------------------------------------------ | |
a30e79fe | 214 | // Create session (--U net6://[...] and destroy |
f3b33d40 BH |
215 | // ------------------------------------------------------------------------ |
216 | // Initialize session handling scenario | |
a30e79fe | 217 | fProxy.setScenario(SCEN_SCENARIO_NETWORK2_TEST); |
f3b33d40 | 218 | |
a30e79fe | 219 | sessionDialogStub.setNetworkUrl("net6://[ffff::eeee:dddd:cccc:0]"); |
f3b33d40 BH |
220 | sessionDialogStub.setStreamedTrace(true); |
221 | ||
222 | session = fFacility.createSession(groups[1]); | |
223 | ||
224 | // Verify that session was created | |
225 | assertNotNull(session); | |
226 | assertEquals("mysession", session.getName()); | |
a30e79fe | 227 | assertEquals("net://[ffff::eeee:dddd:cccc:0]:5342/mysession-20130221-144451 [data: 5343]", session.getSessionPath()); |
f3b33d40 BH |
228 | assertTrue(session.isStreamedTrace()); |
229 | assertEquals(TraceSessionState.INACTIVE, session.getSessionState()); | |
230 | sessionDialogStub.setNetworkUrl(null); | |
231 | ||
232 | fFacility.destroySession(session); | |
233 | ||
234 | // Verify that no more session components exist | |
235 | assertEquals(0, groups[1].getChildren().length); | |
236 | ||
a30e79fe | 237 | |
f3b33d40 BH |
238 | //------------------------------------------------------------------------- |
239 | // Disconnect node | |
240 | //------------------------------------------------------------------------- | |
241 | fFacility.executeCommand(node, "disconnect"); | |
242 | assertEquals(TargetNodeState.DISCONNECTED, node.getTargetNodeState()); | |
243 | ||
244 | //------------------------------------------------------------------------- | |
245 | // Delete node | |
246 | //------------------------------------------------------------------------- | |
247 | ||
248 | fFacility.executeCommand(node, "delete"); | |
249 | assertEquals(0,fFacility.getControlView().getTraceControlRoot().getChildren().length); | |
250 | } | |
251 | ||
a30e79fe | 252 | } |