org.assertj.core.data.Percentage Java Examples
The following examples show how to use
org.assertj.core.data.Percentage.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: DefaultPubSubConfigTest.java From ditto with Eclipse Public License 2.0 | 6 votes |
@Test public void underTestReturnsDefaultValuesIfBaseConfigWasEmpty() { final PubSubConfig underTest = DefaultPubSubConfig.of(ConfigFactory.empty()); softly.assertThat(underTest.getSeed()) .as(PubSubConfig.ConfigValue.SEED.getConfigPath()) .startsWith("Lorem ipsum"); softly.assertThat(underTest.getHashFamilySize()) .as(PubSubConfig.ConfigValue.HASH_FAMILY_SIZE.getConfigPath()) .isEqualTo(10); softly.assertThat(underTest.getRestartDelay()) .as(PubSubConfig.ConfigValue.RESTART_DELAY.getConfigPath()) .isEqualTo(Duration.ofSeconds(10L)); softly.assertThat(underTest.getUpdateInterval()) .as(PubSubConfig.ConfigValue.UPDATE_INTERVAL.getConfigPath()) .isEqualTo(Duration.ofSeconds(3L)); softly.assertThat(underTest.getForceUpdateProbability()) .as(PubSubConfig.ConfigValue.FORCE_UPDATE_PROBABILITY.getConfigPath()) .isCloseTo(0.01, Percentage.withPercentage(1.0)); }
Example #2
Source File: RabbitMQEventBusTest.java From james-project with Apache License 2.0 | 6 votes |
@Test void dispatchShouldStopDeliveringEventsShortlyAfterStopIsCalled() throws Exception { eventBus.start(); MailboxListenerCountingSuccessfulExecution listener = new MailboxListenerCountingSuccessfulExecution(); eventBus.register(listener, GROUP_A); try (Closeable closeable = ConcurrentTestRunner.builder() .operation((threadNumber, step) -> eventBus.dispatch(EVENT, KEY_1).block()) .threadCount(THREAD_COUNT) .operationCount(OPERATION_COUNT) .noErrorLogs() .run()) { TimeUnit.SECONDS.sleep(2); eventBus.stop(); eventBus2.stop(); int callsAfterStop = listener.numberOfEventCalls(); TimeUnit.SECONDS.sleep(1); assertThat(listener.numberOfEventCalls()) .isCloseTo(callsAfterStop, Percentage.withPercentage(2)); } }
Example #3
Source File: JsonUtilTest.java From ja-micro with Apache License 2.0 | 6 votes |
@Test public void extractFieldsTest() { String event = "{\"meta\":{\"name\":\"OneVehicleDynamicData\",\"timestamp\":" + "\"2017-02-14T10:20:37.629Z\",\"grouping\":\"OneVehicleFinderData\"," + "\"distribution_key\":\"665292e8-6a3b-4702-9666-b5624d6c8320\"},\"position\":{" + "\"latitude\":48.042999267578125,\"longitude\":11.510173797607422,\"foo\":7}," + "\"vehicle_id\":\"abcd\",\"fuel_level\":999," + "\"charge_level\":50.0,\"odometer\":12345}"; JsonObject json = (JsonObject) new JsonParser().parse(event); assertThat(jsonUtil.extractInteger(json, "odometer", -1)).isEqualTo(12345); assertThat(jsonUtil.extractDouble(json, "charge_level", -1)) .isCloseTo(50, Percentage.withPercentage(1)); assertThat(jsonUtil.extractString(json, "vehicle_id")).isEqualTo("abcd"); //check dot-notation paths assertThat(jsonUtil.extractInteger(json, "position.foo", -1)).isEqualTo(7); assertThat(jsonUtil.extractDouble(json, "position.latitude", 0)) .isCloseTo(48.043, Percentage.withPercentage(1)); assertThat(jsonUtil.extractString(json, "meta.name")).isEqualTo("OneVehicleDynamicData"); }
Example #4
Source File: DefaultUrlStateMergerTest.java From flink-crawler with Apache License 2.0 | 6 votes |
@Test public void testMergingUnfetched() throws Exception { BaseUrlStateMerger merger = new DefaultUrlStateMerger(); ValidUrl url = new ValidUrl("http://domain.com?q=s"); CrawlStateUrl csu1 = new CrawlStateUrl(url, FetchStatus.UNFETCHED, 100); csu1.setScore(1.0f); CrawlStateUrl csu2 = new CrawlStateUrl(url, FetchStatus.UNFETCHED, 100); csu2.setScore(1.0f); CrawlStateUrl mergedValue = new CrawlStateUrl(); MergeResult result = merger.doMerge(csu1, csu2, mergedValue); assertThat(result).isEqualTo(MergeResult.USE_MERGED); assertThat(mergedValue.getUrl()).isEqualTo(url.getUrl()); assertThat(mergedValue.getScore()).isCloseTo(2.0f, Percentage.withPercentage(0.01)); }
Example #5
Source File: DefaultWebsocketConfigTest.java From ditto with Eclipse Public License 2.0 | 6 votes |
@Test public void underTestReturnsValuesOfConfigFile() { final WebsocketConfig underTest = DefaultWebsocketConfig.of(webSocketTestConfig); softly.assertThat(underTest.getSubscriberBackpressureQueueSize()) .as(WebsocketConfigValue.SUBSCRIBER_BACKPRESSURE_QUEUE_SIZE.getConfigPath()) .isEqualTo(23); softly.assertThat(underTest.getPublisherBackpressureBufferSize()) .as(WebsocketConfigValue.PUBLISHER_BACKPRESSURE_BUFFER_SIZE.getConfigPath()) .isEqualTo(42); softly.assertThat(underTest.getThrottlingRejectionFactor()) .as(WebsocketConfigValue.THROTTLING_REJECTION_FACTOR.getConfigPath()) .isCloseTo(1.875, Percentage.withPercentage(1.0)); softly.assertThat(underTest.getThrottlingConfig().getInterval()) .as("throttling.interval") .isEqualTo(Duration.ofSeconds(8L)); softly.assertThat(underTest.getThrottlingConfig().getLimit()) .as("throttling.limit") .isEqualTo(9); }
Example #6
Source File: DefaultPubSubConfigTest.java From ditto with Eclipse Public License 2.0 | 6 votes |
@Test public void underTestReturnsValuesOfConfigFile() { final PubSubConfig underTest = DefaultPubSubConfig.of(pubSubTestConf); softly.assertThat(underTest.getSeed()) .as(PubSubConfig.ConfigValue.SEED.getConfigPath()) .startsWith("Two households"); softly.assertThat(underTest.getHashFamilySize()) .as(PubSubConfig.ConfigValue.HASH_FAMILY_SIZE.getConfigPath()) .isEqualTo(11); softly.assertThat(underTest.getRestartDelay()) .as(PubSubConfig.ConfigValue.RESTART_DELAY.getConfigPath()) .isEqualTo(Duration.ofSeconds(11L)); softly.assertThat(underTest.getUpdateInterval()) .as(PubSubConfig.ConfigValue.UPDATE_INTERVAL.getConfigPath()) .isEqualTo(Duration.ofSeconds(4L)); softly.assertThat(underTest.getForceUpdateProbability()) .as(PubSubConfig.ConfigValue.FORCE_UPDATE_PROBABILITY.getConfigPath()) .isCloseTo(0.011, Percentage.withPercentage(1.0)); }
Example #7
Source File: PreparedKamonTimerTest.java From ditto with Eclipse Public License 2.0 | 5 votes |
@Test public void getRecords() { sut.record(1, TimeUnit.SECONDS); sut.record(5, TimeUnit.NANOSECONDS); final Long[] records = sut.getRecords(); assertThat(records.length).isEqualTo(2); assertThat(records[1]).isCloseTo(TimeUnit.SECONDS.toNanos(1), Percentage.withPercentage(1)); assertThat(records[0]).isCloseTo(TimeUnit.NANOSECONDS.toNanos(5), Percentage.withPercentage(1)); }
Example #8
Source File: RabbitMQEventBusTest.java From james-project with Apache License 2.0 | 5 votes |
@Test void dispatchShouldStopDeliveringEventsShortlyAfterStopIsCalled() throws Exception { eventBus.start(); eventBus2.start(); MailboxListenerCountingSuccessfulExecution listener = new MailboxListenerCountingSuccessfulExecution(); eventBus.register(listener, GROUP_A); eventBus2.register(listener, GROUP_A); try (Closeable closeable = ConcurrentTestRunner.builder() .operation((threadNumber, step) -> eventBus.dispatch(EVENT, KEY_1).block()) .threadCount(THREAD_COUNT) .operationCount(OPERATION_COUNT) .noErrorLogs() .run()) { TimeUnit.SECONDS.sleep(2); eventBus.stop(); eventBus2.stop(); int callsAfterStop = listener.numberOfEventCalls(); TimeUnit.SECONDS.sleep(1); assertThat(listener.numberOfEventCalls()) .isCloseTo(callsAfterStop, Percentage.withPercentage(2)); } }
Example #9
Source File: FluxRetryWhenTest.java From reactor-core with Apache License 2.0 | 5 votes |
@Test public void fluxRetryRandomBackoff_minBackoffFloor() { for (int i = 0; i < 50; i++) { Exception exception = new IOException("boom retry loop #" + i); List<Long> elapsedList = new ArrayList<>(); StepVerifier.withVirtualTime(() -> Flux.concat(Flux.range(0, 2), Flux.error(exception)) .retryWhen(Retry .backoff(1, Duration.ofMillis(100)) .maxBackoff(Duration.ofMillis(2000)) .jitter(0.9) ) .elapsed() .doOnNext(elapsed -> { if (elapsed.getT2() == 0) elapsedList.add(elapsed.getT1());} ) .map(Tuple2::getT2) ) .thenAwait(Duration.ofMinutes(1)) //ensure whatever the jittered delay that we have time to fit 4 retries .expectNext(0, 1) //normal output .expectNext(0, 1) //1 retry attempts .expectErrorSatisfies(e -> assertThat(e).isInstanceOf(IllegalStateException.class) .hasMessage("Retries exhausted: 1/1") .hasCause(exception)) .verify(Duration.ofSeconds(1)); //vts test shouldn't even take that long assertThat(elapsedList).hasSize(2); assertThat(elapsedList, LongAssert.class) .first() .isEqualTo(0L); assertThat(elapsedList, LongAssert.class) .element(1) .isGreaterThanOrEqualTo(100) //min backoff .isCloseTo(100, Percentage.withPercentage(90)); } }
Example #10
Source File: FluxRetryWhenTest.java From reactor-core with Apache License 2.0 | 5 votes |
@Test public void fluxRetryRandomBackoffDefaultMaxDuration() { Exception exception = new IOException("boom retry"); List<Long> elapsedList = new ArrayList<>(); StepVerifier.withVirtualTime(() -> Flux.concat(Flux.range(0, 2), Flux.error(exception)) .retryWhen(Retry.backoff(4, Duration.ofMillis(100))) .elapsed() .doOnNext(elapsed -> { if (elapsed.getT2() == 0) elapsedList.add(elapsed.getT1());} ) .map(Tuple2::getT2) ) .thenAwait(Duration.ofMinutes(1)) //ensure whatever the jittered delay that we have time to fit 4 retries .expectNext(0, 1) //normal output .expectNext(0, 1, 0, 1, 0, 1, 0, 1) //4 retry attempts .expectErrorSatisfies(e -> assertThat(e).isInstanceOf(IllegalStateException.class) .hasMessage("Retries exhausted: 4/4") .hasCause(exception)) .verify(Duration.ofSeconds(1)); //vts test shouldn't even take that long assertThat(elapsedList).hasSize(5); assertThat(elapsedList, LongAssert.class).first() .isEqualTo(0L); assertThat(elapsedList, LongAssert.class).element(1) .isCloseTo(100, Percentage.withPercentage(50)); assertThat(elapsedList, LongAssert.class).element(2) .isCloseTo(200, Percentage.withPercentage(50)); assertThat(elapsedList, LongAssert.class).element(3) .isCloseTo(400, Percentage.withPercentage(50)); assertThat(elapsedList, LongAssert.class).element(4) .isCloseTo(800, Percentage.withPercentage(50)); }
Example #11
Source File: FluxRetryWhenTest.java From reactor-core with Apache License 2.0 | 5 votes |
@Test public void fluxRetryRandomBackoffDefaultJitter() { Exception exception = new IOException("boom retry"); List<Long> elapsedList = new ArrayList<>(); StepVerifier.withVirtualTime(() -> Flux.concat(Flux.range(0, 2), Flux.error(exception)) .retryWhen(Retry .backoff(4, Duration.ofMillis(100)) .maxBackoff(Duration.ofMillis(2000)) ) .elapsed() .doOnNext(elapsed -> { if (elapsed.getT2() == 0) elapsedList.add(elapsed.getT1());} ) .map(Tuple2::getT2) ) .thenAwait(Duration.ofMinutes(1)) //ensure whatever the jittered delay that we have time to fit 4 retries .expectNext(0, 1) //normal output .expectNext(0, 1, 0, 1, 0, 1, 0, 1) //4 retry attempts .expectErrorSatisfies(e -> assertThat(e).isInstanceOf(IllegalStateException.class) .hasMessage("Retries exhausted: 4/4") .hasCause(exception)) .verify(Duration.ofSeconds(1)); //vts test shouldn't even take that long assertThat(elapsedList).hasSize(5); assertThat(elapsedList, LongAssert.class).first() .isEqualTo(0L); assertThat(elapsedList, LongAssert.class).element(1) .isCloseTo(100, Percentage.withPercentage(50)); assertThat(elapsedList, LongAssert.class).element(2) .isCloseTo(200, Percentage.withPercentage(50)); assertThat(elapsedList, LongAssert.class).element(3) .isCloseTo(400, Percentage.withPercentage(50)); assertThat(elapsedList, LongAssert.class).element(4) .isCloseTo(800, Percentage.withPercentage(50)); }
Example #12
Source File: FluxRetryWhenTest.java From reactor-core with Apache License 2.0 | 5 votes |
@Test public void fluxRetryRandomBackoff() { Exception exception = new IOException("boom retry"); List<Long> elapsedList = new ArrayList<>(); StepVerifier.withVirtualTime(() -> Flux.concat(Flux.range(0, 2), Flux.error(exception)) .retryWhen(Retry .backoff(4, Duration.ofMillis(100)) .maxBackoff(Duration.ofMillis(2000)) .jitter(0.1) ) .elapsed() .doOnNext(elapsed -> { if (elapsed.getT2() == 0) elapsedList.add(elapsed.getT1());} ) .map(Tuple2::getT2) ) .thenAwait(Duration.ofMinutes(1)) //ensure whatever the jittered delay that we have time to fit 4 retries .expectNext(0, 1) //normal output .expectNext(0, 1, 0, 1, 0, 1, 0, 1) //4 retry attempts .expectErrorSatisfies(e -> assertThat(e).isInstanceOf(IllegalStateException.class) .hasMessage("Retries exhausted: 4/4") .hasCause(exception)) .verify(Duration.ofSeconds(1)); //vts test shouldn't even take that long assertThat(elapsedList).hasSize(5); assertThat(elapsedList, LongAssert.class).first() .isEqualTo(0L); assertThat(elapsedList, LongAssert.class).element(1) .isCloseTo(100, Percentage.withPercentage(10)); assertThat(elapsedList, LongAssert.class).element(2) .isCloseTo(200, Percentage.withPercentage(10)); assertThat(elapsedList, LongAssert.class).element(3) .isCloseTo(400, Percentage.withPercentage(10)); assertThat(elapsedList, LongAssert.class).element(4) .isCloseTo(800, Percentage.withPercentage(10)); }
Example #13
Source File: MonoRetryWhenTest.java From reactor-core with Apache License 2.0 | 5 votes |
@Test public void monoRetryRandomBackoff_minBackoffFloor() { for (int i = 0; i < 50; i++) { AtomicInteger errorCount = new AtomicInteger(); Exception exception = new IOException("boom retry loop #" + i); List<Long> elapsedList = new ArrayList<>(); StepVerifier.withVirtualTime(() -> Mono.error(exception) .doOnError(e -> { errorCount.incrementAndGet(); elapsedList.add(Schedulers.parallel().now(TimeUnit.MILLISECONDS)); }) .retryWhen(Retry.backoff(1, Duration.ofMillis(100)) .maxBackoff(Duration.ofMillis(2000)) .jitter(0.9) ) ) .thenAwait(Duration.ofMinutes(1)) //ensure whatever the jittered delay that we have time to fit 4 retries .expectErrorSatisfies(e -> assertThat(e).isInstanceOf(IllegalStateException.class) .hasMessage("Retries exhausted: 1/1") .hasCause(exception)) .verify(Duration.ofSeconds(1)); //vts test shouldn't even take that long assertThat(errorCount).hasValue(2); assertThat(elapsedList).hasSize(2); assertThat(elapsedList.get(0)).isEqualTo(0L); assertThat(elapsedList.get(1) - elapsedList.get(0)) .isGreaterThanOrEqualTo(100) //min backoff .isCloseTo(100, Percentage.withPercentage(90)); } }
Example #14
Source File: MonoRetryWhenTest.java From reactor-core with Apache License 2.0 | 5 votes |
@Test public void monoRetryRandomBackoffDefaultMaxDuration() { AtomicInteger errorCount = new AtomicInteger(); Exception exception = new IOException("boom retry"); List<Long> elapsedList = new ArrayList<>(); StepVerifier.withVirtualTime(() -> Mono.error(exception) .doOnError(e -> { errorCount.incrementAndGet(); elapsedList.add(Schedulers.parallel().now(TimeUnit.MILLISECONDS)); }) .retryWhen(Retry.backoff(4, Duration.ofMillis(100))) ) .thenAwait(Duration.ofMinutes(1)) //ensure whatever the jittered delay that we have time to fit 4 retries .expectErrorSatisfies(e -> assertThat(e).isInstanceOf(IllegalStateException.class) .hasMessage("Retries exhausted: 4/4") .hasCause(exception)) .verify(Duration.ofSeconds(1)); //vts test shouldn't even take that long assertThat(errorCount).hasValue(5); assertThat(elapsedList).hasSize(5); assertThat(elapsedList.get(0)).isEqualTo(0L); assertThat(elapsedList.get(1) - elapsedList.get(0)) .isGreaterThanOrEqualTo(100) //min backoff .isCloseTo(100, Percentage.withPercentage(50)); assertThat(elapsedList.get(2) - elapsedList.get(1)) .isCloseTo(200, Percentage.withPercentage(50)); assertThat(elapsedList.get(3) - elapsedList.get(2)) .isCloseTo(400, Percentage.withPercentage(50)); assertThat(elapsedList.get(4) - elapsedList.get(3)) .isCloseTo(800, Percentage.withPercentage(50)); }
Example #15
Source File: MonoRetryWhenTest.java From reactor-core with Apache License 2.0 | 5 votes |
@Test public void monoRetryRandomBackoffDefaultJitter() { AtomicInteger errorCount = new AtomicInteger(); Exception exception = new IOException("boom retry"); List<Long> elapsedList = new ArrayList<>(); StepVerifier.withVirtualTime(() -> Mono.error(exception) .doOnError(e -> { errorCount.incrementAndGet(); elapsedList.add(Schedulers.parallel().now(TimeUnit.MILLISECONDS)); }) .retryWhen(Retry.backoff(4, Duration.ofMillis(100)) .maxBackoff(Duration.ofMillis(2000)) ) ) .thenAwait(Duration.ofMinutes(1)) //ensure whatever the jittered delay that we have time to fit 4 retries .expectErrorSatisfies(e -> assertThat(e).isInstanceOf(IllegalStateException.class) .hasMessage("Retries exhausted: 4/4") .hasCause(exception)) .verify(Duration.ofSeconds(1)); //vts test shouldn't even take that long assertThat(errorCount).hasValue(5); assertThat(elapsedList).hasSize(5); assertThat(elapsedList.get(0)).isEqualTo(0L); assertThat(elapsedList.get(1) - elapsedList.get(0)) .isGreaterThanOrEqualTo(100) //min backoff .isCloseTo(100, Percentage.withPercentage(50)); assertThat(elapsedList.get(2) - elapsedList.get(1)) .isCloseTo(200, Percentage.withPercentage(50)); assertThat(elapsedList.get(3) - elapsedList.get(2)) .isCloseTo(400, Percentage.withPercentage(50)); assertThat(elapsedList.get(4) - elapsedList.get(3)) .isCloseTo(800, Percentage.withPercentage(50)); }
Example #16
Source File: MonoRetryWhenTest.java From reactor-core with Apache License 2.0 | 5 votes |
@Test public void monoRetryRandomBackoff() { AtomicInteger errorCount = new AtomicInteger(); Exception exception = new IOException("boom retry"); List<Long> elapsedList = new ArrayList<>(); StepVerifier.withVirtualTime(() -> Mono.error(exception) .doOnError(e -> { errorCount.incrementAndGet(); elapsedList.add(Schedulers.parallel().now(TimeUnit.MILLISECONDS)); }) .retryWhen(Retry.backoff(4, Duration.ofMillis(100)) .maxBackoff(Duration.ofMillis(2000)) .jitter(0.1) ) ) .thenAwait(Duration.ofMinutes(1)) //ensure whatever the jittered delay that we have time to fit 4 retries .expectErrorSatisfies(e -> assertThat(e).isInstanceOf(IllegalStateException.class) .hasMessage("Retries exhausted: 4/4") .hasCause(exception)) .verify(Duration.ofSeconds(1)); //vts test shouldn't even take that long assertThat(errorCount).hasValue(5); assertThat(elapsedList).hasSize(5); assertThat(elapsedList.get(0)).isEqualTo(0L); assertThat(elapsedList.get(1) - elapsedList.get(0)) .isGreaterThanOrEqualTo(100) //min backoff .isCloseTo(100, Percentage.withPercentage(10)); assertThat(elapsedList.get(2) - elapsedList.get(1)) .isCloseTo(200, Percentage.withPercentage(10)); assertThat(elapsedList.get(3) - elapsedList.get(2)) .isCloseTo(400, Percentage.withPercentage(10)); assertThat(elapsedList.get(4) - elapsedList.get(3)) .isCloseTo(800, Percentage.withPercentage(10)); }
Example #17
Source File: KamonHistogramTest.java From ditto with Eclipse Public License 2.0 | 5 votes |
@Test public void record() { sut.record(4711L); final Long[] recordedValues = sut.getRecordedValues(); assertThat(recordedValues.length).isEqualTo(1); assertThat(recordedValues[0]).isCloseTo(4711L, Percentage.withPercentage(1)); }
Example #18
Source File: DefaultWebsocketConfigTest.java From ditto with Eclipse Public License 2.0 | 5 votes |
@Test public void underTestReturnsDefaultValuesIfBaseConfigWasEmpty() { final WebsocketConfig underTest = DefaultWebsocketConfig.of(ConfigFactory.empty()); softly.assertThat(underTest.getSubscriberBackpressureQueueSize()) .as(WebsocketConfigValue.SUBSCRIBER_BACKPRESSURE_QUEUE_SIZE.getConfigPath()) .isEqualTo(WebsocketConfigValue.SUBSCRIBER_BACKPRESSURE_QUEUE_SIZE.getDefaultValue()); softly.assertThat(underTest.getPublisherBackpressureBufferSize()) .as(WebsocketConfigValue.PUBLISHER_BACKPRESSURE_BUFFER_SIZE.getConfigPath()) .isEqualTo(WebsocketConfigValue.PUBLISHER_BACKPRESSURE_BUFFER_SIZE.getDefaultValue()); softly.assertThat(underTest.getThrottlingRejectionFactor()) .as(WebsocketConfigValue.THROTTLING_REJECTION_FACTOR.getConfigPath()) .isCloseTo((Double) WebsocketConfigValue.THROTTLING_REJECTION_FACTOR.getDefaultValue(), Percentage.withPercentage(1.0)); }
Example #19
Source File: BoundarySamplerTest.java From brave with Apache License 2.0 | 4 votes |
@Override Percentage expectedErrorProbability() { return withPercentage(10); }
Example #20
Source File: CountingSamplerTest.java From brave with Apache License 2.0 | 4 votes |
@Override Percentage expectedErrorProbability() { return withPercentage(0); }
Example #21
Source File: Invoice_DocumentManagement_IntegTest.java From estatio with Apache License 2.0 | 4 votes |
@Test public void when_prelim_letter_any_invoice_receipts_attached_are_ignored() throws IOException { // given Invoice invoice = findInvoice(InvoiceStatus.NEW); DocAndCommForPrelimLetter prelimLetterViewModel = prelimLetterViewModelOf(invoice); assertNoDocumentOrCommunicationsFor(prelimLetterViewModel); // and given there is a receipt attached to the invoice receiptAttachedToInvoice(invoice, "receipt-1.pdf"); invoice = findInvoice(InvoiceStatus.NEW); List<Paperclip> paperclips = paperclipRepository.findByAttachedTo(invoice); assertThat(paperclips).hasSize(1); final DocumentAbstract attachedReceipt = paperclips.get(0).getDocument(); // when DocumentTemplate prelimLetterTemplate = findDocumentTemplateFor(DocumentTypeData.PRELIM_LETTER, invoice); wrap(mixin(InvoiceForLease_prepare.class, invoice)).act(prelimLetterTemplate); Document document = prelimLetterOf(invoice); // (clearing queryResultsCache) invoice = findInvoice(InvoiceStatus.NEW); prelimLetterViewModel = prelimLetterViewModelOf(invoice); // then the newly created prelim letter doc Document prelimLetterDoc = mixin(DocAndCommForPrelimLetter_document.class, prelimLetterViewModel).$$(); assertThat(prelimLetterDoc).isSameAs(document); assertThat(document.getState()).isEqualTo(DocumentState.RENDERED); assertThat(mixin(DocAndCommForPrelimLetter_communication.class, prelimLetterViewModel).$$()).isNull(); // is attached to only invoice paperclips = paperclipRepository.findByDocument(prelimLetterDoc); assertThat(paperclips).hasSize(1); assertThat(paperclips).extracting(x -> x.getAttachedTo()).contains(invoice); // while the invoice itself now has two attachments (the original receipt and the newly created doc) paperclips = paperclipRepository.findByAttachedTo(invoice); assertThat(paperclips).hasSize(2); assertThat(paperclips).extracting(x -> x.getDocument()).contains(attachedReceipt, prelimLetterDoc); // and given PostalAddress sendTo = sendToFor(invoice, PostalAddress.class); // when Blob downloaded = wrap(mixin(InvoiceForLease_sendByPost.class, invoice)).$$(document, sendTo); invoice = findInvoice(InvoiceStatus.NEW); prelimLetterViewModel = prelimLetterViewModelOf(invoice); // then the bytes of downloaded are at least as many as that of the original document (receipt is ignored) assertThat(downloaded).isNotNull(); assertThat(downloaded.getBytes().length).isCloseTo(document.getBlobBytes().length, Percentage.withPercentage(10)); final Communication prelimLetterComm = mixin(DocAndCommForPrelimLetter_communication.class, prelimLetterViewModel).$$(); // then the comm is automatically sent assertThat(prelimLetterComm.getState()).isEqualTo(CommunicationState.SENT); assertThat(prelimLetterComm.getCreatedAt()).isNotNull(); assertThat(prelimLetterComm.getSentAt()).isNotNull(); assertThat(prelimLetterComm.getSubject()).isEqualTo("Prelim letter 2012-01-01, OXF-POISON-003 Poison Perfumeries.pdf"); // and PL doc now also attached to comm, invoice.buyer and invoice.seller (as well as invoice) paperclips = paperclipRepository.findByDocument(prelimLetterDoc); assertThat(paperclips).hasSize(4); assertThat(paperclips).extracting(Paperclip::getAttachedTo).contains(invoice, invoice.getBuyer(), invoice.getSeller(), prelimLetterComm); // and comm attached to PL paperclips = paperclipRepository.findByAttachedTo(prelimLetterComm); assertThat(paperclips).hasSize(1); assertThat(paperclips).extracting(Paperclip::getDocument).contains(prelimLetterDoc); }
Example #22
Source File: MonoRetryWhenTest.java From reactor-core with Apache License 2.0 | 4 votes |
@Test public void monoRetryRandomBackoff_maxBackoffShaves() { AtomicInteger errorCount = new AtomicInteger(); Exception exception = new IOException("boom retry"); List<Long> elapsedList = new ArrayList<>(); StepVerifier.withVirtualTime(() -> Mono.error(exception) .doOnError(e -> { errorCount.incrementAndGet(); elapsedList.add(Schedulers.parallel().now(TimeUnit.MILLISECONDS)); }) .retryWhen(Retry.backoff(4, Duration.ofMillis(100)) .maxBackoff(Duration.ofMillis(220)) .jitter(0.9) ) ) .thenAwait(Duration.ofMinutes(1)) //ensure whatever the jittered delay that we have time to fit 4 retries .expectErrorSatisfies(e -> assertThat(e).isInstanceOf(IllegalStateException.class) .hasMessage("Retries exhausted: 4/4") .hasCause(exception)) .verify(Duration.ofSeconds(1)); //vts test shouldn't even take that long assertThat(errorCount).hasValue(5); assertThat(elapsedList).hasSize(5); assertThat(elapsedList.get(0)).isEqualTo(0L); assertThat(elapsedList.get(1) - elapsedList.get(0)) .isGreaterThanOrEqualTo(100) //min backoff .isCloseTo(100, Percentage.withPercentage(90)); assertThat(elapsedList.get(2) - elapsedList.get(1)) .isCloseTo(200, Percentage.withPercentage(90)) .isGreaterThanOrEqualTo(100) .isLessThanOrEqualTo(220); assertThat(elapsedList.get(3) - elapsedList.get(2)) .isGreaterThanOrEqualTo(100) .isLessThanOrEqualTo(220); assertThat(elapsedList.get(4) - elapsedList.get(3)) .isGreaterThanOrEqualTo(100) .isLessThanOrEqualTo(220); }
Example #23
Source File: KeepAliveHandlerTest.java From armeria with Apache License 2.0 | 4 votes |
private void assertMeter(String name, double expected, Percentage percentage) { assertThat(MoreMeters.measureAll(meterRegistry)).anySatisfy((name0, value) -> { assertThat(name0).isEqualTo(name); assertThat(value).isCloseTo(expected, percentage); }); }
Example #24
Source File: FluxRetryWhenTest.java From reactor-core with Apache License 2.0 | 4 votes |
@Test public void fluxRetryRandomBackoff_maxBackoffShaves() { Exception exception = new IOException("boom retry"); List<Long> elapsedList = new ArrayList<>(); StepVerifier.withVirtualTime(() -> Flux.concat(Flux.range(0, 2), Flux.error(exception)) .retryWhen(Retry .backoff(4, Duration.ofMillis(100)) .maxBackoff(Duration.ofMillis(220)) .jitter(0.9) ) .elapsed() .doOnNext(elapsed -> { if (elapsed.getT2() == 0) elapsedList.add(elapsed.getT1());} ) .map(Tuple2::getT2) ) .thenAwait(Duration.ofMinutes(1)) //ensure whatever the jittered delay that we have time to fit 4 retries .expectNext(0, 1) //normal output .expectNext(0, 1, 0, 1, 0, 1, 0, 1) //4 retry attempts .expectErrorSatisfies(e -> assertThat(e).isInstanceOf(IllegalStateException.class) .hasMessage("Retries exhausted: 4/4") .hasCause(exception)) .verify(Duration.ofSeconds(1)); //vts test shouldn't even take that long assertThat(elapsedList).hasSize(5); assertThat(elapsedList, LongAssert.class) .first() .isEqualTo(0L); assertThat(elapsedList, LongAssert.class) .element(1) .isGreaterThanOrEqualTo(100) //min backoff .isCloseTo(100, Percentage.withPercentage(90)); assertThat(elapsedList, LongAssert.class) .element(2) .isCloseTo(200, Percentage.withPercentage(90)) .isGreaterThanOrEqualTo(100) .isLessThanOrEqualTo(220); assertThat(elapsedList, LongAssert.class) .element(3) .isGreaterThanOrEqualTo(100) .isLessThanOrEqualTo(220); assertThat(elapsedList, LongAssert.class) .element(4) .isGreaterThanOrEqualTo(100) .isLessThanOrEqualTo(220); }
Example #25
Source File: SuiteTests.java From osmo with GNU Lesser General Public License v2.1 | 4 votes |
private void assertTestStepStat(TestSuite suite, String name, double mean, double std) { SummaryStatistics stats = suite.getCurrentTest().statsFor(name); assertThat(stats).isNotNull(); assertThat(stats.getMean()).isEqualTo(mean); assertThat(stats.getStandardDeviation()).isCloseTo(std, Percentage.withPercentage(0.02)); }
Example #26
Source File: SuiteTests.java From osmo with GNU Lesser General Public License v2.1 | 4 votes |
private void assertSuiteStepStat(TestSuite suite, String name, double mean, double std) { SummaryStatistics stats = suite.statsForStep(name); assertThat(stats).isNotNull(); assertThat(stats.getMean()).isEqualTo(mean); assertThat(stats.getStandardDeviation()).isCloseTo(std, Percentage.withPercentage(0.02)); }
Example #27
Source File: SamplerTest.java From brave with Apache License 2.0 | votes |
abstract Percentage expectedErrorProbability();