use of co.cask.cdap.api.data.format.FormatSpecification in project cdap by caskdata.
the class CombinedLogRecordFormatTest method testCLFLogWithEscapedDoubleQuotes.
@Test
public void testCLFLogWithEscapedDoubleQuotes() throws UnsupportedTypeException, UnexpectedFormatException {
CombinedLogRecordFormat format = new CombinedLogRecordFormat();
FormatSpecification spec = new FormatSpecification(CombinedLogRecordFormat.class.getCanonicalName(), null, ImmutableMap.<String, String>of());
format.initialize(spec);
String data = "10.10.10.10 - - [01/Feb/2015:06:38:58 +0000] \"GET /plugins/servlet/buildStatusImage/CDAP-DUT " + "HTTP/1.1\" 301 257 \"http://cdap.io/\" \"\\\"Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, " + "like Gecko) Chrome/31.0.1650.57 Safari/537.36 OPR/18.0.1284.49\\\"\"";
StructuredRecord output = format.read(new StreamEvent(ByteBuffer.wrap(Bytes.toBytes(data))));
Assert.assertEquals("10.10.10.10", output.get("remote_host"));
Assert.assertNull(output.get("remote_login"));
Assert.assertNull(output.get("auth_user"));
Assert.assertEquals("01/Feb/2015:06:38:58 +0000", output.get("request_time"));
Assert.assertEquals("GET /plugins/servlet/buildStatusImage/CDAP-DUT HTTP/1.1", output.get("request"));
Assert.assertEquals(301, output.get("status"));
Assert.assertEquals(257, output.get("content_length"));
Assert.assertEquals("http://cdap.io/", output.get("referrer"));
Assert.assertEquals("\\\"Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) " + "Chrome/31.0.1650.57 Safari/537.36 OPR/18.0.1284.49\\\"", output.get("user_agent"));
}
use of co.cask.cdap.api.data.format.FormatSpecification in project cdap by caskdata.
the class CombinedLogRecordFormatTest method testCLFLogWithNull.
@Test
public void testCLFLogWithNull() throws UnsupportedTypeException, UnexpectedFormatException {
CombinedLogRecordFormat format = new CombinedLogRecordFormat();
FormatSpecification spec = new FormatSpecification(CombinedLogRecordFormat.class.getCanonicalName(), null, ImmutableMap.<String, String>of());
format.initialize(spec);
String data = "10.10.10.10 - - [01/Feb/2015:09:58:24 +0000] \"-\" 408 - \"-\" \"-\"";
StructuredRecord output = format.read(new StreamEvent(ByteBuffer.wrap(Bytes.toBytes(data))));
Assert.assertEquals("10.10.10.10", output.get("remote_host"));
Assert.assertNull(output.get("remote_login"));
Assert.assertNull(output.get("auth_user"));
Assert.assertEquals("01/Feb/2015:09:58:24 +0000", output.get("request_time"));
Assert.assertNull(output.get("request"));
Assert.assertEquals(408, output.get("status"));
Assert.assertNull(output.get("content_length"));
Assert.assertNull(output.get("referrer"));
Assert.assertNull(output.get("user_agent"));
}
use of co.cask.cdap.api.data.format.FormatSpecification in project cdap by caskdata.
the class EntityExistenceTest method setup.
@BeforeClass
public static void setup() throws Exception {
CConfiguration cConf = CConfiguration.create();
cConf.set(Constants.INSTANCE_NAME, EXISTS);
Injector injector = AppFabricTestHelper.getInjector(cConf);
NamespaceStore nsStore = injector.getInstance(NamespaceStore.class);
ArtifactRepository artifactRepository = injector.getInstance(ArtifactRepository.class);
cConf = injector.getInstance(CConfiguration.class);
nsStore.create(new NamespaceMeta.Builder().setName(EXISTS).build());
existenceVerifier = injector.getInstance(EntityExistenceVerifier.class);
LocalLocationFactory lf = new LocalLocationFactory(TEMPORARY_FOLDER.newFolder());
File artifactFile = new File(AppJarHelper.createDeploymentJar(lf, AllProgramsApp.class).toURI());
artifactRepository.addArtifact(ARTIFACT.toId(), artifactFile);
AppFabricTestHelper.deployApplication(NAMESPACE.toId(), AllProgramsApp.class, null, cConf);
StreamAdmin streamAdmin = injector.getInstance(StreamAdmin.class);
streamAdmin.createOrUpdateView(VIEW, new ViewSpecification(new FormatSpecification("csv", null)));
}
use of co.cask.cdap.api.data.format.FormatSpecification in project cdap by caskdata.
the class MetadataHttpHandlerTestRun method testSearchResultPagination.
@Test
public void testSearchResultPagination() throws Exception {
NamespaceId namespace = new NamespaceId("pagination");
namespaceClient.create(new NamespaceMeta.Builder().setName(namespace).build());
StreamId stream = namespace.stream("text");
DatasetId dataset = namespace.dataset("mydataset");
StreamViewId view = stream.view("view");
DatasetId trackerDataset = namespace.dataset("_auditLog");
// create entities so system metadata is annotated
streamClient.create(stream);
streamViewClient.createOrUpdate(view, new ViewSpecification(new FormatSpecification("csv", null, null)));
datasetClient.create(dataset, new DatasetInstanceConfiguration(Table.class.getName(), Collections.<String, String>emptyMap()));
datasetClient.create(trackerDataset, new DatasetInstanceConfiguration(Table.class.getName(), Collections.<String, String>emptyMap()));
// search with showHidden to true
EnumSet<EntityTypeSimpleName> targets = EnumSet.allOf(EntityTypeSimpleName.class);
String sort = AbstractSystemMetadataWriter.ENTITY_NAME_KEY + " asc";
// search to get all the above entities offset 0, limit interger max and cursors 0
MetadataSearchResponse searchResponse = searchMetadata(namespace, "*", targets, sort, 0, Integer.MAX_VALUE, 0, null, true);
List<MetadataSearchResultRecord> expectedResults = ImmutableList.of(new MetadataSearchResultRecord(trackerDataset), new MetadataSearchResultRecord(dataset), new MetadataSearchResultRecord(stream), new MetadataSearchResultRecord(view));
List<String> expectedCursors = ImmutableList.of();
Assert.assertEquals(expectedResults, new ArrayList<>(searchResponse.getResults()));
Assert.assertEquals(expectedCursors, searchResponse.getCursors());
// no offset, limit 1, no cursors
searchResponse = searchMetadata(namespace, "*", targets, sort, 0, 1, 0, null);
expectedResults = ImmutableList.of(new MetadataSearchResultRecord(dataset));
expectedCursors = ImmutableList.of();
Assert.assertEquals(expectedResults, new ArrayList<>(searchResponse.getResults()));
Assert.assertEquals(expectedCursors, searchResponse.getCursors());
// no offset, limit 1, 2 cursors, should return 1st result, with 2 cursors
searchResponse = searchMetadata(namespace, "*", targets, sort, 0, 1, 2, null);
expectedResults = ImmutableList.of(new MetadataSearchResultRecord(dataset));
expectedCursors = ImmutableList.of(stream.getEntityName(), view.getEntityName());
Assert.assertEquals(expectedResults, new ArrayList<>(searchResponse.getResults()));
Assert.assertEquals(expectedCursors, searchResponse.getCursors());
// offset 1, limit 1, 2 cursors, should return 2nd result, with only 1 cursor since we don't have enough data
searchResponse = searchMetadata(namespace, "*", targets, sort, 1, 1, 2, null);
expectedResults = ImmutableList.of(new MetadataSearchResultRecord(stream));
expectedCursors = ImmutableList.of(view.getEntityName());
Assert.assertEquals(expectedResults, new ArrayList<>(searchResponse.getResults()));
Assert.assertEquals(expectedCursors, searchResponse.getCursors());
// offset 2, limit 1, 2 cursors, should return 3rd result, with 0 cursors since we don't have enough data
searchResponse = searchMetadata(namespace, "*", targets, sort, 2, 1, 2, null);
expectedResults = ImmutableList.of(new MetadataSearchResultRecord(view));
Assert.assertEquals(expectedResults, new ArrayList<>(searchResponse.getResults()));
Assert.assertTrue(searchResponse.getCursors().isEmpty());
// offset 3, limit 1, 2 cursors, should 0 results, with 0 cursors since we don't have enough data
searchResponse = searchMetadata(namespace, "*", targets, sort, 3, 1, 2, null);
Assert.assertTrue(searchResponse.getResults().isEmpty());
Assert.assertTrue(searchResponse.getCursors().isEmpty());
// no offset, no limit, should return everything
searchResponse = searchMetadata(namespace, "*", targets, sort, 0, Integer.MAX_VALUE, 4, null);
expectedResults = ImmutableList.of(new MetadataSearchResultRecord(dataset), new MetadataSearchResultRecord(stream), new MetadataSearchResultRecord(view));
Assert.assertEquals(expectedResults, new ArrayList<>(searchResponse.getResults()));
Assert.assertTrue(searchResponse.getCursors().isEmpty());
// cleanup
namespaceClient.delete(namespace);
}
use of co.cask.cdap.api.data.format.FormatSpecification in project cdap by caskdata.
the class MetadataHttpHandlerTestRun method testSearchResultSorting.
@Test
public void testSearchResultSorting() throws Exception {
NamespaceId namespace = new NamespaceId("sorting");
namespaceClient.create(new NamespaceMeta.Builder().setName(namespace).build());
StreamId stream = namespace.stream("text");
DatasetId dataset = namespace.dataset("mydataset");
StreamViewId view = stream.view("view");
// create entities so system metadata is annotated
// also ensure that they are created at least 1 ms apart
streamClient.create(stream);
TimeUnit.MILLISECONDS.sleep(1);
streamViewClient.createOrUpdate(view, new ViewSpecification(new FormatSpecification("csv", null, null)));
TimeUnit.MILLISECONDS.sleep(1);
datasetClient.create(dataset, new DatasetInstanceConfiguration(Table.class.getName(), Collections.<String, String>emptyMap()));
// search with bad sort param
EnumSet<EntityTypeSimpleName> targets = EnumSet.allOf(EntityTypeSimpleName.class);
// test ascending order of entity name
Set<MetadataSearchResultRecord> searchResults = searchMetadata(namespace, "*", targets, AbstractSystemMetadataWriter.ENTITY_NAME_KEY + " asc");
List<MetadataSearchResultRecord> expected = ImmutableList.of(new MetadataSearchResultRecord(dataset), new MetadataSearchResultRecord(stream), new MetadataSearchResultRecord(view));
Assert.assertEquals(expected, new ArrayList<>(searchResults));
// test descending order of entity name
searchResults = searchMetadata(namespace, "*", targets, AbstractSystemMetadataWriter.ENTITY_NAME_KEY + " desc");
expected = ImmutableList.of(new MetadataSearchResultRecord(view), new MetadataSearchResultRecord(stream), new MetadataSearchResultRecord(dataset));
Assert.assertEquals(expected, new ArrayList<>(searchResults));
// test ascending order of creation time
searchResults = searchMetadata(namespace, "*", targets, AbstractSystemMetadataWriter.CREATION_TIME_KEY + " asc");
expected = ImmutableList.of(new MetadataSearchResultRecord(stream), new MetadataSearchResultRecord(view), new MetadataSearchResultRecord(dataset));
Assert.assertEquals(expected, new ArrayList<>(searchResults));
// test descending order of creation time
searchResults = searchMetadata(namespace, "*", targets, AbstractSystemMetadataWriter.CREATION_TIME_KEY + " desc");
expected = ImmutableList.of(new MetadataSearchResultRecord(dataset), new MetadataSearchResultRecord(view), new MetadataSearchResultRecord(stream));
Assert.assertEquals(expected, new ArrayList<>(searchResults));
// cleanup
namespaceClient.delete(namespace);
}
Aggregations