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 2023/10/02 12:40:02 UTC
[plc4x] 02/02: fix: Made sure the OpcuaSubscriptionHandleTest doesn't run on Docker.
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
commit a5e78c8489b7b6811737e1767e6036f61b8fb0da
Author: Christofer Dutz <cd...@apache.org>
AuthorDate: Mon Oct 2 14:39:43 2023 +0200
fix: Made sure the OpcuaSubscriptionHandleTest doesn't run on Docker.
---
.../protocol/OpcuaSubscriptionHandleTest.java | 2 +
.../org/apache/plc4x/test/DisableInDockerFlag.java | 37 ++++++++++++++++
.../plc4x/test/DisableInDockerFlagCondition.java | 50 ++++++++++++++++++++++
3 files changed, 89 insertions(+)
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 20dd30fa70..143703f569 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.DisableInDockerFlag;
import org.apache.plc4x.test.DisableOnParallelsVmFlag;
import org.eclipse.milo.examples.server.ExampleServer;
import org.junit.jupiter.api.*;
@@ -42,6 +43,7 @@ import static org.assertj.core.api.Assertions.assertThat;
// I tracked it down into the core of Milo several times now, but got lost in there.
// It's not a big issue as the GitHub runners and the Apache Jenkins still run the test.
@DisableOnParallelsVmFlag
+@DisableInDockerFlag
public class OpcuaSubscriptionHandleTest {
private static final Logger LOGGER = LoggerFactory.getLogger(OpcuaPlcDriverTest.class);
diff --git a/plc4j/utils/test-utils/src/main/java/org/apache/plc4x/test/DisableInDockerFlag.java b/plc4j/utils/test-utils/src/main/java/org/apache/plc4x/test/DisableInDockerFlag.java
new file mode 100644
index 0000000000..414a859446
--- /dev/null
+++ b/plc4j/utils/test-utils/src/main/java/org/apache/plc4x/test/DisableInDockerFlag.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 when run in Docker.
+ * 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(DisableInDockerFlagCondition.class)
+public @interface DisableInDockerFlag {
+}
diff --git a/plc4j/utils/test-utils/src/main/java/org/apache/plc4x/test/DisableInDockerFlagCondition.java b/plc4j/utils/test-utils/src/main/java/org/apache/plc4x/test/DisableInDockerFlagCondition.java
new file mode 100644
index 0000000000..a481117a11
--- /dev/null
+++ b/plc4j/utils/test-utils/src/main/java/org/apache/plc4x/test/DisableInDockerFlagCondition.java
@@ -0,0 +1,50 @@
+/*
+ * 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.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.*;
+
+public class DisableInDockerFlagCondition implements ExecutionCondition {
+
+ private static final boolean isDocker;
+ static {
+ boolean localIsDocker = false;
+ if (SystemUtils.IS_OS_LINUX) {
+ File dockerEnvFile = new File("/.dockerenv");
+ if(dockerEnvFile.exists()) {
+ localIsDocker = true;
+ }
+ }
+ isDocker = localIsDocker;
+ }
+
+ @Override
+ public ConditionEvaluationResult evaluateExecutionCondition(ExtensionContext extensionContext) {
+ if(isDocker) {
+ return ConditionEvaluationResult.disabled("Docker detected");
+ }
+ return ConditionEvaluationResult.enabled("Docker not detected");
+ }
+
+}