use of co.cask.cdap.api.data.format.FormatSpecification in project cdap by caskdata.
the class MetadataHttpHandlerTestRun method before.
@Before
public void before() throws Exception {
addAppArtifact(artifactId, AppWithDataset.class);
AppRequest<Config> appRequest = new AppRequest<>(new ArtifactSummary(artifactId.getArtifact(), artifactId.getVersion()));
appClient.deploy(application, appRequest);
FormatSpecification format = new FormatSpecification("csv", null, null);
ViewSpecification viewSpec = new ViewSpecification(format, null);
streamViewClient.createOrUpdate(myview, viewSpec);
}
use of co.cask.cdap.api.data.format.FormatSpecification in project cdap by caskdata.
the class StreamInputFormatTest method testFormatStreamRecordReader.
@Test
public void testFormatStreamRecordReader() throws IOException, InterruptedException {
File inputDir = tmpFolder.newFolder();
File partition = new File(inputDir, "1.1000");
partition.mkdirs();
File eventFile = new File(partition, "bucket.1.0." + StreamFileType.EVENT.getSuffix());
File indexFile = new File(partition, "bucket.1.0." + StreamFileType.INDEX.getSuffix());
// write 1 event
StreamDataFileWriter writer = new StreamDataFileWriter(Files.newOutputStreamSupplier(eventFile), Files.newOutputStreamSupplier(indexFile), 100L);
StreamEvent streamEvent = new StreamEvent(ImmutableMap.of("header1", "value1", "header2", "value2"), Charsets.UTF_8.encode("hello world"), 1000);
writer.append(streamEvent);
writer.close();
FormatSpecification formatSpec = new FormatSpecification(TextRecordFormat.class.getName(), Schema.recordOf("event", Schema.Field.of("body", Schema.of(Schema.Type.STRING))), Collections.<String, String>emptyMap());
Configuration conf = new Configuration();
AbstractStreamInputFormat.setStreamId(conf, DUMMY_ID);
AbstractStreamInputFormat.setBodyFormatSpecification(conf, formatSpec);
AbstractStreamInputFormat.setStreamPath(conf, inputDir.toURI());
TaskAttemptContext context = new TaskAttemptContextImpl(conf, new TaskAttemptID());
AbstractStreamInputFormat format = new AbstractStreamInputFormat() {
@Override
public AuthorizationEnforcer getAuthorizationEnforcer(TaskAttemptContext context) {
return new NoOpAuthorizer();
}
@Override
public AuthenticationContext getAuthenticationContext(TaskAttemptContext context) {
return new AuthenticationTestContext();
}
};
// read all splits and store the results in the list
List<GenericStreamEventData<StructuredRecord>> recordsRead = Lists.newArrayList();
List<InputSplit> inputSplits = format.getSplits(context);
for (InputSplit split : inputSplits) {
RecordReader<LongWritable, GenericStreamEventData<StructuredRecord>> recordReader = format.createRecordReader(split, context);
recordReader.initialize(split, context);
while (recordReader.nextKeyValue()) {
recordsRead.add(recordReader.getCurrentValue());
}
}
// should only have read 1 record
Assert.assertEquals(1, recordsRead.size());
GenericStreamEventData<StructuredRecord> eventData = recordsRead.get(0);
Assert.assertEquals(streamEvent.getHeaders(), eventData.getHeaders());
Assert.assertEquals("hello world", eventData.getBody().get("body"));
}
use of co.cask.cdap.api.data.format.FormatSpecification in project cdap by caskdata.
the class ViewSystemMetadataWriterTest method getViewMetadataSchema.
private String getViewMetadataSchema(String format, @Nullable Schema schema) {
StreamViewId viewId = NamespaceId.DEFAULT.stream("mystream").view("myview");
FormatSpecification formatSpec = new FormatSpecification(format, schema);
ViewSpecification viewSpec = new ViewSpecification(formatSpec);
NoOpMetadataStore metadataStore = new NoOpMetadataStore();
ViewSystemMetadataWriter writer = new ViewSystemMetadataWriter(metadataStore, viewId, viewSpec, false);
return writer.getSchemaToAdd();
}
use of co.cask.cdap.api.data.format.FormatSpecification in project cdap by caskdata.
the class StreamHandlerTest method testPutStreamConfigDefaults.
@Test
public void testPutStreamConfigDefaults() throws Exception {
// Now, create the new stream.
HttpURLConnection urlConn = openURL(createURL("streams/stream_defaults"), HttpMethod.PUT);
Assert.assertEquals(HttpResponseStatus.OK.getCode(), urlConn.getResponseCode());
urlConn.disconnect();
// put a new config
urlConn = openURL(createPropertiesURL("stream_defaults"), HttpMethod.PUT);
urlConn.setDoOutput(true);
// don't give the schema to make sure a default gets used
FormatSpecification formatSpecification = new FormatSpecification(Formats.TEXT, null, null);
StreamProperties streamProperties = new StreamProperties(2L, formatSpecification, 20);
urlConn.getOutputStream().write(GSON.toJson(streamProperties).getBytes(Charsets.UTF_8));
Assert.assertEquals(HttpResponseStatus.OK.getCode(), urlConn.getResponseCode());
urlConn.disconnect();
// test the config ttl by calling info
urlConn = openURL(createStreamInfoURL("stream_defaults"), HttpMethod.GET);
Assert.assertEquals(HttpResponseStatus.OK.getCode(), urlConn.getResponseCode());
StreamProperties actual = GSON.fromJson(new String(ByteStreams.toByteArray(urlConn.getInputStream()), Charsets.UTF_8), StreamProperties.class);
urlConn.disconnect();
StreamProperties expected = new StreamProperties(2L, StreamConfig.DEFAULT_STREAM_FORMAT, 20);
Assert.assertEquals(expected, actual);
}
use of co.cask.cdap.api.data.format.FormatSpecification in project cdap by caskdata.
the class GrokRecordFormatTest method testSyslog.
@Test
public void testSyslog() throws Exception {
FormatSpecification spec = new FormatSpecification(Formats.SYSLOG, null, Collections.<String, String>emptyMap());
RecordFormat<StreamEvent, StructuredRecord> format = RecordFormats.createInitializedFormat(spec);
String message = "Oct 17 08:59:00 suod newsyslog[6215]: logfile turned over";
StructuredRecord record = format.read(new StreamEvent(ByteBuffer.wrap(Bytes.toBytes(message))));
Assert.assertEquals("Oct 17 08:59:00", record.get("timestamp"));
Assert.assertEquals("suod", record.get("logsource"));
Assert.assertEquals("newsyslog", record.get("program"));
Assert.assertEquals("6215", record.get("pid"));
Assert.assertEquals("logfile turned over", record.get("message"));
message = "Oct 17 08:59:04 cdr.cs.colorado.edu amd[29648]: " + "noconn option exists, and was turned on! (May cause NFS hangs on some systems...)";
record = format.read(new StreamEvent(ByteBuffer.wrap(Bytes.toBytes(message))));
Assert.assertEquals("Oct 17 08:59:04", record.get("timestamp"));
Assert.assertEquals("cdr.cs.colorado.edu", record.get("logsource"));
Assert.assertEquals("amd", record.get("program"));
Assert.assertEquals("29648", record.get("pid"));
Assert.assertEquals("noconn option exists, and was turned on! (May cause NFS hangs on some systems...)", record.get("message"));
}
Aggregations