You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@plc4x.apache.org by cd...@apache.org on 2022/07/13 17:34:30 UTC
[plc4x] branch develop updated: chore(plc4j): Added a new Unit-Test annotation to let a test only get executed if the build is not run on a Parallels VM.
This is an automated email from the ASF dual-hosted git repository.
cdutz pushed a commit to branch develop
in repository https://gitbox.apache.org/repos/asf/plc4x.git
The following commit(s) were added to refs/heads/develop by this push:
new bd0b41bdb chore(plc4j): Added a new Unit-Test annotation to let a test only get executed if the build is not run on a Parallels VM.
bd0b41bdb is described below
commit bd0b41bdbd99fe85925700be0ab4fde8bf735e7a
Author: christoferdutz <ch...@c-ware.de>
AuthorDate: Wed Jul 13 19:34:16 2022 +0200
chore(plc4j): Added a new Unit-Test annotation to let a test only get executed if the build is not run on a Parallels VM.
---
.../protocol/OpcuaSubscriptionHandleTest.java | 16 +----
plc4j/utils/test-utils/pom.xml | 4 ++
.../plc4x/test/DisableOnParallelsVmFlag.java | 37 +++++++++++
.../test/DisableOnParallelsVmFlagCondition.java | 76 ++++++++++++++++++++++
4 files changed, 119 insertions(+), 14 deletions(-)
diff --git a/plc4j/drivers/opcua/src/test/java/org/apache/plc4x/java/opcua/protocol/OpcuaSubscriptionHandleTest.java b/plc4j/drivers/opcua/src/test/java/org/apache/plc4x/java/opcua/protocol/OpcuaSubscriptionHandleTest.java
index 5db5a9c62..07f0c06a1 100644
--- a/plc4j/drivers/opcua/src/test/java/org/apache/plc4x/java/opcua/protocol/OpcuaSubscriptionHandleTest.java
+++ b/plc4j/drivers/opcua/src/test/java/org/apache/plc4x/java/opcua/protocol/OpcuaSubscriptionHandleTest.java
@@ -24,6 +24,7 @@ import org.apache.plc4x.java.api.messages.PlcSubscriptionRequest;
import org.apache.plc4x.java.api.messages.PlcSubscriptionResponse;
import org.apache.plc4x.java.api.types.PlcResponseCode;
import org.apache.plc4x.java.opcua.OpcuaPlcDriverTest;
+import org.apache.plc4x.test.DisableOnParallelsVmFlag;
import org.eclipse.milo.examples.server.ExampleServer;
import org.junit.jupiter.api.*;
import org.slf4j.Logger;
@@ -35,22 +36,9 @@ import java.nio.file.Paths;
import static org.junit.jupiter.api.Assumptions.assumeTrue;
+@DisableOnParallelsVmFlag
public class OpcuaSubscriptionHandleTest {
- @BeforeAll
- static void setUp() {
- assumeTrue(() -> {
- String OS = System.getProperty("os.name").toLowerCase();
- if (OS.contains("nix")
- || OS.contains("nux")
- || OS.contains("aix")) {
- return false;
- }
-
- return true;
- }, "somehow opcua doesn't run properly on linux");
- }
-
private static final Logger LOGGER = LoggerFactory.getLogger(OpcuaPlcDriverTest.class);
private static ExampleServer exampleServer;
diff --git a/plc4j/utils/test-utils/pom.xml b/plc4j/utils/test-utils/pom.xml
index 47531c10e..2d8d794d8 100644
--- a/plc4j/utils/test-utils/pom.xml
+++ b/plc4j/utils/test-utils/pom.xml
@@ -79,6 +79,10 @@
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
</dependency>
+ <dependency>
+ <groupId>commons-io</groupId>
+ <artifactId>commons-io</artifactId>
+ </dependency>
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-artifact</artifactId>
diff --git a/plc4j/utils/test-utils/src/main/java/org/apache/plc4x/test/DisableOnParallelsVmFlag.java b/plc4j/utils/test-utils/src/main/java/org/apache/plc4x/test/DisableOnParallelsVmFlag.java
new file mode 100644
index 000000000..378c4ef7c
--- /dev/null
+++ b/plc4j/utils/test-utils/src/main/java/org/apache/plc4x/test/DisableOnParallelsVmFlag.java
@@ -0,0 +1,37 @@
+/*
+ * 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
+ *
+ * https://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.test;
+
+import org.junit.jupiter.api.extension.ExtendWith;
+
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+
+/**
+ * Some tests seem to only fail or block on VMs run by Parallels.
+ * Instead of trying to fix this problem, we'll try this for the
+ * time till someone finds the problem.
+ */
+@Target({ElementType.TYPE, ElementType.METHOD})
+@Retention(RetentionPolicy.RUNTIME)
+@ExtendWith(DisableOnParallelsVmFlagCondition.class)
+public @interface DisableOnParallelsVmFlag {
+}
diff --git a/plc4j/utils/test-utils/src/main/java/org/apache/plc4x/test/DisableOnParallelsVmFlagCondition.java b/plc4j/utils/test-utils/src/main/java/org/apache/plc4x/test/DisableOnParallelsVmFlagCondition.java
new file mode 100644
index 000000000..e50d7747f
--- /dev/null
+++ b/plc4j/utils/test-utils/src/main/java/org/apache/plc4x/test/DisableOnParallelsVmFlagCondition.java
@@ -0,0 +1,76 @@
+/*
+ * 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
+ *
+ * https://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.test;
+
+import org.apache.commons.io.IOUtils;
+import org.apache.commons.lang3.SystemUtils;
+import org.junit.jupiter.api.extension.ConditionEvaluationResult;
+import org.junit.jupiter.api.extension.ExecutionCondition;
+import org.junit.jupiter.api.extension.ExtensionContext;
+
+import java.io.*;
+import java.nio.charset.StandardCharsets;
+
+public class DisableOnParallelsVmFlagCondition implements ExecutionCondition {
+
+ private static final String PARALLELS_STRING = "Parallels Virtual Platform";
+ private static final boolean isParallels;
+ static {
+ boolean localIsParallels = false;
+ if(SystemUtils.IS_OS_WINDOWS) {
+ // TODO: If on Windows: Run "systeminfo /fo CSV /nh" command and check if the output contains "Parallels Virtual Platform"
+ try {
+ var processBuilder = new ProcessBuilder();
+ processBuilder.command("systeminfo", "/fo", "CSV", "/nh");
+ var process = processBuilder.start();
+ try (var reader = new BufferedReader(
+ new InputStreamReader(process.getInputStream()))) {
+ String line;
+ while ((line = reader.readLine()) != null) {
+ if(line.contains(PARALLELS_STRING)) {
+ localIsParallels = true;
+ break;
+ }
+ }
+ }
+ } catch (Exception err) {
+ // Ignore this...
+ }
+ } else if (SystemUtils.IS_OS_LINUX) {
+ // If on Linux: check /sys/devices/virtual/dmi/id/product_name contains "Parallels Virtual Platform"
+ File productNameFile = new File("/sys/devices/virtual/dmi/id/product_name");
+ try(InputStream is = new FileInputStream(productNameFile)) {
+ String content = IOUtils.toString(is, StandardCharsets.UTF_8);
+ localIsParallels = content.contains(PARALLELS_STRING);
+ } catch (IOException e) {
+ // Ignore this...
+ }
+ }
+ isParallels = localIsParallels;
+ }
+
+ @Override
+ public ConditionEvaluationResult evaluateExecutionCondition(ExtensionContext extensionContext) {
+ if(isParallels) {
+ return ConditionEvaluationResult.disabled("Parallels detected");
+ }
+ return ConditionEvaluationResult.enabled("Parallels not detected");
+ }
+
+}