@Test public void should_return_a_perf_issue_if_heap_allocation_is_greater_than_expected() { ExpectMaxHeapAllocation annotation = JvmAnnotationBuilder.expectMaxHeapAllocation(3.75 * 1024 , AllocationUnit.MEGA_BYTE); Allocation measuredAllocation = Allocation.ofBytes(4724464025L); VerifiablePerformanceIssue maxHeapAllocationPerfIssueVerifier = MaxHeapAllocationPerfVerifier.INSTANCE; @SuppressWarnings("unchecked") PerfIssue perfIssue = maxHeapAllocationPerfIssueVerifier.verifyPerfIssue(annotation, measuredAllocation); assertThat(perfIssue).isNotEqualTo(PerfIssue.NONE); String description = perfIssue.getDescription(); assertThat(description).contains("Expected heap allocation (test method thread) to be less than 3.75 Giga bytes but is 4.40 Giga bytes (4 724 464 025 bytes)."); }
@Override public PerfIssue verifyPerfIssue(ExpectMaxHeapAllocation annotation, Allocation measuredAllocation) { Allocation maxExpectedAllocation = new Allocation(annotation.value(), annotation.unit()); if(maxExpectedAllocation.isLessThan(measuredAllocation)) { String assertionMessage = "Expected heap allocation (test method thread) to be less than " + byteAllocationMeasureFormatter.format(maxExpectedAllocation) + " but is " + byteAllocationMeasureFormatter.formatAndAppendAllocationInBytes(measuredAllocation) + "."; String description = assertionMessage + System.lineSeparator() + measuredAllocation.getComment(); return new PerfIssue(description); } return PerfIssue.NONE; }
MaxHeapAllocationPerfVerifier implements VerifiablePerformanceIssue<ExpectMaxHeapAllocation, Allocation> { @Override public PerfIssue verifyPerfIssue(ExpectMaxHeapAllocation annotation, Allocation measuredAllocation) { Allocation maxExpectedAllocation = new Allocation(annotation.value(), annotation.unit()); if(maxExpectedAllocation.isLessThan(measuredAllocation)) { String assertionMessage = "Expected heap allocation (test method thread) to be less than " + byteAllocationMeasureFormatter.format(maxExpectedAllocation) + " but is " + byteAllocationMeasureFormatter.formatAndAppendAllocationInBytes(measuredAllocation) + "."; String description = assertionMessage + System.lineSeparator() + measuredAllocation.getComment(); return new PerfIssue(description); } return PerfIssue.NONE; } }
MaxHeapAllocationPerfVerifier implements VerifiablePerformanceIssue<ExpectMaxHeapAllocation, Allocation> { @Override public PerfIssue verifyPerfIssue(ExpectMaxHeapAllocation annotation, Allocation measuredAllocation) { Allocation maxExpectedAllocation = new Allocation(annotation.value(), annotation.unit()); if(maxExpectedAllocation.isLessThan(measuredAllocation)) { String assertionMessage = "Expected heap allocation (test method thread) to be less than " + byteAllocationMeasureFormatter.format(maxExpectedAllocation) + " but is " + byteAllocationMeasureFormatter.formatAndAppendAllocationInBytes(measuredAllocation) + "."; String description = assertionMessage + System.lineSeparator() + measuredAllocation.getComment(); return new PerfIssue(description); } return PerfIssue.NONE; } private  MaxHeapAllocationPerfVerifier(); }
MaxHeapAllocationPerfVerifier implements VerifiablePerformanceIssue<ExpectMaxHeapAllocation, Allocation> { @Override public PerfIssue verifyPerfIssue(ExpectMaxHeapAllocation annotation, Allocation measuredAllocation) { Allocation maxExpectedAllocation = new Allocation(annotation.value(), annotation.unit()); if(maxExpectedAllocation.isLessThan(measuredAllocation)) { String assertionMessage = "Expected heap allocation (test method thread) to be less than " + byteAllocationMeasureFormatter.format(maxExpectedAllocation) + " but is " + byteAllocationMeasureFormatter.formatAndAppendAllocationInBytes(measuredAllocation) + "."; String description = assertionMessage + System.lineSeparator() + measuredAllocation.getComment(); return new PerfIssue(description); } return PerfIssue.NONE; } private  MaxHeapAllocationPerfVerifier(); @Override PerfIssue verifyPerfIssue(ExpectMaxHeapAllocation annotation, Allocation measuredAllocation); }
MaxHeapAllocationPerfVerifier implements VerifiablePerformanceIssue<ExpectMaxHeapAllocation, Allocation> { @Override public PerfIssue verifyPerfIssue(ExpectMaxHeapAllocation annotation, Allocation measuredAllocation) { Allocation maxExpectedAllocation = new Allocation(annotation.value(), annotation.unit()); if(maxExpectedAllocation.isLessThan(measuredAllocation)) { String assertionMessage = "Expected heap allocation (test method thread) to be less than " + byteAllocationMeasureFormatter.format(maxExpectedAllocation) + " but is " + byteAllocationMeasureFormatter.formatAndAppendAllocationInBytes(measuredAllocation) + "."; String description = assertionMessage + System.lineSeparator() + measuredAllocation.getComment(); return new PerfIssue(description); } return PerfIssue.NONE; } private  MaxHeapAllocationPerfVerifier(); @Override PerfIssue verifyPerfIssue(ExpectMaxHeapAllocation annotation, Allocation measuredAllocation); static final VerifiablePerformanceIssue INSTANCE; }