Commit | Line | Data |
---|---|---|
589d0d33 | 1 | /********************************************************************** |
60ae41e1 | 2 | * Copyright (c) 2013, 2014 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 | |
11 | **********************************************************************/ | |
12 | ||
13 | package org.eclipse.linuxtools.lttng2.ui.tests.control.model.component; | |
14 | ||
15 | import static org.junit.Assert.assertEquals; | |
16 | import static org.junit.Assert.assertNotNull; | |
17 | import static org.junit.Assert.assertTrue; | |
18 | ||
19 | import java.io.File; | |
20 | import java.net.URL; | |
21 | import java.util.HashMap; | |
22 | import java.util.Map; | |
23 | ||
24 | import org.eclipse.core.runtime.FileLocator; | |
25 | import org.eclipse.core.runtime.Path; | |
26 | import org.eclipse.linuxtools.internal.lttng2.core.control.model.TargetNodeState; | |
27 | import org.eclipse.linuxtools.internal.lttng2.core.control.model.TraceSessionState; | |
28 | import org.eclipse.linuxtools.internal.lttng2.stubs.dialogs.CreateSessionDialogStub; | |
29 | import org.eclipse.linuxtools.internal.lttng2.stubs.dialogs.DestroyConfirmDialogStub; | |
30 | import org.eclipse.linuxtools.internal.lttng2.stubs.dialogs.GetEventInfoDialogStub; | |
31 | import org.eclipse.linuxtools.internal.lttng2.stubs.service.TestRemoteSystemProxy; | |
32 | import org.eclipse.linuxtools.internal.lttng2.ui.views.control.dialogs.TraceControlDialogFactory; | |
33 | import org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.ITraceControlComponent; | |
34 | import org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.impl.TargetNodeComponent; | |
35 | import org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.impl.TraceSessionComponent; | |
36 | import org.eclipse.linuxtools.internal.lttng2.ui.views.control.property.TraceSessionPropertySource; | |
37 | import org.eclipse.rse.core.RSECorePlugin; | |
38 | import org.eclipse.rse.core.model.IHost; | |
39 | import org.eclipse.rse.core.model.ISystemProfile; | |
40 | import org.eclipse.rse.core.model.ISystemRegistry; | |
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; | |
66 | private TestRemoteSystemProxy fProxy; | |
67 | private String fTestFile; | |
68 | ||
69 | // ------------------------------------------------------------------------ | |
70 | // Housekeeping | |
71 | // ------------------------------------------------------------------------ | |
72 | ||
73 | /** | |
74 | * Perform pre-test initialization. | |
75 | * | |
76 | * @throws Exception | |
77 | * if the initialization fails for some reason | |
78 | */ | |
79 | @Before | |
80 | public void setUp() throws Exception { | |
81 | fFacility = TraceControlTestFacility.getInstance(); | |
82 | fFacility.init(); | |
83 | fProxy = new TestRemoteSystemProxy(); | |
84 | URL location = FileLocator.find(FrameworkUtil.getBundle(this.getClass()), new Path(TraceControlTestFacility.DIRECTORY + File.separator + TEST_STREAM), null); | |
85 | File testfile = new File(FileLocator.toFileURL(location).toURI()); | |
86 | fTestFile = testfile.getAbsolutePath(); | |
87 | } | |
88 | ||
89 | /** | |
90 | * Perform post-test clean-up. | |
91 | */ | |
92 | @After | |
93 | public void tearDown() { | |
94 | fFacility.waitForJobs(); | |
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 | ||
112 | ISystemRegistry registry = RSECorePlugin.getTheSystemRegistry(); | |
113 | ISystemProfile profile = registry.createSystemProfile("myProfile", true); | |
114 | IHost host = registry.createLocalHost(profile, "myProfile", "user"); | |
115 | ||
116 | TargetNodeComponent node = new TargetNodeComponent("myNode", root, host, fProxy); | |
117 | ||
118 | root.addChild(node); | |
119 | fFacility.waitForJobs(); | |
120 | ||
121 | fFacility.executeCommand(node, "connect"); | |
122 | int i = 0; | |
123 | while ((i < 10) && (node.getTargetNodeState() != TargetNodeState.CONNECTED)) { | |
124 | i++; | |
125 | fFacility.delay(TraceControlTestFacility.GUI_REFESH_DELAY); | |
126 | } | |
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 | // --- snapshot session --- | |
135 | CreateSessionDialogStub sessionDialog = new CreateSessionDialogStub(); | |
136 | sessionDialog.setSnapshot(true); | |
137 | ||
138 | TraceControlDialogFactory.getInstance().setCreateSessionDialog(sessionDialog); | |
139 | TraceControlDialogFactory.getInstance().setGetEventInfoDialog(new GetEventInfoDialogStub()); | |
140 | TraceControlDialogFactory.getInstance().setConfirmDialog(new DestroyConfirmDialogStub()); | |
141 | ||
142 | // Initialize scenario | |
143 | fProxy.setScenario(SCEN_CREATE_SESSION); | |
144 | ||
145 | // ------------------------------------------------------------------------ | |
146 | // Create session | |
147 | // ------------------------------------------------------------------------ | |
148 | TraceSessionComponent session = fFacility.createSession(groups[1]); | |
149 | ||
150 | // Verify that session was created | |
151 | assertNotNull(session); | |
152 | assertEquals("mysession", session.getName()); | |
153 | assertTrue(session.isSnapshotSession()); | |
154 | assertNotNull(session.getSnapshotInfo()); | |
155 | assertEquals("snapshot-1", session.getSnapshotInfo().getName()); | |
156 | assertEquals("/home/user/lttng-traces/mysession-20130913-141651", session.getSnapshotInfo().getSnapshotPath()); | |
157 | assertEquals(1, session.getSnapshotInfo().getId()); | |
158 | ||
159 | // ------------------------------------------------------------------------ | |
160 | // Start session | |
161 | // ------------------------------------------------------------------------ | |
162 | fFacility.startSession(session); | |
163 | assertEquals(TraceSessionState.ACTIVE, session.getSessionState()); | |
164 | ||
165 | // verify properties | |
166 | Object adapter = session.getAdapter(IPropertySource.class); | |
167 | assertNotNull(adapter); | |
168 | assertTrue(adapter instanceof TraceSessionPropertySource); | |
169 | ||
170 | TraceSessionPropertySource sessionSource = (TraceSessionPropertySource)adapter; | |
171 | IPropertyDescriptor[] descriptors = sessionSource.getPropertyDescriptors(); | |
172 | assertNotNull(descriptors); | |
173 | ||
e0838ca1 | 174 | Map<String,String> map = new HashMap<>(); |
589d0d33 BH |
175 | map.put(TraceSessionPropertySource.TRACE_SESSION_NAME_PROPERTY_ID, "mysession"); |
176 | map.put(TraceSessionPropertySource.TRACE_SNAPSHOT_NAME_PROPERTY_ID, "snapshot-1"); | |
177 | map.put(TraceSessionPropertySource.TRACE_SNAPSHOT_PATH_PROPERTY_ID, "/home/user/lttng-traces/mysession-20130913-141651"); | |
178 | map.put(TraceSessionPropertySource.TRACE_SNAPSHOT_ID_PROPERTY_ID, "1"); | |
179 | map.put(TraceSessionPropertySource.TRACE_SESSION_STATE_PROPERTY_ID, TraceSessionState.ACTIVE.name()); | |
180 | ||
181 | for (int j = 0; j < descriptors.length; j++) { | |
182 | String expected = map.get(descriptors[j].getId()); | |
183 | assertNotNull(expected); | |
184 | assertEquals(expected, sessionSource.getPropertyValue(descriptors[j].getId()).toString()); | |
185 | } | |
186 | ||
187 | // ------------------------------------------------------------------------ | |
188 | // Record snapshot | |
189 | // ------------------------------------------------------------------------ | |
190 | fFacility.executeCommand(session, "snapshot"); | |
191 | ||
192 | // ------------------------------------------------------------------------ | |
193 | // Stop snapshot | |
194 | // ------------------------------------------------------------------------ | |
195 | fFacility.stopSession(session); | |
196 | assertEquals(TraceSessionState.INACTIVE, session.getSessionState()); | |
197 | ||
198 | // ------------------------------------------------------------------------ | |
199 | // Destroy session | |
200 | // ------------------------------------------------------------------------ | |
201 | fFacility.destroySession(session); | |
202 | ||
203 | // Verify that no more session components exist | |
204 | assertEquals(0, groups[1].getChildren().length); | |
205 | ||
206 | //------------------------------------------------------------------------- | |
207 | // Disconnect node | |
208 | //------------------------------------------------------------------------- | |
209 | fFacility.executeCommand(node, "disconnect"); | |
210 | assertEquals(TargetNodeState.DISCONNECTED, node.getTargetNodeState()); | |
211 | ||
212 | //------------------------------------------------------------------------- | |
213 | // Delete node | |
214 | //------------------------------------------------------------------------- | |
215 | ||
216 | fFacility.executeCommand(node, "delete"); | |
217 | ||
218 | assertEquals(0,fFacility.getControlView().getTraceControlRoot().getChildren().length); | |
219 | } | |
220 | } |