@Test public void testSetPeriod() { MyPeriodicWatch watch = new MyPeriodicWatch("watch"); watch.start(); Assert.assertEquals(PeriodicWatch.DEFAULT_PERIOD, watch.getPeriod()); for (int i = 0; i < 10; i++) { long value = Math.round(Math.random() * 100) + 1; watch.setPeriod(value); Assert.assertEquals(value, watch.getPeriod()); } try { watch.setPeriod(0); Assert.fail("IllegalArgumentException expected but not thrown"); } catch (IllegalArgumentException e) { } try { watch.setPeriod(-1); Assert.fail("IllegalArgumentException expected but not thrown"); } catch (IllegalArgumentException e) { } watch.setPeriod(500); Utils.sleep(5000); watch.stop(); Assert.assertTrue(watch.log().length() >= 8); Assert.assertTrue(watch.log().length() <= 12); watch.log().delete(0, watch.log().length()); watch.setPeriod(1000); Utils.sleep(5000); watch.stop(); Assert.assertTrue(watch.log().length() >= 3); Assert.assertTrue(watch.log().length() <= 7); watch.log().delete(0, watch.log().length()); watch.setPeriod(1000); Utils.sleep(5000); watch.stop(); Assert.assertTrue(watch.log().length() == 0); watch.log().delete(0, watch.log().length()); watch.setPeriod(500); Utils.sleep(5000); watch.stop(); Assert.assertTrue(watch.log().length() >= 8); Assert.assertTrue(watch.log().length() <= 12); watch.log().delete(0, watch.log().length()); Utils.close(watch.getWatchDataSource()); }
public void setPeriod(long newPeriod) { if(newPeriod == period) return; if(newPeriod <= 0) throw new IllegalArgumentException("period cannot be less then or equal to zero"); this.period = newPeriod; if(watchTimer!=null) { stop(); start(); } }
PeriodicWatch extends ThresholdWatch implements PeriodicWatchMBean { public void setPeriod(long newPeriod) { if(newPeriod == period) return; if(newPeriod <= 0) throw new IllegalArgumentException("period cannot be less then or equal to zero"); this.period = newPeriod; if(watchTimer!=null) { stop(); start(); } } }
PeriodicWatch extends ThresholdWatch implements PeriodicWatchMBean { public void setPeriod(long newPeriod) { if(newPeriod == period) return; if(newPeriod <= 0) throw new IllegalArgumentException("period cannot be less then or equal to zero"); this.period = newPeriod; if(watchTimer!=null) { stop(); start(); } } PeriodicWatch(String id);  PeriodicWatch(String id, Configuration config);  PeriodicWatch(WatchDataSource watchDataSource, String id); }
PeriodicWatch extends ThresholdWatch implements PeriodicWatchMBean { public void setPeriod(long newPeriod) { if(newPeriod == period) return; if(newPeriod <= 0) throw new IllegalArgumentException("period cannot be less then or equal to zero"); this.period = newPeriod; if(watchTimer!=null) { stop(); start(); } } PeriodicWatch(String id);  PeriodicWatch(String id, Configuration config);  PeriodicWatch(WatchDataSource watchDataSource, String id); void start(); void stop(); long getPeriod(); void setPeriod(long newPeriod); }
PeriodicWatch extends ThresholdWatch implements PeriodicWatchMBean { public void setPeriod(long newPeriod) { if(newPeriod == period) return; if(newPeriod <= 0) throw new IllegalArgumentException("period cannot be less then or equal to zero"); this.period = newPeriod; if(watchTimer!=null) { stop(); start(); } } PeriodicWatch(String id);  PeriodicWatch(String id, Configuration config);  PeriodicWatch(WatchDataSource watchDataSource, String id); void start(); void stop(); long getPeriod(); void setPeriod(long newPeriod); static final long DEFAULT_PERIOD; }