Search in sources :

Example 1 with ENTITY_NAME_KEY

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);
}
Also used : IntStream(java.util.stream.IntStream) DESCRIPTION_KEY(io.cdap.cdap.spi.metadata.MetadataConstants.DESCRIPTION_KEY) Arrays(java.util.Arrays) Drop(io.cdap.cdap.spi.metadata.MetadataMutation.Drop) HashMap(java.util.HashMap) Random(java.util.Random) USER(io.cdap.cdap.api.metadata.MetadataScope.USER) ENTITY_NAME_KEY(io.cdap.cdap.spi.metadata.MetadataConstants.ENTITY_NAME_KEY) CompletionService(java.util.concurrent.CompletionService) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) SlowTests(io.cdap.cdap.test.SlowTests) TAG(io.cdap.cdap.spi.metadata.MetadataKind.TAG) ImmutableList(com.google.common.collect.ImmutableList) After(org.junit.After) Map(java.util.Map) MetadataEntity(io.cdap.cdap.api.metadata.MetadataEntity) ExecutorService(java.util.concurrent.ExecutorService) Nullable(javax.annotation.Nullable) PROPERTY(io.cdap.cdap.spi.metadata.MetadataKind.PROPERTY) Tasks(io.cdap.cdap.common.utils.Tasks) ImmutableSet(com.google.common.collect.ImmutableSet) ImmutableMap(com.google.common.collect.ImmutableMap) Beta(io.cdap.cdap.api.annotation.Beta) SYSTEM(io.cdap.cdap.api.metadata.MetadataScope.SYSTEM) Update(io.cdap.cdap.spi.metadata.MetadataMutation.Update) Throwables(com.google.common.base.Throwables) Set(java.util.Set) Test(org.junit.Test) IOException(java.io.IOException) Category(org.junit.experimental.categories.Category) Maps(com.google.common.collect.Maps) Schema(io.cdap.cdap.api.data.schema.Schema) Collectors(java.util.stream.Collectors) Sets(com.google.common.collect.Sets) Executors(java.util.concurrent.Executors) TTL_KEY(io.cdap.cdap.spi.metadata.MetadataConstants.TTL_KEY) Create(io.cdap.cdap.spi.metadata.MetadataMutation.Create) TimeUnit(java.util.concurrent.TimeUnit) CREATION_TIME_KEY(io.cdap.cdap.spi.metadata.MetadataConstants.CREATION_TIME_KEY) List(java.util.List) MetadataScope(io.cdap.cdap.api.metadata.MetadataScope) Assert(org.junit.Assert) Comparator(java.util.Comparator) Remove(io.cdap.cdap.spi.metadata.MetadataMutation.Remove) Collections(java.util.Collections) ExecutorCompletionService(java.util.concurrent.ExecutorCompletionService) MetadataEntity(io.cdap.cdap.api.metadata.MetadataEntity) Update(io.cdap.cdap.spi.metadata.MetadataMutation.Update) ArrayList(java.util.ArrayList) Drop(io.cdap.cdap.spi.metadata.MetadataMutation.Drop) Test(org.junit.Test)

Example 2 with ENTITY_NAME_KEY

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);
}
Also used : IntStream(java.util.stream.IntStream) DESCRIPTION_KEY(io.cdap.cdap.spi.metadata.MetadataConstants.DESCRIPTION_KEY) Arrays(java.util.Arrays) Drop(io.cdap.cdap.spi.metadata.MetadataMutation.Drop) HashMap(java.util.HashMap) Random(java.util.Random) USER(io.cdap.cdap.api.metadata.MetadataScope.USER) ENTITY_NAME_KEY(io.cdap.cdap.spi.metadata.MetadataConstants.ENTITY_NAME_KEY) CompletionService(java.util.concurrent.CompletionService) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) SlowTests(io.cdap.cdap.test.SlowTests) TAG(io.cdap.cdap.spi.metadata.MetadataKind.TAG) ImmutableList(com.google.common.collect.ImmutableList) After(org.junit.After) Map(java.util.Map) MetadataEntity(io.cdap.cdap.api.metadata.MetadataEntity) ExecutorService(java.util.concurrent.ExecutorService) Nullable(javax.annotation.Nullable) PROPERTY(io.cdap.cdap.spi.metadata.MetadataKind.PROPERTY) Tasks(io.cdap.cdap.common.utils.Tasks) ImmutableSet(com.google.common.collect.ImmutableSet) ImmutableMap(com.google.common.collect.ImmutableMap) Beta(io.cdap.cdap.api.annotation.Beta) SYSTEM(io.cdap.cdap.api.metadata.MetadataScope.SYSTEM) Update(io.cdap.cdap.spi.metadata.MetadataMutation.Update) Throwables(com.google.common.base.Throwables) Set(java.util.Set) Test(org.junit.Test) IOException(java.io.IOException) Category(org.junit.experimental.categories.Category) Maps(com.google.common.collect.Maps) Schema(io.cdap.cdap.api.data.schema.Schema) Collectors(java.util.stream.Collectors) Sets(com.google.common.collect.Sets) Executors(java.util.concurrent.Executors) TTL_KEY(io.cdap.cdap.spi.metadata.MetadataConstants.TTL_KEY) Create(io.cdap.cdap.spi.metadata.MetadataMutation.Create) TimeUnit(java.util.concurrent.TimeUnit) CREATION_TIME_KEY(io.cdap.cdap.spi.metadata.MetadataConstants.CREATION_TIME_KEY) List(java.util.List) MetadataScope(io.cdap.cdap.api.metadata.MetadataScope) Assert(org.junit.Assert) Comparator(java.util.Comparator) Remove(io.cdap.cdap.spi.metadata.MetadataMutation.Remove) Collections(java.util.Collections) ExecutorCompletionService(java.util.concurrent.ExecutorCompletionService) Update(io.cdap.cdap.spi.metadata.MetadataMutation.Update) Drop(io.cdap.cdap.spi.metadata.MetadataMutation.Drop) Test(org.junit.Test)

Aggregations

Throwables (com.google.common.base.Throwables)2 ImmutableList (com.google.common.collect.ImmutableList)2 ImmutableMap (com.google.common.collect.ImmutableMap)2 ImmutableSet (com.google.common.collect.ImmutableSet)2 Maps (com.google.common.collect.Maps)2 Sets (com.google.common.collect.Sets)2 Beta (io.cdap.cdap.api.annotation.Beta)2 Schema (io.cdap.cdap.api.data.schema.Schema)2 MetadataEntity (io.cdap.cdap.api.metadata.MetadataEntity)2 MetadataScope (io.cdap.cdap.api.metadata.MetadataScope)2 SYSTEM (io.cdap.cdap.api.metadata.MetadataScope.SYSTEM)2 USER (io.cdap.cdap.api.metadata.MetadataScope.USER)2 Tasks (io.cdap.cdap.common.utils.Tasks)2 CREATION_TIME_KEY (io.cdap.cdap.spi.metadata.MetadataConstants.CREATION_TIME_KEY)2 DESCRIPTION_KEY (io.cdap.cdap.spi.metadata.MetadataConstants.DESCRIPTION_KEY)2 ENTITY_NAME_KEY (io.cdap.cdap.spi.metadata.MetadataConstants.ENTITY_NAME_KEY)2 TTL_KEY (io.cdap.cdap.spi.metadata.MetadataConstants.TTL_KEY)2 PROPERTY (io.cdap.cdap.spi.metadata.MetadataKind.PROPERTY)2 TAG (io.cdap.cdap.spi.metadata.MetadataKind.TAG)2 Create (io.cdap.cdap.spi.metadata.MetadataMutation.Create)2