@Test public void moduleShouldBeInitializedWhenRuntimeIsEnabledWithoutAnyTransactions() throws InterruptedException { GraphDatabaseService database = builder() .setConfig( TestModuleBootstrapper.MODULE_ENABLED, TestModuleBootstrapper.MODULE_ENABLED.getDefaultValue()) .setConfig( TestModuleBootstrapper.MODULE_CONFIG, TestModuleBootstrapper.MODULE_CONFIG.getDefaultValue()) .newGraphDatabase(); registerShutdownHook(database); Thread.sleep(1000); assertEquals(1, TEST_RUNTIME_MODULES.size()); assertTrue(TEST_RUNTIME_MODULES.get(0).isInitialized()); assertEquals("configValue", TEST_RUNTIME_MODULES.get(0).getConfig().get("configKey")); database.shutdown(); assertFalse(TEST_RUNTIME_MODULES.get(0).isInitialized()); }
@Test public void moduleShouldBeInitializedWhenAnotherModuleIsMisConfigured() throws InterruptedException { GraphDatabaseService database = builder() .setConfig("com.graphaware.module.wrong1.enabled", "com.not.existent.Bootstrapper") .setConfig("com.graphaware.module.wrong2.2", "com.not.existent.Bootstrapper") .setConfig( TestModuleBootstrapper.MODULE_ENABLED, TestModuleBootstrapper.MODULE_ENABLED.getDefaultValue()) .setConfig( TestModuleBootstrapper.MODULE_CONFIG, TestModuleBootstrapper.MODULE_CONFIG.getDefaultValue()) .newGraphDatabase(); registerShutdownHook(database); try (Transaction tx = database.beginTx()) { database.createNode(); tx.success(); } assertEquals(1, TEST_RUNTIME_MODULES.size()); assertTrue(TEST_RUNTIME_MODULES.get(0).isInitialized()); assertEquals("configValue", TEST_RUNTIME_MODULES.get(0).getConfig().get("configKey")); database.shutdown(); assertFalse(TEST_RUNTIME_MODULES.get(0).isInitialized()); }
@Test public void moduleShouldBeInitializedWhenRuntimeIsEnabled() throws InterruptedException { GraphDatabaseService database = builder() .setConfig( TestModuleBootstrapper.MODULE_ENABLED, TestModuleBootstrapper.MODULE_ENABLED.getDefaultValue()) .setConfig( TestModuleBootstrapper.MODULE_CONFIG, TestModuleBootstrapper.MODULE_CONFIG.getDefaultValue()) .newGraphDatabase(); registerShutdownHook(database); try (Transaction tx = database.beginTx()) { database.createNode(); // tx just to kick off Runtime init tx.success(); } assertEquals(1, TEST_RUNTIME_MODULES.size()); assertTrue(TEST_RUNTIME_MODULES.get(0).isInitialized()); assertEquals("configValue", TEST_RUNTIME_MODULES.get(0).getConfig().get("configKey")); database.shutdown(); assertFalse(TEST_RUNTIME_MODULES.get(0).isInitialized()); }