@Test public void shouldLogTimeoutExceptionIfWaitingForConnectionToMainDsTooLong() throws SQLException, InterruptedException, UnknownHostException { Hades<SqlTimeBasedMonitorImpl> hades = new Hades<SqlTimeBasedMonitorImpl>( createMockDataSource("mainDs", false, 1100), createMockDataSource("failoverDs", false, 0), "mainDs", "failoverDsName"); Repo repo = SqlTimeBasedTimerTaskMonitorTest.createSqlTimeRepoMock(); SqlTimeCalculatorImpl loadCalculator = new SqlTimeCalculatorImpl( hades, 1, null, repo, "select", 1, 1); SqlTimeBasedTimerTaskMonitor monitor = new SqlTimeBasedTimerTaskMonitor( hades, 1, 1, 1, false, false, loadCalculator, 1, 1, 1, repo); monitor.init(); monitor.run(); assertEquals(ExceptionEnum.valueForException(new ConnTimeout(new MonitorRunLogPrefix())), monitor.getLastQueryTimeNanos(true)); }
public void init(M monitor) { Utils.assertNotNull(monitor, "monitor"); Utils.assertSame(monitor.getHades(), this, "monitor.hades != this; ensure that each association of a hades and a monitor is one-to-one"); if (this.monitor.compareAndSet(null, monitor)) { logger.info("hades " + this + " for the first time associated with a monitor; new monitor: " + monitor); } else { M oldMonitor = this.monitor.getAndSet(monitor); logger.info("hades " + this + " associated with monitor " + monitor + "; old monitor: " + oldMonitor); } }
Hades implements DataSource, HadesMBean { public void init(M monitor) { Utils.assertNotNull(monitor, "monitor"); Utils.assertSame(monitor.getHades(), this, "monitor.hades != this; ensure that each association of a hades and a monitor is one-to-one"); if (this.monitor.compareAndSet(null, monitor)) { logger.info("hades " + this + " for the first time associated with a monitor; new monitor: " + monitor); } else { M oldMonitor = this.monitor.getAndSet(monitor); logger.info("hades " + this + " associated with monitor " + monitor + "; old monitor: " + oldMonitor); } } }
Hades implements DataSource, HadesMBean { public void init(M monitor) { Utils.assertNotNull(monitor, "monitor"); Utils.assertSame(monitor.getHades(), this, "monitor.hades != this; ensure that each association of a hades and a monitor is one-to-one"); if (this.monitor.compareAndSet(null, monitor)) { logger.info("hades " + this + " for the first time associated with a monitor; new monitor: " + monitor); } else { M oldMonitor = this.monitor.getAndSet(monitor); logger.info("hades " + this + " associated with monitor " + monitor + "; old monitor: " + oldMonitor); } } Hades(DataSource mainDataSource, DataSource failoverDataSource, String mainDsName, String failoverDsName); }
Hades implements DataSource, HadesMBean { public void init(M monitor) { Utils.assertNotNull(monitor, "monitor"); Utils.assertSame(monitor.getHades(), this, "monitor.hades != this; ensure that each association of a hades and a monitor is one-to-one"); if (this.monitor.compareAndSet(null, monitor)) { logger.info("hades " + this + " for the first time associated with a monitor; new monitor: " + monitor); } else { M oldMonitor = this.monitor.getAndSet(monitor); logger.info("hades " + this + " associated with monitor " + monitor + "; old monitor: " + oldMonitor); } } Hades(DataSource mainDataSource, DataSource failoverDataSource, String mainDsName, String failoverDsName); void init(M monitor); Connection getConnection(); Connection getConnection(String username, String password); Connection getConnection(MonitorRunLogPrefix logPrefix, boolean failover); @Override String toString(); String desc(boolean failover); void pinMainDataSource(); void pinFailoverDataSource(); void removePin(); boolean getPinEnabled(); Boolean getFailoverDataSourcePinned(); boolean isFailoverActive(); String getActiveDataSourceName(); String getFailoverLoad(); String getMainLoad(); int getLoginTimeout(); PrintWriter getLogWriter(); void setLoginTimeout(int loginTimeout); void setLogWriter(PrintWriter printWriter); T unwrap(Class<T> iface); boolean isWrapperFor(Class<?> iface); M getMonitor(); String getFailoverDsName(); String getMainDsName(); String getDsName(boolean failover); String getDsName(boolean failover, boolean fixedWidth); }
Hades implements DataSource, HadesMBean { public void init(M monitor) { Utils.assertNotNull(monitor, "monitor"); Utils.assertSame(monitor.getHades(), this, "monitor.hades != this; ensure that each association of a hades and a monitor is one-to-one"); if (this.monitor.compareAndSet(null, monitor)) { logger.info("hades " + this + " for the first time associated with a monitor; new monitor: " + monitor); } else { M oldMonitor = this.monitor.getAndSet(monitor); logger.info("hades " + this + " associated with monitor " + monitor + "; old monitor: " + oldMonitor); } } Hades(DataSource mainDataSource, DataSource failoverDataSource, String mainDsName, String failoverDsName); void init(M monitor); Connection getConnection(); Connection getConnection(String username, String password); Connection getConnection(MonitorRunLogPrefix logPrefix, boolean failover); @Override String toString(); String desc(boolean failover); void pinMainDataSource(); void pinFailoverDataSource(); void removePin(); boolean getPinEnabled(); Boolean getFailoverDataSourcePinned(); boolean isFailoverActive(); String getActiveDataSourceName(); String getFailoverLoad(); String getMainLoad(); int getLoginTimeout(); PrintWriter getLogWriter(); void setLoginTimeout(int loginTimeout); void setLogWriter(PrintWriter printWriter); T unwrap(Class<T> iface); boolean isWrapperFor(Class<?> iface); M getMonitor(); String getFailoverDsName(); String getMainDsName(); String getDsName(boolean failover); String getDsName(boolean failover, boolean fixedWidth);  }