use of co.cask.cdap.api.dataset.DatasetSpecification in project cdap by caskdata.
the class TestDatasetDefinition method getDataset.
@Override
public TestDataset getDataset(DatasetContext datasetContext, DatasetSpecification spec, Map<String, String> arguments, ClassLoader classLoader) throws IOException {
DatasetSpecification kvTableSpec = spec.getSpecification("kv");
KeyValueTable table = tableDef.getDataset(datasetContext, kvTableSpec, DatasetDefinition.NO_ARGUMENTS, classLoader);
return new TestDataset(spec, table, arguments);
}
use of co.cask.cdap.api.dataset.DatasetSpecification in project cdap by caskdata.
the class AbstractDatasetFrameworkTest method testBasicManagement.
@Test
public void testBasicManagement() throws Exception {
DatasetTypeId tableType = NAMESPACE_ID.datasetType(Table.class.getName());
// Adding modules
DatasetFramework framework = getFramework();
framework.addModule(IN_MEMORY, new InMemoryTableModule());
framework.addModule(CORE, new CoreDatasetsModule());
framework.addModule(FILE, new FileSetModule());
framework.addModule(KEY_VALUE, new SingleTypeModule(SimpleKVTable.class));
// keyvalue has been added in the system namespace
Assert.assertTrue(framework.hasSystemType(Table.class.getName()));
Assert.assertFalse(framework.hasSystemType(SimpleKVTable.class.getName()));
Assert.assertTrue(framework.hasType(tableType));
Assert.assertTrue(framework.hasType(SIMPLE_KV_TYPE));
// Creating instances
framework.addInstance(Table.class.getName(), MY_TABLE, DatasetProperties.EMPTY);
Assert.assertTrue(framework.hasInstance(MY_TABLE));
DatasetSpecification spec = framework.getDatasetSpec(MY_TABLE);
Assert.assertNotNull(spec);
Assert.assertEquals(MY_TABLE.getEntityName(), spec.getName());
Assert.assertEquals(Table.class.getName(), spec.getType());
framework.addInstance(Table.class.getName(), MY_TABLE2, DatasetProperties.EMPTY);
Assert.assertTrue(framework.hasInstance(MY_TABLE2));
// Update instances
File baseDir = TMP_FOLDER.newFolder();
framework.addInstance(FileSet.class.getName(), MY_DS, FileSetProperties.builder().setBasePath(baseDir.getPath()).setDataExternal(true).build());
// this should fail because it would "internalize" external data
try {
framework.updateInstance(MY_DS, DatasetProperties.EMPTY);
Assert.fail("update should have thrown instance conflict");
} catch (InstanceConflictException e) {
// expected
}
baseDir = TMP_FOLDER.newFolder();
// this should succeed because it simply changes the external path
framework.updateInstance(MY_DS, FileSetProperties.builder().setBasePath(baseDir.getPath()).setDataExternal(true).build());
spec = framework.getDatasetSpec(MY_DS);
Assert.assertNotNull(spec);
Assert.assertEquals(baseDir.getPath(), FileSetProperties.getBasePath(spec.getProperties()));
// cleanup
try {
framework.deleteAllModules(NAMESPACE_ID);
Assert.fail("should not delete modules: there are datasets using their types");
} catch (DatasetManagementException e) {
// expected
}
// types are still there
Assert.assertTrue(framework.hasType(tableType));
Assert.assertTrue(framework.hasType(SIMPLE_KV_TYPE));
framework.deleteAllInstances(NAMESPACE_ID);
Assert.assertEquals(0, framework.getInstances(NAMESPACE_ID).size());
Assert.assertFalse(framework.hasInstance(MY_TABLE));
Assert.assertNull(framework.getDatasetSpec(MY_TABLE));
Assert.assertFalse(framework.hasInstance(MY_TABLE2));
Assert.assertNull(framework.getDatasetSpec(MY_TABLE2));
// now it should succeed
framework.deleteAllModules(NAMESPACE_ID);
Assert.assertTrue(framework.hasSystemType(Table.class.getName()));
Assert.assertFalse(framework.hasType(tableType));
Assert.assertFalse(framework.hasType(SIMPLE_KV_TYPE));
}
use of co.cask.cdap.api.dataset.DatasetSpecification in project cdap by caskdata.
the class DatasetsUtilTest method testFix.
private void testFix(String type, DatasetProperties props) {
DatasetDefinition def = DatasetFrameworkTestUtil.getDatasetDefinition(inMemoryDatasetFramework, NamespaceId.DEFAULT, type);
Assert.assertNotNull(def);
DatasetSpecification spec = def.configure("nn", props);
Map<String, String> originalProperties = DatasetsUtil.fixOriginalProperties(spec).getOriginalProperties();
Assert.assertEquals(props.getProperties(), originalProperties);
}
use of co.cask.cdap.api.dataset.DatasetSpecification in project cdap by caskdata.
the class DatasetDefinitionRegistryWithDefaultModules method testCompositeDatasetReconfigure.
// tests that CompositeDatasetDefinition correctly delegates reconfigure() to its embedded types
@Test
public void testCompositeDatasetReconfigure() throws IncompatibleUpdateException {
CompositeDatasetDefinition composite = new CompositeDatasetDefinition("composite", "pedantic", new PedanticDatasetDefinition("pedantic")) {
@Override
public Dataset getDataset(DatasetContext datasetContext, DatasetSpecification spec, Map arguments, ClassLoader classLoader) throws IOException {
return null;
}
};
DatasetSpecification spec = composite.configure("nn", DatasetProperties.EMPTY);
DatasetSpecification respec = composite.reconfigure("nn", DatasetProperties.EMPTY, spec);
Assert.assertEquals(spec, respec);
try {
composite.reconfigure("nn", DatasetProperties.builder().add("immutable", "x").build(), spec);
Assert.fail("reconfigure should have thrown exception");
} catch (IncompatibleUpdateException e) {
// expected
}
}
use of co.cask.cdap.api.dataset.DatasetSpecification in project cdap by caskdata.
the class NoTxKeyValueTableTest method test.
@Test
public void test() throws IOException {
DatasetDefinition<? extends NoTxKeyValueTable, ? extends DatasetAdmin> def = getDefinition();
DatasetSpecification spec = def.configure("table", DatasetProperties.EMPTY);
ClassLoader cl = NoTxKeyValueTable.class.getClassLoader();
DatasetContext datasetContext = DatasetContext.from(NAMESPACE_ID.getEntityName());
// create & exists
DatasetAdmin admin = def.getAdmin(datasetContext, spec, cl);
Assert.assertFalse(admin.exists());
admin.create();
Assert.assertTrue(admin.exists());
// put/get
NoTxKeyValueTable table = def.getDataset(datasetContext, spec, NO_ARGS, cl);
Assert.assertNull(table.get(KEY1));
table.put(KEY1, VALUE1);
Assert.assertArrayEquals(VALUE1, table.get(KEY1));
Assert.assertNull(table.get(KEY2));
// override
table.put(KEY1, VALUE2);
Assert.assertArrayEquals(VALUE2, table.get(KEY1));
Assert.assertNull(table.get(KEY2));
// delete & truncate
table.put(KEY2, VALUE1);
Assert.assertArrayEquals(VALUE2, table.get(KEY1));
Assert.assertArrayEquals(VALUE1, table.get(KEY2));
table.put(KEY2, null);
Assert.assertNull(table.get(KEY2));
Assert.assertArrayEquals(VALUE2, table.get(KEY1));
admin.truncate();
Assert.assertNull(table.get(KEY1));
Assert.assertNull(table.get(KEY2));
Assert.assertTrue(admin.exists());
admin.drop();
Assert.assertFalse(admin.exists());
// drop should cleanup data
admin.create();
Assert.assertTrue(admin.exists());
Assert.assertNull(table.get(KEY1));
Assert.assertNull(table.get(KEY2));
table.put(KEY1, VALUE1);
Assert.assertArrayEquals(VALUE1, table.get(KEY1));
admin.drop();
Assert.assertFalse(admin.exists());
admin.create();
Assert.assertTrue(admin.exists());
Assert.assertNull(table.get(KEY1));
}
Aggregations