Refine search
@Test public void withSubclass() throws InterruptedException { Assume.group(TestGroup.PERFORMANCE); ctx = new AnnotationConfigApplicationContext(FixedRateTaskConfigSubclass.class); assertEquals(2, ctx.getBean(ScheduledTaskHolder.class).getScheduledTasks().size()); Thread.sleep(100); assertThat(ctx.getBean(AtomicInteger.class).get(), greaterThanOrEqualTo(10)); }
private static void assertNumberOfFreeIdsEquals( File databaseDirectory, FileSystemAbstraction fs, long numberOfFreeIds ) { long fileSize = fs.getFileSize( new File( databaseDirectory, "neostore.propertystore.db.strings.id" ) ); long fileSizeWithoutHeader = fileSize - 9; long actualFreeIds = fileSizeWithoutHeader / 8; assertThat( "Id file should at least have a 9 byte header", fileSize, greaterThanOrEqualTo( 9L ) ); assertThat( "File should contain the expected number of free ids", actualFreeIds, is( numberOfFreeIds ) ); assertThat( "File size should not contain more bytes than expected", 8 * numberOfFreeIds, is( fileSizeWithoutHeader ) ); } }
@Test public void everyTableShouldHaveAPrimaryKeyColumn() throws Exception { flyway.migrate(); List<String> tableNames = jdbcTemplate.queryForList(getAllTableNames, String.class, jdbcTemplate.getDataSource().getConnection().getCatalog()); assertThat(tableNames, hasSize(greaterThan(0))); for (String tableName : tableNames) { int count = jdbcTemplate.queryForObject(checkPrimaryKeyExists, Integer.class, jdbcTemplate.getDataSource().getConnection().getCatalog(), tableName); assertThat(format("%s is missing primary key", tableName), count, greaterThanOrEqualTo(1)); } }
@Test public void withFixedRateTask() throws InterruptedException { Assume.group(TestGroup.PERFORMANCE); ctx = new AnnotationConfigApplicationContext(FixedRateTaskConfig.class); assertEquals(2, ctx.getBean(ScheduledTaskHolder.class).getScheduledTasks().size()); Thread.sleep(100); assertThat(ctx.getBean(AtomicInteger.class).get(), greaterThanOrEqualTo(10)); }
@Test public void everyTableShouldHaveAPrimaryKeyColumn() throws Exception { flyway.migrate(); List<String> tableNames = jdbcTemplate.queryForList(getAllTableNames, String.class, jdbcTemplate.getDataSource().getConnection().getCatalog()); assertThat(tableNames, hasSize(greaterThan(0))); for (String tableName : tableNames) { int count = jdbcTemplate.queryForObject(checkPrimaryKeyExists, Integer.class, jdbcTemplate.getDataSource().getConnection().getCatalog(), tableName); assertThat(format("%s is missing primary key", tableName), count, greaterThanOrEqualTo(1)); } }
private void checkBetween(double start, double end, Duration time) { assertThat((double) time.toMillis(), greaterThanOrEqualTo(start)); assertThat((double) time.toMillis(), lessThanOrEqualTo(end)); } }
@Test public void withExplicitScheduledTaskRegistrar() throws InterruptedException { Assume.group(TestGroup.PERFORMANCE); ctx = new AnnotationConfigApplicationContext(ExplicitScheduledTaskRegistrarConfig.class); assertEquals(1, ctx.getBean(ScheduledTaskHolder.class).getScheduledTasks().size()); Thread.sleep(100); assertThat(ctx.getBean(AtomicInteger.class).get(), greaterThanOrEqualTo(10)); assertThat(ctx.getBean(ExplicitScheduledTaskRegistrarConfig.class).threadName, startsWith("explicitScheduler1")); }
@Test public void everyTableShouldHaveAPrimaryKeyColumn() throws Exception { flyway.migrate(); List<String> tableNames = jdbcTemplate.queryForList(getAllTableNames, String.class, jdbcTemplate.getDataSource().getConnection().getCatalog()); assertThat(tableNames, hasSize(greaterThan(0))); for (String tableName : tableNames) { int count = jdbcTemplate.queryForObject(checkPrimaryKeyExists, Integer.class, jdbcTemplate.getDataSource().getConnection().getCatalog(), tableName); assertThat(format("%s is missing primary key", tableName), count, greaterThanOrEqualTo(1)); } try { jdbcTemplate.execute(insertNewOauthCodeRecord); } catch (Exception _) { fail("oauth_code table should auto increment primary key when inserting data."); } }
private void assertBetween(Long actual, long min, long max) { assertThat(actual, greaterThanOrEqualTo(min)); assertThat(actual, lessThanOrEqualTo(max)); }
@Test public void withExplicitScheduler() throws InterruptedException { Assume.group(TestGroup.PERFORMANCE); ctx = new AnnotationConfigApplicationContext(ExplicitSchedulerConfig.class); assertEquals(1, ctx.getBean(ScheduledTaskHolder.class).getScheduledTasks().size()); Thread.sleep(100); assertThat(ctx.getBean(AtomicInteger.class).get(), greaterThanOrEqualTo(10)); assertThat(ctx.getBean(ExplicitSchedulerConfig.class).threadName, startsWith("explicitScheduler-")); assertTrue(Arrays.asList(ctx.getDefaultListableBeanFactory().getDependentBeans("myTaskScheduler")).contains( TaskManagementConfigUtils.SCHEDULED_ANNOTATION_PROCESSOR_BEAN_NAME)); }
@Test public void shouldLockRelationshipsWhileReadingThem() throws Exception { // given @SuppressWarnings( "unchecked" ) Visitor<EntityUpdates,Exception> visitor = mock( Visitor.class ); StoreScan<Exception> storeScan = storeView.visitRelationships( new int[]{relTypeId}, id -> id == relPropertyKeyId, visitor ); // when storeScan.run(); // then assertThat( "allocated locks: " + lockMocks.keySet(), lockMocks.size(), greaterThanOrEqualTo( 2 ) ); Lock lock0 = lockMocks.get( 0L ); Lock lock1 = lockMocks.get( 1L ); assertNotNull( "Lock[relationship=0] never acquired", lock0 ); assertNotNull( "Lock[relationship=1] never acquired", lock1 ); InOrder order = inOrder( locks, lock0, lock1 ); order.verify( locks ).acquireRelationshipLock( 0, LockService.LockType.READ_LOCK ); order.verify( lock0 ).release(); order.verify( locks ).acquireRelationshipLock( 1, LockService.LockType.READ_LOCK ); order.verify( lock1 ).release(); }
private void checkBounded( Supplier<NumberValue> supplier ) { for ( int i = 0; i < ITERATIONS; i++ ) { NumberValue value = supplier.get(); assertThat( value, notNullValue() ); assertThat( value.compareTo( ZERO_INT ), greaterThanOrEqualTo( 0 ) ); assertThat( value.compareTo( UPPER ), lessThan( 0 ) ); } } }
@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 everyTableShouldHaveAPrimaryKeyColumn() throws Exception { flyway.migrate(); List<String> tableNames = jdbcTemplate.queryForList(getAllTableNames, String.class, jdbcTemplate.getDataSource().getConnection().getCatalog()); assertThat(tableNames, hasSize(greaterThan(0))); for (String tableName : tableNames) { int count = jdbcTemplate.queryForObject(checkPrimaryKeyExists, Integer.class, jdbcTemplate.getDataSource().getConnection().getCatalog(), tableName, "%" + tableName + "_pk%"); assertThat(format("%s is missing primary key", tableName), count, greaterThanOrEqualTo(1)); } try { jdbcTemplate.execute(insertNewOauthCodeRecord); } catch (Exception _) { fail("oauth_code table should auto increment primary key when inserting data."); } }
@Override public void postSend(Message<?> message, MessageChannel channel, boolean sent) { Object payload = message.getPayload(); assertThat(payload, instanceOf(String.class)); Date date = null; try { date = DateFormat.getDateTimeInstance(DateFormat.LONG, DateFormat.DEFAULT).parse((String) payload); } catch (ParseException e) { fail("fail to parse date"); } assertThat(new Date().compareTo(date), greaterThanOrEqualTo(0)); stopLatch.countDown(); }
@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 shouldLockNodesWhileReadingThem() throws Exception { // given @SuppressWarnings( "unchecked" ) Visitor<EntityUpdates,Exception> visitor = mock( Visitor.class ); StoreScan<Exception> storeScan = storeView.visitNodes( new int[]{labelId}, id -> id == propertyKeyId, visitor, null, false ); // when storeScan.run(); // then assertThat( "allocated locks: " + lockMocks.keySet(), lockMocks.size(), greaterThanOrEqualTo( 2 ) ); Lock lock0 = lockMocks.get( 0L ); Lock lock1 = lockMocks.get( 1L ); assertNotNull( "Lock[node=0] never acquired", lock0 ); assertNotNull( "Lock[node=1] never acquired", lock1 ); InOrder order = inOrder( locks, lock0, lock1 ); order.verify( locks ).acquireNodeLock( 0, LockService.LockType.READ_LOCK ); order.verify( lock0 ).release(); order.verify( locks ).acquireNodeLock( 1, LockService.LockType.READ_LOCK ); order.verify( lock1 ).release(); }
private void waitForTicks(int minTicks) { try { Awaitility.with() .pollInterval(1, TimeUnit.MILLISECONDS) .atMost(Testing.TEST_TIMEOUT_MS, TimeUnit.MILLISECONDS) .untilAsserted(() -> assertThat(tickTupleCount.get(), Matchers.greaterThanOrEqualTo(minTicks))); } catch (ConditionTimeoutException e) { throw new AssertionError(e.getMessage()); } }
@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 shouldSendLastDataFrameAsHeartbeatWhenIdle() { final StatusMessageFlyweight msg = mock(StatusMessageFlyweight.class); when(msg.consumptionTermId()).thenReturn(INITIAL_TERM_ID); when(msg.consumptionTermOffset()).thenReturn(0); when(msg.receiverWindowLength()).thenReturn(ALIGNED_FRAME_LENGTH); publication.onStatusMessage(msg, rcvAddress); final UnsafeBuffer buffer = new UnsafeBuffer(ByteBuffer.allocateDirect(PAYLOAD.length)); buffer.putBytes(0, PAYLOAD); termAppenders[0].appendUnfragmentedMessage(headerWriter, buffer, 0, PAYLOAD.length, null, INITIAL_TERM_ID); sender.doWork(); assertThat(receivedFrames.size(), is(2)); // should send ticks receivedFrames.remove(); // skip setup & data frame receivedFrames.remove(); currentTimestamp += Configuration.PUBLICATION_HEARTBEAT_TIMEOUT_NS - 1; sender.doWork(); assertThat(receivedFrames.size(), is(0)); // should not send yet currentTimestamp += 10; sender.doWork(); assertThat(receivedFrames.size(), greaterThanOrEqualTo(1)); // should send ticks dataHeader.wrap(receivedFrames.remove()); assertThat(dataHeader.frameLength(), is(0)); assertThat(dataHeader.termOffset(), is(offsetOfMessage(2))); }