use of org.eclipse.scout.rt.ui.html.json.desktop.DownloadHandlerStorage.BinaryResourceHolderWithAction in project scout.rt by eclipse.
the class DownloadHandlerStorageTest method testGet.
@Test
public void testGet() {
final CountDownLatch secondGet = new CountDownLatch(1);
final CountDownLatch elementRemoved = new CountDownLatch(1);
DownloadHandlerStorage storage = new DownloadHandlerStorage() {
@Override
protected long getTTLForResource(BinaryResource res) {
return 50L;
}
@Override
protected void removeOnTimeout(String key) {
waitFor(secondGet);
super.removeOnTimeout(key);
elementRemoved.countDown();
}
};
BinaryResource res = new BinaryResource("bar.txt", null);
BinaryResourceHolder holder = new BinaryResourceHolder(res);
storage.put(KEY, holder, OpenUriAction.NEW_WINDOW);
assertEquals(1, storage.futureMap().size());
BinaryResourceHolderWithAction holderWithAction = storage.get(KEY);
assertEquals(OpenUriAction.NEW_WINDOW, holderWithAction.getOpenUriAction());
assertEquals(res, holderWithAction.getHolder().get());
assertFalse("Must not contain download interceptor.", containsDownloadInterceptor(holderWithAction.getHolder()));
holderWithAction = storage.get(KEY);
assertEquals(res, holderWithAction.getHolder().get());
assertTrue("Must contain download interceptor.", containsDownloadInterceptor(holderWithAction.getHolder()));
secondGet.countDown();
waitFor(elementRemoved);
assertNull(storage.get(KEY));
assertEquals("futureMap must be cleared after timeout", 0, storage.futureMap().size());
}
use of org.eclipse.scout.rt.ui.html.json.desktop.DownloadHandlerStorage.BinaryResourceHolderWithAction in project scout.rt by eclipse.
the class DownloadHandlerStorageTest method testRemove.
@Test
public void testRemove() {
DownloadHandlerStorage storage = new DownloadHandlerStorage() {
@Override
protected long getRemovalTimeoutAfterFirstRequest() {
return 100L;
}
};
BinaryResource res = new BinaryResource("bar.txt", null);
BinaryResourceHolder holder = new BinaryResourceHolder(res);
storage.put(KEY, holder, OpenUriAction.DOWNLOAD);
assertEquals(1, storage.futureMap().size());
BinaryResourceHolderWithAction holderWithAction = storage.get(KEY);
assertEquals(OpenUriAction.DOWNLOAD, holderWithAction.getOpenUriAction());
assertEquals(res, holderWithAction.getHolder().get());
assertEquals("future should still be in futureMap", 1, storage.futureMap().size());
assertEquals(res, holderWithAction.getHolder().get());
SleepUtil.sleepElseLog(150, TimeUnit.MILLISECONDS);
assertEquals("futureMap must be cleared after timeout", 0, storage.futureMap().size());
assertNull(storage.get(KEY));
}
Aggregations