Search in sources :

Example 1 with ConditionTimeoutException

use of org.awaitility.core.ConditionTimeoutException in project JavaFXLibrary by eficode.

the class HelperFunctions method waitUntilExists.

public static Node waitUntilExists(String target, int timeout, String timeUnit) {
    robotLog("TRACE", "Waiting until target \"" + target.toString() + "\" becomes existent, timeout=" + Integer.toString(timeout) + ", timeUnit=" + timeUnit);
    try {
        Awaitility.setDefaultTimeout(timeout, getTimeUnit(timeUnit));
        AtomicReference<Node> node = new AtomicReference<>();
        Awaitility.await().until(() -> {
            node.set(robot.lookup(target).query());
            return node.get() != null;
        });
        robotLog("TRACE", "Node located: \"" + node.get().toString() + "\"");
        return node.get();
    } catch (ConditionTimeoutException e) {
        throw new JavaFXLibraryNonFatalException("Given element \"" + target.toString() + "\" was not found within given timeout of " + Integer.toString(timeout) + " " + timeUnit);
    }
}
Also used : JavaFXLibraryNonFatalException(javafxlibrary.exceptions.JavaFXLibraryNonFatalException) Node(javafx.scene.Node) ConditionTimeoutException(org.awaitility.core.ConditionTimeoutException) AtomicReference(java.util.concurrent.atomic.AtomicReference)

Example 2 with ConditionTimeoutException

use of org.awaitility.core.ConditionTimeoutException in project pinpoint by naver.

the class PipelineFactoryTest method testBind.

@Test
public void testBind() throws Exception {
    PinpointServerAcceptor serverAcceptor = null;
    Socket socket = null;
    try {
        serverAcceptor = new PinpointServerAcceptor(ChannelFilter.BYPASS, new TestPipelineFactory());
        final DiscardServerHandler discardServerHandler = new DiscardServerHandler();
        serverAcceptor.setMessageHandler(discardServerHandler);
        serverAcceptor.bind("127.0.0.1", bindPort);
        socket = new Socket("127.0.0.1", bindPort);
        socket.getOutputStream().write((START_KEY + "Test").getBytes());
        socket.getOutputStream().flush();
        assertMessageReceivedCount(1, discardServerHandler);
        socket.getOutputStream().write(('@' + "Test").getBytes());
        socket.getOutputStream().flush();
        try {
            assertMessageReceivedCount(2, discardServerHandler);
            Assert.fail();
        } catch (ConditionTimeoutException e) {
        // ignore
        }
    } finally {
        IOUtils.closeQuietly(socket);
        PinpointRPCTestUtils.close(serverAcceptor);
    }
}
Also used : ConditionTimeoutException(org.awaitility.core.ConditionTimeoutException) DiscardServerHandler(com.navercorp.pinpoint.rpc.DiscardServerHandler) Socket(java.net.Socket) Test(org.junit.Test)

Example 3 with ConditionTimeoutException

use of org.awaitility.core.ConditionTimeoutException in project pinpoint by naver.

the class AwaitIOUtils method read.

public static byte[] read(final InputStream inputStream, long waitUnitTime, long maxWaitTime) throws IOException {
    try {
        waitForIoReady(inputStream, waitUnitTime, maxWaitTime);
    } catch (ConditionTimeoutException e) {
        throw new IOException("no available data", e);
    }
    int availableSize = inputStream.available();
    byte[] payload = new byte[availableSize];
    inputStream.read(payload);
    return payload;
}
Also used : ConditionTimeoutException(org.awaitility.core.ConditionTimeoutException) IOException(java.io.IOException)

Example 4 with ConditionTimeoutException

use of org.awaitility.core.ConditionTimeoutException in project AntennaPod by AntennaPod.

the class EspressoTestUtils method tryKillPlaybackService.

public static void tryKillPlaybackService() {
    Context context = InstrumentationRegistry.getInstrumentation().getTargetContext();
    context.stopService(new Intent(context, PlaybackService.class));
    try {
        // Android has no reliable way to stop a service instantly.
        // Calling stopSelf marks allows the system to destroy the service but the actual call
        // to onDestroy takes until the next GC of the system, which we can not influence.
        // Try to wait for the service at least a bit.
        Awaitility.await().atMost(10, TimeUnit.SECONDS).until(() -> !PlaybackService.isRunning);
    } catch (ConditionTimeoutException e) {
        e.printStackTrace();
    }
    InstrumentationRegistry.getInstrumentation().waitForIdleSync();
}
Also used : Context(android.content.Context) ConditionTimeoutException(org.awaitility.core.ConditionTimeoutException) Intent(android.content.Intent) PlaybackService(de.danoeh.antennapod.core.service.playback.PlaybackService)

Example 5 with ConditionTimeoutException

use of org.awaitility.core.ConditionTimeoutException in project AntennaPod by AntennaPod.

the class AutoDownloadTest method downloadsEnqueuedToAfterCurrent_CurrentAdvancedToNextOnPlaybackComplete.

/**
 * A cross-functional test, ensuring playback's behavior works with Auto Download in boundary condition.
 *
 * Scenario:
 * - For setting enqueue location AFTER_CURRENTLY_PLAYING
 * - when playback of an episode is complete and the app advances to the next episode (continuous playback on)
 * - when automatic download kicks in,
 * - ensure the next episode is the current playing one, needed for AFTER_CURRENTLY_PLAYING enqueue location.
 */
@Test
public void downloadsEnqueuedToAfterCurrent_CurrentAdvancedToNextOnPlaybackComplete() throws Exception {
    // continuous playback
    UserPreferences.setFollowQueue(true);
    // Setup: feeds and queue
    // downloads 3 of them, leave some in new state (auto-downloadable)
    stubFeedsServer.addLocalFeedData(false);
    List<FeedItem> queue = DBReader.getQueue();
    assertTrue(queue.size() > 1);
    FeedItem item0 = queue.get(0);
    FeedItem item1 = queue.get(1);
    // Actual test
    // Play the first one in the queue
    playEpisode(item0);
    try {
        // when playback is complete, advances to the next one, and auto download kicks in,
        // ensure that currently playing has been advanced to the next one by this point.
        Awaitility.await("advanced to the next episode").atMost(6000, // the test mp3 media is 3-second long. twice should be enough
        MILLISECONDS).until(() -> item1.getMedia().getId() == stubDownloadAlgorithm.getCurrentlyPlayingAtDownload());
    } catch (ConditionTimeoutException cte) {
        long actual = stubDownloadAlgorithm.getCurrentlyPlayingAtDownload();
        fail("when auto download is triggered, the next episode should be playing: (" + item1.getId() + ", " + item1.getTitle() + ") . " + "Actual playing: (" + actual + ")");
    }
}
Also used : FeedItem(de.danoeh.antennapod.model.feed.FeedItem) ConditionTimeoutException(org.awaitility.core.ConditionTimeoutException) Test(org.junit.Test)

Aggregations

ConditionTimeoutException (org.awaitility.core.ConditionTimeoutException)7 Context (android.content.Context)2 Intent (android.content.Intent)2 Test (org.junit.Test)2 DiscardServerHandler (com.navercorp.pinpoint.rpc.DiscardServerHandler)1 DownloadService (de.danoeh.antennapod.core.service.download.DownloadService)1 PlaybackService (de.danoeh.antennapod.core.service.playback.PlaybackService)1 FeedItem (de.danoeh.antennapod.model.feed.FeedItem)1 IOException (java.io.IOException)1 Socket (java.net.Socket)1 AtomicReference (java.util.concurrent.atomic.AtomicReference)1 Node (javafx.scene.Node)1 JavaFXLibraryNonFatalException (javafxlibrary.exceptions.JavaFXLibraryNonFatalException)1 ILocalTopology (org.apache.storm.ILocalCluster.ILocalTopology)1 AckFailMapTracker (org.apache.storm.testing.AckFailMapTracker)1 FeederSpout (org.apache.storm.testing.FeederSpout)1 TopologyBuilder (org.apache.storm.topology.TopologyBuilder)1 Fields (org.apache.storm.tuple.Fields)1 Values (org.apache.storm.tuple.Values)1 Test (org.junit.jupiter.api.Test)1