Search in sources :

Example 1 with ValidatedConfiguration

use of io.divolte.server.config.ValidatedConfiguration in project divolte-collector by divolte.

the class FileFlusherTest method setupConfiguration.

private FileStrategyConfiguration setupConfiguration(final String roll, final String syncDuration, final String syncRecords) {
    final Config config = ConfigFactory.parseMap(ImmutableMap.<String, Object>builder().put("divolte.sinks.hdfs.type", "hdfs").put("divolte.sinks.hdfs.file_strategy.roll_every", roll).put("divolte.sinks.hdfs.file_strategy.sync_file_after_duration", syncDuration).put("divolte.sinks.hdfs.file_strategy.sync_file_after_records", syncRecords).put("divolte.sinks.hdfs.file_strategy.working_dir", "/tmp/work").put("divolte.sinks.hdfs.file_strategy.publish_dir", "/tmp/published").build()).withFallback(ConfigFactory.parseResources("reference-test.conf"));
    final ValidatedConfiguration vc = new ValidatedConfiguration(() -> config);
    return vc.configuration().getSinkConfiguration("hdfs", HdfsSinkConfiguration.class).fileStrategy;
}
Also used : Config(com.typesafe.config.Config) HdfsSinkConfiguration(io.divolte.server.config.HdfsSinkConfiguration) ValidatedConfiguration(io.divolte.server.config.ValidatedConfiguration)

Example 2 with ValidatedConfiguration

use of io.divolte.server.config.ValidatedConfiguration in project divolte-collector by divolte.

the class FileFlusherLocalHdfsTest method setupFlusher.

private void setupFlusher(final String rollEvery, final int recordCount) throws IOException {
    final Config config = ConfigFactory.parseMap(ImmutableMap.of("divolte.sinks.hdfs.file_strategy.roll_every", rollEvery, "divolte.sinks.hdfs.file_strategy.working_dir", tempInflightDir.toString(), "divolte.sinks.hdfs.file_strategy.publish_dir", tempPublishDir.toString())).withFallback(ConfigFactory.parseResources("hdfs-flusher-test.conf")).withFallback(ConfigFactory.parseResources("reference-test.conf"));
    final ValidatedConfiguration vc = new ValidatedConfiguration(() -> config);
    records = LongStream.range(0, recordCount).mapToObj((time) -> new GenericRecordBuilder(schema).set("ts", time).set("remoteHost", ARBITRARY_IP).build()).collect(Collectors.toList());
    flusher = new FileFlusher(vc.configuration().getSinkConfiguration("hdfs", FileSinkConfiguration.class).fileStrategy, HdfsFileManager.newFactory(vc, "hdfs", schema).create());
}
Also used : Config(com.typesafe.config.Config) FileFlusher(io.divolte.server.filesinks.FileFlusher) GenericRecordBuilder(org.apache.avro.generic.GenericRecordBuilder) ValidatedConfiguration(io.divolte.server.config.ValidatedConfiguration) FileSinkConfiguration(io.divolte.server.config.FileSinkConfiguration)

Example 3 with ValidatedConfiguration

use of io.divolte.server.config.ValidatedConfiguration in project divolte-collector by divolte.

the class TrackingJavaScriptResourceTest method setup.

@Before
public void setup() throws IOException {
    // Essential test to ensure at build-time that our JavaScript can be compiled.
    final ValidatedConfiguration vc = new ValidatedConfiguration(() -> config);
    trackingJavaScript = TrackingJavaScriptResource.create(vc, "browser");
}
Also used : ValidatedConfiguration(io.divolte.server.config.ValidatedConfiguration) Before(org.junit.Before)

Example 4 with ValidatedConfiguration

use of io.divolte.server.config.ValidatedConfiguration in project divolte-collector by divolte.

the class DslRecordMapperTest method shouldMapAllGeoIpFields.

@Test
public void shouldMapAllGeoIpFields() throws IOException, InterruptedException, ClosedServiceException {
    /*
         * Have to work around not being able to create a HttpServerExchange a bit.
         * We setup a actual server just to do a request and capture the HttpServerExchange
         * instance. Then we setup a DslRecordMapper instance with a mock ip2geo lookup service,
         * we then use the previously captured exchange object against our locally created mapper
         * instance to test the ip2geo mapping (using the a mock lookup service).
         */
    setupServer("minimal-mapping.groovy");
    final EventPayload payload = request("http://www.example.com");
    final File geoMappingFile = File.createTempFile("geo-mapping", ".groovy");
    copyResourceToFile("geo-mapping.groovy", geoMappingFile);
    final ImmutableMap<String, Object> mappingConfig = ImmutableMap.of("divolte.mappings.test.mapping_script_file", geoMappingFile.getAbsolutePath(), "divolte.mappings.test.schema_file", avroFile.getAbsolutePath());
    final Config geoConfig = ConfigFactory.parseMap(mappingConfig).withFallback(ConfigFactory.parseResources("base-test-server.conf")).withFallback(ConfigFactory.parseResources("reference-test.conf"));
    final ValidatedConfiguration vc = new ValidatedConfiguration(() -> geoConfig);
    final CityResponse mockResponseWithEverything = loadFromClassPath("/city-response-with-everything.json", new TypeReference<CityResponse>() {
    });
    final Map<String, Object> expectedMapping = loadFromClassPath("/city-response-expected-mapping.json", new TypeReference<Map<String, Object>>() {
    });
    final LookupService mockLookupService = mock(LookupService.class);
    when(mockLookupService.lookup(any())).thenReturn(Optional.of(mockResponseWithEverything));
    final DslRecordMapper mapper = new DslRecordMapper(vc, geoMappingFile.getAbsolutePath(), new Schema.Parser().parse(Resources.toString(Resources.getResource("TestRecord.avsc"), StandardCharsets.UTF_8)), Optional.of(mockLookupService));
    final GenericRecord record = mapper.newRecordFromExchange(payload.event);
    // Validate the results.
    verify(mockLookupService).lookup(any());
    verifyNoMoreInteractions(mockLookupService);
    expectedMapping.forEach((k, v) -> {
        final Object recordValue = record.get(k);
        assertEquals("Property " + k + " not mapped correctly.", v, recordValue);
    });
    Files.delete(geoMappingFile.toPath());
}
Also used : DslRecordMapper(io.divolte.server.recordmapping.DslRecordMapper) Config(com.typesafe.config.Config) ValidatedConfiguration(io.divolte.server.config.ValidatedConfiguration) JsonParser(com.fasterxml.jackson.core.JsonParser) CityResponse(com.maxmind.geoip2.model.CityResponse) LookupService(io.divolte.server.ip2geo.LookupService) GenericRecord(org.apache.avro.generic.GenericRecord) ImmutableMap(com.google.common.collect.ImmutableMap) EventPayload(io.divolte.server.ServerTestUtils.EventPayload) Test(org.junit.Test)

Aggregations

ValidatedConfiguration (io.divolte.server.config.ValidatedConfiguration)4 Config (com.typesafe.config.Config)3 JsonParser (com.fasterxml.jackson.core.JsonParser)1 ImmutableMap (com.google.common.collect.ImmutableMap)1 CityResponse (com.maxmind.geoip2.model.CityResponse)1 EventPayload (io.divolte.server.ServerTestUtils.EventPayload)1 FileSinkConfiguration (io.divolte.server.config.FileSinkConfiguration)1 HdfsSinkConfiguration (io.divolte.server.config.HdfsSinkConfiguration)1 FileFlusher (io.divolte.server.filesinks.FileFlusher)1 LookupService (io.divolte.server.ip2geo.LookupService)1 DslRecordMapper (io.divolte.server.recordmapping.DslRecordMapper)1 GenericRecord (org.apache.avro.generic.GenericRecord)1 GenericRecordBuilder (org.apache.avro.generic.GenericRecordBuilder)1 Before (org.junit.Before)1 Test (org.junit.Test)1