@Test public void countsSubscriptionsFuseable() { Mono<Integer> source = Mono.just(10); Mono<Integer> test = new MonoMetricsFuseable<>(source, registry); test.subscribe(); Counter meter = registry.find(METER_SUBSCRIBED) .counter(); assertThat(meter).isNotNull(); assertThat(meter.count()).as("after 1s subscribe").isEqualTo(1); test.subscribe(); test.subscribe(); assertThat(meter.count()).as("after more subscribe").isEqualTo(3); }
@Test public void countsSubscriptions() { Mono<Integer> source = Mono.just(1) .hide(); Mono<Integer> test = new MonoMetrics<>(source, registry); test.subscribe(); Counter meter = registry.find(METER_SUBSCRIBED) .counter(); assertThat(meter).isNotNull(); assertThat(meter.count()).as("after 1s subscribe").isEqualTo(1); test.subscribe(); test.subscribe(); assertThat(meter.count()).as("after more subscribe").isEqualTo(3); }
@Test public void countsSubscriptionsFuseable() { Flux<Integer> source = Flux.range(1, 10); Flux<Integer> test = new FluxMetricsFuseable<>(source, registry); test.subscribe(); Counter meter = registry.find(METER_SUBSCRIBED) .counter(); assertThat(meter).isNotNull(); assertThat(meter.count()).as("after 1s subscribe").isEqualTo(1); test.subscribe(); test.subscribe(); assertThat(meter.count()).as("after more subscribe").isEqualTo(3); }
@Test public void countsSubscriptions() { Flux<Integer> source = Flux.range(1, 10) .hide(); Flux<Integer> test = new FluxMetrics<>(source, registry); test.subscribe(); Counter meter = registry.find(METER_SUBSCRIBED) .counter(); assertThat(meter).isNotNull(); assertThat(meter.count()).as("after 1s subscribe").isEqualTo(1); test.subscribe(); test.subscribe(); assertThat(meter.count()).as("after more subscribe").isEqualTo(3); }
@Test public void queuePollTracksOnNext() { //prepare registry with mock clock MockClock clock = new MockClock(); removeRegistry(); registry = new SimpleMeterRegistry(SimpleConfig.DEFAULT, clock); Metrics.globalRegistry.add(registry); AssertSubscriber<Integer> testSubscriber = AssertSubscriber.create(); MicrometerFluxMetricsFuseableSubscriber<Integer> fuseableSubscriber = new MicrometerFluxMetricsFuseableSubscriber<>(testSubscriber, registry, clock, "foo", Collections.emptyList()); Fuseable.QueueSubscription<Integer> testQueue = new FluxPeekFuseableTest.AssertQueueSubscription<>(); testQueue.offer(1); fuseableSubscriber.onSubscribe(testQueue); clock.add(Duration.ofMillis(200)); Integer val1 = fuseableSubscriber.poll(); Integer val2 = fuseableSubscriber.poll(); assertThat(val1).isEqualTo(1); assertThat(val2).isNull(); //test meters Timer nextTimer = registry.find(METER_ON_NEXT_DELAY) .timer(); assertThat(nextTimer).isNotNull(); assertThat(nextTimer.max(TimeUnit.MILLISECONDS)).as("onNext max delay").isEqualTo(200); }
@Test public void queuePollSyncTracksOnComplete() { //prepare registry with mock clock MockClock clock = new MockClock(); removeRegistry(); registry = new SimpleMeterRegistry(SimpleConfig.DEFAULT, clock); Metrics.globalRegistry.add(registry); AssertSubscriber<Integer> testSubscriber = AssertSubscriber.create(); MicrometerFluxMetricsFuseableSubscriber<Integer> fuseableSubscriber = new MicrometerFluxMetricsFuseableSubscriber<>(testSubscriber, registry, clock, "foo", Collections.emptyList()); Fuseable.QueueSubscription<Integer> testQueue = new FluxPeekFuseableTest.AssertQueueSubscription<>(); testQueue.offer(1); fuseableSubscriber.onSubscribe(testQueue); fuseableSubscriber.requestFusion(Fuseable.SYNC); clock.add(Duration.ofMillis(200)); Integer val1 = fuseableSubscriber.poll(); clock.add(Duration.ofMillis(123)); Integer val2 = fuseableSubscriber.poll(); assertThat(val1).isEqualTo(1); assertThat(val2).isNull(); //test meters Timer terminationTimer = registry.find(METER_FLOW_DURATION) .tag(TAG_STATUS, TAGVALUE_ON_COMPLETE) .timer(); assertThat(terminationTimer).isNotNull(); assertThat(terminationTimer.max(TimeUnit.MILLISECONDS)).as("terminate max delay").isEqualTo(323); }
@Test public void queuePollSyncTracksOnComplete() { //prepare registry with mock clock MockClock clock = new MockClock(); removeRegistry(); registry = new SimpleMeterRegistry(SimpleConfig.DEFAULT, clock); Metrics.globalRegistry.add(registry); AssertSubscriber<Integer> testSubscriber = AssertSubscriber.create(); MicrometerMonoMetricsFuseableSubscriber<Integer> fuseableSubscriber = new MicrometerMonoMetricsFuseableSubscriber<>(testSubscriber, registry, clock, "foo", Collections.emptyList()); Fuseable.QueueSubscription<Integer> testQueue = new FluxPeekFuseableTest.AssertQueueSubscription<>(); testQueue.offer(1); fuseableSubscriber.onSubscribe(testQueue); fuseableSubscriber.requestFusion(Fuseable.SYNC); clock.add(Duration.ofMillis(200)); Integer val1 = fuseableSubscriber.poll(); clock.add(Duration.ofMillis(123)); Integer val2 = fuseableSubscriber.poll(); assertThat(val1).isEqualTo(1); assertThat(val2).isNull(); //test meters Timer terminationTimer = registry.find(METER_FLOW_DURATION) .tag(TAG_STATUS, TAGVALUE_ON_COMPLETE) .timer(); assertThat(terminationTimer).isNotNull(); assertThat(terminationTimer.max(TimeUnit.MILLISECONDS)).as("terminate max delay").isEqualTo(323); }
@Test public void subscribeToComplete() { Mono<Long> source = Mono.delay(Duration.ofMillis(100)) .hide(); new MonoMetrics<>(source, registry) .block(); Timer stcCompleteTimer = registry.find(METER_FLOW_DURATION) .tag(TAG_STATUS, TAGVALUE_ON_COMPLETE) .timer(); Timer stcErrorTimer = registry.find(METER_FLOW_DURATION) .tag(TAG_STATUS, TAGVALUE_ON_ERROR) .timer(); Timer stcCancelTimer = registry.find(METER_FLOW_DURATION) .tag(TAG_STATUS, TAGVALUE_CANCEL) .timer(); assertThat(stcCompleteTimer.max(TimeUnit.MILLISECONDS)) .as("subscribe to complete timer") .isGreaterThanOrEqualTo(100); assertThat(stcErrorTimer) .as("subscribe to error timer is lazily registered") .isNull(); assertThat(stcCancelTimer.max(TimeUnit.MILLISECONDS)) .as("subscribe to cancel timer") .isZero(); }
@Test public void queuePollError() { //prepare registry with mock clock MockClock clock = new MockClock(); removeRegistry(); registry = new SimpleMeterRegistry(SimpleConfig.DEFAULT, clock); Metrics.globalRegistry.add(registry); AssertSubscriber<Integer> testSubscriber = AssertSubscriber.create(); MicrometerMonoMetricsFuseableSubscriber<Integer> fuseableSubscriber = new MicrometerMonoMetricsFuseableSubscriber<>(testSubscriber, registry, clock, "foo", Collections.emptyList()); FluxPeekFuseableTest.AssertQueueSubscription<Integer> testQueue = new FluxPeekFuseableTest.AssertQueueSubscription<>(); testQueue.setCompleteWithError(true); testQueue.offer(1); fuseableSubscriber.onSubscribe(testQueue); fuseableSubscriber.requestFusion(Fuseable.SYNC); clock.add(Duration.ofMillis(200)); Integer val1 = fuseableSubscriber.poll(); assertThat(val1).isEqualTo(1); clock.add(Duration.ofMillis(123)); assertThatIllegalStateException().isThrownBy(fuseableSubscriber::poll) .withMessage("AssertQueueSubscriber poll error"); //test meters Timer terminationTimer = registry.find(METER_FLOW_DURATION) .tag(TAG_STATUS, TAGVALUE_ON_ERROR) .timer(); assertThat(terminationTimer).isNotNull(); assertThat(terminationTimer.max(TimeUnit.MILLISECONDS)).as("terminate max delay").isEqualTo(323); }
@Test public void queuePollError() { //prepare registry with mock clock MockClock clock = new MockClock(); removeRegistry(); registry = new SimpleMeterRegistry(SimpleConfig.DEFAULT, clock); Metrics.globalRegistry.add(registry); AssertSubscriber<Integer> testSubscriber = AssertSubscriber.create(); MicrometerFluxMetricsFuseableSubscriber<Integer> fuseableSubscriber = new MicrometerFluxMetricsFuseableSubscriber<>(testSubscriber, registry, clock, "foo", Collections.emptyList()); FluxPeekFuseableTest.AssertQueueSubscription<Integer> testQueue = new FluxPeekFuseableTest.AssertQueueSubscription<>(); testQueue.setCompleteWithError(true); testQueue.offer(1); fuseableSubscriber.onSubscribe(testQueue); fuseableSubscriber.requestFusion(Fuseable.SYNC); clock.add(Duration.ofMillis(200)); Integer val1 = fuseableSubscriber.poll(); assertThat(val1).isEqualTo(1); clock.add(Duration.ofMillis(123)); assertThatIllegalStateException().isThrownBy(fuseableSubscriber::poll) .withMessage("AssertQueueSubscriber poll error"); //test meters Timer terminationTimer = registry.find(METER_FLOW_DURATION) .tag(TAG_STATUS, TAGVALUE_ON_ERROR) .timer(); assertThat(terminationTimer).isNotNull(); assertThat(terminationTimer.max(TimeUnit.MILLISECONDS)).as("terminate max delay").isEqualTo(323); }
public void hasLastValue(double expectedValue) { Point lastPoint = getLastPoint(); assertThat(lastPoint.value) .as("Last recorded value of metric [" + metricName + "]") .isEqualTo(expectedValue); }
private void checkResult(List<?> result, String name, int distanceIndex, Double distance, Offset<Double> offset) { Assertions.assertThat( result.get( 0 ) ).as( name + " - name" ).isEqualTo( name ); if ( distance == null ) { Assertions.assertThat( result.get( distanceIndex ) ).as( name + " - distance" ).isNull(); } else { Assertions.assertThat( (Double) result.get( distanceIndex ) ) .as( name + " - distance" ) .isCloseTo( distance, offset ); } } }
public void hasLastValue(int expectedValue) { Point lastPoint = getLastPoint(); final Point penultimatePoint = getPenultimatePoint(); assertThat(lastPoint.value - penultimatePoint.value) .as("Last recorded derivative of metric [" + metricName + "]") .isEqualTo(expectedValue); } }
@CsvMethod public void assertNumberExact(String value, String... identifier) { GwtInstance gwtInstance = object(identifier); Object actual = gwtInstance.getRaw(); if (actual == null) { fail(prefix() + "number is null: " + gwtInstance.identifierToString()); } else if (actual instanceof Integer) { assertThat((Integer) actual).as(prefix() + "Integer").isEqualTo(Integer.parseInt(value)); } else if (actual instanceof Long) { assertThat((Long) actual).as(prefix() + "Long").isEqualTo(Long.parseLong(value)); } else if (actual instanceof Double) { assertThat((Double) actual).as(prefix() + "Double").isEqualTo(Double.parseDouble(value)); } else if (actual instanceof Float) { assertThat((Float) actual).as(prefix() + "Float").isEqualTo(Float.parseFloat(value)); } else { fail(prefix() + "cannot compare object of type " + actual.getClass().getName() + " to <" + value + ">"); } }
@CsvMethod public void assertSmallerThan(String value, String... identifier) { GwtInstance gwtInstance = object(identifier); Object actual = gwtInstance.getRaw(); if (actual == null) { fail(prefix() + "number is null: " + gwtInstance.identifierToString()); } else if (actual instanceof Integer) { assertThat((Integer) actual).as(prefix() + "Integer").isLessThan(Integer.parseInt(value)); } else if (actual instanceof Long) { assertThat((Long) actual).as(prefix() + "Long").isLessThan(Long.parseLong(value)); } else if (actual instanceof Double) { assertThat((Double) actual).as(prefix() + "Double").isLessThan(Double.parseDouble(value)); } else if (actual instanceof Float) { assertThat((Float) actual).as(prefix() + "Float").isLessThan(Float.parseFloat(value)); } else { fail(prefix() + "cannot compare object of type " + actual.getClass().getName() + " to <" + value + ">"); } }
@CsvMethod public void assertBiggerThan(String value, String... identifier) { GwtInstance gwtInstance = object(identifier); Object actual = gwtInstance.getRaw(); if (actual == null) { fail(prefix() + "number is null: " + gwtInstance.identifierToString()); } else if (actual instanceof Integer) { assertThat((Integer) actual).as(prefix() + "Integer").isGreaterThan( Integer.parseInt(value)); } else if (actual instanceof Long) { assertThat((Long) actual).as(prefix() + "Long").isGreaterThan(Long.parseLong(value)); } else if (actual instanceof Double) { assertThat((Double) actual).as(prefix() + "Double").isGreaterThan( Double.parseDouble(value)); } else if (actual instanceof Float) { assertThat((Float) actual).as(prefix() + "Float").isGreaterThan(Float.parseFloat(value)); } else { fail(prefix() + "cannot compare object of type " + actual.getClass().getName() + " to <" + value + ">"); } }
@Test public void cartTaxRoundingModeWithTaxesExcludedFromPrice() { final int centAmount = 25; final double taxRate = 0.14; final boolean isTaxIncluded = false; withTaxedCartWithProduct(client(), centAmount, taxRate, isTaxIncluded, cartWithDefaultRounding -> { assertThat(cartWithDefaultRounding.getTaxRoundingMode()).isEqualTo(RoundingMode.HALF_EVEN); assertThat(extractTaxAmount(cartWithDefaultRounding)) .as("Should be rounded half to even") .isEqualTo(0.03); final CartUpdateCommand updateToHalfUp = CartUpdateCommand.of(cartWithDefaultRounding, ChangeTaxRoundingMode.of(RoundingMode.HALF_UP)); final Cart cartWithHalfUpRounding = client().executeBlocking(updateToHalfUp); assertThat(cartWithHalfUpRounding.getTaxRoundingMode()).isEqualTo(RoundingMode.HALF_UP); assertThat(extractTaxAmount(cartWithHalfUpRounding)) .as("Should be rounded half up") .isEqualTo(0.04); final CartUpdateCommand updateToHalfDown = CartUpdateCommand.of(cartWithHalfUpRounding, ChangeTaxRoundingMode.of(RoundingMode.HALF_DOWN)); final Cart cartWithHalfDownRounding = client().executeBlocking(updateToHalfDown); assertThat(cartWithHalfDownRounding.getTaxRoundingMode()).isEqualTo(RoundingMode.HALF_DOWN); assertThat(extractTaxAmount(cartWithHalfDownRounding)) .as("Should be rounded half down") .isEqualTo(0.03); return cartWithHalfDownRounding; }); }
private static void verifyIssue(TestIssue expected, Issue actual) { if (line(actual) > expected.line()) { fail("Missing issue at line " + expected.line()); } if (line(actual) < expected.line()) { fail("Unexpected issue at line " + line(actual) + ": \"" + message(actual) + "\""); } if (expected.message() != null) { assertThat(message(actual)).as("Bad message at line " + expected.line()).isEqualTo(expected.message()); } if (expected.effortToFix() != null) { assertThat(actual.cost()).as("Bad effortToFix at line " + expected.line()).isEqualTo((double) expected.effortToFix()); } if (expected.startColumn() != null) { assertThat(((PreciseIssue) actual).primaryLocation().startLineOffset() + 1).as("Bad start column at line " + expected.line()).isEqualTo(expected.startColumn()); } if (expected.endColumn() != null) { assertThat(((PreciseIssue) actual).primaryLocation().endLineOffset() + 1).as("Bad end column at line " + expected.line()).isEqualTo(expected.endColumn()); } if (expected.endLine() != null) { assertThat(((PreciseIssue) actual).primaryLocation().endLine()).as("Bad end line at line " + expected.line()).isEqualTo(expected.endLine()); } if (!expected.secondaryLocations().isEmpty()) { assertSecondary(actual, expected); } }
@Test public void cartTaxRoundingModeWithTaxesIncludedInPrice() { final int centAmount = 14; final double taxRate = 0.12; final boolean isTaxIncluded = true; withTaxedCartWithProduct(client(), centAmount, taxRate, isTaxIncluded, cartWithDefaultRounding -> { assertThat(cartWithDefaultRounding.getTaxRoundingMode()).isEqualTo(RoundingMode.HALF_EVEN); assertThat(extractTaxAmount(cartWithDefaultRounding)) .as("Should be rounded half to even") .isEqualTo(0.02); final CartUpdateCommand updateToHalfUp = CartUpdateCommand.of(cartWithDefaultRounding, ChangeTaxRoundingMode.of(RoundingMode.HALF_UP)); final Cart cartWithHalfUpRounding = client().executeBlocking(updateToHalfUp); assertThat(cartWithHalfUpRounding.getTaxRoundingMode()).isEqualTo(RoundingMode.HALF_UP); assertThat(extractTaxAmount(cartWithHalfUpRounding)) .as("Should be rounded half up") .isEqualTo(0.01); final CartUpdateCommand updateToHalfDown = CartUpdateCommand.of(cartWithHalfUpRounding, ChangeTaxRoundingMode.of(RoundingMode.HALF_DOWN)); final Cart cartWithHalfDownRounding = client().executeBlocking(updateToHalfDown); assertThat(cartWithHalfDownRounding.getTaxRoundingMode()).isEqualTo(RoundingMode.HALF_DOWN); assertThat(extractTaxAmount(cartWithHalfDownRounding)) .as("Should be rounded half down") .isEqualTo(0.02); return cartWithHalfDownRounding; }); }