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);
}
}
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));
}
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());
}
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);
}
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();
}
Aggregations