Commit | Line | Data |
---|---|---|
589d0d33 | 1 | /********************************************************************** |
533d0bc3 | 2 | * Copyright (c) 2013, 2015 Ericsson |
589d0d33 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 | |
b732adaa | 11 | * Markus Schorn - Bug 448058: Use org.eclipse.remote in favor of RSE |
589d0d33 BH |
12 | **********************************************************************/ |
13 | ||
9bc60be7 | 14 | package org.eclipse.tracecompass.lttng2.control.ui.tests.model.component; |
589d0d33 BH |
15 | |
16 | import static org.junit.Assert.assertEquals; | |
17 | import static org.junit.Assert.assertNotNull; | |
18 | import static org.junit.Assert.assertTrue; | |
19 | ||
20 | import java.io.File; | |
21 | import java.net.URL; | |
22 | import java.util.HashMap; | |
23 | import java.util.Map; | |
24 | ||
25 | import org.eclipse.core.runtime.FileLocator; | |
26 | import org.eclipse.core.runtime.Path; | |
d8a4fd60 | 27 | import org.eclipse.jdt.annotation.NonNull; |
b732adaa | 28 | import org.eclipse.remote.core.IRemoteConnection; |
9bc60be7 AM |
29 | import org.eclipse.tracecompass.internal.lttng2.control.core.model.TargetNodeState; |
30 | import org.eclipse.tracecompass.internal.lttng2.control.core.model.TraceSessionState; | |
31 | import org.eclipse.tracecompass.internal.lttng2.control.stubs.dialogs.CreateSessionDialogStub; | |
32 | import org.eclipse.tracecompass.internal.lttng2.control.stubs.dialogs.DestroyConfirmDialogStub; | |
33 | import org.eclipse.tracecompass.internal.lttng2.control.stubs.dialogs.GetEventInfoDialogStub; | |
34 | import org.eclipse.tracecompass.internal.lttng2.control.stubs.service.TestRemoteSystemProxy; | |
35 | import org.eclipse.tracecompass.internal.lttng2.control.ui.views.dialogs.TraceControlDialogFactory; | |
36 | import org.eclipse.tracecompass.internal.lttng2.control.ui.views.model.ITraceControlComponent; | |
37 | import org.eclipse.tracecompass.internal.lttng2.control.ui.views.model.impl.TargetNodeComponent; | |
38 | import org.eclipse.tracecompass.internal.lttng2.control.ui.views.model.impl.TraceSessionComponent; | |
39 | import org.eclipse.tracecompass.internal.lttng2.control.ui.views.property.TraceSessionPropertySource; | |
b6b4e8b4 | 40 | import org.eclipse.tracecompass.tmf.remote.core.proxy.TmfRemoteConnectionFactory; |
589d0d33 BH |
41 | import org.eclipse.ui.views.properties.IPropertyDescriptor; |
42 | import org.eclipse.ui.views.properties.IPropertySource; | |
43 | import org.junit.After; | |
44 | import org.junit.Before; | |
45 | import org.junit.Test; | |
46 | import org.osgi.framework.FrameworkUtil; | |
47 | ||
48 | /** | |
49 | * The class <code>TraceControlSnapshotSessionTests</code> contains Snapshot | |
50 | * session test cases for support of LTTng Tools 2.3. | |
51 | */ | |
52 | public class TraceControlSnapshotSessionTests { | |
53 | ||
54 | // ------------------------------------------------------------------------ | |
55 | // Constants | |
56 | // ------------------------------------------------------------------------ | |
57 | ||
58 | private static final String TEST_STREAM = "CreateSessionTest2.cfg"; | |
59 | private static final String SCEN_CREATE_SESSION = "ScenCreateSession"; | |
60 | ||
61 | // ------------------------------------------------------------------------ | |
62 | // Test data | |
63 | // ------------------------------------------------------------------------ | |
64 | ||
65 | private TraceControlTestFacility fFacility; | |
b6b4e8b4 | 66 | private IRemoteConnection fHost = TmfRemoteConnectionFactory.getLocalConnection(); |
d8a4fd60 | 67 | private @NonNull TestRemoteSystemProxy fProxy = new TestRemoteSystemProxy(fHost); |
589d0d33 BH |
68 | private String fTestFile; |
69 | ||
70 | // ------------------------------------------------------------------------ | |
71 | // Housekeeping | |
72 | // ------------------------------------------------------------------------ | |
73 | ||
74 | /** | |
75 | * Perform pre-test initialization. | |
76 | * | |
77 | * @throws Exception | |
78 | * if the initialization fails for some reason | |
79 | */ | |
80 | @Before | |
81 | public void setUp() throws Exception { | |
82 | fFacility = TraceControlTestFacility.getInstance(); | |
83 | fFacility.init(); | |
d8a4fd60 | 84 | fProxy = new TestRemoteSystemProxy(fHost); |
589d0d33 BH |
85 | URL location = FileLocator.find(FrameworkUtil.getBundle(this.getClass()), new Path(TraceControlTestFacility.DIRECTORY + File.separator + TEST_STREAM), null); |
86 | File testfile = new File(FileLocator.toFileURL(location).toURI()); | |
87 | fTestFile = testfile.getAbsolutePath(); | |
88 | } | |
89 | ||
90 | /** | |
91 | * Perform post-test clean-up. | |
92 | */ | |
93 | @After | |
94 | public void tearDown() { | |
589d0d33 BH |
95 | fFacility.dispose(); |
96 | } | |
97 | ||
98 | /** | |
99 | * Run the TraceControlComponent. | |
100 | * | |
101 | * @throws Exception | |
102 | * This will fail the test | |
103 | */ | |
104 | @Test | |
105 | public void testTraceSessionTree() throws Exception { | |
106 | ||
107 | fProxy.setTestFile(fTestFile); | |
108 | fProxy.setScenario(TraceControlTestFacility.SCEN_INIT_TEST); | |
109 | ||
110 | ITraceControlComponent root = fFacility.getControlView().getTraceControlRoot(); | |
111 | ||
d8a4fd60 | 112 | TargetNodeComponent node = new TargetNodeComponent("myNode", root, fProxy); |
589d0d33 BH |
113 | |
114 | root.addChild(node); | |
115 | fFacility.waitForJobs(); | |
116 | ||
117 | fFacility.executeCommand(node, "connect"); | |
118 | int i = 0; | |
119 | while ((i < 10) && (node.getTargetNodeState() != TargetNodeState.CONNECTED)) { | |
120 | i++; | |
121 | fFacility.delay(TraceControlTestFacility.GUI_REFESH_DELAY); | |
122 | } | |
123 | ||
124 | // Get provider groups | |
125 | ITraceControlComponent[] groups = node.getChildren(); | |
126 | assertNotNull(groups); | |
127 | assertEquals(2, groups.length); | |
128 | ||
129 | // Initialize dialog implementations for command execution | |
130 | // --- snapshot session --- | |
131 | CreateSessionDialogStub sessionDialog = new CreateSessionDialogStub(); | |
132 | sessionDialog.setSnapshot(true); | |
133 | ||
134 | TraceControlDialogFactory.getInstance().setCreateSessionDialog(sessionDialog); | |
135 | TraceControlDialogFactory.getInstance().setGetEventInfoDialog(new GetEventInfoDialogStub()); | |
136 | TraceControlDialogFactory.getInstance().setConfirmDialog(new DestroyConfirmDialogStub()); | |
137 | ||
138 | // Initialize scenario | |
139 | fProxy.setScenario(SCEN_CREATE_SESSION); | |
140 | ||
141 | // ------------------------------------------------------------------------ | |
142 | // Create session | |
143 | // ------------------------------------------------------------------------ | |
144 | TraceSessionComponent session = fFacility.createSession(groups[1]); | |
145 | ||
146 | // Verify that session was created | |
147 | assertNotNull(session); | |
148 | assertEquals("mysession", session.getName()); | |
149 | assertTrue(session.isSnapshotSession()); | |
150 | assertNotNull(session.getSnapshotInfo()); | |
151 | assertEquals("snapshot-1", session.getSnapshotInfo().getName()); | |
152 | assertEquals("/home/user/lttng-traces/mysession-20130913-141651", session.getSnapshotInfo().getSnapshotPath()); | |
153 | assertEquals(1, session.getSnapshotInfo().getId()); | |
154 | ||
155 | // ------------------------------------------------------------------------ | |
156 | // Start session | |
157 | // ------------------------------------------------------------------------ | |
158 | fFacility.startSession(session); | |
159 | assertEquals(TraceSessionState.ACTIVE, session.getSessionState()); | |
160 | ||
161 | // verify properties | |
162 | Object adapter = session.getAdapter(IPropertySource.class); | |
163 | assertNotNull(adapter); | |
164 | assertTrue(adapter instanceof TraceSessionPropertySource); | |
165 | ||
166 | TraceSessionPropertySource sessionSource = (TraceSessionPropertySource)adapter; | |
167 | IPropertyDescriptor[] descriptors = sessionSource.getPropertyDescriptors(); | |
168 | assertNotNull(descriptors); | |
169 | ||
e0838ca1 | 170 | Map<String,String> map = new HashMap<>(); |
589d0d33 BH |
171 | map.put(TraceSessionPropertySource.TRACE_SESSION_NAME_PROPERTY_ID, "mysession"); |
172 | map.put(TraceSessionPropertySource.TRACE_SNAPSHOT_NAME_PROPERTY_ID, "snapshot-1"); | |
173 | map.put(TraceSessionPropertySource.TRACE_SNAPSHOT_PATH_PROPERTY_ID, "/home/user/lttng-traces/mysession-20130913-141651"); | |
174 | map.put(TraceSessionPropertySource.TRACE_SNAPSHOT_ID_PROPERTY_ID, "1"); | |
175 | map.put(TraceSessionPropertySource.TRACE_SESSION_STATE_PROPERTY_ID, TraceSessionState.ACTIVE.name()); | |
176 | ||
177 | for (int j = 0; j < descriptors.length; j++) { | |
178 | String expected = map.get(descriptors[j].getId()); | |
179 | assertNotNull(expected); | |
180 | assertEquals(expected, sessionSource.getPropertyValue(descriptors[j].getId()).toString()); | |
181 | } | |
182 | ||
183 | // ------------------------------------------------------------------------ | |
184 | // Record snapshot | |
185 | // ------------------------------------------------------------------------ | |
186 | fFacility.executeCommand(session, "snapshot"); | |
187 | ||
188 | // ------------------------------------------------------------------------ | |
189 | // Stop snapshot | |
190 | // ------------------------------------------------------------------------ | |
191 | fFacility.stopSession(session); | |
192 | assertEquals(TraceSessionState.INACTIVE, session.getSessionState()); | |
193 | ||
194 | // ------------------------------------------------------------------------ | |
195 | // Destroy session | |
196 | // ------------------------------------------------------------------------ | |
197 | fFacility.destroySession(session); | |
198 | ||
199 | // Verify that no more session components exist | |
200 | assertEquals(0, groups[1].getChildren().length); | |
201 | ||
202 | //------------------------------------------------------------------------- | |
203 | // Disconnect node | |
204 | //------------------------------------------------------------------------- | |
205 | fFacility.executeCommand(node, "disconnect"); | |
206 | assertEquals(TargetNodeState.DISCONNECTED, node.getTargetNodeState()); | |
207 | ||
208 | //------------------------------------------------------------------------- | |
209 | // Delete node | |
210 | //------------------------------------------------------------------------- | |
211 | ||
212 | fFacility.executeCommand(node, "delete"); | |
589d0d33 BH |
213 | } |
214 | } |