/** * Tests the GET /dataset/uncached endpoint, for an other error. * @throws Exception Test failed */ @Test public void getUncachedDataset_OtherError() throws Exception { given(dataProvider.getUncachedDataset("ERROR_DATASET", 2)) .willThrow(new DataSourceLookupFailureException("Fatal error!")); // example Spring runtime exception // should return 500 response with JSON respponse mvc.perform(get("/dataset/uncached/ERROR_DATASET/2").accept(MediaType.APPLICATION_JSON_UTF8)) .andExpect(status().isInternalServerError()) .andExpect(content().contentType(MediaType.APPLICATION_JSON_UTF8)) .andExpect(content().string("{\"message\":\"Fatal error!\"}")); }
/** * Tests the GET /entry/uncached endpoint, for an other error. * @throws Exception Test failed */ @Test public void getUncachedDatasetEntry_OtherError() throws Exception { given(dataProvider.getUncachedDatasetEntry("ERROR_DATASET")) .willThrow(new DataSourceLookupFailureException("Fatal error!")); // example Spring runtime exception // should return 500 response with JSON respponse mvc.perform(get("/entry/uncached/ERROR_DATASET").accept(MediaType.APPLICATION_JSON_UTF8)) .andExpect(status().isInternalServerError()) .andExpect(content().contentType(MediaType.APPLICATION_JSON_UTF8)) .andExpect(content().string("{\"message\":\"Fatal error!\"}")); }
/** * Tests the GET /entry/cached endpoint, for an other error. * @throws Exception Test failed */ @Test public void getCachedDatasetEntry_OtherError() throws Exception { given(dataProvider.getCachedDatasetEntry("ERROR_DATASET")) .willThrow(new DataSourceLookupFailureException("Fatal error!")); // example Spring runtime exception // should return 500 response with JSON respponse mvc.perform(get("/entry/cached/ERROR_DATASET").accept(MediaType.APPLICATION_JSON_UTF8)) .andExpect(status().isInternalServerError()) .andExpect(content().contentType(MediaType.APPLICATION_JSON_UTF8)) .andExpect(content().string("{\"message\":\"Fatal error!\"}")); }
@DataProvider public Object[][] statuses() { TitanMigrationManager happyMigrationManager = new TitanMigrationManager(); TitanMigrationManager sadMigrationManager = new TitanMigrationManager(); Whitebox.setInternalState(happyMigrationManager, IS_MIGRATION_COMPLETE_FIELD_NAME, true); Whitebox.setInternalState(sadMigrationManager, IS_MIGRATION_COMPLETE_FIELD_NAME, false); return new Object[][] { new Object[] { mockDbWithUp(), Status.UP, AcsMonitoringUtilities.HealthCode.AVAILABLE, happyMigrationManager }, { mockDbWithException(new TransientDataAccessResourceException("")), Status.DOWN, AcsMonitoringUtilities.HealthCode.UNAVAILABLE, happyMigrationManager }, { mockDbWithException(new QueryTimeoutException("")), Status.DOWN, AcsMonitoringUtilities.HealthCode.UNAVAILABLE, happyMigrationManager }, { mockDbWithException(new DataSourceLookupFailureException("")), Status.DOWN, AcsMonitoringUtilities.HealthCode.UNREACHABLE, happyMigrationManager }, { mockDbWithException(new PermissionDeniedDataAccessException("", null)), Status.DOWN, AcsMonitoringUtilities.HealthCode.MISCONFIGURATION, happyMigrationManager }, { mockDbWithException(new ConcurrencyFailureException("")), Status.DOWN, AcsMonitoringUtilities.HealthCode.ERROR, happyMigrationManager }, { mockDbWithUp(), Status.DOWN, AcsMonitoringUtilities.HealthCode.MIGRATION_INCOMPLETE, sadMigrationManager }, }; }
/** * Get Session * * @return session */ private Session obtainSession() { if (sessionFactory == null) { throw new DataSourceLookupFailureException("sessionFactory must not be empty or null"); } return sessionFactory.getCurrentSession(); }
/** * Sets the hibernate sessionFactory. * * @param sessionFactory * hibernate sessionFactory. */ @Resource public void setSessionFactory(SessionFactory sessionFactory) { if(sessionFactory==null){ throw new DataSourceLookupFailureException("sessionFactory must not be empty or null"); } this.sessionFactory = sessionFactory; }
private void send(Event e) { try { m_eventProxy.send(e); } catch (EventProxyException e1) { throw new DataSourceLookupFailureException("Unable to send event to eventd", e1); } }
private void send(final Event e) { try { m_eventProxy.send(e); } catch (final EventProxyException e1) { throw new DataSourceLookupFailureException("Unable to send event to eventd", e1); } }
@Bean(destroyMethod = "shutdown") @ConditionalOnMissingClass(name = "it.cineca.pst.huborcid.config.HerokuDatabaseConfiguration") @Profile("!" + Constants.SPRING_PROFILE_CLOUD) public DataSource dataSource() { log.debug("Configuring Datasource"); if (dataSourcePropertyResolver.getProperty("url") == null && dataSourcePropertyResolver.getProperty("databaseName") == null) { log.error("Your database connection pool configuration is incorrect! The application" + " cannot start. Please check your Spring profile, current profiles are: {}", Arrays.toString(env.getActiveProfiles())); throw new ApplicationContextException("Database connection pool is not configured correctly"); } HikariConfig config = new HikariConfig(); if(StringUtils.isEmpty(dataSourcePropertyResolver.getProperty("jndi"))){ config.setDataSourceClassName(dataSourcePropertyResolver.getProperty("dataSourceClassName")); if(StringUtils.isEmpty(dataSourcePropertyResolver.getProperty("url"))) { config.addDataSourceProperty("databaseName", dataSourcePropertyResolver.getProperty("databaseName")); config.addDataSourceProperty("serverName", dataSourcePropertyResolver.getProperty("serverName")); } else { config.addDataSourceProperty("url", dataSourcePropertyResolver.getProperty("url")); } config.addDataSourceProperty("user", dataSourcePropertyResolver.getProperty("username")); config.addDataSourceProperty("password", dataSourcePropertyResolver.getProperty("password")); config.setConnectionTimeout(10000); config.setMaximumPoolSize(25); }else{ final JndiDataSourceLookup dataSourceLookup = new JndiDataSourceLookup(); dataSourceLookup.setResourceRef(true); DataSource dataSourceTemp = null; try { dataSourceTemp = dataSourceLookup.getDataSource(dataSourcePropertyResolver.getProperty("jndi")); } catch (DataSourceLookupFailureException e) { log.error("DataSource not found."); } config.setDataSource(dataSourceTemp); } if (metricRegistry != null) { config.setMetricRegistry(metricRegistry); } return new HikariDataSource(config); }