use of co.cask.cdap.client.NamespaceClient in project cdap by caskdata.
the class CLIMainTest method testDataset.
@Test
public void testDataset() throws Exception {
String datasetName = PREFIX + "sdf123lkj";
String ownedDatasetName = PREFIX + "owned";
DatasetTypeClient datasetTypeClient = new DatasetTypeClient(cliConfig.getClientConfig());
DatasetTypeMeta datasetType = datasetTypeClient.list(NamespaceId.DEFAULT).get(0);
testCommandOutputContains(cli, "create dataset instance " + datasetType.getName() + " " + datasetName + " \"a=1\"", "Successfully created dataset");
testCommandOutputContains(cli, "list dataset instances", FakeDataset.class.getSimpleName());
testCommandOutputContains(cli, "get dataset instance properties " + datasetName, "a,1");
// test dataset creation with owner
String commandOutput = getCommandOutput(cli, "create dataset instance " + datasetType.getName() + " " + ownedDatasetName + " \"a=1\"" + " " + "someDescription " + ArgumentName.PRINCIPAL + " alice/somehost.net@somekdc.net");
Assert.assertTrue(commandOutput.contains("Successfully created dataset"));
Assert.assertTrue(commandOutput.contains("alice/somehost.net@somekdc.net"));
// test describing the table returns the given owner information
testCommandOutputContains(cli, "describe dataset instance " + ownedDatasetName, "alice/somehost.net@somekdc.net");
NamespaceClient namespaceClient = new NamespaceClient(cliConfig.getClientConfig());
NamespaceId barspace = new NamespaceId("bar");
namespaceClient.create(new NamespaceMeta.Builder().setName(barspace).build());
cliConfig.setNamespace(barspace);
// list of dataset instances is different in 'foo' namespace
testCommandOutputNotContains(cli, "list dataset instances", FakeDataset.class.getSimpleName());
// also can not create dataset instances if the type it depends on exists only in a different namespace.
DatasetTypeId datasetType1 = barspace.datasetType(datasetType.getName());
testCommandOutputContains(cli, "create dataset instance " + datasetType.getName() + " " + datasetName, new DatasetTypeNotFoundException(datasetType1).getMessage());
testCommandOutputContains(cli, "use namespace default", "Now using namespace 'default'");
try {
testCommandOutputContains(cli, "truncate dataset instance " + datasetName, "Successfully truncated");
} finally {
testCommandOutputContains(cli, "delete dataset instance " + datasetName, "Successfully deleted");
}
String datasetName2 = PREFIX + "asoijm39485";
String description = "test-description-for-" + datasetName2;
testCommandOutputContains(cli, "create dataset instance " + datasetType.getName() + " " + datasetName2 + " \"a=1\"" + " " + description, "Successfully created dataset");
testCommandOutputContains(cli, "list dataset instances", description);
testCommandOutputContains(cli, "delete dataset instance " + datasetName2, "Successfully deleted");
testCommandOutputContains(cli, "delete dataset instance " + ownedDatasetName, "Successfully deleted");
}
Aggregations