use of org.apache.cayenne.event.DefaultEventManager in project cayenne by apache.
the class DataDomainIT method testShutdownCache.
@Test
public void testShutdownCache() {
DataDomain domain = new DataDomain("X");
final boolean[] cacheShutdown = new boolean[1];
DefaultEventManager eventManager = new DefaultEventManager();
try {
DataRowStore cache = new DataRowStore("Y", new DefaultRuntimeProperties(Collections.<String, String>emptyMap()), eventManager) {
@Override
public void shutdown() {
cacheShutdown[0] = true;
}
};
domain.setSharedSnapshotCache(cache);
domain.shutdown();
} finally {
eventManager.shutdown();
}
assertTrue(cacheShutdown[0]);
}
use of org.apache.cayenne.event.DefaultEventManager in project cayenne by apache.
the class DefaultDataRowStoreFactoryIT method testGetDataRowStoreWithParameters.
@Test
public void testGetDataRowStoreWithParameters() {
final DataDomain DOMAIN = new DataDomain("test");
final EventManager EVENT_MANAGER = new DefaultEventManager();
final int CACHE_SIZE = 500;
Module testModule = binder -> {
binder.bind(DataDomain.class).toInstance(DOMAIN);
binder.bind(EventManager.class).toInstance(EVENT_MANAGER);
binder.bind(TransactionManager.class).to(DefaultTransactionManager.class);
binder.bind(TransactionFactory.class).to(DefaultTransactionFactory.class);
binder.bind(JdbcEventLogger.class).to(Slf4jJdbcEventLogger.class);
binder.bind(RuntimeProperties.class).to(DefaultRuntimeProperties.class);
binder.bind(EventBridge.class).toProvider(NoopEventBridgeProvider.class);
binder.bind(DataRowStoreFactory.class).to(DefaultDataRowStoreFactory.class);
ServerModule.setSnapshotCacheSize(binder, CACHE_SIZE);
};
Injector injector = DIBootstrap.createInjector(testModule);
DataRowStore dataStore = injector.getInstance(DataRowStoreFactory.class).createDataRowStore("test");
assertNotNull(dataStore);
assertEquals(dataStore.maximumSize(), CACHE_SIZE);
}
use of org.apache.cayenne.event.DefaultEventManager in project cayenne by apache.
the class ClientModuleTest method testDataChannel.
@Test
public void testDataChannel() {
Map<String, String> properties = new HashMap<>();
ClientModule module = new ClientModule() {
@Override
public void configure(Binder binder) {
super.configure(binder);
// use a noop connection to prevent startup errors...
binder.bind(ClientConnection.class).to(MockClientConnection.class);
}
};
Injector injector = DIBootstrap.createInjector(module);
DataChannel channel = injector.getInstance(DataChannel.class);
assertNotNull(channel);
assertTrue(channel instanceof ClientChannel);
assertSame("DataChannel must be a singleton", channel, injector.getInstance(DataChannel.class));
ClientChannel clientChannel = (ClientChannel) channel;
assertTrue(clientChannel.getConnection() instanceof MockClientConnection);
assertTrue(clientChannel.getEventManager() instanceof DefaultEventManager);
assertFalse(clientChannel.isChannelEventsEnabled());
}
use of org.apache.cayenne.event.DefaultEventManager in project cayenne by apache.
the class ClientRuntimeTest method testShutdown.
@Test
public void testShutdown() throws Exception {
Map<String, String> properties = new HashMap<>();
ClientRuntime runtime = ClientRuntime.builder().properties(properties).build();
// make sure objects to be shut down are resolved
EventManager em = runtime.getInjector().getInstance(EventManager.class);
assertNotNull(em);
assertTrue(em instanceof DefaultEventManager);
assertFalse(((DefaultEventManager) em).isStopped());
runtime.getInjector().shutdown();
assertTrue(((DefaultEventManager) em).isStopped());
}
use of org.apache.cayenne.event.DefaultEventManager in project cayenne by apache.
the class ClientChannelTest method testEventBridgeFailure.
@Test
public void testEventBridgeFailure() throws Exception {
MockClientConnection connection = new MockClientConnection() {
@Override
public EventBridge getServerEventBridge() throws CayenneRuntimeException {
return new EventBridge(Collections.EMPTY_LIST, "ext") {
@Override
protected void sendExternalEvent(CayenneEvent localEvent) throws Exception {
}
@Override
protected void shutdownExternal() throws Exception {
}
@Override
protected void startupExternal() throws Exception {
// intentionally throw an exception
throw new CayenneRuntimeException("Test failure");
}
};
}
};
// default constructor must fail
try {
new ClientChannel(connection, false, new MockEventManager(), false);
fail("Channel didn't throw on broken EventBridge");
} catch (CayenneRuntimeException e) {
// expected
}
try {
DefaultEventManager manager = new DefaultEventManager(2);
managers.add(manager);
new ClientChannel(connection, false, manager, false);
fail("Channel didn't throw on broken EventBridge");
} catch (CayenneRuntimeException e) {
// expected
}
try {
DefaultEventManager manager = new DefaultEventManager(2);
managers.add(manager);
new ClientChannel(connection, false, manager, true);
} catch (CayenneRuntimeException e) {
fail("Channel threw on broken EventBridge");
}
}
Aggregations