Search in sources :

Example 1 with CREATION_TIME_KEY

use of io.cdap.cdap.spi.metadata.MetadataConstants.CREATION_TIME_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 CREATION_TIME_KEY

use of io.cdap.cdap.spi.metadata.MetadataConstants.CREATION_TIME_KEY in project cdap by caskdata.

the class MetadataStorageTest method testBatch.

@Test
public void testBatch() throws IOException {
    MetadataEntity entity = MetadataEntity.ofDataset("a", "b");
    Map<ScopedNameOfKind, MetadataDirective> directives = ImmutableMap.of(new ScopedNameOfKind(PROPERTY, SYSTEM, CREATION_TIME_KEY), MetadataDirective.PRESERVE, new ScopedNameOfKind(PROPERTY, SYSTEM, DESCRIPTION_KEY), MetadataDirective.KEEP);
    MetadataStorage mds = getMetadataStorage();
    Create create = new Create(entity, new Metadata(SYSTEM, tags("batch"), props(CREATION_TIME_KEY, "12345678", DESCRIPTION_KEY, "hello", "other", "value")), directives);
    MetadataChange change = mds.apply(create, MutationOptions.DEFAULT);
    Assert.assertEquals(Metadata.EMPTY, change.getBefore());
    Assert.assertEquals(create.getMetadata(), change.getAfter());
    List<MetadataMutation> mutations = ImmutableList.of(new Update(entity, new Metadata(USER, tags("tag1", "tag2"))), new Drop(entity), new Create(entity, new Metadata(SYSTEM, tags("batch"), props(CREATION_TIME_KEY, "23456789", "other", "different")), directives), new Update(entity, new Metadata(USER, tags("tag3"), props("key", "value"))), new Remove(entity, ImmutableSet.of(new ScopedNameOfKind(PROPERTY, SYSTEM, "other"), new ScopedNameOfKind(TAG, USER, "tag2"))), new Create(entity, new Metadata(SYSTEM, tags("realtime"), props(CREATION_TIME_KEY, "33456789", DESCRIPTION_KEY, "new description", "other", "yet other")), directives));
    // apply all mutations in sequence
    List<MetadataChange> changes = mutations.stream().map(mutation -> {
        try {
            return mds.apply(mutation, MutationOptions.DEFAULT);
        } catch (IOException e) {
            throw Throwables.propagate(e);
        }
    }).collect(Collectors.toList());
    // drop and recreate the entity
    mds.apply(new Drop(entity), MutationOptions.DEFAULT);
    change = mds.apply(create, MutationOptions.DEFAULT);
    Assert.assertEquals(Metadata.EMPTY, change.getBefore());
    Assert.assertEquals(create.getMetadata(), change.getAfter());
    // apply all mutations in batch
    List<MetadataChange> batchChanges = mds.batch(mutations, MutationOptions.DEFAULT);
    // make sure the same mutations were applied
    Assert.assertEquals(changes, batchChanges);
    // clean up
    mds.apply(new Drop(entity), 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) Remove(io.cdap.cdap.spi.metadata.MetadataMutation.Remove) IOException(java.io.IOException) Update(io.cdap.cdap.spi.metadata.MetadataMutation.Update) Drop(io.cdap.cdap.spi.metadata.MetadataMutation.Drop) Create(io.cdap.cdap.spi.metadata.MetadataMutation.Create) 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