use of java.util.concurrent.TimeUnit.MILLISECONDS in project ExoPlayer by google.
the class SessionCallbackBuilderTest method allowedCommand_afterCurrentMediaItemPrepared_notifiesSeekToAvailable.
@Test
public void allowedCommand_afterCurrentMediaItemPrepared_notifiesSeekToAvailable() throws Exception {
List<MediaItem> testPlaylist = new ArrayList<>();
testPlaylist.add(TestUtils.createMediaItem(R.raw.video_desks));
UriMediaItem secondPlaylistItem = TestUtils.createMediaItem(R.raw.video_big_buck_bunny);
testPlaylist.add(secondPlaylistItem);
CountDownLatch readAllowedLatch = new CountDownLatch(1);
playerTestRule.setDataSourceInstrumentation(dataSpec -> {
if (dataSpec.uri.equals(secondPlaylistItem.getUri())) {
try {
assertThat(readAllowedLatch.await(PLAYER_STATE_CHANGE_WAIT_TIME_MS, MILLISECONDS)).isTrue();
} catch (Exception e) {
assertWithMessage("Unexpected exception %s", e).fail();
}
}
});
try (MediaSession session = createMediaSession(sessionPlayerConnector, new SessionCallbackBuilder(context, sessionPlayerConnector).build())) {
assertPlayerResultSuccess(sessionPlayerConnector.setPlaylist(testPlaylist, null));
assertPlayerResultSuccess(sessionPlayerConnector.prepare());
CountDownLatch seekToAllowedForSecondMediaItem = new CountDownLatch(1);
OnAllowedCommandsChangedListener allowedCommandsChangedListener = (controller, allowedCommands) -> {
if (allowedCommands.hasCommand(SessionCommand.COMMAND_CODE_PLAYER_SEEK_TO) && controller.getCurrentMediaItemIndex() == 1) {
seekToAllowedForSecondMediaItem.countDown();
}
};
try (MediaController controller = createConnectedController(session, /* onConnectedListener= */
null, allowedCommandsChangedListener)) {
assertPlayerResultSuccess(sessionPlayerConnector.skipToNextPlaylistItem());
readAllowedLatch.countDown();
assertThat(seekToAllowedForSecondMediaItem.await(CONTROLLER_COMMAND_WAIT_TIME_MS, MILLISECONDS)).isTrue();
}
}
}
use of java.util.concurrent.TimeUnit.MILLISECONDS in project ignite by apache.
the class DistributedProcessCoordinatorLeftTest method testCoordinatorFailed.
/**
* Tests that coordinator failing during sending single result not cause node failure and the process finishes.
*
* <ol>
* <li>Start new process of {@link DistributedProcess}.</li>
* <li>The coordinator fails.</li>
* <li>Nodes try to send a single message to the not-alive coordinator.</li>
* <li>{@link DistributedProcess} process a node left event and reinitialize a new coordinator.</li>
* <li>Process finishes.</li>
* </ol>
*
* @throws Exception If failed.
*/
@Test
public void testCoordinatorFailed() throws Exception {
startGrids(NODES_CNT);
CountDownLatch startLatch = new CountDownLatch(NODES_CNT);
CountDownLatch finishLatch = new CountDownLatch(NODES_CNT - 1);
HashMap<String, DistributedProcess<Integer, Integer>> processes = new HashMap<>();
int processRes = 1;
for (Ignite grid : G.allGrids()) {
DistributedProcess<Integer, Integer> dp = new DistributedProcess<>(((IgniteEx) grid).context(), TEST_PROCESS, req -> {
IgniteInternalFuture<Integer> fut = runAsync(() -> {
try {
nodeLeftLatch.await();
} catch (InterruptedException ignored) {
fail("Unexpected interrupt.");
}
return req;
});
// It is guaranteed by the LIFO order of future listeners notifying.
if (!grid.name().equals(getTestIgniteInstanceName(STOP_NODE_IDX)))
fut.listen(f -> msgSendLatch.countDown());
startLatch.countDown();
return fut;
}, (uuid, res, err) -> {
if (res.values().size() == NODES_CNT - 1 && res.values().stream().allMatch(i -> i == processRes))
finishLatch.countDown();
else
fail("Unexpected process result [res=" + res + ", err=" + err + ']');
});
processes.put(grid.name(), dp);
}
processes.get(grid(STOP_NODE_IDX).name()).start(UUID.randomUUID(), processRes);
assertTrue(startLatch.await(TIMEOUT, MILLISECONDS));
stopGrid(STOP_NODE_IDX);
assertTrue(finishLatch.await(TIMEOUT, MILLISECONDS));
assertFalse(failure.get());
}
use of java.util.concurrent.TimeUnit.MILLISECONDS in project ignite by apache.
the class EventsRemoteSecurityContextCheckTest method checkRemoteListenWithNullFilter.
/**
*/
private void checkRemoteListenWithNullFilter(boolean async) throws Exception {
for (IgniteEx initiator : initiators()) {
IgniteCache<Object, Object> cache = initiator.createCache(new CacheConfiguration<>("test_cache_" + INDEX.incrementAndGet()).setCacheMode(REPLICATED));
CountDownLatch srvNodesListenedLatch = new CountDownLatch(initiator.cluster().forServers().nodes().size());
IgniteBiPredicate<UUID, ? extends Event> locLsnr = (uuid, e) -> {
srvNodesListenedLatch.countDown();
return true;
};
UUID lsnrId = async ? initiator.events().remoteListenAsync(locLsnr, null, EVT_CACHE_OBJECT_PUT).get() : initiator.events().remoteListen(locLsnr, null, EVT_CACHE_OBJECT_PUT);
try {
cache.put("key", "val");
assertTrue(srvNodesListenedLatch.await(getTestTimeout(), MILLISECONDS));
} finally {
initiator.events().stopRemoteListen(lsnrId);
}
}
}
use of java.util.concurrent.TimeUnit.MILLISECONDS in project ignite by apache.
the class CacheContinuousQueryFilterDeploymentFailedTest method testContinuousQueryFilterDeploymentFailed.
/**
* Tests continuous query behavior in case of filter deployment obtaining failure.
*
* @throws Exception If failed.
*/
@Test
@SuppressWarnings({ "ThrowableNotThrown" })
public void testContinuousQueryFilterDeploymentFailed() throws Exception {
startGrids(NODES_CNT - 1);
IgniteEx cli = startClientGrid(NODES_CNT - 1);
IgniteCache<Integer, Integer> cache = cli.createCache(DEFAULT_CACHE_NAME);
ContinuousQuery<Integer, Integer> qry = new ContinuousQuery<>();
Class<Factory<CacheEntryEventFilter<Integer, Integer>>> rmtFilterFactoryCls = (Class<Factory<CacheEntryEventFilter<Integer, Integer>>>) getExternalClassLoader().loadClass("org.apache.ignite.tests.p2p.CacheDeploymentEntryEventFilterFactory");
qry.setRemoteFilterFactory(rmtFilterFactoryCls.newInstance());
spi(grid(1)).blockMessages((node, msg) -> msg instanceof GridDeploymentRequest);
assertThrowsWithCause(() -> cache.query(qry), CacheException.class);
assertTrue(stopRoutineLatch.await(getTestTimeout(), MILLISECONDS));
assertTrue(allGrids().stream().allMatch(g -> ((IgniteEx) g).context().systemView().view(CQ_SYS_VIEW).size() == 0));
}
use of java.util.concurrent.TimeUnit.MILLISECONDS in project airlift by airlift.
the class TestJwksService method testTimedReload.
@Test
public void testTimedReload() throws InterruptedException {
AtomicReference<Supplier<Response>> response = new AtomicReference<>(() -> mockResponse(HttpStatus.OK, JSON_UTF_8, EMPTY_KEYS));
JwksService service = new JwksService(URI.create("http://example.com"), new TestingHttpClient(request -> response.get().get()), new Duration(1, MILLISECONDS));
assertEmptyKeys(service);
try {
// start service
response.set(() -> mockResponse(HttpStatus.OK, JSON_UTF_8, EMPTY_KEYS));
service.start();
while (!service.getKeys().isEmpty()) {
// noinspection BusyWait
Thread.sleep(1000);
}
response.set(() -> mockResponse(HttpStatus.OK, JSON_UTF_8, TEST_JWKS_RESPONSE));
while (service.getKeys().isEmpty()) {
// noinspection BusyWait
Thread.sleep(1000);
}
assertTestKeys(service);
} finally {
service.stop();
}
}
Aggregations