You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@plc4x.apache.org by jf...@apache.org on 2018/11/25 13:40:30 UTC

[incubator-plc4x] branch features/scraper-builder created (now fe8e751)

This is an automated email from the ASF dual-hosted git repository.

jfeinauer pushed a change to branch features/scraper-builder
in repository https://gitbox.apache.org/repos/asf/incubator-plc4x.git.


      at fe8e751  [plc4j-scraper] Fix in Builder.

This branch includes the following new commits:

     new edbf0c8  [plc4j-scraper] Extended ResultHandler.java to also pass jobname and connection alias.
     new 777829a  [plc4j-scraper] Added javadoc.
     new 0abbdd0  [plc4j-scraper] Added Builder for Job / Scraper config.
     new fe8e751  [plc4j-scraper] Fix in Builder.

The 4 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.



[incubator-plc4x] 01/04: [plc4j-scraper] Extended ResultHandler.java to also pass jobname and connection alias.

Posted by jf...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

jfeinauer pushed a commit to branch features/scraper-builder
in repository https://gitbox.apache.org/repos/asf/incubator-plc4x.git

commit edbf0c803a831c375bbe75a8d0b145391d855f11
Author: Julian Feinauer <j....@pragmaticminds.de>
AuthorDate: Sun Nov 25 10:56:43 2018 +0100

    [plc4j-scraper] Extended ResultHandler.java to also pass jobname and connection alias.
---
 .../apache/plc4x/java/scraper/ResultHandler.java}  | 26 +++++++++++-----------
 .../org/apache/plc4x/java/scraper/Scraper.java     |  7 ------
 .../org/apache/plc4x/java/scraper/ScraperTask.java |  6 ++---
 .../apache/plc4x/java/scraper/ScraperRunner.java   |  2 +-
 .../apache/plc4x/java/scraper/ScraperTaskTest.java |  8 +++----
 .../org/apache/plc4x/java/scraper/ScraperTest.java |  8 +++----
 6 files changed, 25 insertions(+), 32 deletions(-)

diff --git a/plc4j/utils/scraper/src/test/java/org/apache/plc4x/java/scraper/ScraperRunner.java b/plc4j/utils/scraper/src/main/java/org/apache/plc4x/java/scraper/ResultHandler.java
similarity index 59%
copy from plc4j/utils/scraper/src/test/java/org/apache/plc4x/java/scraper/ScraperRunner.java
copy to plc4j/utils/scraper/src/main/java/org/apache/plc4x/java/scraper/ResultHandler.java
index fa91ea5..f6ad53c 100644
--- a/plc4j/utils/scraper/src/test/java/org/apache/plc4x/java/scraper/ScraperRunner.java
+++ b/plc4j/utils/scraper/src/main/java/org/apache/plc4x/java/scraper/ResultHandler.java
@@ -19,20 +19,20 @@
 
 package org.apache.plc4x.java.scraper;
 
-import org.apache.plc4x.java.scraper.config.ScraperConfiguration;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
+import java.util.Map;
 
-import java.io.IOException;
-
-public class ScraperRunner {
-
-    private static final Logger LOGGER = LoggerFactory.getLogger(ScraperRunner.class);
+/**
+ * Callback interface to handle results of one run of a {@link ScraperTask}.
+ */
+@FunctionalInterface
+public interface ResultHandler {
 
-    public static void main(String[] args) throws IOException {
-        ScraperConfiguration configuration = ScraperConfiguration.fromFile("plc4j/utils/scraper/src/test/resources/example.yml");
-        Scraper scraper = new Scraper(configuration, m -> {}/*LOGGER.info("Results: {}", m)*/);
+    /**
+     * Callback handler.
+     * @param job name of the job (from config)
+     * @param alias alias of the connection (<b>not</b> connection String)
+     * @param results Results in the form alias to result value
+     */
+    void handle(String job, String alias, Map<String, Object> results);
 
-        scraper.start();
-    }
 }
diff --git a/plc4j/utils/scraper/src/main/java/org/apache/plc4x/java/scraper/Scraper.java b/plc4j/utils/scraper/src/main/java/org/apache/plc4x/java/scraper/Scraper.java
index 44e9fc6..52efa8e 100644
--- a/plc4j/utils/scraper/src/main/java/org/apache/plc4x/java/scraper/Scraper.java
+++ b/plc4j/utils/scraper/src/main/java/org/apache/plc4x/java/scraper/Scraper.java
@@ -153,11 +153,4 @@ public class Scraper {
         futures.clear();
     }
 
-    @FunctionalInterface
-    public interface ResultHandler {
-
-        void handle(Map<String, Object> results);
-
-    }
-
 }
diff --git a/plc4j/utils/scraper/src/main/java/org/apache/plc4x/java/scraper/ScraperTask.java b/plc4j/utils/scraper/src/main/java/org/apache/plc4x/java/scraper/ScraperTask.java
index afbfe07..3175ee1 100644
--- a/plc4j/utils/scraper/src/main/java/org/apache/plc4x/java/scraper/ScraperTask.java
+++ b/plc4j/utils/scraper/src/main/java/org/apache/plc4x/java/scraper/ScraperTask.java
@@ -55,7 +55,7 @@ public class ScraperTask implements Runnable {
     private final Map<String, String> fields;
     private final long requestTimeoutMs;
     private final ExecutorService handlerService;
-    private final Scraper.ResultHandler resultHandler;
+    private final ResultHandler resultHandler;
 
     private final AtomicLong requestCounter = new AtomicLong(0);
     private final AtomicLong successCounter = new AtomicLong(0);
@@ -63,7 +63,7 @@ public class ScraperTask implements Runnable {
     private final DescriptiveStatistics failedStatistics = new DescriptiveStatistics(1000);
 
     public ScraperTask(PlcDriverManager driverManager, String jobName, String connectionAlias, String connectionString,
-                       Map<String, String> fields, long requestTimeoutMs, ExecutorService handlerService, Scraper.ResultHandler resultHandler) {
+                       Map<String, String> fields, long requestTimeoutMs, ExecutorService handlerService, ResultHandler resultHandler) {
         Validate.notNull(driverManager);
         Validate.notBlank(jobName);
         Validate.notBlank(connectionAlias);
@@ -123,7 +123,7 @@ public class ScraperTask implements Runnable {
             // Validate response
             validateResponse(response);
             // Handle response (Async)
-            CompletableFuture.runAsync(() -> resultHandler.handle(transformResponseToMap(response)), handlerService);
+            CompletableFuture.runAsync(() -> resultHandler.handle(jobName, connectionAlias, transformResponseToMap(response)), handlerService);
         } catch (Exception e) {
             LOGGER.debug("Exception during scrape", e);
             handleException(e);
diff --git a/plc4j/utils/scraper/src/test/java/org/apache/plc4x/java/scraper/ScraperRunner.java b/plc4j/utils/scraper/src/test/java/org/apache/plc4x/java/scraper/ScraperRunner.java
index fa91ea5..029a25a 100644
--- a/plc4j/utils/scraper/src/test/java/org/apache/plc4x/java/scraper/ScraperRunner.java
+++ b/plc4j/utils/scraper/src/test/java/org/apache/plc4x/java/scraper/ScraperRunner.java
@@ -31,7 +31,7 @@ public class ScraperRunner {
 
     public static void main(String[] args) throws IOException {
         ScraperConfiguration configuration = ScraperConfiguration.fromFile("plc4j/utils/scraper/src/test/resources/example.yml");
-        Scraper scraper = new Scraper(configuration, m -> {}/*LOGGER.info("Results: {}", m)*/);
+        Scraper scraper = new Scraper(configuration, (j, a, m) -> LOGGER.info("Results from {}/{}: {}", j, a, m));
 
         scraper.start();
     }
diff --git a/plc4j/utils/scraper/src/test/java/org/apache/plc4x/java/scraper/ScraperTaskTest.java b/plc4j/utils/scraper/src/test/java/org/apache/plc4x/java/scraper/ScraperTaskTest.java
index a83a939..670a0b7 100644
--- a/plc4j/utils/scraper/src/test/java/org/apache/plc4x/java/scraper/ScraperTaskTest.java
+++ b/plc4j/utils/scraper/src/test/java/org/apache/plc4x/java/scraper/ScraperTaskTest.java
@@ -54,7 +54,7 @@ public class ScraperTaskTest implements WithAssertions {
         when(mockDevice.read(any())).thenReturn(Pair.of(PlcResponseCode.OK, new DefaultStringFieldItem("hallo")));
 
         ScraperTask scraperTask = new ScraperTask(driverManager, "job1", "m1", "mock:scraper", Collections.singletonMap("a", "b"),
-            1_000, ForkJoinPool.commonPool(), m -> {});
+            1_000, ForkJoinPool.commonPool(), (j,a,m) -> {});
 
         scraperTask.run();
     }
@@ -71,7 +71,7 @@ public class ScraperTaskTest implements WithAssertions {
             when(mockDevice.read(any())).thenReturn(Pair.of(PlcResponseCode.NOT_FOUND, new DefaultStringFieldItem("hallo")));
 
             ScraperTask scraperTask = new ScraperTask(driverManager, "job1", "m1",
-                "mock:scraper", Collections.singletonMap("a", "b"), 1_000, ForkJoinPool.commonPool(), m -> {});
+                "mock:scraper", Collections.singletonMap("a", "b"), 1_000, ForkJoinPool.commonPool(), (j,a,m) -> {});
 
             // When
             scraperTask.run();
@@ -86,7 +86,7 @@ public class ScraperTaskTest implements WithAssertions {
             when(driverManager.getConnection(anyString())).thenThrow(new PlcConnectionException("stfu"));
 
             ScraperTask scraperTask = new ScraperTask(driverManager, "job1", "m1", "mock:scraper", Collections.singletonMap("a", "b"),
-                1_000, ForkJoinPool.commonPool(), m -> {});
+                1_000, ForkJoinPool.commonPool(), (j,a,m) -> {});
 
             ScraperTask spy = spy(scraperTask);
             spy.run();
@@ -99,7 +99,7 @@ public class ScraperTaskTest implements WithAssertions {
             when(driverManager.getConnection(anyString())).thenThrow(new PlcConnectionException("stfu"));
             ScheduledExecutorService pool = Executors.newScheduledThreadPool(1);
             ScraperTask scraperTask = new ScraperTask(driverManager, "job1", "m1", "mock:scraper", Collections.singletonMap("a", "b"),
-                1_000, ForkJoinPool.commonPool(), m -> {});
+                1_000, ForkJoinPool.commonPool(), (j,a,m) -> {});
 
             Future<?> future = pool.scheduleAtFixedRate(scraperTask, 0, 10, TimeUnit.MILLISECONDS);
 
diff --git a/plc4j/utils/scraper/src/test/java/org/apache/plc4x/java/scraper/ScraperTest.java b/plc4j/utils/scraper/src/test/java/org/apache/plc4x/java/scraper/ScraperTest.java
index 1822a20..40637d2 100644
--- a/plc4j/utils/scraper/src/test/java/org/apache/plc4x/java/scraper/ScraperTest.java
+++ b/plc4j/utils/scraper/src/test/java/org/apache/plc4x/java/scraper/ScraperTest.java
@@ -71,7 +71,7 @@ class ScraperTest implements WithAssertions {
             return new GenericKeyedObjectPool<>(pooledPlcConnectionFactory, config);
         });
 
-        Scraper scraper = new Scraper(m -> {}, driverManager, Arrays.asList(
+        Scraper scraper = new Scraper((j,a,m) -> {}, driverManager, Arrays.asList(
             new ScrapeJob("job1",
                 10,
                 Collections.singletonMap("tim", CONN_STRING_TIM),
@@ -95,7 +95,7 @@ class ScraperTest implements WithAssertions {
 
         when(mockDevice.read(any())).thenReturn(Pair.of(PlcResponseCode.OK, new DefaultIntegerFieldItem(1)));
 
-        Scraper scraper = new Scraper(m -> {}, driverManager, Collections.singletonList(
+        Scraper scraper = new Scraper((j,a,m) -> {}, driverManager, Collections.singletonList(
             new ScrapeJob("job1",
                 10,
                 Collections.singletonMap("m1", "mock:m1"),
@@ -119,7 +119,7 @@ class ScraperTest implements WithAssertions {
     void stop_stopsAllJobs() {
         PlcDriverManager driverManager = new PlcDriverManager();
 
-        Scraper scraper = new Scraper(m -> {}, driverManager, Collections.singletonList(
+        Scraper scraper = new Scraper((j,a,m) -> {}, driverManager, Collections.singletonList(
             new ScrapeJob("job1",
                 1,
                 Collections.singletonMap("m1", "mock:m1"),
@@ -146,7 +146,7 @@ class ScraperTest implements WithAssertions {
 
         when(mockDevice.read(any())).thenReturn(Pair.of(PlcResponseCode.OK, new DefaultIntegerFieldItem(1)));
 
-        Scraper scraper = new Scraper(m -> {}, driverManager, Collections.singletonList(
+        Scraper scraper = new Scraper((j,a,m) -> {}, driverManager, Collections.singletonList(
             new ScrapeJob("job1",
                 1,
                 Collections.singletonMap("m1", "mock:m1"),


[incubator-plc4x] 02/04: [plc4j-scraper] Added javadoc.

Posted by jf...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

jfeinauer pushed a commit to branch features/scraper-builder
in repository https://gitbox.apache.org/repos/asf/incubator-plc4x.git

commit 777829a1a0b93415967c25b170c9196d8be7c9f0
Author: Julian Feinauer <j....@pragmaticminds.de>
AuthorDate: Sun Nov 25 11:02:28 2018 +0100

    [plc4j-scraper] Added javadoc.
---
 .../main/java/org/apache/plc4x/java/scraper/ScrapeJob.java |  5 +++++
 .../java/org/apache/plc4x/java/scraper/ScraperTask.java    |  4 +++-
 .../apache/plc4x/java/scraper/config/JobConfiguration.java | 14 ++++++++++----
 .../plc4x/java/scraper/config/ScraperConfiguration.java    |  6 +++++-
 4 files changed, 23 insertions(+), 6 deletions(-)

diff --git a/plc4j/utils/scraper/src/main/java/org/apache/plc4x/java/scraper/ScrapeJob.java b/plc4j/utils/scraper/src/main/java/org/apache/plc4x/java/scraper/ScrapeJob.java
index 14502bb..d399c64 100644
--- a/plc4j/utils/scraper/src/main/java/org/apache/plc4x/java/scraper/ScrapeJob.java
+++ b/plc4j/utils/scraper/src/main/java/org/apache/plc4x/java/scraper/ScrapeJob.java
@@ -21,6 +21,11 @@ package org.apache.plc4x.java.scraper;
 
 import java.util.Map;
 
+/**
+ * POJO Object to transport all Job informtation.
+ * Is generated from {@link org.apache.plc4x.java.scraper.config.ScraperConfiguration} by
+ * merging the sources and the {@link org.apache.plc4x.java.scraper.config.JobConfiguration}.
+ */
 public class ScrapeJob {
 
     private final String name;
diff --git a/plc4j/utils/scraper/src/main/java/org/apache/plc4x/java/scraper/ScraperTask.java b/plc4j/utils/scraper/src/main/java/org/apache/plc4x/java/scraper/ScraperTask.java
index 3175ee1..56f3f8b 100644
--- a/plc4j/utils/scraper/src/main/java/org/apache/plc4x/java/scraper/ScraperTask.java
+++ b/plc4j/utils/scraper/src/main/java/org/apache/plc4x/java/scraper/ScraperTask.java
@@ -42,7 +42,9 @@ import java.util.function.Function;
 import java.util.stream.Collectors;
 
 /**
- * Plc Scraper that scrapes one source.
+ * Plc Scraper Task that scrapes one source.
+ * One {@link ScrapeJob} gets split into multiple tasks.
+ * One task for each source that is defined in the {@link org.apache.plc4x.java.scraper.config.JobConfiguration}.
  */
 public class ScraperTask implements Runnable {
 
diff --git a/plc4j/utils/scraper/src/main/java/org/apache/plc4x/java/scraper/config/JobConfiguration.java b/plc4j/utils/scraper/src/main/java/org/apache/plc4x/java/scraper/config/JobConfiguration.java
index 6cb2ede..2fd50f7 100644
--- a/plc4j/utils/scraper/src/main/java/org/apache/plc4x/java/scraper/config/JobConfiguration.java
+++ b/plc4j/utils/scraper/src/main/java/org/apache/plc4x/java/scraper/config/JobConfiguration.java
@@ -21,14 +21,13 @@ package org.apache.plc4x.java.scraper.config;
 
 import com.fasterxml.jackson.annotation.JsonCreator;
 import com.fasterxml.jackson.annotation.JsonProperty;
-import com.fasterxml.jackson.databind.ObjectMapper;
-import com.fasterxml.jackson.dataformat.yaml.YAMLFactory;
-import org.apache.plc4x.java.api.exceptions.PlcRuntimeException;
 
-import java.io.IOException;
 import java.util.List;
 import java.util.Map;
 
+/**
+ * Configuration for one {@link org.apache.plc4x.java.scraper.ScrapeJob} in the @{@link ScraperConfiguration}.
+ */
 public class JobConfiguration {
 
     private final String name;
@@ -36,6 +35,13 @@ public class JobConfiguration {
     private final List<String> sources;
     private final Map<String, String> fields;
 
+    /**
+     * Default construcotr
+     * @param name Job Name / identifier
+     * @param scrapeRate Scrape rate in ms
+     * @param sources source alias (<b>not</b> connection string but the alias (from @{@link ScraperConfiguration}).
+     * @param fields Map from field alias (how it is named in the result map) to plc4x field query
+     */
     @JsonCreator
     JobConfiguration(@JsonProperty(value = "name", required = true) String name,
                             @JsonProperty(value = "scrapeRate", required = true) int scrapeRate,
diff --git a/plc4j/utils/scraper/src/main/java/org/apache/plc4x/java/scraper/config/ScraperConfiguration.java b/plc4j/utils/scraper/src/main/java/org/apache/plc4x/java/scraper/config/ScraperConfiguration.java
index 48d688c..785e01d 100644
--- a/plc4j/utils/scraper/src/main/java/org/apache/plc4x/java/scraper/config/ScraperConfiguration.java
+++ b/plc4j/utils/scraper/src/main/java/org/apache/plc4x/java/scraper/config/ScraperConfiguration.java
@@ -39,12 +39,16 @@ import java.util.stream.Collectors;
 /**
  * Configuration class for {@link Scraper}.
  */
-
 public class ScraperConfiguration {
 
     private final Map<String, String> sources;
     private final List<JobConfiguration> jobConfigurations;
 
+    /**
+     * Default constructor.
+     * @param sources Map from connection alias to connection string
+     * @param jobConfigurations List of configurations one for each Job
+     */
     @JsonCreator
     ScraperConfiguration(@JsonProperty(value = "sources", required = true) Map<String, String> sources,
                          @JsonProperty(value = "jobs", required = true) List<JobConfiguration> jobConfigurations) {


[incubator-plc4x] 03/04: [plc4j-scraper] Added Builder for Job / Scraper config.

Posted by jf...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

jfeinauer pushed a commit to branch features/scraper-builder
in repository https://gitbox.apache.org/repos/asf/incubator-plc4x.git

commit 0abbdd0317bb33e30852409275bddcda254e8892
Author: Julian Feinauer <j....@pragmaticminds.de>
AuthorDate: Sun Nov 25 11:20:03 2018 +0100

    [plc4j-scraper] Added Builder for Job / Scraper config.
---
 .../scraper/config/JobConfigurationBuilder.java    | 60 ++++++++++++++++++++++
 .../config/ScraperConfigurationBuilder.java        | 48 +++++++++++++++++
 .../config/ScraperConfigurationBuilderTest.java    | 51 ++++++++++++++++++
 3 files changed, 159 insertions(+)

diff --git a/plc4j/utils/scraper/src/main/java/org/apache/plc4x/java/scraper/config/JobConfigurationBuilder.java b/plc4j/utils/scraper/src/main/java/org/apache/plc4x/java/scraper/config/JobConfigurationBuilder.java
new file mode 100644
index 0000000..5a62b66
--- /dev/null
+++ b/plc4j/utils/scraper/src/main/java/org/apache/plc4x/java/scraper/config/JobConfigurationBuilder.java
@@ -0,0 +1,60 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.plc4x.java.scraper.config;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+public class JobConfigurationBuilder {
+
+    private final ScraperConfigurationBuilder parent;
+    private final String name;
+    private final int scrapeRateMs;
+
+    private final List<String> sources = new ArrayList<>();
+    private final Map<String, String> fields = new HashMap<>();
+
+    public JobConfigurationBuilder(ScraperConfigurationBuilder parent, String name, int scrapeRateMs) {
+        this.parent = parent;
+        this.name = name;
+        this.scrapeRateMs = scrapeRateMs;
+    }
+
+    public JobConfigurationBuilder source(String alias) {
+        this.sources.add(alias);
+        return this;
+    }
+
+    public JobConfigurationBuilder field(String alias, String fieldQuery) {
+        this.fields.put(alias, fieldQuery);
+        return this;
+    }
+
+    private JobConfiguration buildInternal() {
+        return new JobConfiguration(name, scrapeRateMs, sources, fields);
+    }
+
+    public ScraperConfigurationBuilder build() {
+        parent.addJobConfiguration(this.buildInternal());
+        return this.parent;
+    }
+}
diff --git a/plc4j/utils/scraper/src/main/java/org/apache/plc4x/java/scraper/config/ScraperConfigurationBuilder.java b/plc4j/utils/scraper/src/main/java/org/apache/plc4x/java/scraper/config/ScraperConfigurationBuilder.java
new file mode 100644
index 0000000..06c9b85
--- /dev/null
+++ b/plc4j/utils/scraper/src/main/java/org/apache/plc4x/java/scraper/config/ScraperConfigurationBuilder.java
@@ -0,0 +1,48 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.plc4x.java.scraper.config;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+public class ScraperConfigurationBuilder {
+
+    private final Map<String, String> sources = new HashMap<>();
+    private final List<JobConfiguration> jobConfigurations = new ArrayList<>();
+
+    public ScraperConfigurationBuilder addSource(String alias, String connectionString) {
+        sources.put(alias, connectionString);
+        return this;
+    }
+
+    public JobConfigurationBuilder job(String name, int scrapeRateMs) {
+        return new JobConfigurationBuilder(this, name, scrapeRateMs);
+    }
+
+    public ScraperConfiguration build() {
+        return new ScraperConfiguration(sources, jobConfigurations);
+    }
+
+    void addJobConfiguration(JobConfiguration configuration) {
+        this.jobConfigurations.add(configuration);
+    }
+}
diff --git a/plc4j/utils/scraper/src/test/java/org/apache/plc4x/java/scraper/config/ScraperConfigurationBuilderTest.java b/plc4j/utils/scraper/src/test/java/org/apache/plc4x/java/scraper/config/ScraperConfigurationBuilderTest.java
new file mode 100644
index 0000000..63a232a
--- /dev/null
+++ b/plc4j/utils/scraper/src/test/java/org/apache/plc4x/java/scraper/config/ScraperConfigurationBuilderTest.java
@@ -0,0 +1,51 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.plc4x.java.scraper.config;
+
+import org.junit.jupiter.api.Test;
+
+import java.util.Arrays;
+import java.util.List;
+
+import static org.junit.jupiter.api.Assertions.*;
+
+class ScraperConfigurationBuilderTest {
+
+    @Test
+    void checkSyntax() {
+        ScraperConfigurationBuilder builder = new ScraperConfigurationBuilder();
+        List<String> sources = Arrays.asList("s1", "s2");
+        List<String> jobs = Arrays.asList("j1", "j2");
+
+        sources.forEach(source -> builder.addSource(source, source));
+        for (String job : jobs) {
+            JobConfigurationBuilder jobConfigurationBuilder = builder.job(job, 10);
+            for (int i = 1; i <= 100; i++) {
+                jobConfigurationBuilder.field("f" + i, "qry" + i);
+            }
+            jobConfigurationBuilder.build();
+        }
+
+        ScraperConfiguration configuration = builder.build();
+
+        // TODO add assert.
+        System.out.println(configuration);
+    }
+}
\ No newline at end of file


[incubator-plc4x] 04/04: [plc4j-scraper] Fix in Builder.

Posted by jf...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

jfeinauer pushed a commit to branch features/scraper-builder
in repository https://gitbox.apache.org/repos/asf/incubator-plc4x.git

commit fe8e75107b544ae8c1ef46f061f0648cc72ed4fa
Author: Julian Feinauer <j....@pragmaticminds.de>
AuthorDate: Sun Nov 25 11:22:06 2018 +0100

    [plc4j-scraper] Fix in Builder.
---
 .../java/scraper/config/ScraperConfigurationBuilderTest.java | 12 ++++++++++--
 1 file changed, 10 insertions(+), 2 deletions(-)

diff --git a/plc4j/utils/scraper/src/test/java/org/apache/plc4x/java/scraper/config/ScraperConfigurationBuilderTest.java b/plc4j/utils/scraper/src/test/java/org/apache/plc4x/java/scraper/config/ScraperConfigurationBuilderTest.java
index 63a232a..7311a9d 100644
--- a/plc4j/utils/scraper/src/test/java/org/apache/plc4x/java/scraper/config/ScraperConfigurationBuilderTest.java
+++ b/plc4j/utils/scraper/src/test/java/org/apache/plc4x/java/scraper/config/ScraperConfigurationBuilderTest.java
@@ -19,6 +19,9 @@
 
 package org.apache.plc4x.java.scraper.config;
 
+import com.fasterxml.jackson.core.JsonProcessingException;
+import com.fasterxml.jackson.databind.ObjectMapper;
+import com.fasterxml.jackson.dataformat.yaml.YAMLFactory;
 import org.junit.jupiter.api.Test;
 
 import java.util.Arrays;
@@ -29,7 +32,7 @@ import static org.junit.jupiter.api.Assertions.*;
 class ScraperConfigurationBuilderTest {
 
     @Test
-    void checkSyntax() {
+    void checkSyntax() throws JsonProcessingException {
         ScraperConfigurationBuilder builder = new ScraperConfigurationBuilder();
         List<String> sources = Arrays.asList("s1", "s2");
         List<String> jobs = Arrays.asList("j1", "j2");
@@ -37,6 +40,7 @@ class ScraperConfigurationBuilderTest {
         sources.forEach(source -> builder.addSource(source, source));
         for (String job : jobs) {
             JobConfigurationBuilder jobConfigurationBuilder = builder.job(job, 10);
+            sources.forEach(jobConfigurationBuilder::source);
             for (int i = 1; i <= 100; i++) {
                 jobConfigurationBuilder.field("f" + i, "qry" + i);
             }
@@ -45,7 +49,11 @@ class ScraperConfigurationBuilderTest {
 
         ScraperConfiguration configuration = builder.build();
 
+        ObjectMapper mapper = new ObjectMapper(new YAMLFactory());
+
+        String s = mapper.writeValueAsString(configuration);
+
         // TODO add assert.
-        System.out.println(configuration);
+        System.out.println(s);
     }
 }
\ No newline at end of file