-
Notifications
You must be signed in to change notification settings - Fork 388
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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.
- Loading branch information
Showing
4 changed files
with
119 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
37 changes: 37 additions & 0 deletions
37
plc4j/utils/test-utils/src/main/java/org/apache/plc4x/test/DisableOnParallelsVmFlag.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 { | ||
} |
76 changes: 76 additions & 0 deletions
76
...ils/test-utils/src/main/java/org/apache/plc4x/test/DisableOnParallelsVmFlagCondition.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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"); | ||
} | ||
|
||
} |