use of io.cdap.cdap.spi.metadata.MetadataConstants.ENTITY_NAME_KEY in project cdap by caskdata.
the class MetadataStorageTest method testSortedSearchAndPagination.
@Test
public void testSortedSearchAndPagination() throws IOException {
MetadataStorage mds = getMetadataStorage();
// create 10 unique random entity ids with random creation times
NoDupRandom random = new NoDupRandom();
List<MetadataEntity> entities = new ArrayList<>();
for (int i = 0; i < 10; i++) {
entities.add(ofDataset("myns", "ds" + String.valueOf(random.nextInt(1000))));
}
long creationTime = System.currentTimeMillis() - TimeUnit.MINUTES.toMillis(60);
List<MetadataRecord> records = entities.stream().map(entity -> new MetadataRecord(entity, new Metadata(SYSTEM, props(MetadataConstants.CREATION_TIME_KEY, String.valueOf(creationTime + random.nextInt(1000000)), MetadataConstants.ENTITY_NAME_KEY, entity.getValue(entity.getType()))))).collect(Collectors.toList());
// index all entities
mds.batch(records.stream().map(record -> new MetadataMutation.Update(record.getEntity(), record.getMetadata())).collect(Collectors.toList()), MutationOptions.DEFAULT);
testSortedSearch(mds, records, ENTITY_NAME_KEY);
testSortedSearch(mds, records, CREATION_TIME_KEY);
// clean up
mds.batch(entities.stream().map(Drop::new).collect(Collectors.toList()), MutationOptions.DEFAULT);
}
use of io.cdap.cdap.spi.metadata.MetadataConstants.ENTITY_NAME_KEY in project cdap by caskdata.
the class MetadataStorageTest method testCursorsOffsetsAndTotals.
@Test
public void testCursorsOffsetsAndTotals() throws IOException {
MetadataStorage mds = getMetadataStorage();
List<MetadataRecord> records = IntStream.range(0, 20).mapToObj(i -> new MetadataRecord(ofDataset(DEFAULT_NAMESPACE, "ds" + i), new Metadata(SYSTEM, props(ENTITY_NAME_KEY, "ds" + i)))).collect(Collectors.toList());
mds.batch(records.stream().map(record -> new Update(record.getEntity(), record.getMetadata())).collect(Collectors.toList()), MutationOptions.DEFAULT);
// no cursors
validateCursorAndOffset(mds, 0, 10, null, false, 10, 0, 10, true, false);
validateCursorAndOffset(mds, 5, 10, null, false, 10, 5, 10, true, false);
validateCursorAndOffset(mds, 10, 10, null, false, 10, 10, 10, false, false);
validateCursorAndOffset(mds, 15, 10, null, false, 5, 15, 10, false, false);
validateCursorAndOffset(mds, 20, 10, null, false, 0, 20, 10, false, false);
validateCursorAndOffset(mds, 25, 10, null, false, 0, 25, 10, false, false);
// request cursors, but don't use them
validateCursorAndOffset(mds, 0, 10, null, true, 10, 0, 10, true, true);
validateCursorAndOffset(mds, 0, 20, null, true, 20, 0, 20, false, false);
validateCursorAndOffset(mds, 0, 30, null, true, 20, 0, 30, false, false);
// test that passing in an empty string as the cursor has the same effect as null
validateCursorAndOffset(mds, 0, 10, "", true, 10, 0, 10, true, true);
validateCursorAndOffset(mds, 0, 20, "", true, 20, 0, 20, false, false);
validateCursorAndOffset(mds, 0, 30, "", true, 20, 0, 30, false, false);
// request cursor, and use it
String cursor = validateCursorAndOffset(mds, 0, 8, null, true, 8, 0, 8, true, true);
cursor = validateCursorAndOffset(mds, 0, 8, cursor, true, 8, 8, 8, true, true);
validateCursorAndOffset(mds, 0, 8, cursor, true, 4, 16, 8, false, false);
// request a cursor that matches evenly with the number of results
cursor = validateCursorAndOffset(mds, 0, 10, null, true, 10, 0, 10, true, true);
validateCursorAndOffset(mds, 0, 10, cursor, true, 10, 10, 10, false, false);
// ensure that offset and limit are superseded by cursor
cursor = validateCursorAndOffset(mds, 0, 4, null, true, 4, 0, 4, true, true);
cursor = validateCursorAndOffset(mds, 0, 0, cursor, true, 4, 4, 4, true, true);
cursor = validateCursorAndOffset(mds, 10, 100, cursor, true, 4, 8, 4, true, true);
cursor = validateCursorAndOffset(mds, 12, 2, cursor, true, 4, 12, 4, true, true);
validateCursorAndOffset(mds, 1, 1, cursor, true, 4, 16, 4, false, false);
// ensure that we can start searching without cursor, with offset, and request a cursor
// whether a cursor is returned, is implementation dependent
cursor = validateCursorAndOffset(mds, 4, 4, null, true, 4, 4, 4, true, null);
validateCursorAndOffset(mds, 8, 4, cursor, true, 4, 8, 4, true, null);
// clean up
mds.batch(records.stream().map(MetadataRecord::getEntity).map(Drop::new).collect(Collectors.toList()), MutationOptions.DEFAULT);
}
Aggregations