Search in sources :

Example 1 with NamespaceClient

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");
}
Also used : DatasetTypeClient(co.cask.cdap.client.DatasetTypeClient) DatasetTypeId(co.cask.cdap.proto.id.DatasetTypeId) NamespaceMeta(co.cask.cdap.proto.NamespaceMeta) NamespaceClient(co.cask.cdap.client.NamespaceClient) DatasetTypeMeta(co.cask.cdap.proto.DatasetTypeMeta) NamespaceId(co.cask.cdap.proto.id.NamespaceId) DatasetTypeNotFoundException(co.cask.cdap.common.DatasetTypeNotFoundException) FakeDataset(co.cask.cdap.client.app.FakeDataset) Test(org.junit.Test)

Aggregations

DatasetTypeClient (co.cask.cdap.client.DatasetTypeClient)1 NamespaceClient (co.cask.cdap.client.NamespaceClient)1 FakeDataset (co.cask.cdap.client.app.FakeDataset)1 DatasetTypeNotFoundException (co.cask.cdap.common.DatasetTypeNotFoundException)1 DatasetTypeMeta (co.cask.cdap.proto.DatasetTypeMeta)1 NamespaceMeta (co.cask.cdap.proto.NamespaceMeta)1 DatasetTypeId (co.cask.cdap.proto.id.DatasetTypeId)1 NamespaceId (co.cask.cdap.proto.id.NamespaceId)1 Test (org.junit.Test)1