Search in sources :

Example 6 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 7 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)

Example 8 with ConditionTimeoutException

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

the class EspressoTestUtils method tryKillDownloadService.

public static void tryKillDownloadService() {
    Context context = InstrumentationRegistry.getInstrumentation().getTargetContext();
    context.stopService(new Intent(context, DownloadService.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(() -> !DownloadService.isRunning);
    } catch (ConditionTimeoutException e) {
        e.printStackTrace();
    }
    InstrumentationRegistry.getInstrumentation().waitForIdleSync();
}
Also used : Context(android.content.Context) ConditionTimeoutException(org.awaitility.core.ConditionTimeoutException) Intent(android.content.Intent) DownloadService(de.danoeh.antennapod.core.service.download.DownloadService)

Example 9 with ConditionTimeoutException

use of org.awaitility.core.ConditionTimeoutException in project storm by apache.

the class TickTupleTest method testTickTupleWorksWithSystemBolt.

@Test
public void testTickTupleWorksWithSystemBolt() throws Exception {
    try (ILocalCluster cluster = new LocalCluster.Builder().withSimulatedTime().build()) {
        TopologyBuilder builder = new TopologyBuilder();
        FeederSpout feeder = new FeederSpout(new Fields("field1"));
        AckFailMapTracker tracker = new AckFailMapTracker();
        feeder.setAckFailDelegate(tracker);
        builder.setSpout("Spout", feeder);
        builder.setBolt("Bolt", new NoopBolt()).shuffleGrouping("Spout");
        Config topoConf = new Config();
        topoConf.put(Config.TOPOLOGY_TICK_TUPLE_FREQ_SECS, TICK_INTERVAL_SECS);
        try (ILocalTopology topo = cluster.submitTopology("test", topoConf, builder.createTopology())) {
            // Use a bootstrap tuple to wait for topology to be running
            feeder.feed(new Values("val"), 1);
            AssertLoop.assertAcked(tracker, 1);
            /*
                 * Verify that some ticks are received. The interval between ticks is validated by the bolt.
                 * Too few and the checks will time out. Too many and the bolt may crash (not reliably, but the test should become flaky).
                 */
            try {
                cluster.advanceClusterTime(TICK_INTERVAL_SECS);
                waitForTicks(1);
                cluster.advanceClusterTime(TICK_INTERVAL_SECS);
                waitForTicks(2);
                cluster.advanceClusterTime(TICK_INTERVAL_SECS);
                waitForTicks(3);
            } catch (ConditionTimeoutException e) {
                throw new AssertionError(e.getMessage());
            }
            assertNull("The bolt got a tuple that is not a tick tuple " + nonTickTuple.get(), nonTickTuple.get());
        }
    }
}
Also used : ILocalTopology(org.apache.storm.ILocalCluster.ILocalTopology) Fields(org.apache.storm.tuple.Fields) TopologyBuilder(org.apache.storm.topology.TopologyBuilder) TopologyBuilder(org.apache.storm.topology.TopologyBuilder) AckFailMapTracker(org.apache.storm.testing.AckFailMapTracker) Values(org.apache.storm.tuple.Values) ConditionTimeoutException(org.awaitility.core.ConditionTimeoutException) FeederSpout(org.apache.storm.testing.FeederSpout) Test(org.junit.jupiter.api.Test)

Aggregations

ConditionTimeoutException (org.awaitility.core.ConditionTimeoutException)9 IOException (java.io.IOException)3 Context (android.content.Context)2 Intent (android.content.Intent)2 Socket (java.net.Socket)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 AtomicReference (java.util.concurrent.atomic.AtomicReference)1 Node (javafx.scene.Node)1 JavaFXLibraryNonFatalException (javafxlibrary.exceptions.JavaFXLibraryNonFatalException)1 MutableInt (org.apache.commons.lang3.mutable.MutableInt)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