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 **********************************************************************/
13 package org
.eclipse
.tracecompass
.lttng2
.control
.ui
.tests
.model
.component
;
15 import static org
.junit
.Assert
.assertEquals
;
16 import static org
.junit
.Assert
.assertNotNull
;
17 import static org
.junit
.Assert
.assertTrue
;
21 import java
.util
.HashMap
;
24 import org
.eclipse
.core
.runtime
.FileLocator
;
25 import org
.eclipse
.core
.runtime
.Path
;
26 import org
.eclipse
.rse
.core
.RSECorePlugin
;
27 import org
.eclipse
.rse
.core
.model
.IHost
;
28 import org
.eclipse
.rse
.core
.model
.ISystemProfile
;
29 import org
.eclipse
.rse
.core
.model
.ISystemRegistry
;
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 ISystemRegistry registry
= RSECorePlugin
.getTheSystemRegistry();
113 ISystemProfile profile
= registry
.createSystemProfile("myProfile", true);
114 IHost host
= registry
.createLocalHost(profile
, "myProfile", "user");
116 TargetNodeComponent node
= new TargetNodeComponent("myNode", root
, host
, fProxy
);
119 fFacility
.waitForJobs();
121 fFacility
.executeCommand(node
, "connect");
123 while ((i
< 10) && (node
.getTargetNodeState() != TargetNodeState
.CONNECTED
)) {
125 fFacility
.delay(TraceControlTestFacility
.GUI_REFESH_DELAY
);
128 // Get provider groups
129 ITraceControlComponent
[] groups
= node
.getChildren();
130 assertNotNull(groups
);
131 assertEquals(2, groups
.length
);
133 // Initialize dialog implementations for command execution
134 // --- snapshot session ---
135 CreateSessionDialogStub sessionDialog
= new CreateSessionDialogStub();
136 sessionDialog
.setSnapshot(true);
138 TraceControlDialogFactory
.getInstance().setCreateSessionDialog(sessionDialog
);
139 TraceControlDialogFactory
.getInstance().setGetEventInfoDialog(new GetEventInfoDialogStub());
140 TraceControlDialogFactory
.getInstance().setConfirmDialog(new DestroyConfirmDialogStub());
142 // Initialize scenario
143 fProxy
.setScenario(SCEN_CREATE_SESSION
);
145 // ------------------------------------------------------------------------
147 // ------------------------------------------------------------------------
148 TraceSessionComponent session
= fFacility
.createSession(groups
[1]);
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());
159 // ------------------------------------------------------------------------
161 // ------------------------------------------------------------------------
162 fFacility
.startSession(session
);
163 assertEquals(TraceSessionState
.ACTIVE
, session
.getSessionState());
166 Object adapter
= session
.getAdapter(IPropertySource
.class);
167 assertNotNull(adapter
);
168 assertTrue(adapter
instanceof TraceSessionPropertySource
);
170 TraceSessionPropertySource sessionSource
= (TraceSessionPropertySource
)adapter
;
171 IPropertyDescriptor
[] descriptors
= sessionSource
.getPropertyDescriptors();
172 assertNotNull(descriptors
);
174 Map
<String
,String
> map
= new HashMap
<>();
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());
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());
187 // ------------------------------------------------------------------------
189 // ------------------------------------------------------------------------
190 fFacility
.executeCommand(session
, "snapshot");
192 // ------------------------------------------------------------------------
194 // ------------------------------------------------------------------------
195 fFacility
.stopSession(session
);
196 assertEquals(TraceSessionState
.INACTIVE
, session
.getSessionState());
198 // ------------------------------------------------------------------------
200 // ------------------------------------------------------------------------
201 fFacility
.destroySession(session
);
203 // Verify that no more session components exist
204 assertEquals(0, groups
[1].getChildren().length
);
206 //-------------------------------------------------------------------------
208 //-------------------------------------------------------------------------
209 fFacility
.executeCommand(node
, "disconnect");
210 assertEquals(TargetNodeState
.DISCONNECTED
, node
.getTargetNodeState());
212 //-------------------------------------------------------------------------
214 //-------------------------------------------------------------------------
216 fFacility
.executeCommand(node
, "delete");
218 assertEquals(0,fFacility
.getControlView().getTraceControlRoot().getChildren().length
);