From bef2e377c0bc2d424ebdc2401a360d823b4938e0 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Genevi=C3=A8ve=20Bastien?= Date: Fri, 3 Feb 2017 15:55:18 -0500 Subject: [PATCH] ss: Add javadoc to StateSystem#waitUntilBuilt(long) MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit If the timeout specified less or equal to 0, then there will no waiting and this can be used as a "isBuilt" method for the state system. Change-Id: I6110622071249cd456801fc220500740ba72d6b4 Signed-off-by: Geneviève Bastien Reviewed-on: https://git.eclipse.org/r/90309 Reviewed-by: Hudson CI Reviewed-by: Matthew Khouzam Tested-by: Matthew Khouzam Reviewed-by: Alexandre Montplaisir --- .../core/tests/StateSystemTest.java | 82 +++++++++++++++++++ .../statesystem/core/ITmfStateSystem.java | 3 + 2 files changed, 85 insertions(+) create mode 100644 statesystem/org.eclipse.tracecompass.statesystem.core.tests/src/org/eclipse/tracecompass/statesystem/core/tests/StateSystemTest.java diff --git a/statesystem/org.eclipse.tracecompass.statesystem.core.tests/src/org/eclipse/tracecompass/statesystem/core/tests/StateSystemTest.java b/statesystem/org.eclipse.tracecompass.statesystem.core.tests/src/org/eclipse/tracecompass/statesystem/core/tests/StateSystemTest.java new file mode 100644 index 0000000000..874184432b --- /dev/null +++ b/statesystem/org.eclipse.tracecompass.statesystem.core.tests/src/org/eclipse/tracecompass/statesystem/core/tests/StateSystemTest.java @@ -0,0 +1,82 @@ +/******************************************************************************* + * Copyright (c) 2017 École Polytechnique de Montréal + * + * All rights reserved. This program and the accompanying materials are + * made available under the terms of the Eclipse Public License v1.0 which + * accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + *******************************************************************************/ + +package org.eclipse.tracecompass.statesystem.core.tests; + +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; + +import java.util.concurrent.TimeUnit; + +import org.eclipse.tracecompass.internal.statesystem.core.StateSystem; +import org.eclipse.tracecompass.statesystem.core.ITmfStateSystemBuilder; +import org.eclipse.tracecompass.statesystem.core.backend.IStateHistoryBackend; +import org.eclipse.tracecompass.statesystem.core.backend.StateHistoryBackendFactory; +import org.junit.Before; +import org.junit.Rule; +import org.junit.Test; +import org.junit.rules.TestRule; +import org.junit.rules.Timeout; + +/** + * Test the {@link StateSystem} specific methods + * + * @author Geneviève Bastien + */ +public class StateSystemTest { + + /** Time-out tests after 1 minute. */ + @Rule + public TestRule globalTimeout = new Timeout(1, TimeUnit.MINUTES); + + private ITmfStateSystemBuilder fSs; + + /** + * Create the test state system + */ + @Before + public void setup() { + IStateHistoryBackend backend = StateHistoryBackendFactory.createNullBackend("Test"); + fSs = new StateSystem(backend); + } + + /** + * Test the {@link StateSystem#waitUntilBuilt(long)} method + */ + @Test + public void testWaitUntilBuilt() { + ITmfStateSystemBuilder ss = fSs; + assertNotNull(ss); + + long timeout = 500; + long begin = System.currentTimeMillis(); + assertFalse(ss.waitUntilBuilt(timeout)); + long end = System.currentTimeMillis(); + + /* + * We cannot be sure of the exact time, but just make sure the method + * returned and the delay is longer than the timeout + */ + assertTrue(end - begin >= timeout); + + /* + * The delay is undeterministic, we cannot check anything else than + * whether it returned or not + */ + assertFalse(ss.waitUntilBuilt(0)); + + ss.closeHistory(timeout); + + /* The history is closed, so now these methods should return true */ + assertTrue(ss.waitUntilBuilt(timeout)); + assertTrue(ss.waitUntilBuilt(0)); + } + +} diff --git a/statesystem/org.eclipse.tracecompass.statesystem.core/src/org/eclipse/tracecompass/statesystem/core/ITmfStateSystem.java b/statesystem/org.eclipse.tracecompass.statesystem.core/src/org/eclipse/tracecompass/statesystem/core/ITmfStateSystem.java index 4df70c1619..b9e0099247 100644 --- a/statesystem/org.eclipse.tracecompass.statesystem.core/src/org/eclipse/tracecompass/statesystem/core/ITmfStateSystem.java +++ b/statesystem/org.eclipse.tracecompass.statesystem.core/src/org/eclipse/tracecompass/statesystem/core/ITmfStateSystem.java @@ -97,6 +97,9 @@ public interface ITmfStateSystem { * This can be useful, for example, for a component doing queries * periodically to the system while it is being built. * + * Specifying a timeout of 0 (or less) will return immediately with whether + * the state system is finished building or not. + * * @param timeout * Timeout value in milliseconds * @return True if the return was due to the construction finishing, false -- 2.34.1