Refine search
@Test public void withInitiallyDelayedFixedRateTask() throws InterruptedException { Assume.group(TestGroup.PERFORMANCE); ctx = new AnnotationConfigApplicationContext(FixedRateTaskConfig_withInitialDelay.class); Thread.sleep(1950); AtomicInteger counter = ctx.getBean(AtomicInteger.class); // The @Scheduled method should have been called at least once but // not more times than the delay allows. assertThat(counter.get(), both(greaterThan(0)).and(lessThanOrEqualTo(10))); }
private void assertBetween(Long actual, long min, long max) { assertThat(actual, greaterThanOrEqualTo(min)); assertThat(actual, lessThanOrEqualTo(max)); }
private void checkBetween(double start, double end, Duration time) { assertThat((double) time.toMillis(), greaterThanOrEqualTo(start)); assertThat((double) time.toMillis(), lessThanOrEqualTo(end)); } }
private void assertLessThanOrEqualTo( Value[] o1, Value[] o2 ) { if ( o1 == null || o2 == null ) { return; } int length = Math.min( o1.length, o2.length ); for ( int i = 0; i < length; i++ ) { int compare = Values.COMPARATOR.compare( o1[i], o2[i] ); assertThat( "expected less than or equal to but was " + Arrays.toString( o1 ) + " and " + Arrays.toString( o2 ), compare, lessThanOrEqualTo( 0 ) ); if ( compare != 0 ) { return; } } }
private void expectCallsToCheck( ExecutionMonitor multiMonitor, Object... alternatingMonitorAndCount ) { multiMonitor.check( null ); // null, knowing that our monitors in this test doesn't use 'em for ( int i = 0; i < alternatingMonitorAndCount.length; i++ ) { TestableMonitor monitor = (TestableMonitor) alternatingMonitorAndCount[i++]; int count = (Integer) alternatingMonitorAndCount[i]; assertThat( monitor.timesPolled, lessThanOrEqualTo( count ) ); if ( monitor.timesPolled < count ) { fail( "Polls didn't occur, expected " + Arrays.toString( alternatingMonitorAndCount ) ); } } }
@Test public void testRandomAsciiRange() { final int expectedMinLengthInclusive = 1; final int expectedMaxLengthExclusive = 11; final String pattern = "^\\p{ASCII}{" + expectedMinLengthInclusive + ',' + expectedMaxLengthExclusive + "}$"; int maxCreatedLength = expectedMinLengthInclusive; int minCreatedLength = expectedMaxLengthExclusive - 1; for (int i = 0; i < 1000; i++) { final String s = RandomStringUtils.randomAscii(expectedMinLengthInclusive, expectedMaxLengthExclusive); assertThat("within range", s.length(), allOf(greaterThanOrEqualTo(expectedMinLengthInclusive), lessThanOrEqualTo(expectedMaxLengthExclusive - 1))); assertTrue(s, s.matches(pattern)); if (s.length() < minCreatedLength) { minCreatedLength = s.length(); } if (s.length() > maxCreatedLength) { maxCreatedLength = s.length(); } } assertThat("min generated, may fail randomly rarely", minCreatedLength, is(expectedMinLengthInclusive)); assertThat("max generated, may fail randomly rarely", maxCreatedLength, is(expectedMaxLengthExclusive - 1)); }
@Test public void testRandomNumericRange() { final int expectedMinLengthInclusive = 1; final int expectedMaxLengthExclusive = 11; final String pattern = "^\\p{Digit}{" + expectedMinLengthInclusive + ',' + expectedMaxLengthExclusive + "}$"; int maxCreatedLength = expectedMinLengthInclusive; int minCreatedLength = expectedMaxLengthExclusive - 1; for (int i = 0; i < 1000; i++) { final String s = RandomStringUtils.randomNumeric(expectedMinLengthInclusive, expectedMaxLengthExclusive); assertThat("within range", s.length(), allOf(greaterThanOrEqualTo(expectedMinLengthInclusive), lessThanOrEqualTo(expectedMaxLengthExclusive - 1))); assertTrue(s, s.matches(pattern)); if (s.length() < minCreatedLength) { minCreatedLength = s.length(); } if (s.length() > maxCreatedLength) { maxCreatedLength = s.length(); } } assertThat("min generated, may fail randomly rarely", minCreatedLength, is(expectedMinLengthInclusive)); assertThat("max generated, may fail randomly rarely", maxCreatedLength, is(expectedMaxLengthExclusive - 1)); }
@Test public void testRandomAlphabeticRange() { final int expectedMinLengthInclusive = 1; final int expectedMaxLengthExclusive = 11; final String pattern = "^\\p{Alpha}{" + expectedMinLengthInclusive + ',' + expectedMaxLengthExclusive + "}$"; int maxCreatedLength = expectedMinLengthInclusive; int minCreatedLength = expectedMaxLengthExclusive - 1; for (int i = 0; i < 1000; i++) { final String s = RandomStringUtils.randomAlphabetic(expectedMinLengthInclusive, expectedMaxLengthExclusive); assertThat("within range", s.length(), allOf(greaterThanOrEqualTo(expectedMinLengthInclusive), lessThanOrEqualTo(expectedMaxLengthExclusive - 1))); assertTrue(s, s.matches(pattern)); if (s.length() < minCreatedLength) { minCreatedLength = s.length(); } if (s.length() > maxCreatedLength) { maxCreatedLength = s.length(); } } assertThat("min generated, may fail randomly rarely", minCreatedLength, is(expectedMinLengthInclusive)); assertThat("max generated, may fail randomly rarely", maxCreatedLength, is(expectedMaxLengthExclusive - 1)); }
@Test public void testRandomPrintRange() { final int expectedMinLengthInclusive = 1; final int expectedMaxLengthExclusive = 11; final String pattern = "^\\p{Print}{" + expectedMinLengthInclusive + ',' + expectedMaxLengthExclusive + "}$"; int maxCreatedLength = expectedMinLengthInclusive; int minCreatedLength = expectedMaxLengthExclusive - 1; for (int i = 0; i < 1000; i++) { final String s = RandomStringUtils.randomPrint(expectedMinLengthInclusive, expectedMaxLengthExclusive); assertThat("within range", s.length(), allOf(greaterThanOrEqualTo(expectedMinLengthInclusive), lessThanOrEqualTo(expectedMaxLengthExclusive - 1))); assertTrue(s, s.matches(pattern)); if (s.length() < minCreatedLength) { minCreatedLength = s.length(); } if (s.length() > maxCreatedLength) { maxCreatedLength = s.length(); } } assertThat("min generated, may fail randomly rarely", minCreatedLength, is(expectedMinLengthInclusive)); assertThat("max generated, may fail randomly rarely", maxCreatedLength, is(expectedMaxLengthExclusive - 1)); }
@Test public void testRandomAlphanumericRange() { final int expectedMinLengthInclusive = 1; final int expectedMaxLengthExclusive = 11; final String pattern = "^\\p{Alnum}{" + expectedMinLengthInclusive + ',' + expectedMaxLengthExclusive + "}$"; int maxCreatedLength = expectedMinLengthInclusive; int minCreatedLength = expectedMaxLengthExclusive - 1; for (int i = 0; i < 1000; i++) { final String s = RandomStringUtils.randomAlphanumeric(expectedMinLengthInclusive, expectedMaxLengthExclusive); assertThat("within range", s.length(), allOf(greaterThanOrEqualTo(expectedMinLengthInclusive), lessThanOrEqualTo(expectedMaxLengthExclusive - 1))); assertTrue(s, s.matches(pattern)); if (s.length() < minCreatedLength) { minCreatedLength = s.length(); } if (s.length() > maxCreatedLength) { maxCreatedLength = s.length(); } } assertThat("min generated, may fail randomly rarely", minCreatedLength, is(expectedMinLengthInclusive)); assertThat("max generated, may fail randomly rarely", maxCreatedLength, is(expectedMaxLengthExclusive - 1)); }
@Test public void testRandomGraphRange() { final int expectedMinLengthInclusive = 1; final int expectedMaxLengthExclusive = 11; final String pattern = "^\\p{Graph}{" + expectedMinLengthInclusive + ',' + expectedMaxLengthExclusive + "}$"; int maxCreatedLength = expectedMinLengthInclusive; int minCreatedLength = expectedMaxLengthExclusive - 1; for (int i = 0; i < 1000; i++) { final String s = RandomStringUtils.randomGraph(expectedMinLengthInclusive, expectedMaxLengthExclusive); assertThat("within range", s.length(), allOf(greaterThanOrEqualTo(expectedMinLengthInclusive), lessThanOrEqualTo(expectedMaxLengthExclusive - 1))); assertTrue(s, s.matches(pattern)); if (s.length() < minCreatedLength) { minCreatedLength = s.length(); } if (s.length() > maxCreatedLength) { maxCreatedLength = s.length(); } } assertThat("min generated, may fail randomly rarely", minCreatedLength, is(expectedMinLengthInclusive)); assertThat("max generated, may fail randomly rarely", maxCreatedLength, is(expectedMaxLengthExclusive - 1)); }
@Test public void should_return_random_with_range_and_format_from_template() throws IOException { runWithConfiguration("template_with_function.json"); String response = helper.get(remoteUrl("/random_template_with_range_and_format")); double result = Double.parseDouble(response); assertThat(result, lessThan(100d)); assertThat(result, greaterThan(0d)); String target = Iterables.get(Splitter.on('.').split(response), 1); assertThat(target.length(), lessThanOrEqualTo(6)); }
@Test public void nextAsciiString() { for ( int i = 0; i < ITERATIONS; i++ ) { TextValue textValue = randomValues.nextAsciiTextValue( 10, 20 ); String asString = textValue.stringValue(); int length = asString.length(); assertThat( length, greaterThanOrEqualTo( 10 ) ); assertThat( length, lessThanOrEqualTo( 20 ) ); } }
@Override public void run() throws Exception { String response = helper.get(remoteUrl("/random")); try { double result = Double.parseDouble(response); assertThat(result, lessThan(100d)); assertThat(result, greaterThan(0d)); String target = Splitter.on('.').splitToList(response).get(1); assertThat(target.length(), lessThanOrEqualTo(6)); } catch (NumberFormatException e) { fail(); } } });
@Test public void should_return_random_with_format_from_template() throws IOException { runWithConfiguration("template_with_function.json"); String response = helper.get(remoteUrl("/random_template_with_format")); String target = Iterables.get(Splitter.on('.').split(response), 1); assertThat(target.length(), lessThanOrEqualTo(6)); }
@Test public void nextLongValueBoundedAndShifted() { Set<Value> values = new HashSet<>(); for ( int i = 0; i < ITERATIONS; i++ ) { LongValue value = randomValues.nextLongValue( 1337, 1337 + BOUND ); assertThat( value, notNullValue() ); assertThat( value.compareTo( longValue( 1337 ) ), greaterThanOrEqualTo( 0 ) ); assertThat( value.toString(), value.compareTo( longValue( 1337 + BOUND ) ), lessThanOrEqualTo( 0 ) ); values.add( value ); } assertThat( values.size(), greaterThan( 1 ) ); }
@Test public void nextString() { for ( int i = 0; i < ITERATIONS; i++ ) { TextValue textValue = randomValues.nextTextValue( 10, 20 ); String asString = textValue.stringValue(); int length = asString.codePointCount( 0, asString.length() ); assertThat( length, greaterThanOrEqualTo( 10 ) ); assertThat( length, lessThanOrEqualTo( 20 ) ); } }
@Test public void shouldLimitSizeToMaxSize() { for (int i = 0; i < (CAPACITY * 2); i++) { cache.put(i, Integer.toString(i)); } assertThat(cache.size(), greaterThan(0)); assertThat(cache.size(), lessThanOrEqualTo(CAPACITY)); }
@Test public void initialisingBufferMustConsumeMemoryFromMemoryManager() { long initialUsedMemory = mman.usedMemory(); pageList.initBuffer( pageRef ); long resultingUsedMemory = mman.usedMemory(); int allocatedMemory = (int) (resultingUsedMemory - initialUsedMemory); assertThat( allocatedMemory, greaterThanOrEqualTo( pageSize ) ); assertThat( allocatedMemory, lessThanOrEqualTo( pageSize + ALIGNMENT ) ); }
@Test public void shouldNotBlockPublisherWhenSendingToServer() throws InterruptedException { SlowResource resource = new SlowResource(); final ConsoleOutputTransmitter transmitter = new ConsoleOutputTransmitter(resource); int numberToSend = 4; int actuallySent = transmitData(transmitter, numberToSend); transmitter.stop(); assertThat("Send should not block.", numberToSend, lessThanOrEqualTo(actuallySent)); }