Search in sources :

Example 1 with IBeanInstanceProducer

use of org.eclipse.scout.rt.platform.IBeanInstanceProducer in project scout.rt by eclipse.

the class ClientSessionTest method testStopWithBlockingClientCallback.

@Test
public void testStopWithBlockingClientCallback() throws Exception {
    TestingUtility.registerBean(new BeanMetaData(TestEnvironmentClientSession.class));
    TestingUtility.registerBean(new BeanMetaData(JobCompletionDelayOnSessionShutdown.class).withProducer(new IBeanInstanceProducer<JobCompletionDelayOnSessionShutdown>() {

        @Override
        public JobCompletionDelayOnSessionShutdown produce(IBean<JobCompletionDelayOnSessionShutdown> bean) {
            return new JobCompletionDelayOnSessionShutdown() {

                @Override
                protected Long getDefaultValue() {
                    return 1000L;
                }
            };
        }
    }));
    session = BEANS.get(ClientSessionProvider.class).provide(ClientRunContexts.empty().withUserAgent(UserAgents.createDefault()));
    // request a geo location
    Future<Coordinates> geo = ModelJobs.schedule(new Callable<Future<Coordinates>>() {

        @Override
        public Future<Coordinates> call() throws Exception {
            return IDesktop.CURRENT.get().requestGeolocation();
        }
    }, ModelJobs.newInput(ClientRunContexts.empty().withSession(session, true))).awaitDoneAndGet();
    assertFalse(geo.isDone());
    // close from ui
    ModelJobs.schedule(new IRunnable() {

        @Override
        public void run() throws Exception {
            session.getDesktop().getUIFacade().closeFromUI(true);
        }
    }, ModelJobs.newInput(ClientRunContexts.empty().withSession(session, true))).awaitDone();
    assertTrue(geo.isCancelled());
}
Also used : BeanMetaData(org.eclipse.scout.rt.platform.BeanMetaData) IBeanInstanceProducer(org.eclipse.scout.rt.platform.IBeanInstanceProducer) Coordinates(org.eclipse.scout.rt.client.ui.Coordinates) JobCompletionDelayOnSessionShutdown(org.eclipse.scout.rt.client.ClientConfigProperties.JobCompletionDelayOnSessionShutdown) IRunnable(org.eclipse.scout.rt.platform.util.concurrent.IRunnable) IBean(org.eclipse.scout.rt.platform.IBean) Callable(java.util.concurrent.Callable) TestEnvironmentClientSession(org.eclipse.scout.rt.client.testenvironment.TestEnvironmentClientSession) Test(org.junit.Test)

Example 2 with IBeanInstanceProducer

use of org.eclipse.scout.rt.platform.IBeanInstanceProducer in project scout.rt by eclipse.

the class ClientSessionTest method testStopWithBlockingMessageBox.

@Test
public void testStopWithBlockingMessageBox() throws Exception {
    TestingUtility.registerBean(new BeanMetaData(TestEnvironmentClientSession.class));
    TestingUtility.registerBean(new BeanMetaData(JobCompletionDelayOnSessionShutdown.class).withProducer(new IBeanInstanceProducer<JobCompletionDelayOnSessionShutdown>() {

        @Override
        public JobCompletionDelayOnSessionShutdown produce(IBean<JobCompletionDelayOnSessionShutdown> bean) {
            return new JobCompletionDelayOnSessionShutdown() {

                @Override
                protected Long getDefaultValue() {
                    return 1000L;
                }
            };
        }
    }));
    session = BEANS.get(ClientSessionProvider.class).provide(ClientRunContexts.empty().withUserAgent(UserAgents.createDefault()));
    // show a messagebox
    IFuture<Integer> f = ModelJobs.schedule(new Callable<Integer>() {

        @Override
        public Integer call() throws Exception {
            messageBox = MessageBoxes.createYesNo();
            return messageBox.show();
        }
    }, ModelJobs.newInput(ClientRunContexts.empty().withSession(session, true)));
    try {
        f.awaitDoneAndGet(1, TimeUnit.SECONDS);
        fail("must throw a " + TimedOutError.class.getName());
    } catch (TimedOutError e) {
    // nop
    }
    assertFalse(f.isDone());
    // close from ui
    ModelJobs.schedule(new IRunnable() {

        @Override
        public void run() throws Exception {
            session.getDesktop().getUIFacade().closeFromUI(true);
        }
    }, ModelJobs.newInput(ClientRunContexts.empty().withSession(session, true))).awaitDone();
    assertEquals(JobState.DONE, f.getState());
}
Also used : BeanMetaData(org.eclipse.scout.rt.platform.BeanMetaData) IBeanInstanceProducer(org.eclipse.scout.rt.platform.IBeanInstanceProducer) JobCompletionDelayOnSessionShutdown(org.eclipse.scout.rt.client.ClientConfigProperties.JobCompletionDelayOnSessionShutdown) TimedOutError(org.eclipse.scout.rt.platform.util.concurrent.TimedOutError) IRunnable(org.eclipse.scout.rt.platform.util.concurrent.IRunnable) IBean(org.eclipse.scout.rt.platform.IBean) TestEnvironmentClientSession(org.eclipse.scout.rt.client.testenvironment.TestEnvironmentClientSession) Test(org.junit.Test)

Aggregations

JobCompletionDelayOnSessionShutdown (org.eclipse.scout.rt.client.ClientConfigProperties.JobCompletionDelayOnSessionShutdown)2 TestEnvironmentClientSession (org.eclipse.scout.rt.client.testenvironment.TestEnvironmentClientSession)2 BeanMetaData (org.eclipse.scout.rt.platform.BeanMetaData)2 IBean (org.eclipse.scout.rt.platform.IBean)2 IBeanInstanceProducer (org.eclipse.scout.rt.platform.IBeanInstanceProducer)2 IRunnable (org.eclipse.scout.rt.platform.util.concurrent.IRunnable)2 Test (org.junit.Test)2 Callable (java.util.concurrent.Callable)1 Coordinates (org.eclipse.scout.rt.client.ui.Coordinates)1 TimedOutError (org.eclipse.scout.rt.platform.util.concurrent.TimedOutError)1