1 /**********************************************************************
2 * Copyright (c) 2013, 2015 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
.jdt
.annotation
.NonNull
;
28 import org
.eclipse
.remote
.core
.IRemoteConnection
;
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
;
40 import org
.eclipse
.tracecompass
.tmf
.remote
.core
.proxy
.TmfRemoteConnectionFactory
;
41 import org
.eclipse
.tracecompass
.tmf
.ui
.tests
.shared
.WaitUtils
;
42 import org
.eclipse
.ui
.views
.properties
.IPropertyDescriptor
;
43 import org
.eclipse
.ui
.views
.properties
.IPropertySource
;
44 import org
.junit
.After
;
45 import org
.junit
.Before
;
46 import org
.junit
.Test
;
47 import org
.osgi
.framework
.FrameworkUtil
;
50 * The class {@link TraceControlSnapshotSessionTest} contains Snapshot
51 * session test cases for support of LTTng Tools 2.3.
53 public class TraceControlSnapshotSessionTest
{
55 // ------------------------------------------------------------------------
57 // ------------------------------------------------------------------------
59 private static final String TEST_STREAM
= "CreateSessionTest2.cfg";
60 private static final String SCEN_CREATE_SESSION
= "ScenCreateSession";
62 // ------------------------------------------------------------------------
64 // ------------------------------------------------------------------------
66 private TraceControlTestFacility fFacility
;
67 private IRemoteConnection fHost
= TmfRemoteConnectionFactory
.getLocalConnection();
68 private @NonNull TestRemoteSystemProxy fProxy
= new TestRemoteSystemProxy(fHost
);
69 private String fTestFile
;
71 // ------------------------------------------------------------------------
73 // ------------------------------------------------------------------------
76 * Perform pre-test initialization.
79 * if the initialization fails for some reason
82 public void setUp() throws Exception
{
83 fFacility
= TraceControlTestFacility
.getInstance();
85 fProxy
= new TestRemoteSystemProxy(fHost
);
86 URL location
= FileLocator
.find(FrameworkUtil
.getBundle(this.getClass()), new Path(TraceControlTestFacility
.DIRECTORY
+ File
.separator
+ TEST_STREAM
), null);
87 File testfile
= new File(FileLocator
.toFileURL(location
).toURI());
88 fTestFile
= testfile
.getAbsolutePath();
92 * Perform post-test clean-up.
95 public void tearDown() {
100 * Run the TraceControlComponent.
103 * This will fail the test
106 public void testTraceSessionTree() throws Exception
{
108 fProxy
.setTestFile(fTestFile
);
109 fProxy
.setScenario(TraceControlTestFacility
.SCEN_INIT_TEST
);
111 ITraceControlComponent root
= fFacility
.getControlView().getTraceControlRoot();
113 TargetNodeComponent node
= new TargetNodeComponent("myNode", root
, fProxy
);
116 fFacility
.waitForJobs();
118 fFacility
.executeCommand(node
, "connect");
119 WaitUtils
.waitUntil(new TargetNodeConnectedCondition(node
));
121 // Get provider groups
122 ITraceControlComponent
[] groups
= node
.getChildren();
123 assertNotNull(groups
);
124 assertEquals(2, groups
.length
);
126 // Initialize dialog implementations for command execution
127 // --- snapshot session ---
128 CreateSessionDialogStub sessionDialog
= new CreateSessionDialogStub();
129 sessionDialog
.setSnapshot(true);
131 TraceControlDialogFactory
.getInstance().setCreateSessionDialog(sessionDialog
);
132 TraceControlDialogFactory
.getInstance().setGetEventInfoDialog(new GetEventInfoDialogStub());
133 TraceControlDialogFactory
.getInstance().setConfirmDialog(new DestroyConfirmDialogStub());
135 // Initialize scenario
136 fProxy
.setScenario(SCEN_CREATE_SESSION
);
138 // ------------------------------------------------------------------------
140 // ------------------------------------------------------------------------
141 TraceSessionComponent session
= fFacility
.createSession(groups
[1]);
143 // Verify that session was created
144 assertNotNull(session
);
145 assertEquals("mysession", session
.getName());
146 assertTrue(session
.isSnapshotSession());
147 assertNotNull(session
.getSnapshotInfo());
148 assertEquals("snapshot-1", session
.getSnapshotInfo().getName());
149 assertEquals("/home/user/lttng-traces/mysession-20130913-141651", session
.getSnapshotInfo().getSnapshotPath());
150 assertEquals(1, session
.getSnapshotInfo().getId());
152 // ------------------------------------------------------------------------
154 // ------------------------------------------------------------------------
155 fFacility
.startSession(session
);
156 assertEquals(TraceSessionState
.ACTIVE
, session
.getSessionState());
159 Object adapter
= session
.getAdapter(IPropertySource
.class);
160 assertNotNull(adapter
);
161 assertTrue(adapter
instanceof TraceSessionPropertySource
);
163 TraceSessionPropertySource sessionSource
= (TraceSessionPropertySource
)adapter
;
164 IPropertyDescriptor
[] descriptors
= sessionSource
.getPropertyDescriptors();
165 assertNotNull(descriptors
);
167 Map
<String
,String
> map
= new HashMap
<>();
168 map
.put(TraceSessionPropertySource
.TRACE_SESSION_NAME_PROPERTY_ID
, "mysession");
169 map
.put(TraceSessionPropertySource
.TRACE_SNAPSHOT_NAME_PROPERTY_ID
, "snapshot-1");
170 map
.put(TraceSessionPropertySource
.TRACE_SNAPSHOT_PATH_PROPERTY_ID
, "/home/user/lttng-traces/mysession-20130913-141651");
171 map
.put(TraceSessionPropertySource
.TRACE_SNAPSHOT_ID_PROPERTY_ID
, "1");
172 map
.put(TraceSessionPropertySource
.TRACE_SESSION_STATE_PROPERTY_ID
, TraceSessionState
.ACTIVE
.name());
174 for (int j
= 0; j
< descriptors
.length
; j
++) {
175 String expected
= map
.get(descriptors
[j
].getId());
176 assertNotNull(expected
);
177 assertEquals(expected
, sessionSource
.getPropertyValue(descriptors
[j
].getId()).toString());
180 // ------------------------------------------------------------------------
182 // ------------------------------------------------------------------------
183 fFacility
.executeCommand(session
, "snapshot");
185 // ------------------------------------------------------------------------
187 // ------------------------------------------------------------------------
188 fFacility
.stopSession(session
);
189 assertEquals(TraceSessionState
.INACTIVE
, session
.getSessionState());
191 // ------------------------------------------------------------------------
192 // Record snapshot in inactive mode
193 // ------------------------------------------------------------------------
194 fFacility
.executeCommand(session
, "snapshot");
196 // ------------------------------------------------------------------------
198 // ------------------------------------------------------------------------
199 fFacility
.destroySession(session
);
201 // Verify that no more session components exist
202 assertEquals(0, groups
[1].getChildren().length
);
204 //-------------------------------------------------------------------------
206 //-------------------------------------------------------------------------
207 fFacility
.executeCommand(node
, "disconnect");
208 assertEquals(TargetNodeState
.DISCONNECTED
, node
.getTargetNodeState());
210 //-------------------------------------------------------------------------
212 //-------------------------------------------------------------------------
214 fFacility
.executeCommand(node
, "delete");