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);
}
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);
}
Aggregations