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/24 08:32:41 UTC
[incubator-plc4x] 01/02: [plc4j-scraper] Added module,
initial tests.
This is an automated email from the ASF dual-hosted git repository.
jfeinauer pushed a commit to branch feature/plc4j-scraper
in repository https://gitbox.apache.org/repos/asf/incubator-plc4x.git
commit eba8955550896c4930a05fd276fc67aabfac623a
Author: Julian Feinauer <j....@pragmaticminds.de>
AuthorDate: Sat Nov 24 09:09:34 2018 +0100
[plc4j-scraper] Added module, initial tests.
---
plc4j/utils/pom.xml | 1 +
plc4j/utils/scraper/pom.xml | 59 +++++++++++++++
.../apache/plc4x/java/s7/ManualS7PlcDriverMT.java | 85 ++++++++++++++++++++++
3 files changed, 145 insertions(+)
diff --git a/plc4j/utils/pom.xml b/plc4j/utils/pom.xml
index c9f3d82..f511bd8 100644
--- a/plc4j/utils/pom.xml
+++ b/plc4j/utils/pom.xml
@@ -39,6 +39,7 @@
<module>raw-sockets</module>
<module>test-utils</module>
<module>wireshark-utils</module>
+ <module>scraper</module>
</modules>
</project>
\ No newline at end of file
diff --git a/plc4j/utils/scraper/pom.xml b/plc4j/utils/scraper/pom.xml
new file mode 100644
index 0000000..9b2e372
--- /dev/null
+++ b/plc4j/utils/scraper/pom.xml
@@ -0,0 +1,59 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ ~ 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.
+ -->
+
+<project xmlns="http://maven.apache.org/POM/4.0.0"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+ <parent>
+ <artifactId>plc4j-utils</artifactId>
+ <groupId>org.apache.plc4x</groupId>
+ <version>0.3.0-SNAPSHOT</version>
+ </parent>
+ <modelVersion>4.0.0</modelVersion>
+
+ <artifactId>plc4j-scraper</artifactId>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.apache.commons</groupId>
+ <artifactId>commons-math3</artifactId>
+ <version>3.5</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.plc4x</groupId>
+ <artifactId>plc4j-api</artifactId>
+ <version>0.3.0-SNAPSHOT</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.plc4x</groupId>
+ <artifactId>plc4j-driver-s7</artifactId>
+ <version>0.3.0-SNAPSHOT</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.plc4x</groupId>
+ <artifactId>plc4j-connection-pool</artifactId>
+ <version>0.3.0-SNAPSHOT</version>
+ <scope>test</scope>
+ </dependency>
+ </dependencies>
+
+
+</project>
\ No newline at end of file
diff --git a/plc4j/utils/scraper/src/test/java/org/apache/plc4x/java/s7/ManualS7PlcDriverMT.java b/plc4j/utils/scraper/src/test/java/org/apache/plc4x/java/s7/ManualS7PlcDriverMT.java
new file mode 100644
index 0000000..af60176
--- /dev/null
+++ b/plc4j/utils/scraper/src/test/java/org/apache/plc4x/java/s7/ManualS7PlcDriverMT.java
@@ -0,0 +1,85 @@
+/*
+ * 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.s7;
+
+import org.apache.commons.math3.stat.descriptive.DescriptiveStatistics;
+import org.apache.plc4x.java.PlcDriverManager;
+import org.apache.plc4x.java.api.PlcConnection;
+import org.apache.plc4x.java.api.messages.PlcReadResponse;
+import org.apache.plc4x.java.utils.connectionpool.PooledPlcDriverManager;
+import org.junit.Test;
+
+import java.util.ArrayList;
+import java.util.Locale;
+import java.util.concurrent.CompletableFuture;
+import java.util.concurrent.TimeUnit;
+import java.util.stream.Collectors;
+
+public class ManualS7PlcDriverMT {
+
+ public static final String CONN_STRING = "s7://10.10.64.22/0/1";
+ public static final String FIELD_STRING = "%DB225:DBW0:INT";
+
+// public static final String CONN_STRING = "s7://10.10.64.20/0/1";
+// public static final String FIELD_STRING = "%DB3:DBD32:DINT";
+
+ @Test
+ public void simpleLoop() {
+ PlcDriverManager plcDriverManager = new PooledPlcDriverManager();
+
+ DescriptiveStatistics statistics = new DescriptiveStatistics();
+ for (int i = 1; i <= 1000; i++) {
+
+ long start = System.nanoTime();
+ try (PlcConnection connection = plcDriverManager.getConnection(CONN_STRING)) {
+ CompletableFuture<? extends PlcReadResponse> future = connection.readRequestBuilder()
+ .addItem("distance", FIELD_STRING)
+ .build()
+ .execute();
+
+ PlcReadResponse response = future.get(10, TimeUnit.SECONDS);
+
+ System.out.println(i + " " + response.getLong("distance"));
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ long end = System.nanoTime();
+ statistics.addValue((double)(end-start));
+ }
+
+ printStatistics(statistics);
+ }
+
+ @Test
+ public void scheduledLoop() {
+
+ }
+
+ private void printStatistics(DescriptiveStatistics statistics) {
+ System.out.println("Mean response time: " + TimeUnit.NANOSECONDS.toMillis((long)statistics.getMean()) + " ms");
+ System.out.println("Median response time: " + TimeUnit.NANOSECONDS.toMillis((long)statistics.getPercentile(50)) + " ms");
+ for (int i = 10; i <= 90; i += 10) {
+ System.out.println(String.format(Locale.ENGLISH, "Percentile %3d %%: %5d ms", i, TimeUnit.NANOSECONDS.toMillis((long) statistics.getPercentile(i))));
+ }
+ for (int i = 91; i <= 100; i++) {
+ System.out.println(String.format(Locale.ENGLISH, "Percentile %3d %%: %5d ms", i, TimeUnit.NANOSECONDS.toMillis((long) statistics.getPercentile(i))));
+ }
+ }
+}