1 /**********************************************************************
2 * Copyright (c) 2013, 2014 Ericsson
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
10 * Bernd Hufmann - Initial API and implementation
11 * Markus Schorn - Bug 448058: Use org.eclipse.remote in favor of RSE
12 **********************************************************************/
14 package org
.eclipse
.tracecompass
.lttng2
.control
.ui
.tests
.model
.component
;
16 import static org
.junit
.Assert
.assertEquals
;
17 import static org
.junit
.Assert
.assertNotNull
;
18 import static org
.junit
.Assert
.assertTrue
;
22 import java
.util
.HashMap
;
25 import org
.eclipse
.core
.runtime
.FileLocator
;
26 import org
.eclipse
.core
.runtime
.Path
;
27 import org
.eclipse
.remote
.core
.IRemoteConnection
;
28 import org
.eclipse
.remote
.core
.IRemoteConnectionManager
;
29 import org
.eclipse
.remote
.core
.RemoteServices
;
30 import org
.eclipse
.tracecompass
.internal
.lttng2
.control
.core
.model
.TargetNodeState
;
31 import org
.eclipse
.tracecompass
.internal
.lttng2
.control
.core
.model
.TraceSessionState
;
32 import org
.eclipse
.tracecompass
.internal
.lttng2
.control
.stubs
.dialogs
.CreateSessionDialogStub
;
33 import org
.eclipse
.tracecompass
.internal
.lttng2
.control
.stubs
.dialogs
.DestroyConfirmDialogStub
;
34 import org
.eclipse
.tracecompass
.internal
.lttng2
.control
.stubs
.dialogs
.GetEventInfoDialogStub
;
35 import org
.eclipse
.tracecompass
.internal
.lttng2
.control
.stubs
.service
.TestRemoteSystemProxy
;
36 import org
.eclipse
.tracecompass
.internal
.lttng2
.control
.ui
.views
.dialogs
.TraceControlDialogFactory
;
37 import org
.eclipse
.tracecompass
.internal
.lttng2
.control
.ui
.views
.model
.ITraceControlComponent
;
38 import org
.eclipse
.tracecompass
.internal
.lttng2
.control
.ui
.views
.model
.impl
.TargetNodeComponent
;
39 import org
.eclipse
.tracecompass
.internal
.lttng2
.control
.ui
.views
.model
.impl
.TraceSessionComponent
;
40 import org
.eclipse
.tracecompass
.internal
.lttng2
.control
.ui
.views
.property
.TraceSessionPropertySource
;
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
;
49 * The class <code>TraceControlSnapshotSessionTests</code> contains Snapshot
50 * session test cases for support of LTTng Tools 2.3.
52 public class TraceControlSnapshotSessionTests
{
54 // ------------------------------------------------------------------------
56 // ------------------------------------------------------------------------
58 private static final String TEST_STREAM
= "CreateSessionTest2.cfg";
59 private static final String SCEN_CREATE_SESSION
= "ScenCreateSession";
61 // ------------------------------------------------------------------------
63 // ------------------------------------------------------------------------
65 private TraceControlTestFacility fFacility
;
66 private TestRemoteSystemProxy fProxy
;
67 private String fTestFile
;
69 // ------------------------------------------------------------------------
71 // ------------------------------------------------------------------------
74 * Perform pre-test initialization.
77 * if the initialization fails for some reason
80 public void setUp() throws Exception
{
81 fFacility
= TraceControlTestFacility
.getInstance();
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();
90 * Perform post-test clean-up.
93 public void tearDown() {
94 fFacility
.waitForJobs();
99 * Run the TraceControlComponent.
102 * This will fail the test
105 public void testTraceSessionTree() throws Exception
{
107 fProxy
.setTestFile(fTestFile
);
108 fProxy
.setScenario(TraceControlTestFacility
.SCEN_INIT_TEST
);
110 ITraceControlComponent root
= fFacility
.getControlView().getTraceControlRoot();
112 IRemoteConnectionManager cm
= RemoteServices
.getLocalServices().getConnectionManager();
113 IRemoteConnection host
= cm
.getConnection(IRemoteConnectionManager
.LOCAL_CONNECTION_NAME
);
115 TargetNodeComponent node
= new TargetNodeComponent("myNode", root
, host
, fProxy
);
118 fFacility
.waitForJobs();
120 fFacility
.executeCommand(node
, "connect");
122 while ((i
< 10) && (node
.getTargetNodeState() != TargetNodeState
.CONNECTED
)) {
124 fFacility
.delay(TraceControlTestFacility
.GUI_REFESH_DELAY
);
127 // Get provider groups
128 ITraceControlComponent
[] groups
= node
.getChildren();
129 assertNotNull(groups
);
130 assertEquals(2, groups
.length
);
132 // Initialize dialog implementations for command execution
133 // --- snapshot session ---
134 CreateSessionDialogStub sessionDialog
= new CreateSessionDialogStub();
135 sessionDialog
.setSnapshot(true);
137 TraceControlDialogFactory
.getInstance().setCreateSessionDialog(sessionDialog
);
138 TraceControlDialogFactory
.getInstance().setGetEventInfoDialog(new GetEventInfoDialogStub());
139 TraceControlDialogFactory
.getInstance().setConfirmDialog(new DestroyConfirmDialogStub());
141 // Initialize scenario
142 fProxy
.setScenario(SCEN_CREATE_SESSION
);
144 // ------------------------------------------------------------------------
146 // ------------------------------------------------------------------------
147 TraceSessionComponent session
= fFacility
.createSession(groups
[1]);
149 // Verify that session was created
150 assertNotNull(session
);
151 assertEquals("mysession", session
.getName());
152 assertTrue(session
.isSnapshotSession());
153 assertNotNull(session
.getSnapshotInfo());
154 assertEquals("snapshot-1", session
.getSnapshotInfo().getName());
155 assertEquals("/home/user/lttng-traces/mysession-20130913-141651", session
.getSnapshotInfo().getSnapshotPath());
156 assertEquals(1, session
.getSnapshotInfo().getId());
158 // ------------------------------------------------------------------------
160 // ------------------------------------------------------------------------
161 fFacility
.startSession(session
);
162 assertEquals(TraceSessionState
.ACTIVE
, session
.getSessionState());
165 Object adapter
= session
.getAdapter(IPropertySource
.class);
166 assertNotNull(adapter
);
167 assertTrue(adapter
instanceof TraceSessionPropertySource
);
169 TraceSessionPropertySource sessionSource
= (TraceSessionPropertySource
)adapter
;
170 IPropertyDescriptor
[] descriptors
= sessionSource
.getPropertyDescriptors();
171 assertNotNull(descriptors
);
173 Map
<String
,String
> map
= new HashMap
<>();
174 map
.put(TraceSessionPropertySource
.TRACE_SESSION_NAME_PROPERTY_ID
, "mysession");
175 map
.put(TraceSessionPropertySource
.TRACE_SNAPSHOT_NAME_PROPERTY_ID
, "snapshot-1");
176 map
.put(TraceSessionPropertySource
.TRACE_SNAPSHOT_PATH_PROPERTY_ID
, "/home/user/lttng-traces/mysession-20130913-141651");
177 map
.put(TraceSessionPropertySource
.TRACE_SNAPSHOT_ID_PROPERTY_ID
, "1");
178 map
.put(TraceSessionPropertySource
.TRACE_SESSION_STATE_PROPERTY_ID
, TraceSessionState
.ACTIVE
.name());
180 for (int j
= 0; j
< descriptors
.length
; j
++) {
181 String expected
= map
.get(descriptors
[j
].getId());
182 assertNotNull(expected
);
183 assertEquals(expected
, sessionSource
.getPropertyValue(descriptors
[j
].getId()).toString());
186 // ------------------------------------------------------------------------
188 // ------------------------------------------------------------------------
189 fFacility
.executeCommand(session
, "snapshot");
191 // ------------------------------------------------------------------------
193 // ------------------------------------------------------------------------
194 fFacility
.stopSession(session
);
195 assertEquals(TraceSessionState
.INACTIVE
, session
.getSessionState());
197 // ------------------------------------------------------------------------
199 // ------------------------------------------------------------------------
200 fFacility
.destroySession(session
);
202 // Verify that no more session components exist
203 assertEquals(0, groups
[1].getChildren().length
);
205 //-------------------------------------------------------------------------
207 //-------------------------------------------------------------------------
208 fFacility
.executeCommand(node
, "disconnect");
209 assertEquals(TargetNodeState
.DISCONNECTED
, node
.getTargetNodeState());
211 //-------------------------------------------------------------------------
213 //-------------------------------------------------------------------------
215 fFacility
.executeCommand(node
, "delete");
217 assertEquals(0,fFacility
.getControlView().getTraceControlRoot().getChildren().length
);