/** Create a new instance. */ SidecarCounter(Clock clock, Id id) { this.clock = clock; this.id = id.withTag(DataType.COUNTER); this.value = new AtomicDouble(0.0); }
/** Create a new instance. */ ServoCounter(Id id, Clock clock, DoubleCounter impl) { this.id = id; this.clock = clock; this.impl = impl; this.count = new AtomicDouble(0.0); this.lastUpdated = new AtomicLong(clock.wallTime()); }
/** Create a new instance. */ public StepDouble(double init, Clock clock, long step) { this.init = init; this.clock = clock; this.step = step; previous = init; current = new AtomicDouble(init); lastInitPos = new AtomicLong(clock.wallTime() / step); }
/** Create a new instance. */ ServoCounter(Id id, Clock clock, DoubleCounter impl) { this.id = id; this.clock = clock; this.impl = impl; this.count = new AtomicDouble(0.0); this.lastUpdated = new AtomicLong(clock.wallTime()); }
/** * Create a new monitor that returns {@code value}. */ ServoGauge(Id id, Clock clock, MonitorConfig config) { super(config.withAdditionalTag(DataSourceType.GAUGE)); this.id = id; this.clock = clock; this.value = new AtomicDouble(Double.NaN); this.lastUpdated = new AtomicLong(clock.wallTime()); }
/** Create a new instance. */ StatelessMaxGauge(Id id, Clock clock, long ttl) { super(id, clock, ttl); value = new AtomicDouble(0.0); stat = id.withTag(Statistic.max).withTags(id.tags()); }
/** Create a new instance. */ StatelessCounter(Id id, Clock clock, long ttl) { super(id, clock, ttl); count = new AtomicDouble(0.0); stat = id.withTag(Statistic.count).withTags(id.tags()); }
@Test public void initWithValue() { AtomicDouble v = new AtomicDouble(42.0); Assertions.assertEquals(42.0, v.get(), 1e-12); }
@Test public void maxValueInfinity() { AtomicDouble v = new AtomicDouble(0.0); v.max(Double.POSITIVE_INFINITY); Assertions.assertEquals(0.0, v.get(), 1e-12); } }
@Test public void set() { AtomicDouble v = new AtomicDouble(13.0); v.set(42.0); Assertions.assertEquals(42.0, v.get(), 1e-12); }
@Test public void maxNaN() { AtomicDouble v = new AtomicDouble(Double.NaN); v.max(0.0); Assertions.assertEquals(0.0, v.get(), 1e-12); }
@Test public void maxGt() { AtomicDouble v = new AtomicDouble(0.0); v.max(2.0); Assertions.assertEquals(2.0, v.get(), 1e-12); }
@Test public void maxValueNaN() { AtomicDouble v = new AtomicDouble(0.0); v.max(Double.NaN); Assertions.assertEquals(0.0, v.get(), 1e-12); }
@Test public void maxLt() { AtomicDouble v = new AtomicDouble(2.0); v.max(0.0); Assertions.assertEquals(2.0, v.get(), 1e-12); }
@Test public void maxNegative() { AtomicDouble v = new AtomicDouble(-42.0); v.max(-41.0); Assertions.assertEquals(-41.0, v.get(), 1e-12); }
@Test public void compareAndSetFail() { AtomicDouble v = new AtomicDouble(13.0); Assertions.assertFalse(v.compareAndSet(12.0, 42.0)); Assertions.assertEquals(13.0, v.get(), 1e-12); }
@Test public void addAndGet() { AtomicDouble v = new AtomicDouble(13.0); Assertions.assertEquals(55.0, v.addAndGet(42.0), 1e-12); Assertions.assertEquals(55.0, v.get(), 1e-12); }
@Test public void getAndSet() { AtomicDouble v = new AtomicDouble(13.0); Assertions.assertEquals(13.0, v.getAndSet(42.0), 1e-12); Assertions.assertEquals(42.0, v.get(), 1e-12); }
@Test public void compareAndSet() { AtomicDouble v = new AtomicDouble(13.0); Assertions.assertTrue(v.compareAndSet(13.0, 42.0)); Assertions.assertEquals(42.0, v.get(), 1e-12); }
@Test public void getAndAdd() { AtomicDouble v = new AtomicDouble(13.0); Assertions.assertEquals(13.0, v.getAndAdd(42.0), 1e-12); Assertions.assertEquals(55.0, v.get(), 1e-12); }