Search in sources :

Example 6 with SparkFileHelper

use of org.openstreetmap.atlas.generator.tools.spark.utilities.SparkFileHelper in project atlas-checks by osmlab.

the class MetricFileGeneratorTest method testFileName.

@Test
public void testFileName() throws IOException {
    final File tempDirectory = this.tempFolder.newFolder();
    final MetricFileGenerator generator = new MetricFileGenerator("some-metrics-log.csv", new SparkFileHelper(FILE_SYSTEM_CONFIG), tempDirectory.getAbsolutePath());
    final String filename = generator.getFilename();
    Assert.assertTrue(filename.matches("^some-metrics-log-\\d+.csv$"));
}
Also used : SparkFileHelper(org.openstreetmap.atlas.generator.tools.spark.utilities.SparkFileHelper) File(java.io.File) Test(org.junit.Test)

Example 7 with SparkFileHelper

use of org.openstreetmap.atlas.generator.tools.spark.utilities.SparkFileHelper in project atlas-checks by osmlab.

the class MetricFileGeneratorTest method processCompleteAndValidate.

private void processCompleteAndValidate(final int eventCount) throws IOException {
    // Generate
    final File tempDirectory = this.tempFolder.newFolder();
    final MetricFileGenerator processor = new MetricFileGenerator("some-file-name.csv", new SparkFileHelper(FILE_SYSTEM_CONFIG), tempDirectory.getAbsolutePath());
    for (int index = 0; index < eventCount; index++) {
        processor.process(SAMPLE_EVENT);
    }
    processor.process(new ShutdownEvent());
    // Validate
    final List<Resource> files = FileSystemHelper.resources(tempDirectory.getAbsolutePath(), FILE_SYSTEM_CONFIG);
    Assert.assertEquals((int) Math.floor(eventCount / (double) BATCH_SIZE) + 1, files.size());
    int actualEventCount = 0;
    for (final Resource file : files) {
        for (final String line : file.lines()) {
            // This is first line
            if (actualEventCount == 0) {
                Assert.assertEquals(MetricEvent.header(), line);
            } else {
                Assert.assertEquals("a-metric-name,60000", line);
            }
            actualEventCount++;
        }
    }
    // Plus 1 is for the header
    Assert.assertEquals(eventCount + 1, actualEventCount);
}
Also used : Resource(org.openstreetmap.atlas.streaming.resource.Resource) SparkFileHelper(org.openstreetmap.atlas.generator.tools.spark.utilities.SparkFileHelper) File(java.io.File)

Aggregations

SparkFileHelper (org.openstreetmap.atlas.generator.tools.spark.utilities.SparkFileHelper)7 File (java.io.File)6 Test (org.junit.Test)3 Resource (org.openstreetmap.atlas.streaming.resource.Resource)3 JsonObject (com.google.gson.JsonObject)1 InputStreamReader (java.io.InputStreamReader)1 ArrayList (java.util.ArrayList)1 Collections (java.util.Collections)1 HashSet (java.util.HashSet)1 List (java.util.List)1 Map (java.util.Map)1 Objects (java.util.Objects)1 Optional (java.util.Optional)1 Set (java.util.Set)1 Consumer (java.util.function.Consumer)1 Collectors (java.util.stream.Collectors)1 Stream (java.util.stream.Stream)1 TaskContext (org.apache.spark.TaskContext)1 JavaPairRDD (org.apache.spark.api.java.JavaPairRDD)1 BaseCheck (org.openstreetmap.atlas.checks.base.BaseCheck)1