Search in sources :

Example 6 with DefaultEventManager

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]);
}
Also used : DefaultEventManager(org.apache.cayenne.event.DefaultEventManager) DefaultRuntimeProperties(org.apache.cayenne.configuration.DefaultRuntimeProperties) Test(org.junit.Test)

Example 7 with DefaultEventManager

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);
}
Also used : RuntimeProperties(org.apache.cayenne.configuration.RuntimeProperties) Injector(org.apache.cayenne.di.Injector) TransactionManager(org.apache.cayenne.tx.TransactionManager) ServerCase(org.apache.cayenne.unit.di.server.ServerCase) Module(org.apache.cayenne.di.Module) MockEventBridgeProvider(org.apache.cayenne.event.MockEventBridgeProvider) DefaultRuntimeProperties(org.apache.cayenne.configuration.DefaultRuntimeProperties) Slf4jJdbcEventLogger(org.apache.cayenne.log.Slf4jJdbcEventLogger) EventBridge(org.apache.cayenne.event.EventBridge) JdbcEventLogger(org.apache.cayenne.log.JdbcEventLogger) TransactionFactory(org.apache.cayenne.tx.TransactionFactory) ServerModule(org.apache.cayenne.configuration.server.ServerModule) DIBootstrap(org.apache.cayenne.di.DIBootstrap) DefaultEventManager(org.apache.cayenne.event.DefaultEventManager) MockEventBridge(org.apache.cayenne.event.MockEventBridge) DefaultTransactionManager(org.apache.cayenne.tx.DefaultTransactionManager) Assert.assertNotNull(org.junit.Assert.assertNotNull) DefaultTransactionFactory(org.apache.cayenne.tx.DefaultTransactionFactory) Test(org.junit.Test) CayenneProjects(org.apache.cayenne.unit.di.server.CayenneProjects) EventManager(org.apache.cayenne.event.EventManager) NoopEventBridgeProvider(org.apache.cayenne.event.NoopEventBridgeProvider) ServerRuntime(org.apache.cayenne.configuration.server.ServerRuntime) UseServerRuntime(org.apache.cayenne.unit.di.server.UseServerRuntime) Assert.assertEquals(org.junit.Assert.assertEquals) DefaultEventManager(org.apache.cayenne.event.DefaultEventManager) EventManager(org.apache.cayenne.event.EventManager) DefaultEventManager(org.apache.cayenne.event.DefaultEventManager) DefaultRuntimeProperties(org.apache.cayenne.configuration.DefaultRuntimeProperties) DefaultTransactionManager(org.apache.cayenne.tx.DefaultTransactionManager) DefaultTransactionFactory(org.apache.cayenne.tx.DefaultTransactionFactory) Slf4jJdbcEventLogger(org.apache.cayenne.log.Slf4jJdbcEventLogger) Injector(org.apache.cayenne.di.Injector) NoopEventBridgeProvider(org.apache.cayenne.event.NoopEventBridgeProvider) Module(org.apache.cayenne.di.Module) ServerModule(org.apache.cayenne.configuration.server.ServerModule) Test(org.junit.Test)

Example 8 with DefaultEventManager

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());
}
Also used : Binder(org.apache.cayenne.di.Binder) DataChannel(org.apache.cayenne.DataChannel) HashMap(java.util.HashMap) Injector(org.apache.cayenne.di.Injector) DefaultEventManager(org.apache.cayenne.event.DefaultEventManager) MockClientConnection(org.apache.cayenne.remote.MockClientConnection) MockClientConnection(org.apache.cayenne.remote.MockClientConnection) ClientConnection(org.apache.cayenne.remote.ClientConnection) ClientChannel(org.apache.cayenne.remote.ClientChannel) Test(org.junit.Test)

Example 9 with DefaultEventManager

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());
}
Also used : DefaultEventManager(org.apache.cayenne.event.DefaultEventManager) EventManager(org.apache.cayenne.event.EventManager) HashMap(java.util.HashMap) DefaultEventManager(org.apache.cayenne.event.DefaultEventManager) Test(org.junit.Test)

Example 10 with DefaultEventManager

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");
    }
}
Also used : DefaultEventManager(org.apache.cayenne.event.DefaultEventManager) CayenneEvent(org.apache.cayenne.event.CayenneEvent) CayenneRuntimeException(org.apache.cayenne.CayenneRuntimeException) EventBridge(org.apache.cayenne.event.EventBridge) MockEventManager(org.apache.cayenne.event.MockEventManager) Test(org.junit.Test)

Aggregations

DefaultEventManager (org.apache.cayenne.event.DefaultEventManager)10 Test (org.junit.Test)7 DefaultRuntimeProperties (org.apache.cayenne.configuration.DefaultRuntimeProperties)4 Injector (org.apache.cayenne.di.Injector)3 EventBridge (org.apache.cayenne.event.EventBridge)3 EventManager (org.apache.cayenne.event.EventManager)3 HashMap (java.util.HashMap)2 MapQueryCache (org.apache.cayenne.cache.MapQueryCache)2 RuntimeProperties (org.apache.cayenne.configuration.RuntimeProperties)2 ServerModule (org.apache.cayenne.configuration.server.ServerModule)2 ServerRuntime (org.apache.cayenne.configuration.server.ServerRuntime)2 DIBootstrap (org.apache.cayenne.di.DIBootstrap)2 Module (org.apache.cayenne.di.Module)2 MockEventBridge (org.apache.cayenne.event.MockEventBridge)2 MockEventBridgeProvider (org.apache.cayenne.event.MockEventBridgeProvider)2 NoopEventBridgeProvider (org.apache.cayenne.event.NoopEventBridgeProvider)2 JdbcEventLogger (org.apache.cayenne.log.JdbcEventLogger)2 Slf4jJdbcEventLogger (org.apache.cayenne.log.Slf4jJdbcEventLogger)2 DataMap (org.apache.cayenne.map.DataMap)2 DefaultTransactionFactory (org.apache.cayenne.tx.DefaultTransactionFactory)2