use of co.cask.cdap.proto.ViewSpecification in project cdap by caskdata.
the class StreamViewHttpHandlerTest method testAll.
@Test
public void testAll() throws Exception {
execute(404, HttpRequest.get(resolve("/v3/namespaces/default/streams/foo/views")).build());
execute(404, HttpRequest.get(resolve("/v3/namespaces/default/streams/foo/views/view1")).build());
execute(404, HttpRequest.delete(resolve("/v3/namespaces/default/streams/foo/views/view1")).build());
execute(200, HttpRequest.put(resolve("/v3/namespaces/default/streams/foo")).build());
execute(404, HttpRequest.delete(resolve("/v3/namespaces/default/streams/foo/views/nonexistent")).build());
List<String> views = execute(200, HttpRequest.get(resolve("/v3/namespaces/default/streams/foo/views")).build(), new TypeToken<List<String>>() {
}.getType());
Assert.assertEquals(ImmutableList.of(), views);
Schema schema = Schema.recordOf("foo", Schema.Field.of("name", Schema.of(Schema.Type.STRING)));
FormatSpecification formatSpec = new FormatSpecification(Formats.AVRO, schema, Collections.<String, String>emptyMap());
ViewSpecification config = new ViewSpecification(formatSpec);
// trying to create without request body should give 400
execute(400, HttpRequest.put(resolve("/v3/namespaces/default/streams/foo/views/view1")).build());
execute(201, HttpRequest.put(resolve("/v3/namespaces/default/streams/foo/views/view1")).withBody(GSON.toJson(config)).build());
ViewDetail actualDetail = execute(200, HttpRequest.get(resolve("/v3/namespaces/default/streams/foo/views/view1")).build(), ViewDetail.class);
Assert.assertEquals(new ViewDetail("view1", new ViewSpecification(config.getFormat(), "stream_foo_view1")), actualDetail);
views = execute(200, HttpRequest.get(resolve("/v3/namespaces/default/streams/foo/views")).build(), new TypeToken<List<String>>() {
}.getType());
Assert.assertEquals(ImmutableList.of("view1"), views);
execute(201, HttpRequest.put(resolve("/v3/namespaces/default/streams/foo/views/view2")).withBody(GSON.toJson(config)).build());
actualDetail = execute(200, HttpRequest.get(resolve("/v3/namespaces/default/streams/foo/views/view2")).build(), ViewDetail.class);
Assert.assertEquals(new ViewDetail("view2", new ViewSpecification(config.getFormat(), "stream_foo_view2")), actualDetail);
views = execute(200, HttpRequest.get(resolve("/v3/namespaces/default/streams/foo/views")).build(), new TypeToken<List<String>>() {
}.getType());
Assert.assertEquals(ImmutableList.of("view1", "view2"), views == null ? null : Ordering.natural().sortedCopy(views));
execute(200, HttpRequest.delete(resolve("/v3/namespaces/default/streams/foo/views/view1")).build());
views = execute(200, HttpRequest.get(resolve("/v3/namespaces/default/streams/foo/views")).build(), new TypeToken<List<String>>() {
}.getType());
Assert.assertEquals(ImmutableList.of("view2"), views);
execute(200, HttpRequest.delete(resolve("/v3/namespaces/default/streams/foo/views/view2")).build());
views = execute(200, HttpRequest.get(resolve("/v3/namespaces/default/streams/foo/views")).build(), new TypeToken<List<String>>() {
}.getType());
Assert.assertEquals(ImmutableList.<String>of(), views);
// Deleting a stream should also delete the associated views
execute(200, HttpRequest.delete(resolve("/v3/namespaces/default/streams/foo")).build());
execute(200, HttpRequest.put(resolve("/v3/namespaces/default/streams/foo")).build());
execute(404, HttpRequest.get(resolve("/v3/namespaces/default/streams/foo/views/view1")).build());
}
use of co.cask.cdap.proto.ViewSpecification in project cdap by caskdata.
the class ViewAdmin method createOrUpdate.
public boolean createOrUpdate(StreamViewId viewId, ViewSpecification spec) throws Exception {
try {
ViewSpecification previousSpec = store.get(viewId);
if (spec.getTableName() == null) {
// use the previous table name
spec = new ViewSpecification(spec.getFormat(), previousSpec.getTableName());
} else if (!spec.getTableName().equals(previousSpec.getTableName())) {
throw new IllegalArgumentException(String.format("Cannot change table name for view %s", viewId));
}
explore.disableExploreStream(viewId.getParent(), previousSpec.getTableName());
} catch (NotFoundException e) {
// pass through
}
if (spec.getTableName() == null) {
spec = new ViewSpecification(spec.getFormat(), naming.getTableName(viewId));
}
explore.enableExploreStream(viewId.getParent(), spec.getTableName(), spec.getFormat());
boolean result = store.createOrUpdate(viewId, spec);
ViewSystemMetadataWriter systemMetadataWriter = new ViewSystemMetadataWriter(metadataStore, viewId, spec, !result);
systemMetadataWriter.write();
return result;
}
use of co.cask.cdap.proto.ViewSpecification in project cdap by caskdata.
the class StreamClientTestRun method testStreamDeleteAfterCreatingView.
@Test
public void testStreamDeleteAfterCreatingView() throws Exception {
StreamId testStream = NamespaceId.DEFAULT.stream("testStream");
streamClient.create(testStream);
// should throw StreamNotFoundException if the stream has not been successfully created in the previous step
streamClient.getConfig(testStream);
StreamViewClient streamViewClient = new StreamViewClient(clientConfig);
StreamViewId testView = testStream.view("testView");
ViewSpecification testViewSpec = new ViewSpecification(new FormatSpecification("csv", null, null));
Assert.assertTrue(streamViewClient.createOrUpdate(testView, testViewSpec));
// test stream delete
streamClient.delete(testStream);
// recreate the stream and the view
streamClient.create(testStream);
// should throw StreamNotFoundException if the stream has not been successfully created in the previous step
streamClient.getConfig(testStream);
Assert.assertTrue(streamViewClient.createOrUpdate(testView, testViewSpec));
// test that namespace deletion succeeds
namespaceClient.delete(NamespaceId.DEFAULT);
}
Aggregations