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