Search in sources :

Example 6 with BeanMetaData

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

the class FileServiceTest method syncRemoteFilesToPath.

@Test
public void syncRemoteFilesToPath() {
    // register services
    List<IBean<?>> reg = TestingUtility.registerBeans(new BeanMetaData(DummyRemoteFileService.class).withInitialInstance(new DummyRemoteFileService()).withApplicationScoped(true));
    // start with clean setup
    File outFolder = new File(TEST_DIR_OUT);
    assertFalse("Folder is not synchronized yet, but exists", outFolder.exists());
    try {
        // synchronize test folder to path
        FileService svc = new FileService();
        svc.syncRemoteFilesToPath(TEST_DIR_OUT, TEST_DIR_IN, null);
        File synchronizedFile = new File(TEST_PATH_1);
        File synchronizedFile2 = new File(TEST_PATH_2);
        File synchronizedFolder = new File(TEST_DIR_OUT);
        assertTrue("Synchronized file does not exist " + synchronizedFile, synchronizedFile.exists());
        assertTrue("Synchronized file does not exist " + synchronizedFile2, synchronizedFile2.exists());
        assertTrue("Synchronized folder does not exist " + synchronizedFolder, synchronizedFolder.exists());
        assertTrue("Incorrect number of synchronized files", synchronizedFolder.listFiles().length == 2);
        // synchronize again
        svc.syncRemoteFilesToPath(TEST_DIR_OUT, TEST_DIR_IN, null);
        assertTrue("Synchronized file does not exist " + synchronizedFile, synchronizedFile.exists());
        assertTrue("Synchronized file does not exist " + synchronizedFile2, synchronizedFile2.exists());
        assertTrue("Synchronized folder does not exist " + synchronizedFolder, synchronizedFolder.exists());
        assertTrue("Incorrect number of synchronized files", synchronizedFolder.listFiles().length == 2);
    } finally {
        TestingUtility.unregisterBeans(reg);
    }
}
Also used : BeanMetaData(org.eclipse.scout.rt.platform.BeanMetaData) IRemoteFileService(org.eclipse.scout.rt.shared.services.common.file.IRemoteFileService) IBean(org.eclipse.scout.rt.platform.IBean) File(java.io.File) RemoteFile(org.eclipse.scout.rt.shared.services.common.file.RemoteFile) Test(org.junit.Test)

Example 7 with BeanMetaData

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

the class NotificationDispatcherTest method after.

@After
public void after() {
    TestingUtility.unregisterBeans(m_serviceReg);
    // ensure bean hander cache of notification dispatcher gets refreshed
    IBeanManager beanManager = BEANS.getBeanManager();
    IBean<NotificationHandlerRegistry> bean = beanManager.getBean(NotificationHandlerRegistry.class);
    beanManager.unregisterBean(bean);
    beanManager.registerBean(new BeanMetaData(bean));
}
Also used : NotificationHandlerRegistry(org.eclipse.scout.rt.shared.notification.NotificationHandlerRegistry) BeanMetaData(org.eclipse.scout.rt.platform.BeanMetaData) IBeanManager(org.eclipse.scout.rt.platform.IBeanManager) After(org.junit.After)

Example 8 with BeanMetaData

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

the class LoggerPlatformListener method registerLoggerSupportBean.

protected void registerLoggerSupportBean(IBeanManager beanManager) {
    ILoggerSupport loggerSupport = null;
    String loggerFactoryClassStr = null;
    try {
        StaticLoggerBinder loggerBinder = StaticLoggerBinder.getSingleton();
        loggerFactoryClassStr = loggerBinder.getLoggerFactoryClassStr();
        LOG.debug("Found slf4j logger factory [class={}, classStr={}]", loggerBinder.getLoggerFactory(), loggerFactoryClassStr);
        String loggerSupportFqcn = getLoggerSupportFqcn(loggerFactoryClassStr);
        LOG.debug("Determined scout logger support FQCN {}", loggerSupportFqcn);
        if (loggerSupportFqcn != null) {
            loggerSupport = createLoggerSupport(loggerSupportFqcn);
        }
    } catch (Exception | NoClassDefFoundError e) {
        // catch NoClassDefFoundError by intention (threw if no slf4j binding is available)
        LOG.warn("Could not determine or install factory speicific logger support. Falling back to {}", NullLoggerSupport.class.getName(), e);
    }
    if (loggerSupport == null) {
        loggerSupport = createNullLoggerSupport(loggerFactoryClassStr);
    }
    beanManager.registerBean(new BeanMetaData(ILoggerSupport.class, loggerSupport).withAnnotation(AnnotationFactory.createApplicationScoped()));
    LOG.info("Registered logger support {}", loggerSupport.getClass().getName());
}
Also used : BeanMetaData(org.eclipse.scout.rt.platform.BeanMetaData) StaticLoggerBinder(org.slf4j.impl.StaticLoggerBinder)

Example 9 with BeanMetaData

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

the class ClientJobCancelTest method doPingRequestAsync.

/**
 * Runs a 'ping-request' which gets blocked in the service implementation.
 */
protected RequestData doPingRequestAsync(final String pingRequest) throws Exception {
    final BlockingCountDownLatch serviceCallSetupLatch = new BlockingCountDownLatch(1);
    final BlockingCountDownLatch serviceCallCompletedLatch = new BlockingCountDownLatch(1);
    final AtomicBoolean serviceCallInterrupted = new AtomicBoolean(false);
    // Mock the PingService.
    class PingService implements IPingService {

        @Override
        public String ping(String s) {
            try {
                assertTrue(serviceCallSetupLatch.countDownAndBlock());
            } catch (java.lang.InterruptedException e) {
                serviceCallInterrupted.set(true);
            } finally {
                serviceCallCompletedLatch.countDown();
            }
            return s.toUpperCase();
        }
    }
    // Create a separate RunContext with a separate RunMonitor, so we can wait for the service result in case of cancellation.
    final ClientRunContext runContext = ClientRunContexts.copyCurrent();
    final RunMonitor runMonitor = BEANS.get(RunMonitor.class);
    runContext.withRunMonitor(runMonitor);
    IFuture<String> pingFuture = Jobs.schedule(new Callable<String>() {

        @Override
        public String call() throws Exception {
            return runContext.call(new Callable<String>() {

                @Override
                public String call() throws Exception {
                    IBean<?> bean = TestingUtility.registerBean(new BeanMetaData(PingService.class).withInitialInstance(new PingService()).withApplicationScoped(true));
                    try {
                        return ServiceTunnelUtility.createProxy(IPingService.class).ping(pingRequest);
                    } finally {
                        TestingUtility.unregisterBeans(Arrays.asList(bean));
                    }
                }
            });
        }
    }, Jobs.newInput().withExceptionHandling(null, false));
    // Wait for the ping request to enter service implementation.
    assertTrue(serviceCallSetupLatch.await());
    return new RequestData(pingFuture, runMonitor, serviceCallSetupLatch, serviceCallCompletedLatch, serviceCallInterrupted);
}
Also used : BlockingCountDownLatch(org.eclipse.scout.rt.testing.platform.util.BlockingCountDownLatch) BeanMetaData(org.eclipse.scout.rt.platform.BeanMetaData) IPingService(org.eclipse.scout.rt.shared.services.common.ping.IPingService) Callable(java.util.concurrent.Callable) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) ClientRunContext(org.eclipse.scout.rt.client.context.ClientRunContext) IPingService(org.eclipse.scout.rt.shared.services.common.ping.IPingService) RunMonitor(org.eclipse.scout.rt.platform.context.RunMonitor)

Example 10 with BeanMetaData

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

the class ClientSessionDisposeTest method testDispose.

/**
 * Test might fail when manually debugged.
 */
@Test
public void testDispose() throws Exception {
    Platform.set(new DefaultPlatform());
    Platform.get().start();
    Platform.get().awaitPlatformStarted();
    TestingUtility.registerBean(new BeanMetaData(TestEnvironmentClientSession.class));
    IClientSession session = BEANS.get(ClientSessionProvider.class).provide(ClientRunContexts.empty().withUserAgent(UserAgents.createDefault()));
    WeakReference<IClientSession> ref = new WeakReference<IClientSession>(session);
    session.stop();
    assertTrue(session.isStopping());
    session = null;
    TestingUtility.assertGC(ref);
    Platform.get().stop();
}
Also used : ClientSessionProvider(org.eclipse.scout.rt.client.session.ClientSessionProvider) BeanMetaData(org.eclipse.scout.rt.platform.BeanMetaData) WeakReference(java.lang.ref.WeakReference) DefaultPlatform(org.eclipse.scout.rt.platform.DefaultPlatform) TestEnvironmentClientSession(org.eclipse.scout.rt.client.testenvironment.TestEnvironmentClientSession) Test(org.junit.Test)

Aggregations

BeanMetaData (org.eclipse.scout.rt.platform.BeanMetaData)53 Test (org.junit.Test)18 Before (org.junit.Before)11 IBean (org.eclipse.scout.rt.platform.IBean)9 IBeanManager (org.eclipse.scout.rt.platform.IBeanManager)6 TestEnvironmentClientSession (org.eclipse.scout.rt.client.testenvironment.TestEnvironmentClientSession)5 Callable (java.util.concurrent.Callable)3 JobCompletionDelayOnSessionShutdown (org.eclipse.scout.rt.client.ClientConfigProperties.JobCompletionDelayOnSessionShutdown)3 IRunnable (org.eclipse.scout.rt.platform.util.concurrent.IRunnable)3 After (org.junit.After)3 ArrayList (java.util.ArrayList)2 Subject (javax.security.auth.Subject)2 HttpServletRequest (javax.servlet.http.HttpServletRequest)2 HttpServletResponse (javax.servlet.http.HttpServletResponse)2 HttpSession (javax.servlet.http.HttpSession)2 IMomImplementor (org.eclipse.scout.rt.mom.api.IMomImplementor)2 NullMomImplementor (org.eclipse.scout.rt.mom.api.NullMomImplementor)2 PlatformException (org.eclipse.scout.rt.platform.exception.PlatformException)2 JaxWsImplementorSpecifics (org.eclipse.scout.rt.server.jaxws.implementor.JaxWsImplementorSpecifics)2 IClusterSynchronizationService (org.eclipse.scout.rt.server.services.common.clustersync.IClusterSynchronizationService)2